From e27ab672a4fae54712fb29148128c1206cb16a3b Mon Sep 17 00:00:00 2001 From: Juan Girini Date: Fri, 4 Oct 2024 13:45:52 +0200 Subject: [PATCH 1/2] feat: add reexports needed by murmur-api --- lib/src/lib.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/src/lib.rs b/lib/src/lib.rs index b814991..bb8db21 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -14,24 +14,23 @@ * limitations under the License. */ -use beefy::{known_payloads, Commitment, Payload}; -use etf::murmur::calls::types::{Create, Proxy}; use etf::runtime_types::{ bounded_collections::bounded_vec::BoundedVec, node_template_runtime::RuntimeCall, }; use murmur_core::types::{Identity, IdentityBuilder}; +use subxt::{ + backend::rpc::RpcClient, client::OnlineClient, config::SubstrateConfig, ext::codec::Encode, +}; +use w3f_bls::{DoublePublicKey, SerializableToBytes, TinyBLS377}; +use zeroize::Zeroize; + +pub use beefy::{known_payloads, Commitment, Payload}; +pub use etf::murmur::calls::types::{Create, Proxy}; pub use murmur_core::{ murmur::{Error, MurmurStore}, types::BlockNumber, }; -use subxt::{ - backend::rpc::RpcClient, - client::OnlineClient, - config::SubstrateConfig, - ext::codec::Encode, -}; -use zeroize::Zeroize; -use w3f_bls::{DoublePublicKey, SerializableToBytes, TinyBLS377}; +pub use subxt::tx::Payload as TxPayload; // Generate an interface that we can use from the node's metadata. #[subxt::subxt(runtime_metadata_path = "artifacts/metadata.scale")] @@ -66,7 +65,7 @@ pub fn create( mut ephem_msk: [u8; 32], block_schedule: Vec, round_pubkey_bytes: Vec, -) -> Result<(subxt::tx::Payload, MurmurStore), Error> { +) -> Result<(TxPayload, MurmurStore), Error> { let round_pubkey = DoublePublicKey::::from_bytes(&round_pubkey_bytes) .map_err(|_| Error::InvalidPubkey)?; let mmr_store = MurmurStore::new::( @@ -107,7 +106,7 @@ pub fn prepare_execute( when: BlockNumber, store: MurmurStore, call: RuntimeCall, -) -> Result, Error> { +) -> Result, Error> { let (proof, commitment, ciphertext, pos) = store.execute(seed.clone(), when, call.encode())?; seed.zeroize(); let size = proof.mmr_size(); From fa8279edf30c6efc58db952a29ce0155dffbeaa9 Mon Sep 17 00:00:00 2001 From: Juan Girini Date: Mon, 7 Oct 2024 13:32:17 +0200 Subject: [PATCH 2/2] chore: merge and fix conflicts --- lib/src/bin/murmur/main.rs | 47 +++++++++++++++++++------------------- lib/src/lib.rs | 13 ++++++----- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/lib/src/bin/murmur/main.rs b/lib/src/bin/murmur/main.rs index d70a385..a945986 100644 --- a/lib/src/bin/murmur/main.rs +++ b/lib/src/bin/murmur/main.rs @@ -13,21 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -use subxt_signer::sr25519::dev; -use std::fs::File; -use std::time::Instant; use clap::{Parser, Subcommand}; -use thiserror::Error; -use sp_core::crypto::Ss58Codec; use murmur_lib::{ - etf, - etf::runtime_types::node_template_runtime::RuntimeCall::Balances, - create, - prepare_execute, - idn_connect, - MurmurStore, - BlockNumber, + create, + etf::{self, runtime_types::node_template_runtime::RuntimeCall::Balances}, + idn_connect, prepare_execute, BlockNumber, MurmurStore, }; +use sp_core::crypto::Ss58Codec; +use std::fs::File; +use std::time::Instant; +use subxt_signer::sr25519::dev; +use thiserror::Error; /// Command line #[derive(Parser)] @@ -53,7 +49,7 @@ struct WalletCreationDetails { #[arg(long, short)] seed: String, #[clap(long, short)] - validity: u32 + validity: u32, } #[derive(Parser)] @@ -65,7 +61,7 @@ struct WalletExecuteDetails { #[arg(long, short)] to: String, #[arg(short, long, value_parser = clap::value_parser!(u128))] - amount: u128 + amount: u128, } #[derive(Error, Debug)] @@ -81,7 +77,7 @@ pub enum CLIError { #[error("something went wrong while executing the MMR wallet")] MurmurExecutionFailed, #[error("the murmur store is corrupted or empty")] - CorruptedMurmurStore + CorruptedMurmurStore, } /// the mmr_store file location @@ -113,7 +109,8 @@ async fn main() -> Result<(), Box> { ephem_msk, schedule, round_pubkey_bytes, - ).map_err(|_| CLIError::MurmurCreationFailed)?; + ) + .map_err(|_| CLIError::MurmurCreationFailed)?; // 3. add to storage write_mmr_store(mmr_store.clone(), MMR_STORE_FILEPATH); // sign and send the call @@ -130,10 +127,10 @@ async fn main() -> Result<(), Box> { .map_err(|_| CLIError::InvalidRecipient)?; let bytes: &[u8] = from_ss58.as_ref(); - let from_ss58_sized: [u8;32] = bytes.try_into() - .map_err(|_| CLIError::InvalidRecipient)?; + let from_ss58_sized: [u8; 32] = + bytes.try_into().map_err(|_| CLIError::InvalidRecipient)?; let to = subxt::utils::AccountId32::from(from_ss58_sized); - + let balance_transfer_call = Balances(etf::balances::Call::transfer_allow_death { dest: subxt::utils::MultiAddress::<_, u32>::from(to), value: args.amount, @@ -149,12 +146,14 @@ async fn main() -> Result<(), Box> { target_block_number, store, balance_transfer_call, - ).map_err(|_| CLIError::MurmurExecutionFailed)?; + ) + .map_err(|_| CLIError::MurmurExecutionFailed)?; // submit the tx using alice to sign it - let _result = client.tx() + let _result = client + .tx() .sign_and_submit_then_watch_default(&tx, &dev::alice()) .await; - }, + } } println!("Elapsed time: {:.2?}", before.elapsed()); Ok(()) @@ -163,8 +162,8 @@ async fn main() -> Result<(), Box> { /// read an MMR from a file fn load_mmr_store(path: &str) -> Result { let mmr_store_file = File::open(path).expect("Unable to open file"); - let data: MurmurStore = serde_cbor::from_reader(mmr_store_file) - .map_err(|_| CLIError::CorruptedMurmurStore)?; + let data: MurmurStore = + serde_cbor::from_reader(mmr_store_file).map_err(|_| CLIError::CorruptedMurmurStore)?; Ok(data) } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index bb8db21..fbed771 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -14,9 +14,7 @@ * limitations under the License. */ -use etf::runtime_types::{ - bounded_collections::bounded_vec::BoundedVec, node_template_runtime::RuntimeCall, -}; +use etf::runtime_types::bounded_collections::bounded_vec::BoundedVec; use murmur_core::types::{Identity, IdentityBuilder}; use subxt::{ backend::rpc::RpcClient, client::OnlineClient, config::SubstrateConfig, ext::codec::Encode, @@ -25,7 +23,10 @@ use w3f_bls::{DoublePublicKey, SerializableToBytes, TinyBLS377}; use zeroize::Zeroize; pub use beefy::{known_payloads, Commitment, Payload}; -pub use etf::murmur::calls::types::{Create, Proxy}; +pub use etf::{ + murmur::calls::types::{Create, Proxy}, + runtime_types::node_template_runtime::RuntimeCall, +}; pub use murmur_core::{ murmur::{Error, MurmurStore}, types::BlockNumber, @@ -209,7 +210,7 @@ mod tests { let ephem_msk = [1; 32]; let block_schedule = vec![1, 2, 3, 4, 5, 6, 7]; let double_public_bytes = murmur_test_utils::get_dummy_beacon_pubkey(); - let (call, mmr_store) = create( + let (_call, mmr_store) = create( name.clone(), seed.clone(), ephem_msk, @@ -245,7 +246,7 @@ mod tests { ) .unwrap(); - let (proof, commitment, ciphertext, pos) = mmr_store + let (proof, commitment, ciphertext, _pos) = mmr_store .execute(seed.clone(), 1, balance_transfer_call_2.encode()) .unwrap();