mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 04:34:19 +01:00
[Client] Add vtxo expiration details to balance & Fix coin selection
* add expiry details in balance command * coin selection: sort vtxos by olderFirst * rename type * balance: add next expiration * add next expiration in offchain_balance json * print duration in nextExpiration * fix dust coin selection * refactor sort
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
|
||||
"github.com/urfave/cli/v2"
|
||||
@@ -16,10 +17,15 @@ type vtxo struct {
|
||||
txid string
|
||||
vout uint32
|
||||
poolTxid string
|
||||
expireAt *time.Time
|
||||
}
|
||||
|
||||
func getVtxos(
|
||||
ctx *cli.Context, client arkv1.ArkServiceClient, addr string,
|
||||
ctx *cli.Context,
|
||||
explorer Explorer,
|
||||
client arkv1.ArkServiceClient,
|
||||
addr string,
|
||||
withExpiration bool,
|
||||
) ([]vtxo, error) {
|
||||
response, err := client.ListVtxos(ctx.Context, &arkv1.ListVtxosRequest{
|
||||
Address: addr,
|
||||
@@ -38,6 +44,29 @@ func getVtxos(
|
||||
})
|
||||
}
|
||||
|
||||
if !withExpiration {
|
||||
return vtxos, nil
|
||||
}
|
||||
|
||||
redeemBranches, err := getRedeemBranches(ctx, explorer, client, vtxos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for vtxoTxid, branch := range redeemBranches {
|
||||
expiration, err := branch.ExpireAt()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i, vtxo := range vtxos {
|
||||
if vtxo.txid == vtxoTxid {
|
||||
vtxos[i].expireAt = expiration
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return vtxos, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user