mirror of https://github.com/status-im/nim-eth.git
Merge branch 'master' of github.com:status-im/nim-eth
This commit is contained in:
commit
93637fa060
|
@ -180,6 +180,12 @@ when BlockNumber is int64:
|
||||||
template toBlockNumber*(n: SomeInteger): BlockNumber =
|
template toBlockNumber*(n: SomeInteger): BlockNumber =
|
||||||
int64(n)
|
int64(n)
|
||||||
|
|
||||||
|
template toBlockNumber*(n: UInt256): BlockNumber =
|
||||||
|
n.toInt
|
||||||
|
|
||||||
|
template toInt*(n: BlockNumber): int =
|
||||||
|
int(n)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
template vmWordToBlockNumber*(word: VMWord): BlockNumber =
|
template vmWordToBlockNumber*(word: VMWord): BlockNumber =
|
||||||
word
|
word
|
||||||
|
@ -190,6 +196,12 @@ else:
|
||||||
template toBlockNumber*(n: SomeInteger): BlockNumber =
|
template toBlockNumber*(n: SomeInteger): BlockNumber =
|
||||||
u256(n)
|
u256(n)
|
||||||
|
|
||||||
|
template toBlockNumber*(n: UInt256): BlockNumber =
|
||||||
|
n
|
||||||
|
|
||||||
|
template u256*(n: BlockNumber): UInt256 =
|
||||||
|
n
|
||||||
|
|
||||||
proc toBlockNonce*(n: uint64): BlockNonce =
|
proc toBlockNonce*(n: uint64): BlockNonce =
|
||||||
bigEndian64(addr result[0], unsafeAddr n)
|
bigEndian64(addr result[0], unsafeAddr n)
|
||||||
|
|
||||||
|
@ -303,7 +315,7 @@ proc read*(rlp: var Rlp, T: typedesc[HashOrNum]): T =
|
||||||
if rlp.blobLen == 32:
|
if rlp.blobLen == 32:
|
||||||
result = HashOrNum(isHash: true, hash: rlp.read(Hash256))
|
result = HashOrNum(isHash: true, hash: rlp.read(Hash256))
|
||||||
else:
|
else:
|
||||||
result = HashOrNum(isHash: false, number: rlp.read(UInt256))
|
result = HashOrNum(isHash: false, number: rlp.read(BlockNumber))
|
||||||
|
|
||||||
proc append*(rlpWriter: var RlpWriter, t: Time) {.inline.} =
|
proc append*(rlpWriter: var RlpWriter, t: Time) {.inline.} =
|
||||||
rlpWriter.append(t.toUnix())
|
rlpWriter.append(t.toUnix())
|
||||||
|
|
|
@ -40,7 +40,7 @@ proc hash*(p: Peer): Hash {.inline.} = hash(cast[pointer](p))
|
||||||
|
|
||||||
proc endIndex(b: WantedBlocks): BlockNumber =
|
proc endIndex(b: WantedBlocks): BlockNumber =
|
||||||
result = b.startIndex
|
result = b.startIndex
|
||||||
result += (b.numBlocks - 1).u256
|
result += (b.numBlocks - 1).toBlockNumber
|
||||||
|
|
||||||
proc availableWorkItem(ctx: SyncContext): int =
|
proc availableWorkItem(ctx: SyncContext): int =
|
||||||
var maxPendingBlock = ctx.finalizedBlock
|
var maxPendingBlock = ctx.finalizedBlock
|
||||||
|
|
|
@ -10,16 +10,15 @@ proc getBlockHeaders*(db: AbstractChainDB,
|
||||||
var foundBlock: BlockHeader
|
var foundBlock: BlockHeader
|
||||||
if db.getBlockHeader(req.startBlock, foundBlock):
|
if db.getBlockHeader(req.startBlock, foundBlock):
|
||||||
result.add foundBlock
|
result.add foundBlock
|
||||||
# Quick sanity check for lower bounds, code should be safe though without.
|
|
||||||
if not req.reverse or (foundBlock.blockNumber >= (req.skip + 1).toBlockNumber):
|
while uint64(result.len) < req.maxResults:
|
||||||
while uint64(result.len) < req.maxResults:
|
if not req.reverse:
|
||||||
if not req.reverse:
|
if not db.getSuccessorHeader(foundBlock, foundBlock, req.skip):
|
||||||
if not db.getSuccessorHeader(foundBlock, foundBlock, req.skip):
|
break
|
||||||
break
|
else:
|
||||||
else:
|
if not db.getAncestorHeader(foundBlock, foundBlock, req.skip):
|
||||||
if not db.getAncestorHeader(foundBlock, foundBlock, req.skip):
|
break
|
||||||
break
|
result.add foundBlock
|
||||||
result.add foundBlock
|
|
||||||
|
|
||||||
|
|
||||||
template fetcher*(fetcherName, fetchingFunc, InputType, ResultType: untyped) =
|
template fetcher*(fetcherName, fetchingFunc, InputType, ResultType: untyped) =
|
||||||
|
|
Loading…
Reference in New Issue