2018-11-22 06:40:09 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2018 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
# at your option.
|
|
|
|
# This file may not be copied, modified, or distributed except according to
|
|
|
|
# those terms.
|
|
|
|
|
2019-02-05 19:15:50 +00:00
|
|
|
import hexstrings, nimcrypto, eth/common, byteutils,
|
2018-12-11 10:05:49 +00:00
|
|
|
../db/[db_chain, state_db, storage_types], strutils,
|
|
|
|
../constants, stint
|
2018-11-22 06:40:09 +00:00
|
|
|
|
2018-11-29 17:08:13 +00:00
|
|
|
func toAddress*(value: EthAddressStr): EthAddress = hexToPaddedByteArray[20](value.string)
|
2018-11-22 06:40:09 +00:00
|
|
|
|
|
|
|
func toHash*(value: array[32, byte]): Hash256 {.inline.} =
|
|
|
|
result.data = value
|
|
|
|
|
2018-11-29 17:08:13 +00:00
|
|
|
func toHash*(value: EthHashStr): Hash256 {.inline.} =
|
|
|
|
result = hexToPaddedByteArray[32](value.string).toHash
|
|
|
|
|
2019-01-15 14:02:25 +00:00
|
|
|
proc headerFromTag*(chain: BaseChainDB, blockTag: string): BlockHeader =
|
2018-12-11 10:05:49 +00:00
|
|
|
let tag = blockTag.toLowerAscii
|
|
|
|
case tag
|
|
|
|
of "latest": result = chain.getCanonicalHead()
|
|
|
|
of "earliest": result = chain.getBlockHeader(GENESIS_BLOCK_NUMBER)
|
|
|
|
of "pending":
|
|
|
|
#TODO: Implement get pending block
|
|
|
|
raise newException(ValueError, "Pending tag not yet implemented")
|
|
|
|
else:
|
|
|
|
# Raises are trapped and wrapped in JSON when returned to the user.
|
|
|
|
tag.validateHexQuantity
|
|
|
|
let blockNum = stint.fromHex(UInt256, tag)
|
2019-01-15 14:02:25 +00:00
|
|
|
result = chain.getBlockHeader(blockNum)
|