From c1dee151445d1d9700e0c623916299370868490c Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 5 Jan 2015 00:18:44 +0100 Subject: BlockManager => BlockProcessor --- eth/backend.go | 18 ++++++------- eth/wallet.go | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 eth/wallet.go (limited to 'eth') diff --git a/eth/backend.go b/eth/backend.go index bf6c91282..db8e8e029 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -52,11 +52,11 @@ type Ethereum struct { //*** SERVICES *** // State manager for processing new blocks and managing the over all states - blockManager *core.BlockManager - txPool *core.TxPool - chainManager *core.ChainManager - blockPool *BlockPool - whisper *whisper.Whisper + blockProcessor *core.BlockProcessor + txPool *core.TxPool + chainManager *core.ChainManager + blockPool *BlockPool + whisper *whisper.Whisper net *p2p.Server eventMux *event.TypeMux @@ -122,8 +122,8 @@ func New(config *Config) (*Ethereum, error) { eth.chainManager = core.NewChainManager(eth.EventMux()) eth.txPool = core.NewTxPool(eth.EventMux()) - eth.blockManager = core.NewBlockManager(eth.txPool, eth.chainManager, eth.EventMux()) - eth.chainManager.SetProcessor(eth.blockManager) + eth.blockProcessor = core.NewBlockProcessor(eth.txPool, eth.chainManager, eth.EventMux()) + eth.chainManager.SetProcessor(eth.blockProcessor) eth.whisper = whisper.New() hasBlock := eth.chainManager.HasBlock @@ -169,8 +169,8 @@ func (s *Ethereum) ChainManager() *core.ChainManager { return s.chainManager } -func (s *Ethereum) BlockManager() *core.BlockManager { - return s.blockManager +func (s *Ethereum) BlockProcessor() *core.BlockProcessor { + return s.blockProcessor } func (s *Ethereum) TxPool() *core.TxPool { diff --git a/eth/wallet.go b/eth/wallet.go new file mode 100644 index 000000000..9ec834309 --- /dev/null +++ b/eth/wallet.go @@ -0,0 +1,80 @@ +package eth + +/* +import ( + "crypto/ecdsa" + "errors" + "math/big" + + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/types" +) + +type Account struct { + w *Wallet +} + +func (self *Account) Transact(to *Account, value, gas, price *big.Int, data []byte) error { + return self.w.transact(self, to, value, gas, price, data) +} + +func (self *Account) Address() []byte { + return nil +} + +func (self *Account) PrivateKey() *ecdsa.PrivateKey { + return nil +} + +type Wallet struct{} + +func NewWallet() *Wallet { + return &Wallet{} +} + +func (self *Wallet) GetAccount(i int) *Account { +} + +func (self *Wallet) transact(from, to *Account, value, gas, price *big.Int, data []byte) error { + if from.PrivateKey() == nil { + return errors.New("accounts is not owned (no private key available)") + } + + var createsContract bool + if to == nil { + createsContract = true + } + + var msg *types.Transaction + if contractCreation { + msg = types.NewContractCreationTx(value, gas, price, data) + } else { + msg = types.NewTransactionMessage(to.Address(), value, gas, price, data) + } + + state := self.chainManager.TransState() + nonce := state.GetNonce(key.Address()) + + msg.SetNonce(nonce) + msg.SignECDSA(from.PriateKey()) + + // Do some pre processing for our "pre" events and hooks + block := self.chainManager.NewBlock(from.Address()) + coinbase := state.GetOrNewStateObject(from.Address()) + coinbase.SetGasPool(block.GasLimit()) + self.blockManager.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true) + + err := self.obj.TxPool().Add(tx) + if err != nil { + return nil, err + } + state.SetNonce(key.Address(), nonce+1) + + if contractCreation { + addr := core.AddressFromMessage(tx) + pipelogger.Infof("Contract addr %x\n", addr) + } + + return tx, nil +} +*/ -- cgit