Skip to content

Commit 70f5539

Browse files
bordalixaltafan
andcommitted
Add onboard tx to tx history
Co-authored-by: Pietralberto Mazza <[email protected]>
1 parent c82b4e5 commit 70f5539

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

pkg/client-sdk/covenant_client.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,12 @@ func (a *covenantArkClient) GetTransactionHistory(ctx context.Context) ([]Transa
521521
return nil, err
522522
}
523523

524-
return vtxosToTxsCovenant(config.RoundLifetime, spendableVtxos, spentVtxos)
524+
claimableUtxos, _ := a.getClaimableBoardingUtxos(ctx)
525+
526+
return vtxosToTxsCovenant(config.RoundLifetime, spendableVtxos, spentVtxos, claimableUtxos)
525527
}
526528

527-
func vtxosToTxsCovenant(roundLifetime int64, spendable, spent []client.Vtxo) ([]Transaction, error) {
529+
func vtxosToTxsCovenant(roundLifetime int64, spendable, spent []client.Vtxo, claimableUtxos []explorer.Utxo) ([]Transaction, error) {
528530
transactions := make([]Transaction, 0)
529531

530532
for _, v := range append(spendable, spent...) {
@@ -578,6 +580,17 @@ func vtxosToTxsCovenant(roundLifetime int64, spendable, spent []client.Vtxo) ([]
578580
})
579581
}
580582

583+
for _, u := range claimableUtxos {
584+
transactions = append(transactions, Transaction{
585+
Amount: u.Amount,
586+
BoardingTxid: u.Txid,
587+
Type: TxReceived,
588+
Pending: true,
589+
Claimed: false,
590+
CreatedAt: u.CreatedAt,
591+
})
592+
}
593+
581594
// Sort the slice by age
582595
sort.Slice(transactions, func(i, j int) bool {
583596
txi := transactions[i]

pkg/client-sdk/covenantless_client.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,10 +649,12 @@ func (a *covenantlessArkClient) GetTransactionHistory(ctx context.Context) ([]Tr
649649
xxx, _ := a.getClaimableBoardingUtxos(ctx)
650650
log.Infof("xxx %v", xxx)
651651

652-
return vtxosToTxsCovenantless(config.RoundLifetime, spendableVtxos, spentVtxos)
652+
claimableUtxos, _ := a.getClaimableBoardingUtxos(ctx)
653+
654+
return vtxosToTxsCovenantless(config.RoundLifetime, spendableVtxos, spentVtxos, claimableUtxos)
653655
}
654656

655-
func vtxosToTxsCovenantless(roundLifetime int64, spendable, spent []client.Vtxo) ([]Transaction, error) {
657+
func vtxosToTxsCovenantless(roundLifetime int64, spendable, spent []client.Vtxo, claimableUtxos []explorer.Utxo) ([]Transaction, error) {
656658
transactions := make([]Transaction, 0)
657659

658660
for _, v := range append(spendable, spent...) {
@@ -706,6 +708,17 @@ func vtxosToTxsCovenantless(roundLifetime int64, spendable, spent []client.Vtxo)
706708
})
707709
}
708710

711+
for _, u := range claimableUtxos {
712+
transactions = append(transactions, Transaction{
713+
Amount: u.Amount,
714+
BoardingTxid: u.Txid,
715+
Type: TxReceived,
716+
Pending: true,
717+
Claimed: false,
718+
CreatedAt: u.CreatedAt,
719+
})
720+
}
721+
709722
// Sort the slice by age
710723
sort.Slice(transactions, func(i, j int) bool {
711724
txi := transactions[i]

pkg/client-sdk/explorer/explorer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Utxo struct {
3131
Asset string // liquid only
3232
Delay uint
3333
SpendableAt time.Time
34+
CreatedAt time.Time
3435
}
3536

3637
func (u *Utxo) Sequence() (uint32, error) {
@@ -39,8 +40,10 @@ func (u *Utxo) Sequence() (uint32, error) {
3940

4041
func newUtxo(explorerUtxo ExplorerUtxo, delay uint) Utxo {
4142
utxoTime := explorerUtxo.Status.Blocktime
43+
createdAt := time.Unix(utxoTime, 0)
4244
if utxoTime == 0 {
43-
utxoTime = time.Now().Unix()
45+
createdAt = time.Now()
46+
utxoTime = createdAt.Unix()
4447
}
4548

4649
return Utxo{
@@ -50,6 +53,7 @@ func newUtxo(explorerUtxo ExplorerUtxo, delay uint) Utxo {
5053
Asset: explorerUtxo.Asset,
5154
Delay: delay,
5255
SpendableAt: time.Unix(utxoTime, 0).Add(time.Duration(delay) * time.Second),
56+
CreatedAt: createdAt,
5357
}
5458
}
5559

pkg/client-sdk/types.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@ const (
139139
type TxType string
140140

141141
type Transaction struct {
142-
RoundTxid string
143-
RedeemTxid string
144-
Amount uint64
145-
Type TxType
146-
Pending bool
147-
Claimed bool
148-
CreatedAt time.Time
142+
BoardingTxid string
143+
RoundTxid string
144+
RedeemTxid string
145+
Amount uint64
146+
Type TxType
147+
Pending bool
148+
Claimed bool
149+
CreatedAt time.Time
149150
}

0 commit comments

Comments
 (0)