Bump json-serialization to v0.2.0: Improve lexer flexibility

This commit is contained in:
jangko 2023-12-26 15:12:58 +07:00
parent 540db59357
commit 5e95df6bde
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
4 changed files with 12 additions and 19 deletions

View File

@ -23,9 +23,6 @@ export
type type
Genesis* = ref object Genesis* = ref object
# for geth compatibility
config* : ChainConfig
nonce* : BlockNonce nonce* : BlockNonce
timestamp* : EthTime timestamp* : EthTime
extraData* : seq[byte] extraData* : seq[byte]
@ -148,17 +145,17 @@ proc readValue(reader: var JsonReader, value: var UInt256)
## to `BlockNumber` fields as well as generic `UInt265` fields like the ## to `BlockNumber` fields as well as generic `UInt265` fields like the
## account `balance`. ## account `balance`.
var (accu, ok) = (0.u256, true) var (accu, ok) = (0.u256, true)
if reader.lexer.lazyTok == tkNumeric: let tokKind = reader.tokKind
if tokKind == JsonValueKind.Number:
try: try:
reader.lexer.customIntValueIt: reader.customIntValueIt:
accu = accu * 10 + it.u256 accu = accu * 10 + it.u256
ok = reader.lexer.lazyTok == tkExInt # non-negative wanted
except CatchableError: except CatchableError:
ok = false ok = false
elif reader.lexer.lazyTok == tkQuoted: elif tokKind == JsonValueKind.String:
try: try:
var (sLen, base) = (0, 10) var (sLen, base) = (0, 10)
reader.lexer.customTextValueIt: reader.customStringValueIt:
if ok: if ok:
var num = it.fromHex var num = it.fromHex
if base <= num: if base <= num:
@ -184,7 +181,6 @@ proc readValue(reader: var JsonReader, value: var UInt256)
if not ok: if not ok:
reader.raiseUnexpectedValue("Uint256 parse error") reader.raiseUnexpectedValue("Uint256 parse error")
value = accu value = accu
reader.lexer.next()
proc readValue(reader: var JsonReader, value: var ChainId) proc readValue(reader: var JsonReader, value: var ChainId)
{.gcsafe, raises: [SerializationError, IOError].} = {.gcsafe, raises: [SerializationError, IOError].} =
@ -215,18 +211,15 @@ proc readValue(reader: var JsonReader, value: var EthTime)
# but shanghaiTime and cancunTime in config is in int literal # but shanghaiTime and cancunTime in config is in int literal
proc readValue(reader: var JsonReader, value: var Option[EthTime]) proc readValue(reader: var JsonReader, value: var Option[EthTime])
{.gcsafe, raises: [IOError].} = {.gcsafe, raises: [IOError, JsonReaderError].} =
let tok = reader.lexer.lazyTok if reader.tokKind == JsonValueKind.Null:
if tok == tkNull:
reset value reset value
reader.lexer.next() reader.parseNull()
else: else:
# both readValue(GasInt/AccountNonce) will be called if # both readValue(GasInt/AccountNonce) will be called if
# we use readValue(int64/uint64) # we use readValue(int64/uint64)
let tok {.used.} = reader.lexer.tok # resove lazy token let val = EthTime reader.parseInt(uint64)
let val = EthTime reader.lexer.absIntVal
value = some val value = some val
reader.lexer.next()
proc readValue(reader: var JsonReader, value: var seq[byte]) proc readValue(reader: var JsonReader, value: var seq[byte])
{.gcsafe, raises: [SerializationError, IOError].} = {.gcsafe, raises: [SerializationError, IOError].} =

@ -1 +1 @@
Subproject commit 85b7ea093cb85ee4f433a617b97571bd709d30df Subproject commit 9720b33f9930ba1c62d03cd680a1245c7ac71014

@ -1 +1 @@
Subproject commit 4bdbc29e54fe54049950e352bb969aab97173b35 Subproject commit 68722b14fc7856045eb787150c1c0b95553ba62b

2
vendor/nimbus-eth2 vendored

@ -1 +1 @@
Subproject commit 15147cccb1a45f65556b563f8bc8693d5f020589 Subproject commit 7b6ba48dd98dfc1644b101cc85e0592fa7f16d80