Skip to content

Commit

Permalink
Merge pull request #24 from Doy-lee/doyle-evm-mining-functionality
Browse files Browse the repository at this point in the history
Add EVM automine and mine functionality
  • Loading branch information
Doy-lee authored Jul 4, 2024
2 parents 0975242 + 41a075a commit b476236
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit b476236

Please sign in to comment.