From be3865211c2d8f71e0733b17c469881502e89371 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 9 Nov 2016 01:20:49 +0100 Subject: core/types: remove header accessors These accessors were introduced by light client changes, but the only method that is actually used is GetNumberU64. This commit replaces all uses of .GetNumberU64 with .Number.Uint64. --- light/lightchain_test.go | 2 +- light/odr_test.go | 2 +- light/txpool.go | 14 +++++++------- light/vm_env.go | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'light') diff --git a/light/lightchain_test.go b/light/lightchain_test.go index b7668a3b5..60b909e97 100644 --- a/light/lightchain_test.go +++ b/light/lightchain_test.go @@ -134,7 +134,7 @@ func testFork(t *testing.T, LightChain *LightChain, i, n int, comparator func(td } func printChain(bc *LightChain) { - for i := bc.CurrentHeader().GetNumberU64(); i > 0; i-- { + for i := bc.CurrentHeader().Number.Uint64(); i > 0; i-- { b := bc.GetHeaderByNumber(uint64(i)) fmt.Printf("\t%x %v\n", b.Hash(), b.Difficulty) } diff --git a/light/odr_test.go b/light/odr_test.go index 1cf9bce3c..892b56e94 100644 --- a/light/odr_test.go +++ b/light/odr_test.go @@ -295,7 +295,7 @@ func testChainOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) { } test := func(expFail uint64) { - for i := uint64(0); i <= blockchain.CurrentHeader().GetNumberU64(); i++ { + for i := uint64(0); i <= blockchain.CurrentHeader().Number.Uint64(); i++ { bhash := core.GetCanonicalHash(sdb, i) b1 := fn(NoOdr, sdb, blockchain, nil, bhash) ctx, _ := context.WithTimeout(context.Background(), 200*time.Millisecond) diff --git a/light/txpool.go b/light/txpool.go index 01fd54597..5c4e2dd82 100644 --- a/light/txpool.go +++ b/light/txpool.go @@ -90,7 +90,7 @@ func NewTxPool(config *core.ChainConfig, eventMux *event.TypeMux, chain *LightCh odr: chain.Odr(), chainDb: chain.Odr().Database(), head: chain.CurrentHeader().Hash(), - clearIdx: chain.CurrentHeader().GetNumberU64(), + clearIdx: chain.CurrentHeader().Number.Uint64(), } go pool.eventLoop() @@ -241,11 +241,11 @@ func (pool *TxPool) setNewHead(ctx context.Context, newHeader *types.Header) (tx // find common ancestor, create list of rolled back and new block hashes var oldHashes, newHashes []common.Hash for oldh.Hash() != newh.Hash() { - if oldh.GetNumberU64() >= newh.GetNumberU64() { + if oldh.Number.Uint64() >= newh.Number.Uint64() { oldHashes = append(oldHashes, oldh.Hash()) oldh = pool.chain.GetHeader(oldh.ParentHash, oldh.Number.Uint64()-1) } - if oldh.GetNumberU64() < newh.GetNumberU64() { + if oldh.Number.Uint64() < newh.Number.Uint64() { newHashes = append(newHashes, newh.Hash()) newh = pool.chain.GetHeader(newh.ParentHash, newh.Number.Uint64()-1) if newh == nil { @@ -254,8 +254,8 @@ func (pool *TxPool) setNewHead(ctx context.Context, newHeader *types.Header) (tx } } } - if oldh.GetNumberU64() < pool.clearIdx { - pool.clearIdx = oldh.GetNumberU64() + if oldh.Number.Uint64() < pool.clearIdx { + pool.clearIdx = oldh.Number.Uint64() } // roll back old blocks for _, hash := range oldHashes { @@ -265,14 +265,14 @@ func (pool *TxPool) setNewHead(ctx context.Context, newHeader *types.Header) (tx // check mined txs of new blocks (array is in reversed order) for i := len(newHashes) - 1; i >= 0; i-- { hash := newHashes[i] - if err := pool.checkMinedTxs(ctx, hash, newHeader.GetNumberU64()-uint64(i), txc); err != nil { + if err := pool.checkMinedTxs(ctx, hash, newHeader.Number.Uint64()-uint64(i), txc); err != nil { return txc, err } pool.head = hash } // clear old mined tx entries of old blocks - if idx := newHeader.GetNumberU64(); idx > pool.clearIdx+txPermanent { + if idx := newHeader.Number.Uint64(); idx > pool.clearIdx+txPermanent { idx2 := idx - txPermanent for i := pool.clearIdx; i < idx2; i++ { hash := core.GetCanonicalHash(pool.chainDb, i) diff --git a/light/vm_env.go b/light/vm_env.go index 0f4b90908..e2b43b99b 100644 --- a/light/vm_env.go +++ b/light/vm_env.go @@ -71,7 +71,7 @@ func (self *VMEnv) Depth() int { return self.depth } func (self *VMEnv) SetDepth(i int) { self.depth = i } func (self *VMEnv) GetHash(n uint64) common.Hash { for header := self.chain.GetHeader(self.header.ParentHash, self.header.Number.Uint64()-1); header != nil; header = self.chain.GetHeader(header.ParentHash, header.Number.Uint64()-1) { - if header.GetNumberU64() == n { + if header.Number.Uint64() == n { return header.Hash() } } -- cgit