Skip to content

Commit 6b1a166

Browse files
committed
Fix indexer GetTxHistory api
1 parent ed52ef6 commit 6b1a166

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

server/internal/core/application/indexer.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func (i *indexerService) GetTransactionHistory(
225225
}
226226
}
227227

228-
txs, err := vtxosToTxs(spendable, spent, roundTxids)
228+
txs, err := i.vtxosToTxs(ctx, spendable, spent, roundTxids)
229229
if err != nil {
230230
return nil, err
231231
}
@@ -456,7 +456,9 @@ func flattenNodes(t [][]tree.Node) []Node {
456456
return result
457457
}
458458

459-
func vtxosToTxs(spendable, spent []domain.Vtxo, roundTxids map[string]any) ([]TxHistoryRecord, error) {
459+
func (i *indexerService) vtxosToTxs(
460+
ctx context.Context, spendable, spent []domain.Vtxo, roundTxids map[string]any,
461+
) ([]TxHistoryRecord, error) {
460462
txs := make([]TxHistoryRecord, 0)
461463

462464
// Receivals
@@ -525,10 +527,17 @@ func vtxosToTxs(spendable, spent []domain.Vtxo, roundTxids map[string]any) ([]Tx
525527
resultedAmount := reduceVtxosAmount(resultedVtxos)
526528
spentAmount := reduceVtxosAmount(vtxosBySpentBy[sb])
527529
if spentAmount <= resultedAmount {
528-
continue // settlement or change, ignore
530+
continue // settlement, ignore
529531
}
530-
531532
vtxo := getVtxo(resultedVtxos, vtxosBySpentBy[sb])
533+
if resultedAmount == 0 {
534+
// send all: fetch the created vtxo to source creation and expiration timestamps
535+
vtxos, err := i.repoManager.Vtxos().GetVtxos(ctx, []domain.VtxoKey{{Txid: sb, VOut: 0}})
536+
if err != nil {
537+
return nil, err
538+
}
539+
vtxo = vtxos[0]
540+
}
532541

533542
commitmentTxid := vtxo.RoundTxid
534543
virtualTxid := ""

0 commit comments

Comments
 (0)