Skip to content

Commit

Permalink
improved error detection and handling for NewTransactionFromBytes
Browse files Browse the repository at this point in the history
integrated review comments
  • Loading branch information
bas-vk authored and Bas van Kervel committed Jul 29, 2015
1 parent a281df7 commit 81e2124
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
9 changes: 0 additions & 9 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,6 @@ func NewTransaction(nonce uint64, to common.Address, amount, gasLimit, gasPrice
return &Transaction{data: d}
}

func NewTransactionFromBytes(data []byte) *Transaction {
// TODO: remove this function if possible. callers would
// much better off decoding into transaction directly.
// it's not that hard.
tx := new(Transaction)
rlp.DecodeBytes(data, tx)
return tx
}

func (tx *Transaction) EncodeRLP(w io.Writer) error {
return rlp.Encode(w, &tx.data)
}
Expand Down
17 changes: 14 additions & 3 deletions xeth/xeth.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,12 @@ func (self *XEth) EthTransactionByHash(hash string) (tx *types.Transaction, blha
// some chain, this probably needs to be refactored for more expressiveness
data, _ := self.backend.ExtraDb().Get(common.FromHex(hash))
if len(data) != 0 {
tx = types.NewTransactionFromBytes(data)
dtx := new(types.Transaction)
if err := rlp.DecodeBytes(data, dtx); err != nil {
glog.V(logger.Error).Infoln(err)
return
}
tx = dtx
} else { // check pending transactions
tx = self.backend.TxPool().GetTransaction(common.HexToHash(hash))
}
Expand Down Expand Up @@ -773,8 +778,14 @@ func (self *XEth) FromNumber(str string) string {
}

func (self *XEth) PushTx(encodedTx string) (string, error) {
tx := types.NewTransactionFromBytes(common.FromHex(encodedTx))
err := self.backend.TxPool().Add(tx)
tx := new(types.Transaction)
err := rlp.DecodeBytes(common.FromHex(encodedTx), tx)
if err != nil {
glog.V(logger.Error).Infoln(err)
return "", err
}

err = self.backend.TxPool().Add(tx)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 81e2124

Please sign in to comment.