mirror of https://github.com/status-im/nim-eth.git
Change EthTime from Time to distinct uint64
Cancun test vector demand a uint64 of block timestamp. Therefore using std.Time will not able to pass test.
This commit is contained in:
parent
34ab6bd986
commit
2be8c183d1
|
@ -0,0 +1,51 @@
|
||||||
|
# Nimbus
|
||||||
|
# Copyright (c) 2023 Status Research & Development GmbH
|
||||||
|
# Licensed and distributed under either of
|
||||||
|
# * MIT license (license terms in the root directory or at
|
||||||
|
# https://opensource.org/licenses/MIT).
|
||||||
|
# * Apache v2 license (license terms in the root directory or at
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
# at your option. This file may not be copied, modified, or distributed
|
||||||
|
# except according to those terms.
|
||||||
|
|
||||||
|
import
|
||||||
|
std/times
|
||||||
|
|
||||||
|
type
|
||||||
|
EthTime* = distinct uint64
|
||||||
|
|
||||||
|
func now*(_: type EthTime): EthTime =
|
||||||
|
getTime().utc.toTime.toUnix.EthTime
|
||||||
|
|
||||||
|
func `+`*(a: EthTime, b: EthTime): EthTime =
|
||||||
|
EthTime(a.uint64 + b.uint64)
|
||||||
|
|
||||||
|
func `+`*(a: EthTime, b: uint64): EthTime =
|
||||||
|
EthTime(a.uint64 + b)
|
||||||
|
|
||||||
|
func `-`*(a: EthTime, b: EthTime): EthTime =
|
||||||
|
EthTime(a.uint64 - b.uint64)
|
||||||
|
|
||||||
|
func `-`*(a: EthTime, b: uint64): EthTime =
|
||||||
|
EthTime(a.uint64 - b)
|
||||||
|
|
||||||
|
func `==`*(a: EthTime, b: EthTime): bool =
|
||||||
|
a.uint64 == b.uint64
|
||||||
|
|
||||||
|
func `==`*(a: EthTime, b: uint64): bool =
|
||||||
|
a.uint64 == b
|
||||||
|
|
||||||
|
func `<`*(a: EthTime, b: EthTime): bool =
|
||||||
|
a.uint64 < b.uint64
|
||||||
|
|
||||||
|
func `<`*(a: EthTime, b: uint64): bool =
|
||||||
|
a.uint64 < b
|
||||||
|
|
||||||
|
func `<`*(a: uint64, b: EthTime): bool =
|
||||||
|
a < b.uint64
|
||||||
|
|
||||||
|
func `<=`*(a: EthTime, b: EthTime): bool =
|
||||||
|
a.uint64 <= b.uint64
|
||||||
|
|
||||||
|
func `$`*(x: EthTime): string =
|
||||||
|
$(x.uint64)
|
|
@ -10,17 +10,15 @@
|
||||||
## from many places
|
## from many places
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[options, strutils, times],
|
std/[options, strutils],
|
||||||
stew/[byteutils, endians2], stint,
|
stew/[byteutils, endians2], stint,
|
||||||
./eth_hash
|
./eth_hash, ./eth_times
|
||||||
|
|
||||||
export
|
export
|
||||||
options, stint, eth_hash,
|
options, stint, eth_hash, eth_times
|
||||||
times.Time, times.fromUnix, times.toUnix
|
|
||||||
|
|
||||||
type
|
type
|
||||||
Hash256* = MDigest[256]
|
Hash256* = MDigest[256]
|
||||||
EthTime* = Time
|
|
||||||
VMWord* = UInt256
|
VMWord* = UInt256
|
||||||
BlockNonce* = array[8, byte]
|
BlockNonce* = array[8, byte]
|
||||||
AccountNonce* = uint64
|
AccountNonce* = uint64
|
||||||
|
@ -330,3 +328,4 @@ func `==`*(a, b: NetworkId): bool =
|
||||||
|
|
||||||
func `$`*(x: NetworkId): string =
|
func `$`*(x: NetworkId): string =
|
||||||
`$`(uint(x))
|
`$`(uint(x))
|
||||||
|
|
||||||
|
|
|
@ -377,8 +377,8 @@ proc read*(rlp: var Rlp, T: type Receipt): T =
|
||||||
rlp.read(result.bloom)
|
rlp.read(result.bloom)
|
||||||
rlp.read(result.logs)
|
rlp.read(result.logs)
|
||||||
|
|
||||||
proc read*(rlp: var Rlp, T: type Time): T {.inline.} =
|
proc read*(rlp: var Rlp, T: type EthTime): T {.inline.} =
|
||||||
result = fromUnix(rlp.read(int64))
|
result = EthTime rlp.read(uint64)
|
||||||
|
|
||||||
proc append*(rlpWriter: var RlpWriter, value: HashOrNum) =
|
proc append*(rlpWriter: var RlpWriter, value: HashOrNum) =
|
||||||
case value.isHash
|
case value.isHash
|
||||||
|
@ -393,8 +393,8 @@ proc read*(rlp: var Rlp, T: type HashOrNum): T =
|
||||||
else:
|
else:
|
||||||
result = HashOrNum(isHash: false, number: rlp.read(BlockNumber))
|
result = HashOrNum(isHash: false, number: rlp.read(BlockNumber))
|
||||||
|
|
||||||
proc append*(rlpWriter: var RlpWriter, t: Time) {.inline.} =
|
proc append*(rlpWriter: var RlpWriter, t: EthTime) {.inline.} =
|
||||||
rlpWriter.append(t.toUnix())
|
rlpWriter.append(t.uint64)
|
||||||
|
|
||||||
proc rlpHash*[T](v: T): Hash256 =
|
proc rlpHash*[T](v: T): Hash256 =
|
||||||
keccakHash(rlp.encode(v))
|
keccakHash(rlp.encode(v))
|
||||||
|
|
Loading…
Reference in New Issue