Skip to content

Commit

Permalink
add CreateRawTransaction command
Browse files Browse the repository at this point in the history
  • Loading branch information
dydysy committed Nov 21, 2017
1 parent 16ec440 commit f40b7d3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ _testmain.go
*.test

/examples/example
.idea/
9 changes: 9 additions & 0 deletions bitcoind.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ func (b *Bitcoind) AddMultiSigAddress(cmd *AddMultisigAddressCmd) (address strin
return
}

func (b *Bitcoind) CreateRawTransaction(cmd *CreateRawTransactionCmd) (result string, err error) {
r, err := b.client.call("createrawtransaction", []interface{}{cmd.Inputs, cmd.Amounts})
if err = handleError(err, &r); err != nil {
return
}
err = json.Unmarshal(r.Result, &result)
return
}

func (b *Bitcoind) SignRawTransaction(cmd *SignRawTransactionCmd) (result SignRawTransactionResult, err error) {
r, err := b.client.call("signrawtransaction", []interface{}{cmd.RawTx, cmd.Inputs, cmd.PrivKeys, cmd.Flags})
if err = handleError(err, &r); err != nil {
Expand Down
14 changes: 14 additions & 0 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,17 @@ type SendRawTransactionCmd struct {
HexTx string
AllowHighFees *bool `jsonrpcdefault:"false"`
}

// TransactionInput represents the inputs to a transaction. Specifically a
// transaction hash and output number pair.
type TransactionInput struct {
Txid string `json:"txid"`
Vout uint32 `json:"vout"`
}

// CreateRawTransactionCmd defines the createrawtransaction JSON-RPC command.
type CreateRawTransactionCmd struct {
Inputs []TransactionInput
Amounts map[string]float64 `jsonrpcusage:"{\"address\":amount,...}"` // In BTC
LockTime *int64
}

0 comments on commit f40b7d3

Please sign in to comment.