-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade to nim-json-rpc
v0.4.2 and chronos v4
#64
Conversation
json-rpc now requires nim-json-serialization to convert types to/from json. Use the nim-json-serialization signatures to call the json serialization lib from nim-codex (should be moved to its own lib)
Was removed in json-rpc
Use {.async: (raises: [...].} where needed Annotate provider with {.push raises:[].} Format signatures
- signer procs raise SignerError, provider procs raise ProviderError - WalletError now inherits from SignerError - move wallet module under signers - create jsonrpo moudle under signers - bump nim-json-rpc for null-handling fixes - All jsonrpc provider tests passing, still need to fix others
- removes async: raises from getAddress and signTransaction because derived JsonRpcSigner methods were not being used when dynamically dispatched. Once `raises` was removed from the async annotation, the dynamic dispatch worked again. This is only the case for getAddress and signTransaction. - add gcsafe annotation to wallet.provider so that it matches the base method
EstimateGasError is now a ProviderError (it is a SignerError, and SignerError is a ProviderError), so EstimateGasErrors were not being caught
next step is to: 1. change back any ethers var names that were changed for serialization purposes, eg `from` and `type` 2. move the json util to its own lib
Fixes issue where getAddress and sendTransaction could not be found for MockSigner in tests. The problem was that the async: raises update had not been applied to the MockSigner.
There are too many exceptions to catch individually, including chronos raising CatchableError exceptions in await expansion. There are also many other errors captured inside of the new proc with CatchableError. Instead of making it more complicated and harder to read, I think sticking with excepting CatchableError inside of convertError is a sensible solution
Allows aliasing of de/serialized fields, so revert changes of sender to `from` and transactionType to `type`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, I like these changes a lot. They make exception handling a lot better, and the improved json serialization makes everything simpler.
template `or`(a: JsonNode, b: typed): JsonNode = | ||
if a.isNil: b else: a | ||
|
||
func init*(subscriptions: JsonRpcSubscriptions) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not do this in JsonRpcSubscriptions.new()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main purpose was to allow new
to create an instance of JsonRpcSubscriptions without initializing services, such as parsing of every message, which may be unnecessary or which can lead to race conditions, when the caller simply needed an object instance.
I am not opposed to putting this in new
if you feel strongly about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Perhaps we could call it start
then, instead of init
?
- add comments to hashes shim - remove .catch from callback condition - derive SignerError from EthersError instead of ProviderError. This allows Providers and Signers to be separate, as Ledger does it, to isolate functionality. Some signer functions now raise both ProviderError and SignerError - Update reverts to check for SignerError - Update ERC-20 method comment
nim-json-rpc#head
, in particular has seen some large breaking changes:setMethodHandler
which is how ethers was processing subscription updatescall
returnsJsonString
instead ofJsonNode
nim-json-serialization
exclusively instead of%
andfromJson
This PR addresses those breaking changes and upgrades to chronos v4, which supports proper async exception tracking. Ethers now has proper exception tracking support.
Adding
{.push raises:[].}
as part of the exception tracking support causesTables
withJsonNode
keys to raise anException
(due to a call toJsonNode.hash
). The underlying error was a missing forward declaration forhash
of a particular type. The workaround for this was to create a shim that adds the missing forward declaration and also adds{.raises: [].}
.nim-json-rpc
serialization replaced thejsonmarshal
module with forced serialization vianim-json-serialization
. Asnim-json-serialization
is not a preferred serializer, json serialization was replaced withnim-serde
.