Skip to content

Commit

Permalink
refactor(SPV-1465): add tx outputs mapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgosek-4chain committed Feb 14, 2025
1 parent 3a9a644 commit 9af6d17
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions engine/v2/transaction/txmodels/new_transaction.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package txmodels

import "github.com/samber/lo"

// TransactionInputSource represents a link between a transaction and its source transaction.
// It is used to track which transaction inputs originate from which previous transactions.
type TransactionInputSource struct {
Expand Down Expand Up @@ -37,11 +39,12 @@ func (t *NewTransaction) RawHex() string { return t.rawHex }
// SetRawHex sets the raw hexadecimal representation of the transaction.
func (t *NewTransaction) SetRawHex(hex string) {
t.rawHex = hex
t.transactionInputSources = make([]TransactionInputSource, 0, len(t.Outputs))

for _, o := range t.Outputs {
t.transactionInputSources = append(t.transactionInputSources, TransactionInputSource{TxID: t.ID, SourceTxID: o.TxID})
}
t.transactionInputSources = lo.Map(t.Outputs, func(item NewOutput, index int) TransactionInputSource {
return TransactionInputSource{
TxID: t.ID,
SourceTxID: item.TxID,
}
})
}

// SetBEEFHex sets the BEEF-encoded hexadecimal representation of the transaction.
Expand Down

0 comments on commit 9af6d17

Please sign in to comment.