-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(advance-runner)!: get on-chain machine hash
BREAKING CHANGE: adds the PROVIDER_HTTP_ENDPOINT parameter, which is required to validate snapshots. Validation is enabled by default, but can be disabled by setting SNAPSHOT_VALIDATION_ENABLED to false
- Loading branch information
Showing
14 changed files
with
191 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// (c) Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | ||
|
||
use contracts::cartesi_dapp::CartesiDApp; | ||
use rollups_events::{Address, Hash}; | ||
use snafu::{ResultExt, Snafu}; | ||
use state_fold_types::ethers::{ | ||
prelude::ContractError, | ||
providers::{Http, Provider, RetryClient}, | ||
}; | ||
use std::sync::Arc; | ||
|
||
const MAX_RETRIES: u32 = 10; | ||
const INITIAL_BACKOFF: u64 = 1000; | ||
|
||
#[derive(Debug, Snafu)] | ||
pub enum DappContractError { | ||
#[snafu(display("failed to create a json rpc client"))] | ||
CreateRpcClientError { source: url::ParseError }, | ||
|
||
#[snafu(display("failed to obtain hash from dapp contract"))] | ||
ContractError { | ||
source: ContractError<Provider<RetryClient<Http>>>, | ||
}, | ||
} | ||
|
||
pub async fn get_template_hash( | ||
dapp_address: Address, | ||
provider_http_endpoint: String, | ||
) -> Result<Hash, DappContractError> { | ||
let provider = Provider::new_client( | ||
&provider_http_endpoint, | ||
MAX_RETRIES, | ||
INITIAL_BACKOFF, | ||
) | ||
.context(CreateRpcClientSnafu)?; | ||
|
||
let cartesi_dapp = | ||
CartesiDApp::new(dapp_address.inner(), Arc::new(provider)); | ||
|
||
let template_hash = cartesi_dapp | ||
.get_template_hash() | ||
.call() | ||
.await | ||
.context(ContractSnafu)?; | ||
|
||
Ok(Hash::new(template_hash)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.