nim-ethers/ethers/blocktag.nim

44 lines
1.0 KiB
Nim
Raw Normal View History

2022-01-24 11:14:31 +00:00
import pkg/stint
{.push raises:[].}
2022-01-24 11:14:31 +00:00
type
BlockTagKind = enum
stringBlockTag
numberBlockTag
BlockTag* = object
case kind: BlockTagKind
of stringBlockTag:
stringValue: string
of numberBlockTag:
numberValue: UInt256
func init(_: type BlockTag, value: string): BlockTag =
BlockTag(kind: stringBlockTag, stringValue: value)
func init*(_: type BlockTag, value: UInt256): BlockTag =
BlockTag(kind: numberBlockTag, numberValue: value)
func earliest*(_: type BlockTag): BlockTag =
BlockTag.init("earliest")
func latest*(_: type BlockTag): BlockTag =
BlockTag.init("latest")
func pending*(_: type BlockTag): BlockTag =
BlockTag.init("pending")
func `$`*(blockTag: BlockTag): string =
case blockTag.kind
of stringBlockTag:
blockTag.stringValue
of numberBlockTag:
"0x" & blockTag.numberValue.toHex
func `==`*(a, b: BlockTag): bool =
case a.kind
of stringBlockTag:
a.stringValue == b.stringValue
of numberBlockTag:
a.numberValue == b.numberValue