Skip to content

async payment: drop unconditional forfeits txs #344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions api-spec/openapi/swagger/ark/v1/service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,6 @@
"properties": {
"signedRedeemTx": {
"type": "string"
},
"signedUnconditionalForfeitTxs": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
Expand Down Expand Up @@ -517,12 +511,6 @@
"signedRedeemTx": {
"type": "string",
"title": "signed only by the ASP"
},
"usignedUnconditionalForfeitTxs": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
Expand Down Expand Up @@ -698,12 +686,6 @@
"properties": {
"redeemTx": {
"type": "string"
},
"unconditionalForfeitTxs": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
Expand Down
3 changes: 0 additions & 3 deletions api-spec/protobuf/ark/v1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,10 @@ message CreatePaymentRequest {
}
message CreatePaymentResponse {
string signed_redeem_tx = 1; // signed only by the ASP
repeated string usigned_unconditional_forfeit_txs = 2;
}

message CompletePaymentRequest {
string signed_redeem_tx = 1;
repeated string signed_unconditional_forfeit_txs = 2;
}
message CompletePaymentResponse {}

Expand Down Expand Up @@ -319,5 +317,4 @@ message Vtxo {

message PendingPayment {
string redeem_tx = 1;
repeated string unconditional_forfeit_txs =2;
}
549 changes: 256 additions & 293 deletions api-spec/protobuf/gen/ark/v1/service.pb.go

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions pkg/client-sdk/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ type ASPClient interface {
Ping(ctx context.Context, paymentID string) (RoundEvent, error)
CreatePayment(
ctx context.Context, inputs []Input, outputs []Output,
) (string, []string, error)
) (string, error)
CompletePayment(
ctx context.Context, signedRedeemTx string, signedUnconditionalForfeitTxs []string,
ctx context.Context, signedRedeemTx string,
) error
ListVtxos(ctx context.Context, addr string) ([]Vtxo, []Vtxo, error)
GetRound(ctx context.Context, txID string) (*Round, error)
Expand Down Expand Up @@ -80,14 +80,13 @@ type Input struct {

type Vtxo struct {
Outpoint
Descriptor string
Amount uint64
RoundTxid string
ExpiresAt *time.Time
RedeemTx string
UnconditionalForfeitTxs []string
Pending bool
SpentBy string
Descriptor string
Amount uint64
RoundTxid string
ExpiresAt *time.Time
RedeemTx string
Pending bool
SpentBy string
}

type Output struct {
Expand Down
11 changes: 5 additions & 6 deletions pkg/client-sdk/client/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,24 +238,23 @@ func (a *grpcClient) Ping(

func (a *grpcClient) CreatePayment(
ctx context.Context, inputs []client.Input, outputs []client.Output,
) (string, []string, error) {
) (string, error) {
req := &arkv1.CreatePaymentRequest{
Inputs: ins(inputs).toProto(),
Outputs: outs(outputs).toProto(),
}
resp, err := a.svc.CreatePayment(ctx, req)
if err != nil {
return "", nil, err
return "", err
}
return resp.SignedRedeemTx, resp.UsignedUnconditionalForfeitTxs, nil
return resp.SignedRedeemTx, nil
}

func (a *grpcClient) CompletePayment(
ctx context.Context, redeemTx string, signedForfeitTxs []string,
ctx context.Context, redeemTx string,
) error {
req := &arkv1.CompletePaymentRequest{
SignedRedeemTx: redeemTx,
SignedUnconditionalForfeitTxs: signedForfeitTxs,
SignedRedeemTx: redeemTx,
}
_, err := a.svc.CompletePayment(ctx, req)
return err
Expand Down
17 changes: 7 additions & 10 deletions pkg/client-sdk/client/grpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,21 @@ func (v vtxo) toVtxo() client.Vtxo {
expiresAt = &t
}
var redeemTx string
var uncondForfeitTxs []string
if v.GetPendingData() != nil {
redeemTx = v.GetPendingData().GetRedeemTx()
uncondForfeitTxs = v.GetPendingData().GetUnconditionalForfeitTxs()
}
return client.Vtxo{
Outpoint: client.Outpoint{
Txid: v.GetOutpoint().GetTxid(),
VOut: v.GetOutpoint().GetVout(),
},
Amount: v.GetAmount(),
RoundTxid: v.GetRoundTxid(),
ExpiresAt: expiresAt,
Pending: v.GetPending(),
RedeemTx: redeemTx,
UnconditionalForfeitTxs: uncondForfeitTxs,
SpentBy: v.GetSpentBy(),
Descriptor: v.GetDescriptor_(),
Amount: v.GetAmount(),
RoundTxid: v.GetRoundTxid(),
ExpiresAt: expiresAt,
Pending: v.GetPending(),
RedeemTx: redeemTx,
SpentBy: v.GetSpentBy(),
Descriptor: v.GetDescriptor_(),
}
}

Expand Down
31 changes: 13 additions & 18 deletions pkg/client-sdk/client/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (a *restClient) Ping(

func (a *restClient) CreatePayment(
ctx context.Context, inputs []client.Input, outputs []client.Output,
) (string, []string, error) {
) (string, error) {
ins := make([]*models.V1Input, 0, len(inputs))
for _, i := range inputs {
ins = append(ins, &models.V1Input{
Expand All @@ -365,21 +365,19 @@ func (a *restClient) CreatePayment(
ark_service.NewArkServiceCreatePaymentParams().WithBody(&body),
)
if err != nil {
return "", nil, err
return "", err
}
return resp.GetPayload().SignedRedeemTx, resp.GetPayload().UsignedUnconditionalForfeitTxs, nil
return resp.GetPayload().SignedRedeemTx, nil
}

func (a *restClient) CompletePayment(
ctx context.Context, signedRedeemTx string, signedUncondForfeitTxs []string,
ctx context.Context, signedRedeemTx string,
) error {
req := &arkv1.CompletePaymentRequest{
SignedRedeemTx: signedRedeemTx,
SignedUnconditionalForfeitTxs: signedUncondForfeitTxs,
SignedRedeemTx: signedRedeemTx,
}
body := models.V1CompletePaymentRequest{
SignedRedeemTx: req.GetSignedRedeemTx(),
SignedUnconditionalForfeitTxs: req.GetSignedUnconditionalForfeitTxs(),
SignedRedeemTx: req.GetSignedRedeemTx(),
}
_, err := a.svc.ArkServiceCompletePayment(
ark_service.NewArkServiceCompletePaymentParams().WithBody(&body),
Expand Down Expand Up @@ -493,25 +491,22 @@ func (a *restClient) ListVtxos(
}

var redeemTx string
var uncondForfeitTxs []string
if v.PendingData != nil {
redeemTx = v.PendingData.RedeemTx
uncondForfeitTxs = v.PendingData.UnconditionalForfeitTxs
}

spendableVtxos = append(spendableVtxos, client.Vtxo{
Outpoint: client.Outpoint{
Txid: v.Outpoint.Txid,
VOut: uint32(v.Outpoint.Vout),
},
Amount: uint64(amount),
RoundTxid: v.RoundTxid,
ExpiresAt: expiresAt,
Pending: v.Pending,
RedeemTx: redeemTx,
UnconditionalForfeitTxs: uncondForfeitTxs,
SpentBy: v.SpentBy,
Descriptor: v.Descriptor,
Amount: uint64(amount),
RoundTxid: v.RoundTxid,
ExpiresAt: expiresAt,
Pending: v.Pending,
RedeemTx: redeemTx,
SpentBy: v.SpentBy,
Descriptor: v.Descriptor,
})
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 12 additions & 14 deletions pkg/client-sdk/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,12 @@ func loadFixtures(jsonStr string) (vtxos, map[string]struct{}, error) {
Txid: vtxo.Outpoint.Txid,
VOut: vtxo.Outpoint.Vout,
},
Amount: amount,
RoundTxid: vtxo.PoolTxid,
ExpiresAt: &expireAt,
RedeemTx: vtxo.PendingData.RedeemTx,
UnconditionalForfeitTxs: vtxo.PendingData.UnconditionalForfeitTxs,
Pending: vtxo.Pending,
SpentBy: vtxo.SpentBy,
Amount: amount,
RoundTxid: vtxo.PoolTxid,
ExpiresAt: &expireAt,
RedeemTx: vtxo.PendingData.RedeemTx,
Pending: vtxo.Pending,
SpentBy: vtxo.SpentBy,
}
}

Expand All @@ -221,13 +220,12 @@ func loadFixtures(jsonStr string) (vtxos, map[string]struct{}, error) {
Txid: vtxo.Outpoint.Txid,
VOut: vtxo.Outpoint.Vout,
},
Amount: amount,
RoundTxid: vtxo.PoolTxid,
ExpiresAt: &expireAt,
RedeemTx: vtxo.PendingData.RedeemTx,
UnconditionalForfeitTxs: vtxo.PendingData.UnconditionalForfeitTxs,
Pending: vtxo.Pending,
SpentBy: vtxo.SpentBy,
Amount: amount,
RoundTxid: vtxo.PoolTxid,
ExpiresAt: &expireAt,
RedeemTx: vtxo.PendingData.RedeemTx,
Pending: vtxo.Pending,
SpentBy: vtxo.SpentBy,
}
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/client-sdk/covenantless_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,7 @@ func (a *covenantlessArkClient) SendAsync(
})
}

redeemTx, unconditionalForfeitTxs, err := a.client.CreatePayment(
ctx, inputs, receiversOutput)
redeemTx, err := a.client.CreatePayment(ctx, inputs, receiversOutput)
if err != nil {
return "", err
}
Expand All @@ -667,7 +666,7 @@ func (a *covenantlessArkClient) SendAsync(
}

if err = a.client.CompletePayment(
ctx, signedRedeemTx, unconditionalForfeitTxs,
ctx, signedRedeemTx,
); err != nil {
return "", err
}
Expand Down
6 changes: 3 additions & 3 deletions server/internal/core/application/covenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,12 @@ func (s *covenantService) UpdatePaymentStatus(_ context.Context, id string) (dom
return s.lastEvent, nil
}

func (s *covenantService) CompleteAsyncPayment(ctx context.Context, redeemTx string, unconditionalForfeitTxs []string) error {
func (s *covenantService) CompleteAsyncPayment(ctx context.Context, redeemTx string) error {
return fmt.Errorf("unimplemented")
}

func (s *covenantService) CreateAsyncPayment(ctx context.Context, inputs []ports.Input, receivers []domain.Receiver) (string, []string, error) {
return "", nil, fmt.Errorf("unimplemented")
func (s *covenantService) CreateAsyncPayment(ctx context.Context, inputs []ports.Input, receivers []domain.Receiver) (string, error) {
return "", fmt.Errorf("unimplemented")
}

func (s *covenantService) SignVtxos(ctx context.Context, forfeitTxs []string) error {
Expand Down
Loading
Loading