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

Add EVM automine and mine functionality #24

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/ethyl/provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ struct Provider : public std::enable_shared_from_this<Provider> {
void evm_snapshot_async(json_result_callback cb);
bool evm_revert(std::string_view snapshotId);

// Enables or disables, based on the single boolean argument, the automatic
// mining of new blocks with each new transaction submitted to the network.
// You can use hardhat_getAutomine to get the current value.
bool evm_setAutomine(bool enable);

// Force a block to be mined. Takes no parameters. Mines a block independent
// of whether or not mining is started or stopped.
bool evm_mine();
uint64_t evm_increaseTime(std::chrono::seconds seconds);

std::optional<nlohmann::json> getTransactionByHash(std::string_view transactionHash);
Expand Down
12 changes: 12 additions & 0 deletions src/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,18 @@ void Provider::evm_snapshot_async(json_result_callback cb) {
makeJsonRpcRequest("evm_snapshot", params, std::move(cb));
}

bool Provider::evm_setAutomine(bool enable) {
nlohmann::json params = nlohmann::json::array();
params.push_back(enable);
std::optional<nlohmann::json> result = makeJsonRpcRequest("evm_setAutomine", params);
return result.has_value();
}

bool Provider::evm_mine() {
std::optional<nlohmann::json> result = makeJsonRpcRequest("evm_mine", nlohmann::json::array());
return result.has_value();
}

bool Provider::evm_revert(std::string_view snapshotId) {
nlohmann::json params = nlohmann::json::array();
params.push_back(snapshotId);
Expand Down
Loading