Skip to content

Commit

Permalink
Drop unconditional forfeits txs in offline payment (ark-network#344)
Browse files Browse the repository at this point in the history
* remove unconditionnal forfeit tx

* fix sqlite vtxo repo

* remove pendingData struct

* delete uncond_forfeits_tx table
  • Loading branch information
louisinger authored Oct 4, 2024
1 parent 1d40892 commit 7606b4c
Show file tree
Hide file tree
Showing 33 changed files with 1,639 additions and 1,026 deletions.
30 changes: 2 additions & 28 deletions api-spec/openapi/swagger/ark/v1/service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,6 @@
"properties": {
"signedRedeemTx": {
"type": "string"
},
"signedUnconditionalForfeitTxs": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
Expand Down Expand Up @@ -548,12 +542,6 @@
"signedRedeemTx": {
"type": "string",
"title": "signed only by the ASP"
},
"usignedUnconditionalForfeitTxs": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
Expand Down Expand Up @@ -735,20 +723,6 @@
}
}
},
"v1PendingPayment": {
"type": "object",
"properties": {
"redeemTx": {
"type": "string"
},
"unconditionalForfeitTxs": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"v1PingResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1094,8 +1068,8 @@
"pending": {
"type": "boolean"
},
"pendingData": {
"$ref": "#/definitions/v1PendingPayment"
"redeemTx": {
"type": "string"
},
"amount": {
"type": "string",
Expand Down
8 changes: 1 addition & 7 deletions api-spec/protobuf/ark/v1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,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 @@ -318,14 +316,10 @@ message Vtxo {
int64 expire_at = 6;
bool swept = 7;
bool pending = 8;
PendingPayment pending_data = 9;
string redeem_tx = 9;
uint64 amount = 10;
}

message PendingPayment {
string redeem_tx = 1;
repeated string unconditional_forfeit_txs =2;
}

message GetTransactionsStreamRequest {}
message GetTransactionsStreamResponse {
Expand Down
841 changes: 369 additions & 472 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
21 changes: 7 additions & 14 deletions pkg/client-sdk/client/grpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,18 @@ func (v vtxo) toVtxo() client.Vtxo {
t := time.Unix(v.GetExpireAt(), 0)
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: v.GetRedeemTx(),
SpentBy: v.GetSpentBy(),
Descriptor: v.GetDescriptor_(),
}
}

Expand Down
36 changes: 13 additions & 23 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 @@ -492,26 +490,18 @@ func (a *restClient) ListVtxos(
return nil, nil, err
}

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: v.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.

Loading

0 comments on commit 7606b4c

Please sign in to comment.