-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
7 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,21 @@ | ||
use crate::{generated::AuthoringMetaGetter, utils::setup::get_wallets_handler}; | ||
use ethers::types::{Bytes, H160}; | ||
use ethers::types::Bytes; | ||
use once_cell::sync::Lazy; | ||
use tokio::sync::OnceCell; | ||
|
||
static META_GETTER: Lazy<OnceCell<H160>> = Lazy::new(|| OnceCell::new()); | ||
static META_GETTER: Lazy<OnceCell<Bytes>> = Lazy::new(|| OnceCell::new()); | ||
|
||
async fn meta_getter() -> anyhow::Result<H160> { | ||
match authoring_meta_getter_deploy().await { | ||
Ok(address) => Ok(address), | ||
Err(error) => Err(error), | ||
} | ||
async fn meta_getter() -> anyhow::Result<Bytes> { | ||
let deployer = get_wallets_handler().get_client(0).await?; | ||
let contract = AuthoringMetaGetter::deploy(deployer, ())?.send().await?; | ||
Ok(contract.get_authoring_meta().await?) | ||
} | ||
|
||
async fn get_meta_address() -> anyhow::Result<&'static H160> { | ||
pub async fn get_authoring_meta() -> anyhow::Result<&'static Bytes> { | ||
META_GETTER | ||
.get_or_try_init(|| async { meta_getter().await }) | ||
.await | ||
.map_err(|e| e) | ||
} | ||
|
||
async fn authoring_meta_getter_deploy() -> anyhow::Result<H160> { | ||
let deployer = get_wallets_handler().get_client(0).await?; | ||
let contract = AuthoringMetaGetter::deploy(deployer, ())?.send().await?; | ||
Ok(contract.address()) | ||
} | ||
|
||
/// Get the AuthoringMeta bytes to deploy ExpressionDeployers. | ||
pub async fn get_authoring_meta() -> anyhow::Result<Bytes> { | ||
let meta_address = get_meta_address().await?; | ||
let deployer = get_wallets_handler().get_client(0).await?; | ||
|
||
Ok(AuthoringMetaGetter::new(*meta_address, deployer) | ||
.get_authoring_meta() | ||
.await?) | ||
} |