Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi: add valueIn parameter to wire.NewTxIn. #1287

Merged
merged 1 commit into from
Jun 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, 0, nil))
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, wire.NullValueIn, []byte{})
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, wire.NullValueIn, []byte{})
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, stakeVoteSubsidy, []byte{})
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, wire.NullValueIn, []byte{})
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, wire.NullValueIn, []byte{})
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, int64(utxo.value), nil))
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, 100000000, []byte{txscript.OP_0, txscript.OP_0})
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, 100000000, nil)
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, 0, []byte{OP_0, OP_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, 0, sigScript)
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, 500, nil)
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, valueIn int64, signatureScript []byte) *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, 5000000000, sigScript)
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