diff options
author | obscuren <geffobscura@gmail.com> | 2014-03-05 17:42:51 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-03-05 17:42:51 +0800 |
commit | 92f2abdf769f52ea8e5e6d02bf326744e926f5b4 (patch) | |
tree | 234bcf5278e6804736f7392095733ef133e7fe03 /ethchain/state.go | |
parent | 5b1613d65b0c3471b80990120022b5a745ecab86 (diff) | |
download | dexon-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.tar dexon-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.tar.gz dexon-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.tar.bz2 dexon-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.tar.lz dexon-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.tar.xz dexon-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.tar.zst dexon-92f2abdf769f52ea8e5e6d02bf326744e926f5b4.zip |
Partially refactored server/txpool/block manager/block chain
The Ethereum structure now complies to a EthManager interface which is
being used by the tx pool, block manager and block chain in order to
gain access to each other. It's become simpeler.
TODO: BlockManager => StateManager
Diffstat (limited to 'ethchain/state.go')
-rw-r--r-- | ethchain/state.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/ethchain/state.go b/ethchain/state.go index e6649cf22..be25fe7b4 100644 --- a/ethchain/state.go +++ b/ethchain/state.go @@ -111,3 +111,41 @@ func (s *State) UpdateAccount(addr []byte, account *Account) { func (s *State) Cmp(other *State) bool { return s.trie.Cmp(other.trie) } + +type ObjType byte + +const ( + NilTy ObjType = iota + AccountTy + ContractTy + + UnknownTy +) + +// Returns the object stored at key and the type stored at key +// Returns nil if nothing is stored +func (s *State) Get(key []byte) (*ethutil.Value, ObjType) { + // Fetch data from the trie + data := s.trie.Get(string(key)) + // Returns the nil type, indicating nothing could be retrieved. + // Anything using this function should check for this ret val + if data == "" { + return nil, NilTy + } + + var typ ObjType + val := ethutil.NewValueFromBytes([]byte(data)) + // Check the length of the retrieved value. + // Len 2 = Account + // Len 3 = Contract + // Other = invalid for now. If other types emerge, add them here + if val.Len() == 2 { + typ = AccountTy + } else if val.Len() == 3 { + typ = ContractTy + } else { + typ = UnknownTy + } + + return val, typ +} |