Skip to content

Commit

Permalink
Convert the dynamic builder to the more type-secure static one
Browse files Browse the repository at this point in the history
  • Loading branch information
wirednkod committed Oct 8, 2023
1 parent 3807ece commit 4abb7b8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ sha2 = { version = "0.10.2", default-features = false }
hex = "0.4"
sp-core = "22.0.0"
libp2p = { version = "0.52" }
subxt = "0.32.0"
subxt-signer = { version = "0.32.0", features = ["subxt"]}
subxt = "0.32.1"
subxt-signer = { version = "0.32.1", features = ["subxt"]}
Binary file added crates/orchestrator/src/metadata.scale
Binary file not shown.
7 changes: 4 additions & 3 deletions crates/orchestrator/src/network/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ use std::{
str::FromStr,
};

use subxt::{dynamic::Value, OnlineClient, SubstrateConfig};
use subxt::{subxt, dynamic::Value, OnlineClient, SubstrateConfig};
use subxt_signer::{sr25519::Keypair, SecretUri};
use support::fs::FileSystem;

// use crate::generators::key::generate_pair;
// use sp_core::{sr25519, Pair};
use super::node::NetworkNode;
use crate::{shared::types::RegisterParachainOptions, ScopedFilesystem};

#[subxt(runtime_metadata_path = "src/metadata.scale")]
pub mod substrate{}

#[derive(Debug)]
pub struct Parachain {
pub(crate) chain: Option<String>,
Expand Down
8 changes: 4 additions & 4 deletions crates/orchestrator/src/tx_helper/register_para.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use support::fs::FileSystem;

use crate::{shared::types::RegisterParachainOptions, ScopedFilesystem};

#[subxt::subxt(runtime_metadata_path = "src/metadata.scale")]
pub mod substrate{}

pub async fn register(
options: RegisterParachainOptions,
Expand All @@ -32,9 +34,7 @@ pub async fn register(

let api = OnlineClient::<SubstrateConfig>::from_url(options.node_ws_url).await?;

let schedule_para = subxt::dynamic::tx(
"ParasSudoWrapper",
"sudo_schedule_para_initialize",
let schedule_para = substrate::ParasSudoWrapper::sudo_schedule_para_initialize(
vec![
Value::primitive(options.id.into()),
Value::named_composite([
Expand All @@ -51,7 +51,7 @@ pub async fn register(
],
);

let sudo_call = subxt::dynamic::tx("Sudo", "sudo", vec![schedule_para.into_value()]);
let sudo_call = substrate::Sudo::sudo(schedule_para.into_value());

// TODO: uncomment below and fix the sign and submit (and follow afterwards until
// finalized block) to register the parachain
Expand Down
21 changes: 6 additions & 15 deletions crates/orchestrator/src/tx_helper/validator_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,26 @@ use std::str::FromStr;
use subxt::{dynamic::Value, OnlineClient, SubstrateConfig};
use subxt_signer::{sr25519::Keypair, SecretUri};

#[subxt::subxt(runtime_metadata_path = "src/metadata.scale")]
pub mod substrate{}

pub async fn register(
validator_ids: Vec<String>,
node_ws_url: &str,
) -> Result<(), anyhow::Error> {
println!("Registering validators: {:?}", validator_ids);
// get the seed
// let sudo: Keypair;
// if let Some(possible_seed) = options.seed {
// sudo = Keypair::from_seed(possible_seed).expect("seed should return a Keypair.");
// } else {
let uri = SecretUri::from_str("//Alice")?;
let sudo = Keypair::from_uri(&uri)?;
// }
let uri = SecretUri::from_str("//Alice")?;
let sudo = Keypair::from_uri(&uri)?;

println!("pse");
let api = OnlineClient::<SubstrateConfig>::from_url(node_ws_url).await?;
println!("pse connected");

// let bytes: Vec<Value> = validator_ids.iter().map(|id| Value::from_bytes(id)).collect();
// println!("{:?}", bytes);

let register_call = subxt::dynamic::tx(
"ValidatorManager",
"register_validators",
let register_call = substrate::ValidatorManager::register_validators(
vec![Value::unnamed_composite(vec![Value::from_bytes(validator_ids.first().unwrap().as_bytes())])],
);

let sudo_call = subxt::dynamic::tx("Sudo", "sudo", vec![register_call.into_value()]);
let sudo_call = substrate::Sudo::sudo(register_call.into_value());

println!("pse1");
// TODO: uncomment below and fix the sign and submit (and follow afterwards until
Expand Down

0 comments on commit 4abb7b8

Please sign in to comment.