diff options
author | obscuren <geffobscura@gmail.com> | 2014-01-11 22:27:08 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-01-11 22:27:08 +0800 |
commit | 9571a512861d4a44c36d368f4baa15b2aa81c37d (patch) | |
tree | c5412a119ab885570351f42e512dd2d62d0bae61 /block_manager.go | |
parent | 8bbf879cb31e9cb28700773ed788421f9935ac36 (diff) | |
download | go-tangerine-9571a512861d4a44c36d368f4baa15b2aa81c37d.tar go-tangerine-9571a512861d4a44c36d368f4baa15b2aa81c37d.tar.gz go-tangerine-9571a512861d4a44c36d368f4baa15b2aa81c37d.tar.bz2 go-tangerine-9571a512861d4a44c36d368f4baa15b2aa81c37d.tar.lz go-tangerine-9571a512861d4a44c36d368f4baa15b2aa81c37d.tar.xz go-tangerine-9571a512861d4a44c36d368f4baa15b2aa81c37d.tar.zst go-tangerine-9571a512861d4a44c36d368f4baa15b2aa81c37d.zip |
gofmt no coding standards
Diffstat (limited to 'block_manager.go')
-rw-r--r-- | block_manager.go | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/block_manager.go b/block_manager.go index 59430dca7..968d9a139 100644 --- a/block_manager.go +++ b/block_manager.go @@ -1,90 +1,90 @@ package main import ( - "fmt" - "github.com/ethereum/ethutil-go" + "fmt" + "github.com/ethereum/ethutil-go" ) type BlockChain struct { - lastBlock *ethutil.Block + lastBlock *ethutil.Block - genesisBlock *ethutil.Block + genesisBlock *ethutil.Block } func NewBlockChain() *BlockChain { - bc := &BlockChain{} - bc.genesisBlock = ethutil.NewBlock( ethutil.Encode(ethutil.Genesis) ) + bc := &BlockChain{} + bc.genesisBlock = ethutil.NewBlock(ethutil.Encode(ethutil.Genesis)) - return bc + return bc } type BlockManager struct { - vm *Vm + vm *Vm - blockChain *BlockChain + blockChain *BlockChain } func NewBlockManager() *BlockManager { - bm := &BlockManager{vm: NewVm()} + bm := &BlockManager{vm: NewVm()} - return bm + return bm } // Process a block. func (bm *BlockManager) ProcessBlock(block *ethutil.Block) error { - // TODO Validation (Or move to other part of the application) - if err := bm.ValidateBlock(block); err != nil { - return err - } - - // Get the tx count. Used to create enough channels to 'join' the go routines - txCount := len(block.Transactions()) - // Locking channel. When it has been fully buffered this method will return - lockChan := make(chan bool, txCount) - - // Process each transaction/contract - for _, tx := range block.Transactions() { - // If there's no recipient, it's a contract - if tx.IsContract() { - go bm.ProcessContract(tx, block, lockChan) - } else { - // "finish" tx which isn't a contract - lockChan <- true - } - } - - // Wait for all Tx to finish processing - for i := 0; i < txCount; i++ { - <- lockChan - } - - return nil + // TODO Validation (Or move to other part of the application) + if err := bm.ValidateBlock(block); err != nil { + return err + } + + // Get the tx count. Used to create enough channels to 'join' the go routines + txCount := len(block.Transactions()) + // Locking channel. When it has been fully buffered this method will return + lockChan := make(chan bool, txCount) + + // Process each transaction/contract + for _, tx := range block.Transactions() { + // If there's no recipient, it's a contract + if tx.IsContract() { + go bm.ProcessContract(tx, block, lockChan) + } else { + // "finish" tx which isn't a contract + lockChan <- true + } + } + + // Wait for all Tx to finish processing + for i := 0; i < txCount; i++ { + <-lockChan + } + + return nil } func (bm *BlockManager) ValidateBlock(block *ethutil.Block) error { - return nil + return nil } func (bm *BlockManager) ProcessContract(tx *ethutil.Transaction, block *ethutil.Block, lockChan chan bool) { - // Recovering function in case the VM had any errors - defer func() { - if r := recover(); r != nil { - fmt.Println("Recovered from VM execution with err =", r) - // Let the channel know where done even though it failed (so the execution may resume normally) - lockChan <- true - } - }() - - // Process contract - bm.vm.ProcContract(tx, block, func(opType OpType) bool { - // TODO turn on once big ints are in place - //if !block.PayFee(tx.Hash(), StepFee.Uint64()) { - // return false - //} - - return true // Continue - }) - - // Broadcast we're done - lockChan <- true + // Recovering function in case the VM had any errors + defer func() { + if r := recover(); r != nil { + fmt.Println("Recovered from VM execution with err =", r) + // Let the channel know where done even though it failed (so the execution may resume normally) + lockChan <- true + } + }() + + // Process contract + bm.vm.ProcContract(tx, block, func(opType OpType) bool { + // TODO turn on once big ints are in place + //if !block.PayFee(tx.Hash(), StepFee.Uint64()) { + // return false + //} + + return true // Continue + }) + + // Broadcast we're done + lockChan <- true } |