diff --git a/evm_contracts/src/lib.rs b/evm_contracts/src/lib.rs index 712071b1e..ce75d4a76 100644 --- a/evm_contracts/src/lib.rs +++ b/evm_contracts/src/lib.rs @@ -1,29 +1,32 @@ +use std::{str::FromStr, sync::Arc}; + +use anyhow::Error; use ethers::{ contract::abigen, - prelude::{Provider, SignerMiddleware, LocalWallet}, + prelude::{LocalWallet, Provider, SignerMiddleware}, providers::{Middleware, Ws}, signers::Signer, - types::{H160, U256} + types::{H160, U256}, }; use tracing_wasm::WASMLayerConfigBuilder; use wasm_bindgen::prelude::*; -use anyhow::Error; -use std::{str::FromStr, sync::Arc}; - pub mod utils; pub const ONE_WEEK: u64 = 604_800; -// Generate rust bindings to our solidity contract -abigen!(DIDRegistry, "./src/abi/DIDRegistry.json", derives(serde::Deserialize, serde::Serialize)); +// Generate rust bindings to our solidity contract +abigen!( + DIDRegistry, + "./src/abi/DIDRegistry.json", + derives(serde::Deserialize, serde::Serialize) +); type PrototypeMiddleware = SignerMiddleware, LocalWallet>; async fn deploy_registry() -> Result { utils::set_panic_hook(); - - + tracing::debug!( "DIDRegistry ABI {:?}", &serde_wasm_bindgen::to_value(&*DIDREGISTRY_ABI).unwrap(), @@ -41,9 +44,16 @@ async fn deploy_registry() -> Result { let client = Arc::new(SignerMiddleware::new(provider, wallet)); tracing::info!("Deploying contract..."); - - let did_contract = DIDRegistry::deploy(client.clone(), ()).unwrap().send().await.unwrap(); - tracing::info!("🎉Deployment Success!🎉 Deployed contract at address {:?}", did_contract.address()); + + let did_contract = DIDRegistry::deploy(client.clone(), ()) + .unwrap() + .send() + .await + .unwrap(); + tracing::info!( + "🎉Deployment Success!🎉 Deployed contract at address {:?}", + did_contract.address() + ); Ok(format!("{:x}", did_contract.address())) } @@ -54,13 +64,12 @@ pub fn set_logger() { .set_max_level(tracing::Level::INFO) .build(); tracing_wasm::set_as_global_default_with_config(tracing_config); -} - +} #[wasm_bindgen] pub struct Registry { contract: DIDRegistry, - signer: Arc + signer: Arc, } /// The registry. @@ -70,7 +79,9 @@ impl Registry { #[wasm_bindgen(constructor)] pub async fn new() -> Result { // this could be better, but shows how we may accept environment variables from the outside - let registry_address = deploy_registry().await.map_err(|e| JsError::new(&e.to_string()))?; + let registry_address = deploy_registry() + .await + .map_err(|e| JsError::new(&e.to_string()))?; let endpoint = "ws://127.0.0.1:8545"; let provider = Provider::::connect(endpoint).await?; let chain_id = provider.get_chainid().await?; @@ -86,9 +97,14 @@ impl Registry { Ok(Self { contract, signer }) } - + pub async fn set_attribute(&self, attribute: String) -> Result { - let tx = self.contract.set_attribute(self.signer.address(), *b"did:eth some attribute0000000000", attribute.as_bytes().to_vec().into(), U256::from(ONE_WEEK)); + let tx = self.contract.set_attribute( + self.signer.address(), + *b"did:eth some attribute0000000000", + attribute.as_bytes().to_vec().into(), + U256::from(ONE_WEEK), + ); let receipt = tx.send().await?.await?; tracing::info!("Receipt: {receipt:?}"); Ok(format!("{receipt:?}")) diff --git a/evm_contracts/src/utils.rs b/evm_contracts/src/utils.rs index 474a821db..df0bde0d4 100644 --- a/evm_contracts/src/utils.rs +++ b/evm_contracts/src/utils.rs @@ -19,8 +19,10 @@ pub const PHRASE: &str = "stuff inherit faith park genre spread huge knee ecology private marble supreme"; pub fn key(index: u32) -> LocalWallet { - MnemonicBuilder::::default().phrase(PHRASE).index(index).unwrap().build().unwrap() + MnemonicBuilder::::default() + .phrase(PHRASE) + .index(index) + .unwrap() + .build() + .unwrap() } - - -