Skip to content

Commit 5bfad38

Browse files
committed
replicate changes on covenant client
1 parent 026f30b commit 5bfad38

File tree

1 file changed

+64
-22
lines changed

1 file changed

+64
-22
lines changed

pkg/client-sdk/covenant_client.go

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,39 @@ func (a *covenantArkClient) GetTransactionHistory(ctx context.Context) ([]Transa
526526
return vtxosToTxsCovenant(config.RoundLifetime, spendableVtxos, spentVtxos, boardingTxs)
527527
}
528528

529+
func (a *covenantArkClient) getAllBoardingUtxos(ctx context.Context) ([]explorer.Utxo, error) {
530+
_, boardingAddrs, _, err := a.wallet.GetAddresses(ctx)
531+
if err != nil {
532+
return nil, err
533+
}
534+
535+
utxos := []explorer.Utxo{}
536+
for _, addr := range boardingAddrs {
537+
txs, err := a.explorer.GetTxs(addr)
538+
if err != nil {
539+
continue
540+
}
541+
for _, tx := range txs {
542+
for i, vout := range tx.Vout {
543+
if vout.Address == addr {
544+
createdAt := time.Time{}
545+
if tx.Status.Confirmed {
546+
createdAt = time.Unix(tx.Status.Blocktime, 0)
547+
}
548+
utxos = append(utxos, explorer.Utxo{
549+
Txid: tx.Txid,
550+
Vout: uint32(i),
551+
Amount: vout.Amount,
552+
CreatedAt: createdAt,
553+
})
554+
}
555+
}
556+
}
557+
}
558+
559+
return utxos, nil
560+
}
561+
529562
func (a *covenantArkClient) getClaimableBoardingUtxos(ctx context.Context) ([]explorer.Utxo, error) {
530563
offchainAddrs, boardingAddrs, _, err := a.wallet.GetAddresses(ctx)
531564
if err != nil {
@@ -1389,24 +1422,37 @@ func (a *covenantArkClient) selfTransferAllPendingPayments(
13891422
return roundTxid, nil
13901423
}
13911424

1392-
func (a *covenantArkClient) getBoardingTxs(ctx context.Context) []Transaction {
1425+
func (a *covenantArkClient) getBoardingTxs(ctx context.Context) (transactions []Transaction) {
13931426
utxos, err := a.getClaimableBoardingUtxos(ctx)
13941427
if err != nil {
13951428
return nil
13961429
}
13971430

1398-
txs := make([]Transaction, 0, len(utxos))
1431+
isPending := make(map[string]bool)
13991432
for _, u := range utxos {
1400-
txs = append(txs, Transaction{
1433+
isPending[u.Txid] = true
1434+
}
1435+
1436+
allUtxos, err := a.getAllBoardingUtxos(ctx)
1437+
if err != nil {
1438+
return nil
1439+
}
1440+
1441+
for _, u := range allUtxos {
1442+
pending := false
1443+
if isPending[u.Txid] {
1444+
pending = true
1445+
}
1446+
transactions = append(transactions, Transaction{
14011447
BoardingTxid: u.Txid,
14021448
Amount: u.Amount,
14031449
Type: TxReceived,
1404-
Pending: true,
1405-
Claimed: false,
1450+
Pending: pending,
1451+
Claimed: !pending,
14061452
CreatedAt: u.CreatedAt,
14071453
})
14081454
}
1409-
return txs
1455+
return
14101456
}
14111457

14121458
func vtxosToTxsCovenant(
@@ -1426,22 +1472,18 @@ func vtxosToTxsCovenant(
14261472
for _, v := range append(spendable, spent...) {
14271473
// get vtxo amount
14281474
amount := int(v.Amount)
1429-
if v.Pending {
1430-
// find other spent vtxos that spent this one
1431-
relatedVtxos := findVtxosBySpentBy(spent, v.Txid)
1432-
for _, r := range relatedVtxos {
1433-
if r.Amount < math.MaxInt64 {
1434-
rAmount := int(r.Amount)
1435-
amount -= rAmount
1436-
}
1437-
}
1438-
} else {
1439-
// an onboarding tx has pending false and no pending true related txs
1440-
relatedVtxos := findVtxosBySpentBy(spent, v.RoundTxid)
1441-
if len(relatedVtxos) > 0 { // not an onboard tx, ignore
1442-
continue
1475+
if !v.Pending {
1476+
continue
1477+
}
1478+
// find other spent vtxos that spent this one
1479+
relatedVtxos := findVtxosBySpentBy(spent, v.Txid)
1480+
for _, r := range relatedVtxos {
1481+
if r.Amount < math.MaxInt64 {
1482+
rAmount := int(r.Amount)
1483+
amount -= rAmount
14431484
}
1444-
} // what kind of tx was this? send or receive?
1485+
}
1486+
// what kind of tx was this? send or receive?
14451487
txType := TxReceived
14461488
if amount < 0 {
14471489
txType = TxSent
@@ -1453,6 +1495,7 @@ func vtxosToTxsCovenant(
14531495
pending = true
14541496
claimed = false
14551497
}
1498+
// get redeem txid
14561499
redeemTxid := ""
14571500
if len(v.RedeemTx) > 0 {
14581501
txid, err := getRedeemTxidCovenant(v.RedeemTx)
@@ -1461,7 +1504,6 @@ func vtxosToTxsCovenant(
14611504
}
14621505
redeemTxid = txid
14631506
}
1464-
14651507
// add transaction
14661508
transactions = append(transactions, Transaction{
14671509
RoundTxid: v.RoundTxid,

0 commit comments

Comments
 (0)