diff options
author | obscuren <geffobscura@gmail.com> | 2014-02-23 08:56:48 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-02-23 08:56:48 +0800 |
commit | c66cf95b4019eeaf49db0c02cc7cb73c78098f5e (patch) | |
tree | 3a2d71c6cb493b84af463d2870a2afd4df18e049 /ethchain/block_manager.go | |
parent | 73b9ae95797ce8c38d82cfcb7c793efea268f476 (diff) | |
download | go-tangerine-c66cf95b4019eeaf49db0c02cc7cb73c78098f5e.tar go-tangerine-c66cf95b4019eeaf49db0c02cc7cb73c78098f5e.tar.gz go-tangerine-c66cf95b4019eeaf49db0c02cc7cb73c78098f5e.tar.bz2 go-tangerine-c66cf95b4019eeaf49db0c02cc7cb73c78098f5e.tar.lz go-tangerine-c66cf95b4019eeaf49db0c02cc7cb73c78098f5e.tar.xz go-tangerine-c66cf95b4019eeaf49db0c02cc7cb73c78098f5e.tar.zst go-tangerine-c66cf95b4019eeaf49db0c02cc7cb73c78098f5e.zip |
Added address states for storing a session based address
Diffstat (limited to 'ethchain/block_manager.go')
-rw-r--r-- | ethchain/block_manager.go | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/ethchain/block_manager.go b/ethchain/block_manager.go index 91bcaa468..b82e5a74a 100644 --- a/ethchain/block_manager.go +++ b/ethchain/block_manager.go @@ -5,7 +5,7 @@ import ( "encoding/hex" "fmt" "github.com/ethereum/eth-go/ethutil" - "github.com/ethereum/eth-go/ethwire" + _ "github.com/ethereum/eth-go/ethwire" "github.com/obscuren/secp256k1-go" "log" "math" @@ -19,6 +19,7 @@ type BlockProcessor interface { ProcessBlock(block *Block) } +// TODO rename to state manager type BlockManager struct { // Mutex for locking the block processor. Blocks can only be handled one at a time mutex sync.Mutex @@ -26,6 +27,10 @@ type BlockManager struct { // The block chain :) bc *BlockChain + // States for addresses. You can watch any address + // at any given time + addrStateStore *AddrStateStore + // Stack for processing contracts stack *Stack // non-persistent key/value memory storage @@ -58,11 +63,12 @@ func AddTestNetFunds(block *Block) { func NewBlockManager(speaker PublicSpeaker) *BlockManager { bm := &BlockManager{ //server: s, - bc: NewBlockChain(), - stack: NewStack(), - mem: make(map[string]*big.Int), - Pow: &EasyPow{}, - Speaker: speaker, + bc: NewBlockChain(), + stack: NewStack(), + mem: make(map[string]*big.Int), + Pow: &EasyPow{}, + Speaker: speaker, + addrStateStore: NewAddrStateStore(), } if bm.bc.CurrentBlock == nil { @@ -81,6 +87,22 @@ func NewBlockManager(speaker PublicSpeaker) *BlockManager { return bm } +// Watches any given address and puts it in the address state store +func (bm *BlockManager) WatchAddr(addr []byte) *AddressState { + account := bm.bc.CurrentBlock.GetAddr(addr) + + return bm.addrStateStore.Add(addr, account) +} + +func (bm *BlockManager) GetAddrState(addr []byte) *AddressState { + addrState := bm.addrStateStore.Get(addr) + if addrState == nil { + addrState = bm.WatchAddr(addr) + } + + return addrState +} + func (bm *BlockManager) BlockChain() *BlockChain { return bm.bc } @@ -165,7 +187,7 @@ func (bm *BlockManager) ProcessBlock(block *Block) error { */ // Broadcast the valid block back to the wire - bm.Speaker.Broadcast(ethwire.MsgBlockTy, []interface{}{block.Value().Val}) + //bm.Speaker.Broadcast(ethwire.MsgBlockTy, []interface{}{block.Value().Val}) // If there's a block processor present, pass in the block for further // processing |