@@ -35,21 +35,31 @@ type TransactionInput struct {
3535 SourceTxOutIndex uint32
3636 SequenceNumber uint32
3737 SourceTransaction * Transaction
38+ sourceOutput * TransactionOutput
3839 UnlockingScriptTemplate UnlockingScriptTemplate
3940}
4041
42+ func (i * TransactionInput ) SourceTxOutput () * TransactionOutput {
43+ if i .SourceTransaction != nil {
44+ return i .SourceTransaction .Outputs [i .SourceTxOutIndex ]
45+ }
46+ return i .sourceOutput
47+ }
48+
4149func (i * TransactionInput ) SourceTxScript () * script.Script {
42- if i .SourceTransaction == nil {
43- return nil
50+ sourceTxOut := i .SourceTxOutput ()
51+ if sourceTxOut != nil {
52+ return sourceTxOut .LockingScript
4453 }
45- return i . SourceTransaction . Outputs [ i . SourceTxOutIndex ]. LockingScript
54+ return nil
4655}
4756
4857func (i * TransactionInput ) SourceTxSatoshis () * uint64 {
49- if i .SourceTransaction == nil {
50- return nil
58+ sourceTxOut := i .SourceTxOutput ()
59+ if sourceTxOut != nil {
60+ return & sourceTxOut .Satoshis
5161 }
52- return & i . SourceTransaction . Outputs [ i . SourceTxOutIndex ]. Satoshis
62+ return nil
5363}
5464
5565// ReadFrom reads from the `io.Reader` into the `transaction.TransactionInput`.
@@ -132,7 +142,7 @@ func (i *TransactionInput) readFrom(r io.Reader, extended bool) (int64, error) {
132142 return bytesRead , errors .Wrapf (err , "script(%d): got %d bytes" , scriptLen .Length (), n )
133143 }
134144
135- i .SetSourceTxFromOutput (& TransactionOutput {
145+ i .SetSourceTxOutput (& TransactionOutput {
136146 Satoshis : binary .LittleEndian .Uint64 (prevSatoshis ),
137147 LockingScript : script .NewFromBytes (scriptBytes ),
138148 })
@@ -179,9 +189,6 @@ func (i *TransactionInput) Bytes(clear bool) []byte {
179189 return append (h , util .LittleEndianBytes (i .SequenceNumber , 4 )... )
180190}
181191
182- func (i * TransactionInput ) SetSourceTxFromOutput (txo * TransactionOutput ) {
183- prevTx := & Transaction {}
184- prevTx .Outputs = make ([]* TransactionOutput , i .SourceTxOutIndex + 1 )
185- prevTx .Outputs [i .SourceTxOutIndex ] = txo
186- i .SourceTransaction = prevTx
192+ func (i * TransactionInput ) SetSourceTxOutput (txo * TransactionOutput ) {
193+ i .sourceOutput = txo
187194}
0 commit comments