diff options
author | obscuren <geffobscura@gmail.com> | 2014-01-09 06:43:07 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-01-09 06:43:07 +0800 |
commit | 9f42835a0204ba2508895c1d259340bcda843974 (patch) | |
tree | efc000d040803a65184e6966cbc29029fa485f58 | |
parent | 83bb4a3f265ec9a4fa75388dd6fa212a79a9b218 (diff) | |
download | dexon-9f42835a0204ba2508895c1d259340bcda843974.tar dexon-9f42835a0204ba2508895c1d259340bcda843974.tar.gz dexon-9f42835a0204ba2508895c1d259340bcda843974.tar.bz2 dexon-9f42835a0204ba2508895c1d259340bcda843974.tar.lz dexon-9f42835a0204ba2508895c1d259340bcda843974.tar.xz dexon-9f42835a0204ba2508895c1d259340bcda843974.tar.zst dexon-9f42835a0204ba2508895c1d259340bcda843974.zip |
WIP Block chain
-rw-r--r-- | block_manager.go | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/block_manager.go b/block_manager.go index 0f7a64cf8..134ca0e75 100644 --- a/block_manager.go +++ b/block_manager.go @@ -1,21 +1,26 @@ - - // 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 BlockChain struct { + lastBlock *Block + + genesisBlock *Block +} + +func NewBlockChain() *BlockChain { + bc := &BlockChain{} + bc.genesisBlock = NewBlock( Encode(Genesis) ) + + return bc +} + type BlockManager struct { vm *Vm + + blockChain *BlockChain } func NewBlockManager() *BlockManager { @@ -26,6 +31,11 @@ func NewBlockManager() *BlockManager { // Process a block. func (bm *BlockManager) ProcessBlock(block *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 @@ -50,6 +60,10 @@ func (bm *BlockManager) ProcessBlock(block *Block) error { return nil } +func (bm *BlockManager) ValidateBlock(block *Block) error { + return nil +} + func (bm *BlockManager) ProcessContract(tx *Transaction, block *Block, lockChan chan bool) { // Recovering function in case the VM had any errors defer func() { |