Skip to content

Commit

Permalink
[SDK] Fix tx history & Update WASM (ark-network#353)
Browse files Browse the repository at this point in the history
* bugfix on detecting pending vtxos

* bugfix: don't return on error from previous round

* bugfix on wasm browser storage

* implements listVtxos on SDK

* Bug fix

Co-authored-by: Pietralberto Mazza <[email protected]>

* bug fix

* Fixes

* revert RedeemTx check

* Fix after merge

* bug fix on wasm wrapper

* Fix static tx history (without tx feed)

* add createAt timestamp in Vtxo domain

* Fixes

* Fixes

* Polish

* Fix

* Fix

---------

Co-authored-by: Pietralberto Mazza <[email protected]>
Co-authored-by: altafan <[email protected]>
Co-authored-by: louisinger <[email protected]>
  • Loading branch information
4 people committed Oct 31, 2024
1 parent 79bb474 commit 786a69d
Show file tree
Hide file tree
Showing 28 changed files with 796 additions and 866 deletions.
4 changes: 4 additions & 0 deletions api-spec/openapi/swagger/ark/v1/service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,10 @@
},
"pubkey": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "int64"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions api-spec/protobuf/ark/v1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ message Vtxo {
string redeem_tx = 8;
uint64 amount = 9;
string pubkey = 10;
int64 created_at = 11;
}

message GetTransactionsStreamRequest {}
Expand Down
332 changes: 171 additions & 161 deletions api-spec/protobuf/gen/ark/v1/service.pb.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pkg/client-sdk/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ type Vtxo struct {
Pubkey string
Amount uint64
RoundTxid string
ExpiresAt *time.Time
ExpiresAt time.Time
CreatedAt time.Time
RedeemTx string
IsOOR bool
SpentBy string
Expand Down
8 changes: 2 additions & 6 deletions pkg/client-sdk/client/grpc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,19 @@ type vtxo struct {
}

func (v vtxo) toVtxo() client.Vtxo {
var expiresAt *time.Time
if v.GetExpireAt() > 0 {
t := time.Unix(v.GetExpireAt(), 0)
expiresAt = &t
}
return client.Vtxo{
Outpoint: client.Outpoint{
Txid: v.GetOutpoint().GetTxid(),
VOut: v.GetOutpoint().GetVout(),
},
Amount: v.GetAmount(),
RoundTxid: v.GetRoundTxid(),
ExpiresAt: expiresAt,
ExpiresAt: time.Unix(v.GetExpireAt(), 0),
IsOOR: v.GetIsOor(),
RedeemTx: v.GetRedeemTx(),
SpentBy: v.GetSpentBy(),
Pubkey: v.GetPubkey(),
CreatedAt: time.Unix(v.GetCreatedAt(), 0),
}
}

Expand Down
77 changes: 13 additions & 64 deletions pkg/client-sdk/client/rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,67 +474,8 @@ func (a *restClient) ListVtxos(
return nil, nil, err
}

spendableVtxos := make([]client.Vtxo, 0, len(resp.Payload.SpendableVtxos))
for _, v := range resp.Payload.SpendableVtxos {
var expiresAt *time.Time
if v.ExpireAt != "" && v.ExpireAt != "0" {
expAt, err := strconv.Atoi(v.ExpireAt)
if err != nil {
return nil, nil, err
}
t := time.Unix(int64(expAt), 0)
expiresAt = &t
}

amount, err := strconv.Atoi(v.Amount)
if err != nil {
return nil, nil, err
}

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,
IsOOR: v.IsOor,
RedeemTx: v.RedeemTx,
SpentBy: v.SpentBy,
Pubkey: v.Pubkey,
})
}

spentVtxos := make([]client.Vtxo, 0, len(resp.Payload.SpentVtxos))
for _, v := range resp.Payload.SpentVtxos {
var expiresAt *time.Time
if v.ExpireAt != "" && v.ExpireAt != "0" {
expAt, err := strconv.Atoi(v.ExpireAt)
if err != nil {
return nil, nil, err
}
t := time.Unix(int64(expAt), 0)
expiresAt = &t
}

amount, err := strconv.Atoi(v.Amount)
if err != nil {
return nil, nil, err
}

spentVtxos = append(spentVtxos, client.Vtxo{
Outpoint: client.Outpoint{
Txid: v.Outpoint.Txid,
VOut: uint32(v.Outpoint.Vout),
},
Amount: uint64(amount),
RoundTxid: v.RoundTxid,
ExpiresAt: expiresAt,
SpentBy: v.SpentBy,
Pubkey: v.Pubkey,
})
}
spendableVtxos := vtxosFromRest(resp.Payload.SpendableVtxos)
spentVtxos := vtxosFromRest(resp.Payload.SpentVtxos)

return spendableVtxos, spentVtxos, nil
}
Expand Down Expand Up @@ -676,14 +617,21 @@ func outpointsFromRest(restOutpoints []*models.V1Outpoint) []client.Outpoint {
func vtxosFromRest(restVtxos []*models.V1Vtxo) []client.Vtxo {
vtxos := make([]client.Vtxo, len(restVtxos))
for i, v := range restVtxos {
var expiresAt *time.Time
var expiresAt, createdAt time.Time
if v.ExpireAt != "" && v.ExpireAt != "0" {
expAt, err := strconv.Atoi(v.ExpireAt)
if err != nil {
return nil
}
t := time.Unix(int64(expAt), 0)
expiresAt = &t
expiresAt = time.Unix(int64(expAt), 0)
}

if v.CreatedAt != "" && v.CreatedAt != "0" {
creaAt, err := strconv.Atoi(v.CreatedAt)
if err != nil {
return nil
}
createdAt = time.Unix(int64(creaAt), 0)
}

amount, err := strconv.Atoi(v.Amount)
Expand All @@ -703,6 +651,7 @@ func vtxosFromRest(restVtxos []*models.V1Vtxo) []client.Vtxo {
RedeemTx: v.RedeemTx,
IsOOR: v.IsOor,
SpentBy: v.SpentBy,
CreatedAt: createdAt,
}
}
return vtxos
Expand Down
3 changes: 3 additions & 0 deletions pkg/client-sdk/client/rest/service/models/v1_vtxo.go

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

Loading

0 comments on commit 786a69d

Please sign in to comment.