@@ -336,7 +336,12 @@ func (a *covenantlessArkClient) listenForBoardingTxs(ctx context.Context) {
336
336
for {
337
337
select {
338
338
case <- ticker .C :
339
- txsToAdd , txsToConfirm , rbfTxs , err := a .getBoardingTransactions (ctx )
339
+ _ , boardingAddrs , _ , err := a .wallet .GetAddresses (ctx )
340
+ if err != nil {
341
+ log .WithError (err ).Error ("failed to get all boarding addresses" )
342
+ continue
343
+ }
344
+ txsToAdd , txsToConfirm , rbfTxs , err := a .getBoardingTransactions (ctx , boardingAddrs )
340
345
if err != nil {
341
346
log .WithError (err ).Error ("failed to get pending transactions" )
342
347
continue
@@ -379,7 +384,7 @@ func (a *covenantlessArkClient) listenForBoardingTxs(ctx context.Context) {
379
384
}
380
385
381
386
func (a * covenantlessArkClient ) getBoardingTransactions (
382
- ctx context.Context ,
387
+ ctx context.Context , boardingAddrs []wallet. TapscriptsAddress ,
383
388
) ([]types.Transaction , []string , map [string ]types.Transaction , error ) {
384
389
oldTxs , err := a .store .TransactionStore ().GetAllTransactions (ctx )
385
390
if err != nil {
@@ -390,30 +395,54 @@ func (a *covenantlessArkClient) getBoardingTransactions(
390
395
replacements := make (map [string ]struct {}, 0 )
391
396
for _ , tx := range oldTxs {
392
397
if tx .IsBoarding () && tx .CreatedAt .IsZero () {
393
- fmt .Printf ("CHECK IF %s IS RBF\n " , tx .BoardingTxid )
394
398
isRbf , replacedBy , timestamp , err := a .explorer .IsRBFTx (tx .BoardingTxid , tx .Hex )
395
399
if err != nil {
396
400
return nil , nil , nil , err
397
401
}
398
- fmt .Println (isRbf , replacedBy , timestamp )
399
402
if isRbf {
400
403
txHex , err := a .explorer .GetTxHex (replacedBy )
401
404
if err != nil {
402
405
return nil , nil , nil , err
403
406
}
407
+ rawTx := & wire.MsgTx {}
408
+ if err := rawTx .Deserialize (strings .NewReader (txHex )); err != nil {
409
+ return nil , nil , nil , err
410
+ }
411
+ amount := uint64 (0 )
412
+ netParams := utils .ToBitcoinNetwork (a .Network )
413
+ for _ , addr := range boardingAddrs {
414
+ decoded , err := btcutil .DecodeAddress (addr .Address , & netParams )
415
+ if err != nil {
416
+ return nil , nil , nil , err
417
+ }
418
+ pkScript , err := txscript .PayToAddrScript (decoded )
419
+ if err != nil {
420
+ return nil , nil , nil , err
421
+ }
422
+ for _ , out := range rawTx .TxOut {
423
+ if bytes .Equal (out .PkScript , pkScript ) {
424
+ amount = uint64 (out .Value )
425
+ break
426
+ }
427
+ }
428
+ if amount > 0 {
429
+ break
430
+ }
431
+ }
404
432
rbfTxs [tx .BoardingTxid ] = types.Transaction {
405
433
TransactionKey : types.TransactionKey {
406
434
BoardingTxid : replacedBy ,
407
435
},
408
436
CreatedAt : time .Unix (timestamp , 0 ),
409
437
Hex : txHex ,
438
+ Amount : amount ,
410
439
}
411
440
replacements [replacedBy ] = struct {}{}
412
441
}
413
442
}
414
443
}
415
444
416
- boardingUtxos , err := a .getClaimableBoardingUtxos (ctx , nil )
445
+ boardingUtxos , err := a .getClaimableBoardingUtxos (ctx , boardingAddrs , nil )
417
446
if err != nil {
418
447
return nil , nil , nil , err
419
448
}
@@ -917,7 +946,7 @@ func (a *covenantlessArkClient) CollaborativeExit(
917
946
return "" , fmt .Errorf ("invalid onchain address" )
918
947
}
919
948
920
- offchainAddrs , _ , _ , err := a .wallet .GetAddresses (ctx )
949
+ offchainAddrs , boardingAddrs , _ , err := a .wallet .GetAddresses (ctx )
921
950
if err != nil {
922
951
return "" , err
923
952
}
@@ -951,7 +980,7 @@ func (a *covenantlessArkClient) CollaborativeExit(
951
980
}
952
981
}
953
982
954
- boardingUtxos , err := a .getClaimableBoardingUtxos (ctx , nil )
983
+ boardingUtxos , err := a .getClaimableBoardingUtxos (ctx , boardingAddrs , nil )
955
984
if err != nil {
956
985
return "" , err
957
986
}
@@ -1375,7 +1404,7 @@ func (a *covenantlessArkClient) sendOffchain(
1375
1404
sumOfReceivers += receiver .Amount ()
1376
1405
}
1377
1406
1378
- offchainAddrs , _ , _ , err := a .wallet .GetAddresses (ctx )
1407
+ offchainAddrs , boardingAddrs , _ , err := a .wallet .GetAddresses (ctx )
1379
1408
if err != nil {
1380
1409
return "" , err
1381
1410
}
@@ -1407,7 +1436,7 @@ func (a *covenantlessArkClient) sendOffchain(
1407
1436
}
1408
1437
}
1409
1438
1410
- boardingUtxos , err := a .getClaimableBoardingUtxos (ctx , nil )
1439
+ boardingUtxos , err := a .getClaimableBoardingUtxos (ctx , boardingAddrs , nil )
1411
1440
if err != nil {
1412
1441
return "" , err
1413
1442
}
@@ -2411,12 +2440,9 @@ func (a *covenantlessArkClient) getAllBoardingUtxos(ctx context.Context) ([]type
2411
2440
return utxos , ignoreVtxos , nil
2412
2441
}
2413
2442
2414
- func (a * covenantlessArkClient ) getClaimableBoardingUtxos (ctx context.Context , opts * CoinSelectOptions ) ([]types.Utxo , error ) {
2415
- _ , boardingAddrs , _ , err := a .wallet .GetAddresses (ctx )
2416
- if err != nil {
2417
- return nil , err
2418
- }
2419
-
2443
+ func (a * covenantlessArkClient ) getClaimableBoardingUtxos (
2444
+ _ context.Context , boardingAddrs []wallet.TapscriptsAddress , opts * CoinSelectOptions ,
2445
+ ) ([]types.Utxo , error ) {
2420
2446
claimable := make ([]types.Utxo , 0 )
2421
2447
for _ , addr := range boardingAddrs {
2422
2448
boardingScript , err := bitcointree .ParseVtxoScript (addr .Tapscripts )
0 commit comments