diff options
author | obscuren <obscuren@obscura.com> | 2013-12-26 19:45:52 +0800 |
---|---|---|
committer | obscuren <obscuren@obscura.com> | 2013-12-26 19:45:52 +0800 |
commit | 5db3335dce766bd679c54ea44f6df08a7ff74762 (patch) | |
tree | 75614c847fdc07150351e9aa02353d8f1d23196c /block_manager.go | |
download | go-tangerine-5db3335dce766bd679c54ea44f6df08a7ff74762.tar go-tangerine-5db3335dce766bd679c54ea44f6df08a7ff74762.tar.gz go-tangerine-5db3335dce766bd679c54ea44f6df08a7ff74762.tar.bz2 go-tangerine-5db3335dce766bd679c54ea44f6df08a7ff74762.tar.lz go-tangerine-5db3335dce766bd679c54ea44f6df08a7ff74762.tar.xz go-tangerine-5db3335dce766bd679c54ea44f6df08a7ff74762.tar.zst go-tangerine-5db3335dce766bd679c54ea44f6df08a7ff74762.zip |
Initial commit
Diffstat (limited to 'block_manager.go')
-rw-r--r-- | block_manager.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/block_manager.go b/block_manager.go new file mode 100644 index 000000000..4f0ec1cdb --- /dev/null +++ b/block_manager.go @@ -0,0 +1,55 @@ + + // Blocks, blocks will have transactions. + // Transactions/contracts are updated in goroutines + // Each contract should send a message on a channel with usage statistics + // The statics can be used for fee calculation within the block update method + // Statistics{transaction, /* integers */ normal_ops, store_load, extro_balance, crypto, steps} + // The block updater will wait for all goroutines to be finished and update the block accordingly + // in one go and should use minimal IO overhead. + // The actual block updating will happen within a goroutine as well so normal operation may continue + +package main + +import ( + _"fmt" +) + +type BlockManager struct { + vm *Vm +} + +func NewBlockManager() *BlockManager { + bm := &BlockManager{vm: NewVm()} + + return bm +} + +// Process a block. +func (bm *BlockManager) ProcessBlock(block *Block) error { + txCount := len(block.transactions) + lockChan := make(chan bool, txCount) + + for _, tx := range block.transactions { + go bm.ProcessTransaction(tx, lockChan) + } + + // Wait for all Tx to finish processing + for i := 0; i < txCount; i++ { + <- lockChan + } + + return nil +} + +func (bm *BlockManager) ProcessTransaction(tx *Transaction, lockChan chan bool) { + if tx.recipient == 0x0 { + bm.vm.RunTransaction(tx, func(opType OpType) bool { + // TODO calculate fees + + return true // Continue + }) + } + + // Broadcast we're done + lockChan <- true +} |