mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 12:44:19 +01:00
Add TrustedOnboarding RPC (#138)
* add CreateOnboardingAddress rpc * add TrustedOnboarding rpc * remove log.Info in notifications.go
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user