mirror of
https://github.com/btcsuite/btcd.git
synced 2025-03-13 11:35:52 +01:00
Merge 518b4c8956
into bb52d7d78d
This commit is contained in:
commit
480f20af8e
4 changed files with 24 additions and 19 deletions
|
@ -61,9 +61,10 @@ type TransactionInput struct {
|
||||||
|
|
||||||
// CreateRawTransactionCmd defines the createrawtransaction JSON-RPC command.
|
// CreateRawTransactionCmd defines the createrawtransaction JSON-RPC command.
|
||||||
type CreateRawTransactionCmd struct {
|
type CreateRawTransactionCmd struct {
|
||||||
Inputs []TransactionInput
|
Inputs []TransactionInput
|
||||||
Amounts map[string]float64 `jsonrpcusage:"{\"address\":amount,...}"` // In BTC
|
Amounts map[string]float64 `jsonrpcusage:"{\"address\":amount,...}"` // In BTC
|
||||||
LockTime *int64
|
LockTime *int64
|
||||||
|
Replaceable *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCreateRawTransactionCmd returns a new instance which can be used to issue
|
// NewCreateRawTransactionCmd returns a new instance which can be used to issue
|
||||||
|
@ -72,16 +73,17 @@ type CreateRawTransactionCmd struct {
|
||||||
// Amounts are in BTC. Passing in nil and the empty slice as inputs is equivalent,
|
// Amounts are in BTC. Passing in nil and the empty slice as inputs is equivalent,
|
||||||
// both gets interpreted as the empty slice.
|
// both gets interpreted as the empty slice.
|
||||||
func NewCreateRawTransactionCmd(inputs []TransactionInput, amounts map[string]float64,
|
func NewCreateRawTransactionCmd(inputs []TransactionInput, amounts map[string]float64,
|
||||||
lockTime *int64) *CreateRawTransactionCmd {
|
lockTime *int64, replaceable *bool) *CreateRawTransactionCmd {
|
||||||
// to make sure we're serializing this to the empty list and not null, we
|
// to make sure we're serializing this to the empty list and not null, we
|
||||||
// explicitly initialize the list
|
// explicitly initialize the list
|
||||||
if inputs == nil {
|
if inputs == nil {
|
||||||
inputs = []TransactionInput{}
|
inputs = []TransactionInput{}
|
||||||
}
|
}
|
||||||
return &CreateRawTransactionCmd{
|
return &CreateRawTransactionCmd{
|
||||||
Inputs: inputs,
|
Inputs: inputs,
|
||||||
Amounts: amounts,
|
Amounts: amounts,
|
||||||
LockTime: lockTime,
|
LockTime: lockTime,
|
||||||
|
Replaceable: replaceable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ func TestChainSvrCmds(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
testID := int(1)
|
testID := int(1)
|
||||||
|
trueB := true
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
newCmd func() (interface{}, error)
|
newCmd func() (interface{}, error)
|
||||||
|
@ -54,7 +55,7 @@ func TestChainSvrCmds(t *testing.T) {
|
||||||
{Txid: "123", Vout: 1},
|
{Txid: "123", Vout: 1},
|
||||||
}
|
}
|
||||||
amounts := map[string]float64{"456": .0123}
|
amounts := map[string]float64{"456": .0123}
|
||||||
return btcjson.NewCreateRawTransactionCmd(txInputs, amounts, nil)
|
return btcjson.NewCreateRawTransactionCmd(txInputs, amounts, nil, nil)
|
||||||
},
|
},
|
||||||
marshalled: `{"jsonrpc":"1.0","method":"createrawtransaction","params":[[{"txid":"123","vout":1}],{"456":0.0123}],"id":1}`,
|
marshalled: `{"jsonrpc":"1.0","method":"createrawtransaction","params":[[{"txid":"123","vout":1}],{"456":0.0123}],"id":1}`,
|
||||||
unmarshalled: &btcjson.CreateRawTransactionCmd{
|
unmarshalled: &btcjson.CreateRawTransactionCmd{
|
||||||
|
@ -69,7 +70,7 @@ func TestChainSvrCmds(t *testing.T) {
|
||||||
},
|
},
|
||||||
staticCmd: func() interface{} {
|
staticCmd: func() interface{} {
|
||||||
amounts := map[string]float64{"456": .0123}
|
amounts := map[string]float64{"456": .0123}
|
||||||
return btcjson.NewCreateRawTransactionCmd(nil, amounts, nil)
|
return btcjson.NewCreateRawTransactionCmd(nil, amounts, nil, nil)
|
||||||
},
|
},
|
||||||
marshalled: `{"jsonrpc":"1.0","method":"createrawtransaction","params":[[],{"456":0.0123}],"id":1}`,
|
marshalled: `{"jsonrpc":"1.0","method":"createrawtransaction","params":[[],{"456":0.0123}],"id":1}`,
|
||||||
unmarshalled: &btcjson.CreateRawTransactionCmd{
|
unmarshalled: &btcjson.CreateRawTransactionCmd{
|
||||||
|
@ -81,20 +82,21 @@ func TestChainSvrCmds(t *testing.T) {
|
||||||
name: "createrawtransaction optional",
|
name: "createrawtransaction optional",
|
||||||
newCmd: func() (interface{}, error) {
|
newCmd: func() (interface{}, error) {
|
||||||
return btcjson.NewCmd("createrawtransaction", `[{"txid":"123","vout":1}]`,
|
return btcjson.NewCmd("createrawtransaction", `[{"txid":"123","vout":1}]`,
|
||||||
`{"456":0.0123}`, int64(12312333333))
|
`{"456":0.0123}`, int64(12312333333), &trueB)
|
||||||
},
|
},
|
||||||
staticCmd: func() interface{} {
|
staticCmd: func() interface{} {
|
||||||
txInputs := []btcjson.TransactionInput{
|
txInputs := []btcjson.TransactionInput{
|
||||||
{Txid: "123", Vout: 1},
|
{Txid: "123", Vout: 1},
|
||||||
}
|
}
|
||||||
amounts := map[string]float64{"456": .0123}
|
amounts := map[string]float64{"456": .0123}
|
||||||
return btcjson.NewCreateRawTransactionCmd(txInputs, amounts, btcjson.Int64(12312333333))
|
return btcjson.NewCreateRawTransactionCmd(txInputs, amounts, btcjson.Int64(12312333333), &trueB)
|
||||||
},
|
},
|
||||||
marshalled: `{"jsonrpc":"1.0","method":"createrawtransaction","params":[[{"txid":"123","vout":1}],{"456":0.0123},12312333333],"id":1}`,
|
marshalled: `{"jsonrpc":"1.0","method":"createrawtransaction","params":[[{"txid":"123","vout":1}],{"456":0.0123},12312333333,true],"id":1}`,
|
||||||
unmarshalled: &btcjson.CreateRawTransactionCmd{
|
unmarshalled: &btcjson.CreateRawTransactionCmd{
|
||||||
Inputs: []btcjson.TransactionInput{{Txid: "123", Vout: 1}},
|
Inputs: []btcjson.TransactionInput{{Txid: "123", Vout: 1}},
|
||||||
Amounts: map[string]float64{"456": .0123},
|
Amounts: map[string]float64{"456": .0123},
|
||||||
LockTime: btcjson.Int64(12312333333),
|
LockTime: btcjson.Int64(12312333333),
|
||||||
|
Replaceable: &trueB,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -292,13 +292,13 @@ func (r FutureCreateRawTransactionResult) Receive() (*wire.MsgTx, error) {
|
||||||
//
|
//
|
||||||
// See CreateRawTransaction for the blocking version and more details.
|
// See CreateRawTransaction for the blocking version and more details.
|
||||||
func (c *Client) CreateRawTransactionAsync(inputs []btcjson.TransactionInput,
|
func (c *Client) CreateRawTransactionAsync(inputs []btcjson.TransactionInput,
|
||||||
amounts map[btcutil.Address]btcutil.Amount, lockTime *int64) FutureCreateRawTransactionResult {
|
amounts map[btcutil.Address]btcutil.Amount, lockTime *int64, replaceable *bool) FutureCreateRawTransactionResult {
|
||||||
|
|
||||||
convertedAmts := make(map[string]float64, len(amounts))
|
convertedAmts := make(map[string]float64, len(amounts))
|
||||||
for addr, amount := range amounts {
|
for addr, amount := range amounts {
|
||||||
convertedAmts[addr.String()] = amount.ToBTC()
|
convertedAmts[addr.String()] = amount.ToBTC()
|
||||||
}
|
}
|
||||||
cmd := btcjson.NewCreateRawTransactionCmd(inputs, convertedAmts, lockTime)
|
cmd := btcjson.NewCreateRawTransactionCmd(inputs, convertedAmts, lockTime, replaceable)
|
||||||
return c.SendCmd(cmd)
|
return c.SendCmd(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,9 +306,9 @@ func (c *Client) CreateRawTransactionAsync(inputs []btcjson.TransactionInput,
|
||||||
// and sending to the provided addresses. If the inputs are either nil or an
|
// and sending to the provided addresses. If the inputs are either nil or an
|
||||||
// empty slice, it is interpreted as an empty slice.
|
// empty slice, it is interpreted as an empty slice.
|
||||||
func (c *Client) CreateRawTransaction(inputs []btcjson.TransactionInput,
|
func (c *Client) CreateRawTransaction(inputs []btcjson.TransactionInput,
|
||||||
amounts map[btcutil.Address]btcutil.Amount, lockTime *int64) (*wire.MsgTx, error) {
|
amounts map[btcutil.Address]btcutil.Amount, lockTime *int64, replaceable *bool) (*wire.MsgTx, error) {
|
||||||
|
|
||||||
return c.CreateRawTransactionAsync(inputs, amounts, lockTime).Receive()
|
return c.CreateRawTransactionAsync(inputs, amounts, lockTime, replaceable).Receive()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FutureSendRawTransactionResult is a future promise to deliver the result
|
// FutureSendRawTransactionResult is a future promise to deliver the result
|
||||||
|
|
|
@ -54,6 +54,7 @@ var helpDescsEnUS = map[string]string{
|
||||||
"createrawtransaction-amounts--value": "n.nnn",
|
"createrawtransaction-amounts--value": "n.nnn",
|
||||||
"createrawtransaction-amounts--desc": "The destination address as the key and the amount in BTC as the value",
|
"createrawtransaction-amounts--desc": "The destination address as the key and the amount in BTC as the value",
|
||||||
"createrawtransaction-locktime": "Locktime value; a non-zero value will also locktime-activate the inputs",
|
"createrawtransaction-locktime": "Locktime value; a non-zero value will also locktime-activate the inputs",
|
||||||
|
"createrawtransaction-replaceable": "If false, do not mark this transaction as BIP125-replaceable.",
|
||||||
"createrawtransaction--result0": "Hex-encoded bytes of the serialized transaction",
|
"createrawtransaction--result0": "Hex-encoded bytes of the serialized transaction",
|
||||||
|
|
||||||
// ScriptSig help.
|
// ScriptSig help.
|
||||||
|
|
Loading…
Add table
Reference in a new issue