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 /ethutil | |
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 'ethutil')
-rw-r--r-- | ethutil/value.go | 29 | ||||
-rw-r--r-- | ethutil/value_test.go | 13 |
2 files changed, 42 insertions, 0 deletions
diff --git a/ethutil/value.go b/ethutil/value.go index 3dd84d12d..46681ec2a 100644 --- a/ethutil/value.go +++ b/ethutil/value.go @@ -224,3 +224,32 @@ func (val *Value) Append(v interface{}) *Value { return val } + +type ValueIterator struct { + value *Value + currentValue *Value + idx int +} + +func (val *Value) NewIterator() *ValueIterator { + return &ValueIterator{value: val} +} + +func (it *ValueIterator) Next() bool { + if it.idx >= it.value.Len() { + return false + } + + it.currentValue = it.value.Get(it.idx) + it.idx++ + + return true +} + +func (it *ValueIterator) Value() *Value { + return it.currentValue +} + +func (it *ValueIterator) Idx() int { + return it.idx +} diff --git a/ethutil/value_test.go b/ethutil/value_test.go index 0e2da5328..a100f44bc 100644 --- a/ethutil/value_test.go +++ b/ethutil/value_test.go @@ -50,3 +50,16 @@ func TestValueTypes(t *testing.T) { t.Errorf("expected BigInt to return '%v', got %v", bigExp, bigInt.BigInt()) } } + +func TestIterator(t *testing.T) { + value := NewValue([]interface{}{1, 2, 3}) + it := value.NewIterator() + values := []uint64{1, 2, 3} + i := 0 + for it.Next() { + if values[i] != it.Value().Uint() { + t.Errorf("Expected %d, got %d", values[i], it.Value().Uint()) + } + i++ + } +} |