From b2b9cc3f739bde5cbfceeb6969d10de9f1ca19fd Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Tue, 20 Feb 2018 12:01:42 +0100 Subject: [PATCH] Implement SendRawTransaction Bitcoind RPC method --- bchain/bitcoinrpc.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bchain/bitcoinrpc.go b/bchain/bitcoinrpc.go index 7459a9a8..9432cfd2 100644 --- a/bchain/bitcoinrpc.go +++ b/bchain/bitcoinrpc.go @@ -150,6 +150,18 @@ type resEstimateSmartFee struct { } `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 { ParseBlock(b []byte) (*Block, error) } @@ -396,6 +408,24 @@ func (b *BitcoinRPC) EstimateSmartFee(blocks int, conservative bool) (float64, e 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 { httpData, err := json.Marshal(req) if err != nil {