From bf48a97b0df05ed74e8d2c4d5734476b1d16bc09 Mon Sep 17 00:00:00 2001 From: David Hill Date: Thu, 5 Jun 2014 13:58:28 -0400 Subject: [PATCH] Use NewReader instead of NewBuffer. NewReader is slightly faster, but more importantly, ensures that the data is read-only. --- rpcserver.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index ec9144c3..4e17ddbd 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -786,7 +786,7 @@ func handleDecodeRawTransaction(s *rpcServer, cmd btcjson.Cmd) (interface{}, err } } var mtx btcwire.MsgTx - err = mtx.Deserialize(bytes.NewBuffer(serializedTx)) + err = mtx.Deserialize(bytes.NewReader(serializedTx)) if err != nil { return nil, btcjson.Error{ Code: btcjson.ErrDeserialization.Code, @@ -1683,7 +1683,7 @@ func handleGetWorkSubmission(s *rpcServer, hexData string) (interface{}, error) // Deserialize the block header from the data. var submittedHeader btcwire.BlockHeader - bhBuf := bytes.NewBuffer(data[0:btcwire.MaxBlockHeaderPayload]) + bhBuf := bytes.NewReader(data[0:btcwire.MaxBlockHeaderPayload]) err = submittedHeader.Deserialize(bhBuf) if err != nil { return false, btcjson.Error{ @@ -1888,7 +1888,7 @@ func handleSendRawTransaction(s *rpcServer, cmd btcjson.Cmd) (interface{}, error return nil, btcjson.ErrDecodeHexString } msgtx := btcwire.NewMsgTx() - err = msgtx.Deserialize(bytes.NewBuffer(serializedTx)) + err = msgtx.Deserialize(bytes.NewReader(serializedTx)) if err != nil { err := btcjson.Error{ Code: btcjson.ErrDeserialization.Code,