reth_rpc_api/
ganache.rs

1use alloy_primitives::U256;
2use alloy_rpc_types_anvil::MineOptions;
3use jsonrpsee::{core::RpcResult, proc_macros::rpc};
4
5/// Ganache rpc interface.
6/// https://github.com/trufflesuite/ganache/tree/develop/docs
7#[cfg_attr(not(feature = "client"), rpc(server, namespace = "evm"))]
8#[cfg_attr(feature = "client", rpc(server, client, namespace = "evm"))]
9pub trait GanacheApi {
10    // TODO Ganache is deprecated and this method is not implemented by Anvil and Hardhat.
11    // #[method(name = "addAccount")]
12    // async fn evm_add_account(&self, address: Address, passphrase: B256) -> RpcResult<bool>;
13
14    /// Jump forward in time by the given amount of time, in seconds.
15    ///
16    /// Returns the total time adjustment, in seconds.
17    #[method(name = "increaseTime")]
18    async fn evm_increase_time(&self, seconds: U256) -> RpcResult<i64>;
19
20    /// Force a single block to be mined.
21    ///
22    /// Mines a block independent of whether or not mining is started or stopped. Will mine an empty
23    /// block if there are no available transactions to mine.
24    ///
25    /// Returns "0x0". May return additional meta-data in the future.
26    #[method(name = "mine")]
27    async fn evm_mine(&self, opts: Option<MineOptions>) -> RpcResult<String>;
28
29    // TODO Ganache is deprecated and this method is not implemented by Anvil and Hardhat.
30    // #[method(name = "removeAccount")]
31    // async fn evm_remove_account(address: Address, passphrase: B256) -> RpcResult<bool>;
32
33    /// Revert the state of the blockchain to a previous snapshot. Takes a single parameter, which
34    /// is the snapshot id to revert to. This deletes the given snapshot, as well as any snapshots
35    /// taken after (e.g.: reverting to id 0x1 will delete snapshots with ids 0x1, 0x2, etc.).
36    ///
37    /// Returns `true` if a snapshot was reverted, otherwise `false`.
38    #[method(name = "revert")]
39    async fn evm_revert(&self, snapshot_id: U256) -> RpcResult<bool>;
40
41    // TODO Ganache is deprecated and this method is not implemented by Anvil and Hardhat.
42    // #[method(name = "setAccountBalance")]
43    // async fn evm_set_account_balance(address: Address, balance: U256) -> RpcResult<bool>;
44
45    // TODO Ganache is deprecated and this method is not implemented by Anvil and Hardhat.
46    // #[method(name = "setAccountCode")]
47    // async fn evm_set_account_code(address: Address, code: Bytes) -> RpcResult<bool>;
48
49    // TODO Ganache is deprecated and this method is not implemented by Anvil and Hardhat.
50    // #[method(name = "setAccountNonce")]
51    // async fn evm_set_account_nonce(address: Address, nonce: U256) -> RpcResult<bool>;
52
53    // TODO Ganache is deprecated and this method is not implemented by Anvil and Hardhat.
54    // #[method(name = "setAccountStorageAt")]
55    // async fn evm_set_account_storage_at(address: Address, slot: U256, value: B256) ->
56    // RpcResult<bool>;
57
58    /// Sets the internal clock time to the given timestamp.
59    ///
60    /// **Warning** This will allow you to move backwards in time, which may cause new blocks to
61    /// appear to be mined before old blocks. This will result in an invalid state.
62    ///
63    /// Returns the amount of seconds between the given timestamp and now.
64    #[method(name = "setTime")]
65    async fn evm_set_time(&self, timestamp: u64) -> RpcResult<bool>;
66
67    /// Snapshot the state of the blockchain at the current block. Takes no parameters. Returns the
68    /// id of the snapshot that was created. A snapshot can only be reverted once. After a
69    /// successful evm_revert, the same snapshot id cannot be used again. Consider creating a new
70    /// snapshot after each evm_revert if you need to revert to the same point multiple times.
71    ///
72    /// Returns the hex-encoded identifier for this snapshot.
73    #[method(name = "snapshot")]
74    async fn evm_snapshot(&self) -> RpcResult<U256>;
75}