Remove overloaded UInt256.fromJson (#74)

* Remove overloaded UInt256.fromJson

Rely instead on UInt256.fromJson from nim-serde, which deserializes an empty string for ?UInt256 into UInt256.none. Previously, empty strings were deserialized into 0.u256. BlockNumber was using this deserialization, and it appears that deserializing a missing block number from a TransactionReceipt into 0 might actually cause some issues when waiting on block confirmations.

* bump version of serde

* Remove "v" from version in `.nimble`

* Fix nimble serde version again ¯\_(ツ)_/¯
This commit is contained in:
Eric 2024-05-21 13:09:42 +10:00 committed by GitHub
parent 6393546ad6
commit 958d7b45d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 10 deletions

View File

@ -9,7 +9,7 @@ requires "chronos >= 4.0.0 & < 4.1.0"
requires "contractabi >= 0.6.0 & < 0.7.0"
requires "questionable >= 0.10.2 & < 0.11.0"
requires "json_rpc >= 0.4.0 & < 0.5.0"
requires "serde >= 0.1.1 & < 0.2.0"
requires "serde >= 1.2.1 & < 1.3.0"
requires "stint"
requires "stew"
requires "eth"

View File

@ -47,11 +47,6 @@ func fromJson(_: type Address, json: JsonNode): ?!Address =
func `%`*(integer: UInt256): JsonNode =
%("0x" & toHex(integer))
func fromJson*(_: type UInt256, json: JsonNode): ?!UInt256 =
without result =? UInt256.fromHex(json.getStr()).catch, error:
return UInt256.failure error.msg
success result
# Transaction
# TODO: add option that ignores none Option[T]

View File

@ -26,8 +26,7 @@ suite "JSON Conversions":
json["number"] = newJString("")
let blk2 = !Block.fromJson(json)
check blk2.number.isSome
check blk2.number.get.isZero
check blk2.number.isNone
test "missing block hash in Block isNone":
@ -78,8 +77,7 @@ suite "JSON Conversions":
json["blockNumber"] = newJString("")
without receipt2 =? TransactionReceipt.fromJson(json):
fail
check receipt2.blockNumber.isSome
check receipt2.blockNumber.get.isZero
check receipt2.blockNumber.isNone
test "missing block hash in TransactionReceipt isNone":
let json = %*{