mirror of
https://github.com/aljazceru/ark.git
synced 2026-02-14 07:44:19 +01:00
New boarding protocol (#279)
* [domain] add reverse boarding inputs in Payment struct * [tx-builder] support reverse boarding script * [wallet] add GetTransaction * [api-spec][application] add reverse boarding support in covenantless * [config] add reverse boarding config * [api-spec] add ReverseBoardingAddress RPC * [domain][application] support empty forfeits txs in EndFinalization events * [tx-builder] optional connector output in round tx * [btc-embedded] fix getTx and taproot finalizer * whitelist ReverseBoardingAddress RPC * [test] add reverse boarding integration test * [client] support reverse boarding * [sdk] support reverse boarding * [e2e] add sleep time after faucet * [test] run using bitcoin-core RPC * [tx-builder] fix GetSweepInput * [application][tx-builder] support reverse onboarding in covenant * [cli] support reverse onboarding in covenant CLI * [test] rework integration tests * [sdk] remove onchain wallet, replace by onboarding address * remove old onboarding protocols * [sdk] Fix RegisterPayment * [e2e] add more funds to covenant ASP * [e2e] add sleeping time * several fixes * descriptor boarding * remove boarding delay from info * [sdk] implement descriptor boarding * go mod tidy * fixes and revert error msgs * move descriptor pkg to common * add replace in go.mod * [sdk] fix unit tests * rename DescriptorInput --> BoardingInput * genrest in SDK * remove boarding input from domain * remove all "reverse boarding" * rename "onboarding" ==> "boarding" * remove outdate payment unit test * use tmpfs docker volument for compose testing files * several fixes
This commit is contained in:
@@ -60,11 +60,20 @@ func (h *handler) CompletePayment(ctx context.Context, req *arkv1.CompletePaymen
|
||||
}
|
||||
|
||||
func (h *handler) CreatePayment(ctx context.Context, req *arkv1.CreatePaymentRequest) (*arkv1.CreatePaymentResponse, error) {
|
||||
vtxosKeys, err := parseInputs(req.GetInputs())
|
||||
inputs, err := parseInputs(req.GetInputs())
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
vtxosKeys := make([]domain.VtxoKey, 0, len(inputs))
|
||||
for _, input := range inputs {
|
||||
if !input.IsVtxo() {
|
||||
return nil, status.Error(codes.InvalidArgument, "only vtxos input allowed")
|
||||
}
|
||||
|
||||
vtxosKeys = append(vtxosKeys, input.VtxoKey())
|
||||
}
|
||||
|
||||
receivers, err := parseReceivers(req.GetOutputs())
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
@@ -83,37 +92,6 @@ func (h *handler) CreatePayment(ctx context.Context, req *arkv1.CreatePaymentReq
|
||||
}, 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")
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
if req.GetBoardingTx() == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "missing boarding tx id")
|
||||
}
|
||||
|
||||
tree, err := toCongestionTree(req.GetCongestionTree())
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
if err := h.svc.Onboard(ctx, req.GetBoardingTx(), tree, decodedPubKey); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &arkv1.OnboardResponse{}, nil
|
||||
}
|
||||
|
||||
func (h *handler) Ping(ctx context.Context, req *arkv1.PingRequest) (*arkv1.PingResponse, error) {
|
||||
if req.GetPaymentId() == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "missing payment id")
|
||||
@@ -193,12 +171,11 @@ func (h *handler) Ping(ctx context.Context, req *arkv1.PingRequest) (*arkv1.Ping
|
||||
}
|
||||
|
||||
func (h *handler) RegisterPayment(ctx context.Context, req *arkv1.RegisterPaymentRequest) (*arkv1.RegisterPaymentResponse, error) {
|
||||
vtxosKeys, err := parseInputs(req.GetInputs())
|
||||
inputs, err := parseInputs(req.GetInputs())
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
|
||||
id, err := h.svc.SpendVtxos(ctx, vtxosKeys)
|
||||
id, err := h.svc.SpendVtxos(ctx, inputs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -229,12 +206,23 @@ func (h *handler) ClaimPayment(ctx context.Context, req *arkv1.ClaimPaymentReque
|
||||
}
|
||||
|
||||
func (h *handler) FinalizePayment(ctx context.Context, req *arkv1.FinalizePaymentRequest) (*arkv1.FinalizePaymentResponse, error) {
|
||||
forfeitTxs, err := parseTxs(req.GetSignedForfeitTxs())
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
forfeitTxs := req.GetSignedForfeitTxs()
|
||||
roundTx := req.GetSignedRoundTx()
|
||||
|
||||
if len(forfeitTxs) <= 0 && roundTx == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "missing forfeit txs or round tx")
|
||||
}
|
||||
if err := h.svc.SignVtxos(ctx, forfeitTxs); err != nil {
|
||||
return nil, err
|
||||
|
||||
if len(forfeitTxs) > 0 {
|
||||
if err := h.svc.SignVtxos(ctx, forfeitTxs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if roundTx != "" {
|
||||
if err := h.svc.SignRoundTx(ctx, roundTx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &arkv1.FinalizePaymentResponse{}, nil
|
||||
@@ -355,12 +343,39 @@ func (h *handler) GetInfo(ctx context.Context, req *arkv1.GetInfoRequest) (*arkv
|
||||
}
|
||||
|
||||
return &arkv1.GetInfoResponse{
|
||||
Pubkey: info.PubKey,
|
||||
RoundLifetime: info.RoundLifetime,
|
||||
UnilateralExitDelay: info.UnilateralExitDelay,
|
||||
RoundInterval: info.RoundInterval,
|
||||
Network: info.Network,
|
||||
MinRelayFee: info.MinRelayFee,
|
||||
Pubkey: info.PubKey,
|
||||
RoundLifetime: info.RoundLifetime,
|
||||
UnilateralExitDelay: info.UnilateralExitDelay,
|
||||
RoundInterval: info.RoundInterval,
|
||||
Network: info.Network,
|
||||
MinRelayFee: info.MinRelayFee,
|
||||
BoardingDescriptorTemplate: info.BoardingDescriptorTemplate,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (h *handler) GetBoardingAddress(ctx context.Context, req *arkv1.GetBoardingAddressRequest) (*arkv1.GetBoardingAddressResponse, error) {
|
||||
pubkey := req.GetPubkey()
|
||||
if pubkey == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "missing pubkey")
|
||||
}
|
||||
|
||||
pubkeyBytes, err := hex.DecodeString(pubkey)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid pubkey (invalid hex)")
|
||||
}
|
||||
|
||||
userPubkey, err := secp256k1.ParsePubKey(pubkeyBytes)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, "invalid pubkey (parse error)")
|
||||
}
|
||||
|
||||
addr, err := h.svc.GetBoardingAddress(ctx, userPubkey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &arkv1.GetBoardingAddressResponse{
|
||||
Address: addr,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -548,8 +563,12 @@ func (v vtxoList) toProto(hrp string, aspKey *secp256k1.PublicKey) []*arkv1.Vtxo
|
||||
}
|
||||
list = append(list, &arkv1.Vtxo{
|
||||
Outpoint: &arkv1.Input{
|
||||
Txid: vv.Txid,
|
||||
Vout: vv.VOut,
|
||||
Input: &arkv1.Input_VtxoInput{
|
||||
VtxoInput: &arkv1.VtxoInput{
|
||||
Txid: vv.Txid,
|
||||
Vout: vv.VOut,
|
||||
},
|
||||
},
|
||||
},
|
||||
Receiver: &arkv1.Output{
|
||||
Address: addr,
|
||||
@@ -590,36 +609,3 @@ func castCongestionTree(congestionTree tree.CongestionTree) *arkv1.Tree {
|
||||
Levels: levels,
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
nodes := make([]tree.Node, 0, len(level.Nodes))
|
||||
|
||||
for _, node := range level.Nodes {
|
||||
nodes = append(nodes, tree.Node{
|
||||
Txid: node.Txid,
|
||||
Tx: node.Tx,
|
||||
ParentTxid: node.ParentTxid,
|
||||
Leaf: false,
|
||||
})
|
||||
}
|
||||
|
||||
levels = append(levels, nodes)
|
||||
}
|
||||
|
||||
for j, treeLvl := range levels {
|
||||
for i, node := range treeLvl {
|
||||
if len(levels.Children(node.Txid)) == 0 {
|
||||
levels[j][i].Leaf = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return levels, nil
|
||||
}
|
||||
|
||||
@@ -6,23 +6,11 @@ import (
|
||||
|
||||
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
|
||||
"github.com/ark-network/ark/common"
|
||||
"github.com/ark-network/ark/server/internal/core/application"
|
||||
"github.com/ark-network/ark/server/internal/core/domain"
|
||||
"github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
)
|
||||
|
||||
func parseTxs(txs []string) ([]string, error) {
|
||||
if len(txs) <= 0 {
|
||||
return nil, fmt.Errorf("missing list of forfeit txs")
|
||||
}
|
||||
// TODO abstract this ?
|
||||
// for _, tx := range txs {
|
||||
// if _, err := psetv2.NewPsetFromBase64(tx); err != nil {
|
||||
// return nil, fmt.Errorf("invalid tx format")
|
||||
// }
|
||||
// }
|
||||
return txs, nil
|
||||
}
|
||||
|
||||
func parseAddress(addr string) (string, *secp256k1.PublicKey, *secp256k1.PublicKey, error) {
|
||||
if len(addr) <= 0 {
|
||||
return "", nil, nil, fmt.Errorf("missing address")
|
||||
@@ -30,19 +18,31 @@ func parseAddress(addr string) (string, *secp256k1.PublicKey, *secp256k1.PublicK
|
||||
return common.DecodeAddress(addr)
|
||||
}
|
||||
|
||||
func parseInputs(ins []*arkv1.Input) ([]domain.VtxoKey, error) {
|
||||
func parseInputs(ins []*arkv1.Input) ([]application.Input, error) {
|
||||
if len(ins) <= 0 {
|
||||
return nil, fmt.Errorf("missing inputs")
|
||||
}
|
||||
|
||||
vtxos := make([]domain.VtxoKey, 0, len(ins))
|
||||
inputs := make([]application.Input, 0, len(ins))
|
||||
for _, input := range ins {
|
||||
vtxos = append(vtxos, domain.VtxoKey{
|
||||
Txid: input.GetTxid(),
|
||||
VOut: input.GetVout(),
|
||||
if input.GetBoardingInput() != nil {
|
||||
desc := input.GetBoardingInput().GetDescriptor_()
|
||||
inputs = append(inputs, application.Input{
|
||||
Txid: input.GetBoardingInput().GetTxid(),
|
||||
Index: input.GetBoardingInput().GetVout(),
|
||||
Descriptor: desc,
|
||||
})
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
inputs = append(inputs, application.Input{
|
||||
Txid: input.GetVtxoInput().GetTxid(),
|
||||
Index: input.GetVtxoInput().GetVout(),
|
||||
})
|
||||
}
|
||||
return vtxos, nil
|
||||
|
||||
return inputs, nil
|
||||
}
|
||||
|
||||
func parseReceivers(outs []*arkv1.Output) ([]domain.Receiver, error) {
|
||||
|
||||
@@ -145,10 +145,6 @@ func Whitelist() map[string][]bakery.Op {
|
||||
Entity: EntityArk,
|
||||
Action: "read",
|
||||
}},
|
||||
fmt.Sprintf("/%s/Onboard", arkv1.ArkService_ServiceDesc.ServiceName): {{
|
||||
Entity: EntityArk,
|
||||
Action: "write",
|
||||
}},
|
||||
fmt.Sprintf("/%s/CreatePayment", arkv1.ArkService_ServiceDesc.ServiceName): {{
|
||||
Entity: EntityArk,
|
||||
Action: "write",
|
||||
@@ -161,6 +157,10 @@ func Whitelist() map[string][]bakery.Op {
|
||||
Entity: EntityHealth,
|
||||
Action: "read",
|
||||
}},
|
||||
fmt.Sprintf("/%s/GetBoardingAddress", arkv1.ArkService_ServiceDesc.ServiceName): {{
|
||||
Entity: EntityArk,
|
||||
Action: "read",
|
||||
}},
|
||||
fmt.Sprintf("/%s/SendTreeNonces", arkv1.ArkService_ServiceDesc.ServiceName): {{
|
||||
Entity: EntityArk,
|
||||
Action: "write",
|
||||
|
||||
Reference in New Issue
Block a user