Skip to content

Commit

Permalink
fixing fmt issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 committed Nov 9, 2023
1 parent 9541ffb commit dbb19e7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
52 changes: 34 additions & 18 deletions evm_contracts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<Provider<Ws>, LocalWallet>;

async fn deploy_registry() -> Result<String, Error> {
utils::set_panic_hook();



tracing::debug!(
"DIDRegistry ABI {:?}",
&serde_wasm_bindgen::to_value(&*DIDREGISTRY_ABI).unwrap(),
Expand All @@ -41,9 +44,16 @@ async fn deploy_registry() -> Result<String, Error> {
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()))
}
Expand All @@ -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<PrototypeMiddleware>,
signer: Arc<PrototypeMiddleware>
signer: Arc<PrototypeMiddleware>,
}

/// The registry.
Expand All @@ -70,7 +79,9 @@ impl Registry {
#[wasm_bindgen(constructor)]
pub async fn new() -> Result<Registry, JsError> {
// 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::<Ws>::connect(endpoint).await?;
let chain_id = provider.get_chainid().await?;
Expand All @@ -86,9 +97,14 @@ impl Registry {

Ok(Self { contract, signer })
}

pub async fn set_attribute(&self, attribute: String) -> Result<String, JsError> {
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:?}"))
Expand Down
10 changes: 6 additions & 4 deletions evm_contracts/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<English>::default().phrase(PHRASE).index(index).unwrap().build().unwrap()
MnemonicBuilder::<English>::default()
.phrase(PHRASE)
.index(index)
.unwrap()
.build()
.unwrap()
}



0 comments on commit dbb19e7

Please sign in to comment.