Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[companion] add reexports needed by murmur-api #16

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 23 additions & 24 deletions lib/src/bin/murmur/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -53,7 +49,7 @@ struct WalletCreationDetails {
#[arg(long, short)]
seed: String,
#[clap(long, short)]
validity: u32
validity: u32,
}

#[derive(Parser)]
Expand All @@ -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)]
Expand All @@ -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
Expand Down Expand Up @@ -113,7 +109,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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
Expand All @@ -130,10 +127,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.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,
Expand All @@ -149,12 +146,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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(())
Expand All @@ -163,8 +162,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// read an MMR from a file
fn load_mmr_store(path: &str) -> Result<MurmurStore, CLIError> {
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)
}

Expand Down
34 changes: 17 additions & 17 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
* 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 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,
};
use w3f_bls::{DoublePublicKey, SerializableToBytes, TinyBLS377};
use zeroize::Zeroize;

pub use beefy::{known_payloads, Commitment, Payload};
pub use etf::{
murmur::calls::types::{Create, Proxy},
runtime_types::node_template_runtime::RuntimeCall,
};
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")]
Expand Down Expand Up @@ -66,7 +66,7 @@ pub fn create(
mut ephem_msk: [u8; 32],
block_schedule: Vec<BlockNumber>,
round_pubkey_bytes: Vec<u8>,
) -> Result<(subxt::tx::Payload<Create>, MurmurStore), Error> {
) -> Result<(TxPayload<Create>, MurmurStore), Error> {
let round_pubkey = DoublePublicKey::<TinyBLS377>::from_bytes(&round_pubkey_bytes)
.map_err(|_| Error::InvalidPubkey)?;
let mmr_store = MurmurStore::new::<TinyBLS377, BasicIdBuilder>(
Expand Down Expand Up @@ -107,7 +107,7 @@ pub fn prepare_execute(
when: BlockNumber,
store: MurmurStore,
call: RuntimeCall,
) -> Result<subxt::tx::Payload<Proxy>, Error> {
) -> Result<TxPayload<Proxy>, Error> {
let (proof, commitment, ciphertext, pos) = store.execute(seed.clone(), when, call.encode())?;
seed.zeroize();
let size = proof.mmr_size();
Expand Down Expand Up @@ -210,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,
Expand Down Expand Up @@ -246,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();

Expand Down