Prepare for allowing BlockNumber as int64

This commit is contained in:
kdeme 2019-07-10 09:37:23 +02:00
parent b79fe42095
commit fb7743e9db
2 changed files with 14 additions and 2 deletions

View File

@ -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())

View File

@ -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