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.
|
|
|
|
|
2018-12-11 10:05:49 +00:00
|
|
|
import hexstrings, nimcrypto, eth_common, byteutils,
|
|
|
|
../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
|
|
|
|
|
2018-12-11 10:05:49 +00:00
|
|
|
func headerFromTag*(chain: BaseChainDB, blockTag: string): BlockHeader =
|
|
|
|
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)
|
|
|
|
result = chain.getBlockHeader(blockNum)
|