Skip to content

Commit

Permalink
Add EVM automine and mine functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Doy-lee committed Jun 19, 2024
1 parent b4893cd commit f20a07f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
15 changes: 12 additions & 3 deletions include/ethyl/provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,20 @@ struct Provider {
std::string callReadFunction(const ReadCallData& callData, std::string_view blockNumber = "latest");
std::string callReadFunction(const ReadCallData& callData, uint64_t blockNumberInt);

uint32_t getNetworkChainId();
uint32_t getNetworkChainId();
std::string evm_snapshot();
bool evm_revert(std::string_view snapshotId);

uint64_t evm_increaseTime(std::chrono::seconds seconds);
// 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();

bool evm_revert(std::string_view snapshotId);
uint64_t evm_increaseTime(std::chrono::seconds seconds);

std::optional<nlohmann::json> getTransactionByHash(std::string_view transactionHash);
std::optional<nlohmann::json> getTransactionReceipt(std::string_view transactionHash);
Expand Down
25 changes: 25 additions & 0 deletions src/provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,31 @@ std::string Provider::evm_snapshot() {
throw std::runtime_error("Unable to create snapshot");
}

bool Provider::evm_setAutomine(bool enable) {
nlohmann::json params = nlohmann::json::array();
params.push_back(enable);
cpr::Response response = makeJsonRpcRequest("evm_setAutomine", params, connectTimeout);

if (response.status_code == 200) {
nlohmann::json responseJson = nlohmann::json::parse(response.text);
return !responseJson["result"].is_null();
}

throw std::runtime_error("Unable to set evm_setAutomine value");
}

bool Provider::evm_mine() {
nlohmann::json params = nlohmann::json::array();
cpr::Response response = makeJsonRpcRequest("evm_mine", params, connectTimeout);

if (response.status_code == 200) {
nlohmann::json responseJson = nlohmann::json::parse(response.text);
return !responseJson["result"].is_null();
}

throw std::runtime_error("Unable to evm_mine");
}

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

0 comments on commit f20a07f

Please sign in to comment.