Skip to content

Commit

Permalink
multi: add valueIn parameter to wire.NewTxIn.
Browse files Browse the repository at this point in the history
This adds a valueIn parameter to wire.NewTxIn and updates call sites and associated tests.
  • Loading branch information
dnldd committed Jun 14, 2018
1 parent 5386a63 commit f14dc6d
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion blockchain/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func TestTxValidationErrors(t *testing.T) {
// Create a transaction that is too large
tx := wire.NewMsgTx()
prevOut := wire.NewOutPoint(&chainhash.Hash{0x01}, 0, wire.TxTreeRegular)
tx.AddTxIn(wire.NewTxIn(prevOut, nil))
tx.AddTxIn(wire.NewTxIn(prevOut, nil, 0))
pkScript := bytes.Repeat([]byte{0x00}, wire.MaxBlockPayload)
tx.AddTxOut(wire.NewTxOut(0, pkScript))

Expand Down
10 changes: 5 additions & 5 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ func handleCreateRawTransaction(s *rpcServer, cmd interface{}, closeChan <-chan
}

prevOut := wire.NewOutPoint(txHash, input.Vout, input.Tree)
txIn := wire.NewTxIn(prevOut, []byte{})
txIn := wire.NewTxIn(prevOut, []byte{}, wire.NullValueIn)
if c.LockTime != nil && *c.LockTime != 0 {
txIn.Sequence = wire.MaxTxInSequenceNum - 1
}
Expand Down Expand Up @@ -759,7 +759,7 @@ func handleCreateRawSStx(s *rpcServer, cmd interface{}, closeChan <-chan struct{
}

prevOut := wire.NewOutPoint(txHash, input.Vout, input.Tree)
txIn := wire.NewTxIn(prevOut, []byte{})
txIn := wire.NewTxIn(prevOut, []byte{}, wire.NullValueIn)
mtx.AddTxIn(txIn)
}

Expand Down Expand Up @@ -985,7 +985,7 @@ func handleCreateRawSSGenTx(s *rpcServer, cmd interface{}, closeChan <-chan stru

stakeBaseOutPoint := wire.NewOutPoint(&chainhash.Hash{},
uint32(0xFFFFFFFF), int8(0x01))
txInStakeBase := wire.NewTxIn(stakeBaseOutPoint, []byte{})
txInStakeBase := wire.NewTxIn(stakeBaseOutPoint, []byte{}, stakeVoteSubsidy)
mtx.AddTxIn(txInStakeBase)

for _, input := range c.Inputs {
Expand All @@ -1004,7 +1004,7 @@ func handleCreateRawSSGenTx(s *rpcServer, cmd interface{}, closeChan <-chan stru
}

prevOut := wire.NewOutPoint(txHash, input.Vout, input.Tree)
txIn := wire.NewTxIn(prevOut, []byte{})
txIn := wire.NewTxIn(prevOut, []byte{}, wire.NullValueIn)
mtx.AddTxIn(txIn)
}

Expand Down Expand Up @@ -1145,7 +1145,7 @@ func handleCreateRawSSRtx(s *rpcServer, cmd interface{}, closeChan <-chan struct
}

prevOut := wire.NewOutPoint(txHash, input.Vout, input.Tree)
txIn := wire.NewTxIn(prevOut, []byte{})
txIn := wire.NewTxIn(prevOut, []byte{}, wire.NullValueIn)
mtx.AddTxIn(txIn)
}

Expand Down
2 changes: 1 addition & 1 deletion rpctest/memwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func (m *memWallet) fundTx(tx *wire.MsgTx, amt dcrutil.Amount, feeRate dcrutil.A
// Add the selected output to the transaction, updating the
// current tx size while accounting for the size of the future
// sigScript.
tx.AddTxIn(wire.NewTxIn(&outPoint, nil))
tx.AddTxIn(wire.NewTxIn(&outPoint, nil, int64(utxo.value)))
txSize = tx.SerializeSize() + spendSize*len(tx.TxIn)

// Calculate the fee required for the txn at this point
Expand Down
4 changes: 2 additions & 2 deletions txscript/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func ExampleSignTxOutput() {
// contains a single output that pays to address in the amount of 1 DCR.
originTx := wire.NewMsgTx()
prevOut := wire.NewOutPoint(&chainhash.Hash{}, ^uint32(0), wire.TxTreeRegular)
txIn := wire.NewTxIn(prevOut, []byte{txscript.OP_0, txscript.OP_0})
txIn := wire.NewTxIn(prevOut, []byte{txscript.OP_0, txscript.OP_0}, 100000000)
originTx.AddTxIn(txIn)
pkScript, err := txscript.PayToAddrScript(addr)
if err != nil {
Expand All @@ -122,7 +122,7 @@ func ExampleSignTxOutput() {
// signature script at this point since it hasn't been created or signed
// yet, hence nil is provided for it.
prevOut = wire.NewOutPoint(&originTxHash, 0, wire.TxTreeRegular)
txIn = wire.NewTxIn(prevOut, nil)
txIn = wire.NewTxIn(prevOut, nil, 100000000)
redeemTx.AddTxIn(txIn)

// Ordinarily this would contain that actual destination of the funds,
Expand Down
4 changes: 2 additions & 2 deletions txscript/reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ func createSpendingTx(sigScript, pkScript []byte) *wire.MsgTx {

outPoint := wire.NewOutPoint(&chainhash.Hash{}, ^uint32(0),
wire.TxTreeRegular)
txIn := wire.NewTxIn(outPoint, []byte{OP_0, OP_0})
txIn := wire.NewTxIn(outPoint, []byte{OP_0, OP_0}, 0)
txOut := wire.NewTxOut(0, pkScript)
coinbaseTx.AddTxIn(txIn)
coinbaseTx.AddTxOut(txOut)

spendingTx := wire.NewMsgTx()
coinbaseTxHash := coinbaseTx.TxHash()
outPoint = wire.NewOutPoint(&coinbaseTxHash, 0, wire.TxTreeRegular)
txIn = wire.NewTxIn(outPoint, sigScript)
txIn = wire.NewTxIn(outPoint, sigScript, 0)
txOut = wire.NewTxOut(0, nil)

spendingTx.AddTxIn(txIn)
Expand Down
2 changes: 1 addition & 1 deletion txscript/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2259,7 +2259,7 @@ nexttest:
tx.AddTxOut(output)

for range sigScriptTests[i].inputs {
txin := wire.NewTxIn(coinbaseOutPoint, nil)
txin := wire.NewTxIn(coinbaseOutPoint, nil, 500)
tx.AddTxIn(txin)
}

Expand Down
4 changes: 2 additions & 2 deletions wire/msgtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,12 @@ func (t *TxIn) SerializeSizeWitness() int {
// NewTxIn returns a new Decred transaction input with the provided
// previous outpoint point and signature script with a default sequence of
// MaxTxInSequenceNum.
func NewTxIn(prevOut *OutPoint, signatureScript []byte) *TxIn {
func NewTxIn(prevOut *OutPoint, signatureScript []byte, valueIn int64) *TxIn {
return &TxIn{
PreviousOutPoint: *prevOut,
Sequence: MaxTxInSequenceNum,
SignatureScript: signatureScript,
ValueIn: NullValueIn,
ValueIn: valueIn,
BlockHeight: NullBlockHeight,
BlockIndex: NullBlockIndex,
}
Expand Down
4 changes: 2 additions & 2 deletions wire/msgtx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestTx(t *testing.T) {

// Ensure we get the same transaction input back out.
sigScript := []byte{0x04, 0x31, 0xdc, 0x00, 0x1b, 0x01, 0x62}
txIn := NewTxIn(prevOut, sigScript)
txIn := NewTxIn(prevOut, sigScript, 5000000000)
if !reflect.DeepEqual(&txIn.PreviousOutPoint, prevOut) {
t.Errorf("NewTxIn: wrong prev outpoint - got %v, want %v",
spew.Sprint(&txIn.PreviousOutPoint),
Expand All @@ -88,7 +88,7 @@ func TestTx(t *testing.T) {
}

// Ensure we get the same transaction output back out.
txValue := int64(5000000000)
txValue := txIn.ValueIn - 1000
pkScript := []byte{
0x41, // OP_DATA_65
0x04, 0xd6, 0x4b, 0xdf, 0xd0, 0x9e, 0xb1, 0xc5,
Expand Down

0 comments on commit f14dc6d

Please sign in to comment.