Skip to content

Commit f2a84b0

Browse files
committed
fix list of onboarding tx
1 parent ad03d62 commit f2a84b0

File tree

1 file changed

+52
-6
lines changed

1 file changed

+52
-6
lines changed

pkg/client-sdk/covenantless_client.go

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,39 @@ func (a *covenantlessArkClient) getOffchainBalance(
15081508
return balance, amountByExpiration, nil
15091509
}
15101510

1511+
func (a *covenantlessArkClient) getAllBoardingUtxos(ctx context.Context) ([]explorer.Utxo, error) {
1512+
_, boardingAddrs, _, err := a.wallet.GetAddresses(ctx)
1513+
if err != nil {
1514+
return nil, err
1515+
}
1516+
1517+
utxos := []explorer.Utxo{}
1518+
for _, addr := range boardingAddrs {
1519+
txs, err := a.explorer.GetTxs(addr)
1520+
if err != nil {
1521+
continue
1522+
}
1523+
for _, tx := range txs {
1524+
for i, vout := range tx.Vout {
1525+
if vout.Address == addr {
1526+
createdAt := time.Time{}
1527+
if tx.Status.Confirmed {
1528+
createdAt = time.Unix(tx.Status.Blocktime, 0)
1529+
}
1530+
utxos = append(utxos, explorer.Utxo{
1531+
Txid: tx.Txid,
1532+
Vout: uint32(i),
1533+
Amount: vout.Amount,
1534+
CreatedAt: createdAt,
1535+
})
1536+
}
1537+
}
1538+
}
1539+
}
1540+
1541+
return utxos, nil
1542+
}
1543+
15111544
func (a *covenantlessArkClient) getClaimableBoardingUtxos(ctx context.Context) ([]explorer.Utxo, error) {
15121545
offchainAddrs, boardingAddrs, _, err := a.wallet.GetAddresses(ctx)
15131546
if err != nil {
@@ -1647,24 +1680,37 @@ func (a *covenantlessArkClient) selfTransferAllPendingPayments(
16471680
return roundTxid, nil
16481681
}
16491682

1650-
func (a *covenantlessArkClient) getBoardingTxs(ctx context.Context) []Transaction {
1683+
func (a *covenantlessArkClient) getBoardingTxs(ctx context.Context) (transactions []Transaction) {
16511684
utxos, err := a.getClaimableBoardingUtxos(ctx)
16521685
if err != nil {
16531686
return nil
16541687
}
16551688

1656-
txs := make([]Transaction, 0, len(utxos))
1689+
isPending := make(map[string]bool)
16571690
for _, u := range utxos {
1658-
txs = append(txs, Transaction{
1691+
isPending[u.Txid] = true
1692+
}
1693+
1694+
allUtxos, err := a.getAllBoardingUtxos(ctx)
1695+
if err != nil {
1696+
return nil
1697+
}
1698+
1699+
for _, u := range allUtxos {
1700+
pending := false
1701+
if isPending[u.Txid] {
1702+
pending = true
1703+
}
1704+
transactions = append(transactions, Transaction{
16591705
BoardingTxid: u.Txid,
16601706
Amount: u.Amount,
16611707
Type: TxReceived,
1662-
Pending: true,
1663-
Claimed: false,
1708+
Pending: pending,
1709+
Claimed: !pending,
16641710
CreatedAt: u.CreatedAt,
16651711
})
16661712
}
1667-
return txs
1713+
return
16681714
}
16691715

16701716
func findVtxosBySpentBy(allVtxos []client.Vtxo, txid string) (vtxos []client.Vtxo) {

0 commit comments

Comments
 (0)