Commit Graph

88 Commits

Author SHA1 Message Date
Mark Spanbroek 127c9c9b0d Formatting 2023-07-03 13:09:09 +02:00
Mark Spanbroek 16fa0cfcf8 Use new subscription handling in JSON RPC provider 2023-07-03 13:09:09 +02:00
Mark Spanbroek a7dc0ac9eb Move subscription handling to its own module 2023-07-03 13:09:09 +02:00
Mark Spanbroek 0b951ce146 Set correct content-type for JSON-RPC 2023-07-03 11:29:31 +02:00
Eric Mastro 34b7a82565 fix: pending blocks may not contains block hash
Pending blocks may not contain a block hash and therefore Block.hash should be optional.
2023-07-03 11:29:09 +02:00
Adam Uhlíř 0321e6d7bd
fix: dont export json conversions of jsonrpc (#44) 2023-06-19 14:13:44 +02:00
Adam Uhlíř 18e225607c
fix: eth_call use signers address (#43) 2023-06-13 16:24:59 +02:00
Mark Spanbroek 1ca90d0b3c Allow contract calls to override the block tag 2023-04-19 10:03:50 +02:00
Adam Uhlíř 3c12a65769
feat: erc20 module (#38)
Co-authored-by: Eric Mastro <github@egonat.me>
2023-03-29 13:41:44 +02:00
Ben Bierens 577e02b8a2
enables stylecheck (#36)
* enables stylecheck

* applies style check

* Applying style check

* uses alias to fix ambiguity
2023-03-09 10:58:54 +01:00
Mark Spanbroek e8592bb922 Remove unnecessary error check 2022-09-21 10:29:31 +02:00
Mark Spanbroek 7d2acd65e8 Fix imports 2022-09-21 10:29:31 +02:00
Mark Spanbroek a62ea4fb8f Ensure that `reverts` works with functions with a return type 2022-09-21 10:29:31 +02:00
Mark Spanbroek c5a40e5f9d Remove dependency on json-rpc provider for `reverts` 2022-09-21 10:29:31 +02:00
Mark Spanbroek f545169331 Remove JSON wrapper from error in JSON RPC provider 2022-09-21 10:29:31 +02:00
Mark Spanbroek cac6026b34 Change `reverts` API
- Enables postfix syntax: `call().reverts(reason)`
- Removes doesNotRevert etc; uses `check not` instead
- Removes waitFor(); return Future instead
2022-09-21 10:29:31 +02:00
Mark Spanbroek d001ee8e01 Use `solidityType()` to check indexed event parameter 2022-09-21 10:27:45 +10:00
Eric Mastro 31ffc8992f Update compile time check to use when 2022-09-21 10:27:45 +10:00
Eric Mastro ae2d33aacd Support 1.2.16 distinctBase compilation error 2022-09-21 10:27:45 +10:00
Eric Mastro 0adf56c65b Support distinct types for Event fields
Add support for indexed (and non-indexed) Event fields types that are distinct `ValueType` or `SmallByteArray`. For example,
```nim
type
  DistinctAlias = distinct array[32, byte]
  MyEvent = object of Event
    a {.indexed.}: DistinctAlias
    b: DistinctAlias # also allowed for non-indexed fields

## The below funcs generally need to be included for ABI
## encoding/decoding purposes when implementing distinct types.

func toArray(value: DistinctAlias): array[32, byte] =
  array[32, byte](value)

func encode*(encoder: var AbiEncoder, value: DistinctAlias) =
  encoder.write(value.toArray)

func decode*(decoder: var AbiDecoder,
             T: type DistinctAlias): ?!T =
  let d = ?decoder.read(type array[32, byte])
  success DistinctAlias(d)
```
2022-09-21 10:27:45 +10:00
Eric Mastro 5fe41a76ab PR comments
1. rename helpers to testing and expose externally via `import pkg/ethers/testing`
2. Change detection of revert from `EthersError` to `JsonRpcProviderError`
3, Remove catch of `CatchableError` from revert detection as this would swallow errors. Update tests accordingly.
2022-09-20 13:15:15 +10:00
Eric Mastro f8ba91a297 Catch ValueError from nim-json-rpc 2022-09-20 13:15:15 +10:00
Mark Spanbroek c72cdc5573 [wallet] cleanup 2022-08-08 15:07:41 +02:00
Mark Spanbroek a2d688e34e [wallet] Avoid Option.get() which can raise UnpackDefect 2022-08-08 15:07:41 +02:00
Mark Spanbroek 1a8ca0bcad [wallet] Use questionable to deal with optionals 2022-08-08 15:07:41 +02:00
Mark Spanbroek 0483e1676a [provider] Rename sendRawTransaction -> sendTransaction
To be consistent with ethers.js
2022-08-08 15:07:41 +02:00
Jackie 1af3ab1a0a Make wallet use Provider not JsonRpcProvider 2022-08-08 12:40:36 +02:00
Jackie b72fbb0ed9 small fixes 2022-08-08 12:40:36 +02:00
Jackie 39005a09be Add TODOs 2022-08-08 12:40:36 +02:00
Jackie 456d454f2f Fix bug in wallet 2022-08-08 12:40:36 +02:00
Jackie ac7785dd04 Add new method to wallet 2022-08-08 12:40:36 +02:00
Jackie 4c047fd997 Changes to TransactionOverrides to support EIP1559 2022-08-08 12:40:36 +02:00
Jackie 2c9eb595d2 Add sendRawTransaction 2022-08-08 12:40:36 +02:00
Jackie 671d42889a Add Wallet functionality 2022-08-08 12:40:36 +02:00
Jackie abda8493b0 Change Transaction type to support EIP1559 2022-08-08 12:40:36 +02:00
Mark Spanbroek 16a3d25419 Remove duplication 2022-08-08 12:26:09 +02:00
Jackie 52f57894f5 Fix block subscription 2022-08-08 12:26:09 +02:00
Mark Spanbroek 083af80dcc Introduce separate type for transaction overrides 2022-07-13 09:04:48 +02:00
Mark Spanbroek a7d1944406 Allow for custom transaction properties 2022-07-13 09:04:48 +02:00
Mark Spanbroek 95c5282b8a Raise EthersError when JSON-RPC fails 2022-06-30 10:52:12 +02:00
Mark Spanbroek 9ef6c08072 Handle multiple return types on a contract call 2022-06-14 16:27:43 +02:00
Mark Spanbroek e61c70f5ba Fix: handle dynamically sized return values
Dynamically sized return values such as strings and
sequences were not decoded as part of a tuple, leading
to a difference in byte representation.
2022-06-08 11:23:01 +02:00
Mark Spanbroek 801bf19157 Remove calls to Option.get 2022-05-25 09:28:15 +02:00
Mark Spanbroek 33df1e759d Move `confirm` from `jsonrpc` to `provider` 2022-05-25 09:28:15 +02:00
Mark Spanbroek 2653610b6b Raise EthersError instead of JsonRpcProviderError 2022-05-25 09:28:15 +02:00
Mark Spanbroek 346053e3f2 Turn `confirm` into proc instead of method 2022-05-25 09:28:15 +02:00
Mark Spanbroek fff0d189a5 Ensure that `confirm` future is only finished once
Should fix CI failure
https://github.com/status-im/nim-ethers/runs/6557104597
2022-05-25 09:13:44 +02:00
Mark Spanbroek 649dc8efd0 Allow types that are equivalent to Confirmable
Allows ?TransactionResponse, Option[TransactionResponse] etc
to be used instead of Confirmable.
2022-05-25 09:13:44 +02:00
Eric Mastro c5c9534876 Refactor based on PR comments
- `TransactionReceipt.blockHash` is optional
- Block.number is optional (in case node doesn’t return this in the event)
- Refactor confirmations waiting such that there is no polling for a receipt at the start
- Make BlockHandler and SubscriptionHandler async
- change casing of constants
- change return type checking of contract method to check for `Confirmable` instead of `?TransactionRepsonse`
- Reduce miner sleep to 10ms
- Change `wait` and `Waitable` to `confirm` and `Confirmable` to avoid conflict with chrono’s `.wait`.
- Update params on `.confirm` so that the compiler can restrict values of the `int` to `Positive` and `Natural`.
- Add `Block` and `TransactionReceipt` conversion tests to test for missing block number and block hash.
- Add tests for confirmation calculations and determining if a tx has been mined from its receipt.
- Assume that blockNumber returned from node will be null or empty string, in which case we can parse as 0 and test for that condition.
2022-05-23 11:27:26 +10:00
Eric Mastro a3e888128c feat: Allow contract transactions to be waited on
Allow waiting for a specified number of confirmations for contract transactions.

This change only requires an optional TransactionResponse return type to be added to the contract function. This allows the transaction hash to be passed to `.wait`.

For example, previously the `mint` method looked like this without a return value:
```
method mint(token: TestToken, holder: Address, amount: UInt256) {.base, contract.}
```
it still works without a return value, but if we want to wait for a 3 confirmations, we can now define it like this:
```
method mint(token: TestToken, holder: Address, amount: UInt256): ?TransactionResponse {.base, contract.}
```
and use like this:
```
let receipt = await token.connect(signer0)
                    .mint(accounts[1], 100.u256)
                    .wait(3) # wait for 3 confirmations
```
2022-05-23 11:27:26 +10:00