aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBas van Kervel <basvankervel@gmail.com>2015-07-28 23:14:51 +0800
committerBas van Kervel <bas@ethdev.com>2015-07-29 16:30:00 +0800
commit81e2124ea20503b70fac726868e3bbefd8c02d73 (patch)
tree3098746ba76729dbf19e1e04ce7fa091054436e4
parenta281df783d32270c188d05872b8008eb0b74d042 (diff)
downloaddexon-81e2124ea20503b70fac726868e3bbefd8c02d73.tar.gz
dexon-81e2124ea20503b70fac726868e3bbefd8c02d73.tar.zst
dexon-81e2124ea20503b70fac726868e3bbefd8c02d73.zip
improved error detection and handling for NewTransactionFromBytes
integrated review comments
-rw-r--r--core/types/transaction.go9
-rw-r--r--xeth/xeth.go17
2 files changed, 14 insertions, 12 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go
index cc1793112..85b4c6119 100644
--- a/core/types/transaction.go
+++ b/core/types/transaction.go
@@ -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)
}
diff --git a/xeth/xeth.go b/xeth/xeth.go
index 63826a334..5d54c1f7e 100644
--- a/xeth/xeth.go
+++ b/xeth/xeth.go
@@ -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))
}
@@ -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
}