Add TrustedOnboarding RPC (#138)

* add CreateOnboardingAddress rpc

* add TrustedOnboarding rpc

* remove log.Info in notifications.go
This commit is contained in:
Louis Singer
2024-04-23 14:54:27 +02:00
committed by GitHub
parent 7a58d97a34
commit 740d4fb7b1
11 changed files with 760 additions and 249 deletions

View File

@@ -40,6 +40,37 @@ func NewHandler(service application.Service) arkv1.ArkServiceServer {
return h
}
func (h *handler) TrustedOnboarding(ctx context.Context, req *arkv1.TrustedOnboardingRequest) (*arkv1.TrustedOnboardingResponse, error) {
if req.GetUserPubkey() == "" {
return nil, status.Error(codes.InvalidArgument, "missing user pubkey")
}
pubKey, err := hex.DecodeString(req.GetUserPubkey())
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid user pubkey")
}
decodedPubKey, err := secp256k1.ParsePubKey(pubKey)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid user pubkey")
}
amount := req.GetAmount()
if amount <= 0 {
return nil, status.Error(codes.InvalidArgument, "invalid amount")
}
address, expectedAmount, err := h.svc.TrustedOnboarding(ctx, decodedPubKey, amount)
if err != nil {
return nil, err
}
return &arkv1.TrustedOnboardingResponse{
Address: address,
ExpectedAmount: expectedAmount,
}, nil
}
func (h *handler) Onboard(ctx context.Context, req *arkv1.OnboardRequest) (*arkv1.OnboardResponse, error) {
if req.GetUserPubkey() == "" {
return nil, status.Error(codes.InvalidArgument, "missing user pubkey")
@@ -326,6 +357,10 @@ func castCongestionTree(congestionTree tree.CongestionTree) *arkv1.Tree {
}
func toCongestionTree(treeFromProto *arkv1.Tree) (tree.CongestionTree, error) {
if treeFromProto == nil {
return nil, nil
}
levels := make(tree.CongestionTree, 0, len(treeFromProto.Levels))
for _, level := range treeFromProto.Levels {