Consistantly create empty bytes.Buffers.
This commit is contained in:
parent
d863c75be7
commit
99c986e21f
6 changed files with 18 additions and 18 deletions
14
account.go
14
account.go
|
@ -414,17 +414,17 @@ func (a *Account) ExportWatchingWallet() (*Account, error) {
|
|||
// exportBase64 exports an account's serialized wallet, tx, and utxo
|
||||
// stores as base64-encoded values in a map.
|
||||
func (a *Account) exportBase64() (map[string]string, error) {
|
||||
buf := &bytes.Buffer{}
|
||||
buf := bytes.Buffer{}
|
||||
m := make(map[string]string)
|
||||
|
||||
_, err := a.Wallet.WriteTo(buf)
|
||||
_, err := a.Wallet.WriteTo(&buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m["wallet"] = base64.StdEncoding.EncodeToString(buf.Bytes())
|
||||
buf.Reset()
|
||||
|
||||
if _, err = a.TxStore.WriteTo(buf); err != nil {
|
||||
if _, err = a.TxStore.WriteTo(&buf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m["tx"] = base64.StdEncoding.EncodeToString(buf.Bytes())
|
||||
|
@ -493,14 +493,14 @@ func (a *Account) RescanActiveJob() (*RescanJob, error) {
|
|||
// to send each to the chain server for relay.
|
||||
func (a *Account) ResendUnminedTxs() {
|
||||
txs := a.TxStore.UnminedDebitTxs()
|
||||
txbuf := new(bytes.Buffer)
|
||||
txBuf := bytes.Buffer{}
|
||||
for _, tx := range txs {
|
||||
if err := tx.MsgTx().Serialize(txbuf); err != nil {
|
||||
if err := tx.MsgTx().Serialize(&txBuf); err != nil {
|
||||
// Writing to a bytes.Buffer panics for OOM, and should
|
||||
// not return any other errors.
|
||||
panic(err)
|
||||
}
|
||||
hextx := hex.EncodeToString(txbuf.Bytes())
|
||||
hextx := hex.EncodeToString(txBuf.Bytes())
|
||||
txsha, err := SendRawTransaction(CurrentServerConn(), hextx)
|
||||
if err != nil {
|
||||
// TODO(jrick): Check error for if this tx is a double spend,
|
||||
|
@ -510,7 +510,7 @@ func (a *Account) ResendUnminedTxs() {
|
|||
} else {
|
||||
log.Debugf("Resent unmined transaction %v", txsha)
|
||||
}
|
||||
txbuf.Reset()
|
||||
txBuf.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -296,9 +296,9 @@ func (a *Account) txToPairs(pairs map[string]btcutil.Amount,
|
|||
}
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
buf := bytes.Buffer{}
|
||||
buf.Grow(msgtx.SerializeSize())
|
||||
if err := msgtx.BtcEncode(buf, btcwire.ProtocolVersion); err != nil {
|
||||
if err := msgtx.BtcEncode(&buf, btcwire.ProtocolVersion); err != nil {
|
||||
// Hitting OOM by growing or writing to a bytes.Buffer already
|
||||
// panics, and all returned errors are unexpected.
|
||||
panic(err)
|
||||
|
|
|
@ -1170,9 +1170,9 @@ func sendPairs(icmd btcjson.Cmd, account string, amounts map[string]btcutil.Amou
|
|||
a.ReqNewTxsForAddress(createdTx.changeAddr)
|
||||
}
|
||||
|
||||
serializedTx := bytes.NewBuffer(nil)
|
||||
serializedTx := bytes.Buffer{}
|
||||
serializedTx.Grow(createdTx.tx.MsgTx().SerializeSize())
|
||||
if err := createdTx.tx.MsgTx().Serialize(serializedTx); err != nil {
|
||||
if err := createdTx.tx.MsgTx().Serialize(&serializedTx); err != nil {
|
||||
// Hitting OOM writing to a bytes.Buffer already panics, and
|
||||
// all other errors are unexpected.
|
||||
panic(err)
|
||||
|
|
|
@ -745,8 +745,8 @@ type msgTx btcwire.MsgTx
|
|||
|
||||
func (tx *msgTx) ReadFrom(r io.Reader) (int64, error) {
|
||||
// Read from a TeeReader to return the number of read bytes.
|
||||
buf := new(bytes.Buffer)
|
||||
tr := io.TeeReader(r, buf)
|
||||
buf := bytes.Buffer{}
|
||||
tr := io.TeeReader(r, &buf)
|
||||
if err := (*btcwire.MsgTx)(tx).Deserialize(tr); err != nil {
|
||||
if buf.Len() != 0 && err == io.EOF {
|
||||
err = io.ErrUnexpectedEOF
|
||||
|
@ -762,11 +762,11 @@ func (tx *msgTx) WriteTo(w io.Writer) (int64, error) {
|
|||
// written can be returned to the caller. Writing to a to a
|
||||
// bytes.Buffer never fails except for OOM panics, so check and panic
|
||||
// on any unexpected non-nil returned errors.
|
||||
buf := new(bytes.Buffer)
|
||||
if err := (*btcwire.MsgTx)(tx).Serialize(buf); err != nil {
|
||||
buf := bytes.Buffer{}
|
||||
if err := (*btcwire.MsgTx)(tx).Serialize(&buf); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return io.Copy(w, buf)
|
||||
return io.Copy(w, &buf)
|
||||
}
|
||||
|
||||
// ReadFrom reads a mined transaction output lookup key from r. The total
|
||||
|
|
|
@ -74,7 +74,7 @@ func version() string {
|
|||
// version and build metadata strings. In particular they MUST only contain
|
||||
// characters in semanticAlphabet.
|
||||
func normalizeVerString(str string) string {
|
||||
var result bytes.Buffer
|
||||
result := bytes.Buffer{}
|
||||
for _, r := range str {
|
||||
if strings.ContainsRune(semanticAlphabet, r) {
|
||||
_, err := result.WriteRune(r)
|
||||
|
|
|
@ -96,7 +96,7 @@ func binaryRead(r io.Reader, order binary.ByteOrder, data interface{}) (n int64,
|
|||
|
||||
// See comment for binaryRead().
|
||||
func binaryWrite(w io.Writer, order binary.ByteOrder, data interface{}) (n int64, err error) {
|
||||
var buf bytes.Buffer
|
||||
buf := bytes.Buffer{}
|
||||
if err = binary.Write(&buf, order, data); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue