forked from cerc-io/plugeth
core: actually convert transaction pool
This commit is contained in:
parent
ee7202fa00
commit
17c5ba2b6b
@ -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 {
|
||||
|
@ -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)
|
||||
|
@ -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() }
|
||||
|
Loading…
Reference in New Issue
Block a user