Skip to content
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

Merged
merged 24 commits into from
Feb 19, 2024
Merged

Conversation

emizzle
Copy link
Contributor

@emizzle emizzle commented Feb 8, 2024

nim-json-rpc#head, in particular has seen some large breaking changes:

  • removal of setMethodHandler which is how ethers was processing subscription updates
  • call returns JsonString instead of JsonNode
  • json marshalling uses a custom flavour of nim-json-serialization exclusively instead of % and fromJson

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 causes Tables with JsonNode keys to raise an Exception (due to a call to JsonNode.hash). The underlying error was a missing forward declaration for hash 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 the jsonmarshal module with forced serialization via nim-json-serialization. As nim-json-serialization is not a preferred serializer, json serialization was replaced with nim-serde.

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)
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`
This was referenced Feb 8, 2024
Copy link
Member

@markspanbroek markspanbroek left a 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.

ethers/erc20.nim Outdated Show resolved Hide resolved
ethers/nimshims/hashes.nim Show resolved Hide resolved
ethers/providers/jsonrpc.nim Show resolved Hide resolved
ethers/providers/jsonrpc/subscriptions.nim Outdated Show resolved Hide resolved
ethers/providers/jsonrpc/subscriptions.nim Outdated Show resolved Hide resolved
ethers/providers/jsonrpc/subscriptions.nim Outdated Show resolved Hide resolved
ethers/providers/jsonrpc/subscriptions.nim Outdated Show resolved Hide resolved
ethers/signer.nim Outdated Show resolved Hide resolved
testmodule/providers/jsonrpc/testConversions.nim Outdated Show resolved Hide resolved
template `or`(a: JsonNode, b: typed): JsonNode =
if a.isNil: b else: a

func init*(subscriptions: JsonRpcSubscriptions) =
Copy link
Member

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()?

Copy link
Contributor Author

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.

Copy link
Member

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
@emizzle emizzle merged commit 43500c6 into main Feb 19, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants