@@ -526,6 +526,39 @@ func (a *covenantArkClient) GetTransactionHistory(ctx context.Context) ([]Transa
526
526
return vtxosToTxsCovenant (config .RoundLifetime , spendableVtxos , spentVtxos , boardingTxs )
527
527
}
528
528
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
+
529
562
func (a * covenantArkClient ) getClaimableBoardingUtxos (ctx context.Context ) ([]explorer.Utxo , error ) {
530
563
offchainAddrs , boardingAddrs , _ , err := a .wallet .GetAddresses (ctx )
531
564
if err != nil {
@@ -1389,24 +1422,37 @@ func (a *covenantArkClient) selfTransferAllPendingPayments(
1389
1422
return roundTxid , nil
1390
1423
}
1391
1424
1392
- func (a * covenantArkClient ) getBoardingTxs (ctx context.Context ) []Transaction {
1425
+ func (a * covenantArkClient ) getBoardingTxs (ctx context.Context ) ( transactions []Transaction ) {
1393
1426
utxos , err := a .getClaimableBoardingUtxos (ctx )
1394
1427
if err != nil {
1395
1428
return nil
1396
1429
}
1397
1430
1398
- txs := make ([] Transaction , 0 , len ( utxos ) )
1431
+ isPending := make (map [ string ] bool )
1399
1432
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 {
1401
1447
BoardingTxid : u .Txid ,
1402
1448
Amount : u .Amount ,
1403
1449
Type : TxReceived ,
1404
- Pending : true ,
1405
- Claimed : false ,
1450
+ Pending : pending ,
1451
+ Claimed : ! pending ,
1406
1452
CreatedAt : u .CreatedAt ,
1407
1453
})
1408
1454
}
1409
- return txs
1455
+ return
1410
1456
}
1411
1457
1412
1458
func vtxosToTxsCovenant (
@@ -1426,22 +1472,18 @@ func vtxosToTxsCovenant(
1426
1472
for _ , v := range append (spendable , spent ... ) {
1427
1473
// get vtxo amount
1428
1474
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
1443
1484
}
1444
- } // what kind of tx was this? send or receive?
1485
+ }
1486
+ // what kind of tx was this? send or receive?
1445
1487
txType := TxReceived
1446
1488
if amount < 0 {
1447
1489
txType = TxSent
@@ -1453,6 +1495,7 @@ func vtxosToTxsCovenant(
1453
1495
pending = true
1454
1496
claimed = false
1455
1497
}
1498
+ // get redeem txid
1456
1499
redeemTxid := ""
1457
1500
if len (v .RedeemTx ) > 0 {
1458
1501
txid , err := getRedeemTxidCovenant (v .RedeemTx )
@@ -1461,7 +1504,6 @@ func vtxosToTxsCovenant(
1461
1504
}
1462
1505
redeemTxid = txid
1463
1506
}
1464
-
1465
1507
// add transaction
1466
1508
transactions = append (transactions , Transaction {
1467
1509
RoundTxid : v .RoundTxid ,
0 commit comments