Make nil pointer handling consistent across RPCs.
There are several RPCs which accept a pointer to a hash, transaction, block, etc. Previously not all RPCs handled being passed a nil pointer consistently. Closes #4.
This commit is contained in:
parent
57738b1920
commit
9d9c343247
4 changed files with 81 additions and 36 deletions
15
chain.go
15
chain.go
|
@ -96,8 +96,13 @@ func (r FutureGetBlockResult) Receive() (*btcutil.Block, error) {
|
||||||
//
|
//
|
||||||
// See GetBlock for the blocking version and more details.
|
// See GetBlock for the blocking version and more details.
|
||||||
func (c *Client) GetBlockAsync(blockHash *btcwire.ShaHash) FutureGetBlockResult {
|
func (c *Client) GetBlockAsync(blockHash *btcwire.ShaHash) FutureGetBlockResult {
|
||||||
|
hash := ""
|
||||||
|
if blockHash != nil {
|
||||||
|
hash = blockHash.String()
|
||||||
|
}
|
||||||
|
|
||||||
id := c.NextID()
|
id := c.NextID()
|
||||||
cmd, err := btcjson.NewGetBlockCmd(id, blockHash.String(), false)
|
cmd, err := btcjson.NewGetBlockCmd(id, hash, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newFutureError(err)
|
return newFutureError(err)
|
||||||
}
|
}
|
||||||
|
@ -141,9 +146,13 @@ func (r FutureGetBlockVerboseResult) Receive() (*btcjson.BlockResult, error) {
|
||||||
//
|
//
|
||||||
// See GetBlockVerbose for the blocking version and more details.
|
// See GetBlockVerbose for the blocking version and more details.
|
||||||
func (c *Client) GetBlockVerboseAsync(blockHash *btcwire.ShaHash, verboseTx bool) FutureGetBlockVerboseResult {
|
func (c *Client) GetBlockVerboseAsync(blockHash *btcwire.ShaHash, verboseTx bool) FutureGetBlockVerboseResult {
|
||||||
|
hash := ""
|
||||||
|
if blockHash != nil {
|
||||||
|
hash = blockHash.String()
|
||||||
|
}
|
||||||
|
|
||||||
id := c.NextID()
|
id := c.NextID()
|
||||||
cmd, err := btcjson.NewGetBlockCmd(id, blockHash.String(), true,
|
cmd, err := btcjson.NewGetBlockCmd(id, hash, true, verboseTx)
|
||||||
verboseTx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newFutureError(err)
|
return newFutureError(err)
|
||||||
}
|
}
|
||||||
|
|
14
mining.go
14
mining.go
|
@ -384,13 +384,17 @@ func (r FutureSubmitBlockResult) Receive() error {
|
||||||
//
|
//
|
||||||
// See SubmitBlock for the blocking version and more details.
|
// See SubmitBlock for the blocking version and more details.
|
||||||
func (c *Client) SubmitBlockAsync(block *btcutil.Block, options *btcjson.SubmitBlockOptions) FutureSubmitBlockResult {
|
func (c *Client) SubmitBlockAsync(block *btcutil.Block, options *btcjson.SubmitBlockOptions) FutureSubmitBlockResult {
|
||||||
id := c.NextID()
|
blockHex := ""
|
||||||
blockBytes, err := block.Bytes()
|
if block != nil {
|
||||||
if err != nil {
|
blockBytes, err := block.Bytes()
|
||||||
return newFutureError(err)
|
if err != nil {
|
||||||
|
return newFutureError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
blockHex = hex.EncodeToString(blockBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
blockHex := hex.EncodeToString(blockBytes)
|
id := c.NextID()
|
||||||
cmd, err := btcjson.NewSubmitBlockCmd(id, blockHex, options)
|
cmd, err := btcjson.NewSubmitBlockCmd(id, blockHex, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newFutureError(err)
|
return newFutureError(err)
|
||||||
|
|
|
@ -95,8 +95,13 @@ func (r FutureGetRawTransactionResult) Receive() (*btcutil.Tx, error) {
|
||||||
//
|
//
|
||||||
// See GetRawTransaction for the blocking version and more details.
|
// See GetRawTransaction for the blocking version and more details.
|
||||||
func (c *Client) GetRawTransactionAsync(txHash *btcwire.ShaHash) FutureGetRawTransactionResult {
|
func (c *Client) GetRawTransactionAsync(txHash *btcwire.ShaHash) FutureGetRawTransactionResult {
|
||||||
|
hash := ""
|
||||||
|
if txHash != nil {
|
||||||
|
hash = txHash.String()
|
||||||
|
}
|
||||||
|
|
||||||
id := c.NextID()
|
id := c.NextID()
|
||||||
cmd, err := btcjson.NewGetRawTransactionCmd(id, txHash.String(), 0)
|
cmd, err := btcjson.NewGetRawTransactionCmd(id, hash, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newFutureError(err)
|
return newFutureError(err)
|
||||||
}
|
}
|
||||||
|
@ -141,8 +146,13 @@ func (r FutureGetRawTransactionVerboseResult) Receive() (*btcjson.TxRawResult, e
|
||||||
//
|
//
|
||||||
// See GetRawTransactionVerbose for the blocking version and more details.
|
// See GetRawTransactionVerbose for the blocking version and more details.
|
||||||
func (c *Client) GetRawTransactionVerboseAsync(txHash *btcwire.ShaHash) FutureGetRawTransactionVerboseResult {
|
func (c *Client) GetRawTransactionVerboseAsync(txHash *btcwire.ShaHash) FutureGetRawTransactionVerboseResult {
|
||||||
|
hash := ""
|
||||||
|
if txHash != nil {
|
||||||
|
hash = txHash.String()
|
||||||
|
}
|
||||||
|
|
||||||
id := c.NextID()
|
id := c.NextID()
|
||||||
cmd, err := btcjson.NewGetRawTransactionCmd(id, txHash.String(), 1)
|
cmd, err := btcjson.NewGetRawTransactionCmd(id, hash, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newFutureError(err)
|
return newFutureError(err)
|
||||||
}
|
}
|
||||||
|
@ -294,12 +304,15 @@ func (r FutureSendRawTransactionResult) Receive() (*btcwire.ShaHash, error) {
|
||||||
//
|
//
|
||||||
// See SendRawTransaction for the blocking version and more details.
|
// See SendRawTransaction for the blocking version and more details.
|
||||||
func (c *Client) SendRawTransactionAsync(tx *btcwire.MsgTx, allowHighFees bool) FutureSendRawTransactionResult {
|
func (c *Client) SendRawTransactionAsync(tx *btcwire.MsgTx, allowHighFees bool) FutureSendRawTransactionResult {
|
||||||
// Serialize the transaction and convert to hex string.
|
txHex := ""
|
||||||
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
if tx != nil {
|
||||||
if err := tx.Serialize(buf); err != nil {
|
// Serialize the transaction and convert to hex string.
|
||||||
return newFutureError(err)
|
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
||||||
|
if err := tx.Serialize(buf); err != nil {
|
||||||
|
return newFutureError(err)
|
||||||
|
}
|
||||||
|
txHex = hex.EncodeToString(buf.Bytes())
|
||||||
}
|
}
|
||||||
txHex := hex.EncodeToString(buf.Bytes())
|
|
||||||
|
|
||||||
id := c.NextID()
|
id := c.NextID()
|
||||||
cmd, err := btcjson.NewSendRawTransactionCmd(id, txHex, allowHighFees)
|
cmd, err := btcjson.NewSendRawTransactionCmd(id, txHex, allowHighFees)
|
||||||
|
@ -357,12 +370,15 @@ func (r FutureSignRawTransactionResult) Receive() (*btcwire.MsgTx, bool, error)
|
||||||
//
|
//
|
||||||
// See SignRawTransaction for the blocking version and more details.
|
// See SignRawTransaction for the blocking version and more details.
|
||||||
func (c *Client) SignRawTransactionAsync(tx *btcwire.MsgTx) FutureSignRawTransactionResult {
|
func (c *Client) SignRawTransactionAsync(tx *btcwire.MsgTx) FutureSignRawTransactionResult {
|
||||||
// Serialize the transaction and convert to hex string.
|
txHex := ""
|
||||||
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
if tx != nil {
|
||||||
if err := tx.Serialize(buf); err != nil {
|
// Serialize the transaction and convert to hex string.
|
||||||
return newFutureError(err)
|
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
||||||
|
if err := tx.Serialize(buf); err != nil {
|
||||||
|
return newFutureError(err)
|
||||||
|
}
|
||||||
|
txHex = hex.EncodeToString(buf.Bytes())
|
||||||
}
|
}
|
||||||
txHex := hex.EncodeToString(buf.Bytes())
|
|
||||||
|
|
||||||
id := c.NextID()
|
id := c.NextID()
|
||||||
cmd, err := btcjson.NewSignRawTransactionCmd(id, txHex)
|
cmd, err := btcjson.NewSignRawTransactionCmd(id, txHex)
|
||||||
|
@ -390,12 +406,15 @@ func (c *Client) SignRawTransaction(tx *btcwire.MsgTx) (*btcwire.MsgTx, bool, er
|
||||||
//
|
//
|
||||||
// See SignRawTransaction2 for the blocking version and more details.
|
// See SignRawTransaction2 for the blocking version and more details.
|
||||||
func (c *Client) SignRawTransaction2Async(tx *btcwire.MsgTx, inputs []btcjson.RawTxInput) FutureSignRawTransactionResult {
|
func (c *Client) SignRawTransaction2Async(tx *btcwire.MsgTx, inputs []btcjson.RawTxInput) FutureSignRawTransactionResult {
|
||||||
// Serialize the transaction and convert to hex string.
|
txHex := ""
|
||||||
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
if tx != nil {
|
||||||
if err := tx.Serialize(buf); err != nil {
|
// Serialize the transaction and convert to hex string.
|
||||||
return newFutureError(err)
|
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
||||||
|
if err := tx.Serialize(buf); err != nil {
|
||||||
|
return newFutureError(err)
|
||||||
|
}
|
||||||
|
txHex = hex.EncodeToString(buf.Bytes())
|
||||||
}
|
}
|
||||||
txHex := hex.EncodeToString(buf.Bytes())
|
|
||||||
|
|
||||||
id := c.NextID()
|
id := c.NextID()
|
||||||
cmd, err := btcjson.NewSignRawTransactionCmd(id, txHex, inputs)
|
cmd, err := btcjson.NewSignRawTransactionCmd(id, txHex, inputs)
|
||||||
|
@ -429,12 +448,15 @@ func (c *Client) SignRawTransaction3Async(tx *btcwire.MsgTx,
|
||||||
inputs []btcjson.RawTxInput,
|
inputs []btcjson.RawTxInput,
|
||||||
privKeysWIF []string) FutureSignRawTransactionResult {
|
privKeysWIF []string) FutureSignRawTransactionResult {
|
||||||
|
|
||||||
// Serialize the transaction and convert to hex string.
|
txHex := ""
|
||||||
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
if tx != nil {
|
||||||
if err := tx.Serialize(buf); err != nil {
|
// Serialize the transaction and convert to hex string.
|
||||||
return newFutureError(err)
|
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
||||||
|
if err := tx.Serialize(buf); err != nil {
|
||||||
|
return newFutureError(err)
|
||||||
|
}
|
||||||
|
txHex = hex.EncodeToString(buf.Bytes())
|
||||||
}
|
}
|
||||||
txHex := hex.EncodeToString(buf.Bytes())
|
|
||||||
|
|
||||||
id := c.NextID()
|
id := c.NextID()
|
||||||
cmd, err := btcjson.NewSignRawTransactionCmd(id, txHex, inputs,
|
cmd, err := btcjson.NewSignRawTransactionCmd(id, txHex, inputs,
|
||||||
|
@ -479,12 +501,15 @@ func (c *Client) SignRawTransaction4Async(tx *btcwire.MsgTx,
|
||||||
inputs []btcjson.RawTxInput, privKeysWIF []string,
|
inputs []btcjson.RawTxInput, privKeysWIF []string,
|
||||||
hashType SigHashType) FutureSignRawTransactionResult {
|
hashType SigHashType) FutureSignRawTransactionResult {
|
||||||
|
|
||||||
// Serialize the transaction and convert to hex string.
|
txHex := ""
|
||||||
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
if tx != nil {
|
||||||
if err := tx.Serialize(buf); err != nil {
|
// Serialize the transaction and convert to hex string.
|
||||||
return newFutureError(err)
|
buf := bytes.NewBuffer(make([]byte, 0, tx.SerializeSize()))
|
||||||
|
if err := tx.Serialize(buf); err != nil {
|
||||||
|
return newFutureError(err)
|
||||||
|
}
|
||||||
|
txHex = hex.EncodeToString(buf.Bytes())
|
||||||
}
|
}
|
||||||
txHex := hex.EncodeToString(buf.Bytes())
|
|
||||||
|
|
||||||
id := c.NextID()
|
id := c.NextID()
|
||||||
cmd, err := btcjson.NewSignRawTransactionCmd(id, txHex, inputs,
|
cmd, err := btcjson.NewSignRawTransactionCmd(id, txHex, inputs,
|
||||||
|
|
|
@ -44,8 +44,13 @@ func (r FutureGetTransactionResult) Receive() (*btcjson.GetTransactionResult, er
|
||||||
//
|
//
|
||||||
// See GetTransaction for the blocking version and more details.
|
// See GetTransaction for the blocking version and more details.
|
||||||
func (c *Client) GetTransactionAsync(txHash *btcwire.ShaHash) FutureGetTransactionResult {
|
func (c *Client) GetTransactionAsync(txHash *btcwire.ShaHash) FutureGetTransactionResult {
|
||||||
|
hash := ""
|
||||||
|
if txHash != nil {
|
||||||
|
hash = txHash.String()
|
||||||
|
}
|
||||||
|
|
||||||
id := c.NextID()
|
id := c.NextID()
|
||||||
cmd, err := btcjson.NewGetTransactionCmd(id, txHash.String())
|
cmd, err := btcjson.NewGetTransactionCmd(id, hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newFutureError(err)
|
return newFutureError(err)
|
||||||
}
|
}
|
||||||
|
@ -316,6 +321,7 @@ func (c *Client) ListSinceBlockAsync(blockHash *btcwire.ShaHash) FutureListSince
|
||||||
if blockHash != nil {
|
if blockHash != nil {
|
||||||
hash = blockHash.String()
|
hash = blockHash.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
id := c.NextID()
|
id := c.NextID()
|
||||||
cmd, err := btcjson.NewListSinceBlockCmd(id, hash)
|
cmd, err := btcjson.NewListSinceBlockCmd(id, hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -344,6 +350,7 @@ func (c *Client) ListSinceBlockMinConfAsync(blockHash *btcwire.ShaHash, minConfi
|
||||||
if blockHash != nil {
|
if blockHash != nil {
|
||||||
hash = blockHash.String()
|
hash = blockHash.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
id := c.NextID()
|
id := c.NextID()
|
||||||
cmd, err := btcjson.NewListSinceBlockCmd(id, hash, minConfirms)
|
cmd, err := btcjson.NewListSinceBlockCmd(id, hash, minConfirms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue