Skip to content

Commit

Permalink
Remove overloaded UInt256.fromJson (#74)
Browse files Browse the repository at this point in the history
* 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 ¯\_(ツ)_/¯
  • Loading branch information
emizzle authored May 21, 2024
1 parent 6393546 commit 958d7b4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ethers.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 0 additions & 5 deletions ethers/providers/jsonrpc/conversions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 2 additions & 4 deletions testmodule/providers/jsonrpc/testConversions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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":

Expand Down Expand Up @@ -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 = %*{
Expand Down

0 comments on commit 958d7b4

Please sign in to comment.