Implement SendRawTransaction Bitcoind RPC method
This commit is contained in:
parent
aa2d6d7816
commit
b2b9cc3f73
@ -150,6 +150,18 @@ type resEstimateSmartFee struct {
|
|||||||
} `json:"result"`
|
} `json:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sendrawtransaction
|
||||||
|
|
||||||
|
type cmdSendRawTransaction struct {
|
||||||
|
Method string `json:"method"`
|
||||||
|
Params []string `json:"params"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type resSendRawTransaction struct {
|
||||||
|
Error *RPCError `json:"error"`
|
||||||
|
Result string `json:"result"`
|
||||||
|
}
|
||||||
|
|
||||||
type BlockParser interface {
|
type BlockParser interface {
|
||||||
ParseBlock(b []byte) (*Block, error)
|
ParseBlock(b []byte) (*Block, error)
|
||||||
}
|
}
|
||||||
@ -396,6 +408,24 @@ func (b *BitcoinRPC) EstimateSmartFee(blocks int, conservative bool) (float64, e
|
|||||||
return res.Result.Feerate, nil
|
return res.Result.Feerate, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendRawTransaction sends raw transaction.
|
||||||
|
func (b *BitcoinRPC) SendRawTransaction(tx string) (string, error) {
|
||||||
|
glog.V(1).Info("rpc: sendrawtransaction")
|
||||||
|
|
||||||
|
res := resSendRawTransaction{}
|
||||||
|
req := cmdSendRawTransaction{Method: "sendrawtransaction"}
|
||||||
|
req.Params = []string{tx}
|
||||||
|
err := b.call(&req, &res)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if res.Error != nil {
|
||||||
|
return "", res.Error
|
||||||
|
}
|
||||||
|
return res.Result, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (b *BitcoinRPC) call(req interface{}, res interface{}) error {
|
func (b *BitcoinRPC) call(req interface{}, res interface{}) error {
|
||||||
httpData, err := json.Marshal(req)
|
httpData, err := json.Marshal(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user