[SDK] Fix tx history & Update WASM (#353)

* 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 <altafan@users.noreply.github.com>

* 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 <altafan@users.noreply.github.com>
Co-authored-by: altafan <18440657+altafan@users.noreply.github.com>
Co-authored-by: louisinger <louis@vulpem.com>
This commit is contained in:
João Bordalo
2024-10-31 16:56:46 +00:00
committed by altafan
parent 79bb474dd2
commit 786a69da7d
28 changed files with 801 additions and 871 deletions

View File

@@ -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
}
@@ -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)
@@ -703,6 +651,7 @@ func vtxosFromRest(restVtxos []*models.V1Vtxo) []client.Vtxo {
RedeemTx: v.RedeemTx,
IsOOR: v.IsOor,
SpentBy: v.SpentBy,
CreatedAt: createdAt,
}
}
return vtxos