aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-03-17 19:16:21 +0800
committerFelix Lange <fjl@twurst.com>2015-03-17 19:16:21 +0800
commit17c5ba2b6bfaaeab423f96523b9da13a8fb3febd (patch)
tree62d690139590a6cd7eebb95f1255a858141436f1 /core
parentee7202fa00198abaa423a1483468ca979ac9f3f4 (diff)
downloaddexon-17c5ba2b6bfaaeab423f96523b9da13a8fb3febd.tar
dexon-17c5ba2b6bfaaeab423f96523b9da13a8fb3febd.tar.gz
dexon-17c5ba2b6bfaaeab423f96523b9da13a8fb3febd.tar.bz2
dexon-17c5ba2b6bfaaeab423f96523b9da13a8fb3febd.tar.lz
dexon-17c5ba2b6bfaaeab423f96523b9da13a8fb3febd.tar.xz
dexon-17c5ba2b6bfaaeab423f96523b9da13a8fb3febd.tar.zst
dexon-17c5ba2b6bfaaeab423f96523b9da13a8fb3febd.zip
core: actually convert transaction pool
Diffstat (limited to 'core')
-rw-r--r--core/state_transition.go19
-rw-r--r--core/transaction_pool.go15
-rw-r--r--core/vm_env.go2
3 files changed, 19 insertions, 17 deletions
diff --git a/core/state_transition.go b/core/state_transition.go
index 29de501b0..72999de7e 100644
--- a/core/state_transition.go
+++ b/core/state_transition.go
@@ -5,7 +5,6 @@ import (
"math/big"
"github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/vm"
)
@@ -57,13 +56,8 @@ type Message interface {
Data() []byte
}
-func AddressFromMessage(msg Message) []byte {
- // Generate a new address
- return crypto.Sha3(common.NewValue([]interface{}{msg.From(), msg.Nonce()}).Encode())[12:]
-}
-
func MessageCreatesContract(msg Message) bool {
- return len(msg.To()) == 0
+ return msg.To() == nil
}
func MessageGasValue(msg Message) *big.Int {
@@ -93,13 +87,18 @@ func (self *StateTransition) Coinbase() *state.StateObject {
return self.state.GetOrNewStateObject(self.coinbase)
}
func (self *StateTransition) From() *state.StateObject {
- return self.state.GetOrNewStateObject(self.msg.From())
+ f, _ := self.msg.From()
+ return self.state.GetOrNewStateObject(f)
}
func (self *StateTransition) To() *state.StateObject {
- if self.msg != nil && MessageCreatesContract(self.msg) {
+ if self.msg == nil {
return nil
}
- return self.state.GetOrNewStateObject(self.msg.To())
+ to := self.msg.To()
+ if to == nil {
+ return nil // contract creation
+ }
+ return self.state.GetOrNewStateObject(*to)
}
func (self *StateTransition) UseGas(amount *big.Int) error {
diff --git a/core/transaction_pool.go b/core/transaction_pool.go
index 2efc0511c..7c50e5e53 100644
--- a/core/transaction_pool.go
+++ b/core/transaction_pool.go
@@ -91,8 +91,9 @@ func (self *TxPool) addTx(tx *types.Transaction) {
}
func (self *TxPool) add(tx *types.Transaction) error {
- if self.txs[tx.Hash()] != nil {
- return fmt.Errorf("Known transaction (%x)", tx.Hash()[0:4])
+ hash := tx.Hash()
+ if self.txs[hash] != nil {
+ return fmt.Errorf("Known transaction (%x)", hash[0:4])
}
err := self.ValidateTransaction(tx)
if err != nil {
@@ -102,7 +103,7 @@ func (self *TxPool) add(tx *types.Transaction) error {
self.addTx(tx)
var toname string
- if to, valid := tx.To(); valid {
+ if to := tx.To(); to != nil {
toname = common.Bytes2Hex(to[:4])
} else {
toname = "[NEW_CONTRACT]"
@@ -111,7 +112,7 @@ func (self *TxPool) add(tx *types.Transaction) error {
// verified in ValidateTransaction.
f, _ := tx.From()
from := common.Bytes2Hex(f[:4])
- txplogger.Debugf("(t) %x => %s (%v) %x\n", from, to, tx.Value, tx.Hash())
+ txplogger.Debugf("(t) %x => %s (%v) %x\n", from, toname, tx.Value, tx.Hash())
// Notify the subscribers
go self.eventMux.Post(TxPreEvent{tx})
@@ -137,7 +138,8 @@ func (self *TxPool) AddTransactions(txs []*types.Transaction) {
if err := self.add(tx); err != nil {
txplogger.Debugln(err)
} else {
- txplogger.Debugf("tx %x\n", tx.Hash()[0:4])
+ h := tx.Hash()
+ txplogger.Debugf("tx %x\n", h[:4])
}
}
}
@@ -161,7 +163,8 @@ func (pool *TxPool) RemoveInvalid(query StateQuery) {
var removedTxs types.Transactions
for _, tx := range pool.txs {
- sender := query.GetAccount(tx.From())
+ from, _ := tx.From()
+ sender := query.GetAccount(from[:])
err := pool.ValidateTransaction(tx)
if err != nil || sender.Nonce() >= tx.Nonce() {
removedTxs = append(removedTxs, tx)
diff --git a/core/vm_env.go b/core/vm_env.go
index fb4253f5b..1ddbd5e5e 100644
--- a/core/vm_env.go
+++ b/core/vm_env.go
@@ -28,7 +28,7 @@ func NewEnv(state *state.StateDB, chain *ChainManager, msg Message, block *types
}
}
-func (self *VMEnv) Origin() common.Address { return self.msg.From() }
+func (self *VMEnv) Origin() common.Address { f, _ := self.msg.From(); return f }
func (self *VMEnv) BlockNumber() *big.Int { return self.block.Number() }
func (self *VMEnv) Coinbase() common.Address { return self.block.Coinbase() }
func (self *VMEnv) Time() int64 { return self.block.Time() }