Skip to content
Snippets Groups Projects
Commit 097361e5 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

WIP generic runtime

parent 8c8f3dc2
No related branches found
No related tags found
No related merge requests found
......@@ -22,3 +22,11 @@ serde_json = "1.0.94"
sp-core = { git = "https://github.com/duniter/substrate", branch = "duniter-substrate-v0.9.32" }
subxt = { git = "https://github.com/duniter/subxt.git", branch = "duniter-substrate-v0.9.32" }
tokio = { version = "1.26.0", features = ["macros"] }
# allows to build gcli with different predefined networks
[features]
default = ["dev"] # default feature is "dev"
dev = []
gdev = []
gtest = []
g1 = []
use crate::{gdev, indexer::*, Client};
use crate::*;
use crate::indexer::*;
use anyhow::{anyhow, Result};
use std::collections::{hash_map, HashMap};
......@@ -31,7 +32,7 @@ impl<'a> IdentityCache<'a> {
.client
.storage()
.fetch(
&gdev::storage().identity().identities(identity_id),
&runtime::storage().identity().identities(identity_id),
Some(parent_hash),
)
.await?
......
use crate::{gdev, indexer::*, Args, Client};
use crate::*;
use crate::indexer::*;
use anyhow::Result;
use sp_core::{sr25519::Pair, H256};
......@@ -7,7 +8,7 @@ use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner};
pub async fn technical_committee_members(client: Client, args: &Args) -> Result<()> {
let parent_hash = client
.storage()
.fetch(&gdev::storage().system().parent_hash(), None)
.fetch(&runtime::storage().system().parent_hash(), None)
.await?
.unwrap();
......@@ -27,7 +28,7 @@ pub async fn technical_committee_members(client: Client, args: &Args) -> Result<
for account_id in client
.storage()
.fetch(
&gdev::storage().technical_committee().members(),
&runtime::storage().technical_committee().members(),
Some(parent_hash),
)
.await?
......@@ -45,7 +46,7 @@ pub async fn technical_committee_members(client: Client, args: &Args) -> Result<
client
.storage()
.fetch(
&gdev::storage().identity().identity_index_of(&account_id),
&runtime::storage().identity().identity_index_of(&account_id),
Some(parent_hash),
)
.await
......@@ -66,14 +67,14 @@ pub async fn technical_committee_members(client: Client, args: &Args) -> Result<
pub async fn technical_committee_proposals(client: Client) -> Result<()> {
let parent_hash = client
.storage()
.fetch(&gdev::storage().system().parent_hash(), None)
.fetch(&runtime::storage().system().parent_hash(), None)
.await?
.unwrap();
let mut proposals_iter = client
.storage()
.iter(
gdev::storage()
runtime::storage()
.technical_committee()
.proposal_of(H256::default()),
10,
......@@ -99,7 +100,7 @@ pub async fn technical_committee_vote(
client
.tx()
.sign_and_submit_then_watch(
&gdev::tx()
&runtime::tx()
.technical_committee()
.vote(proposal_hash, proposal_index, vote),
&PairSigner::new(pair),
......
use crate::{cache, gdev, indexer::*, Args, Client};
use crate::*;
use crate::indexer::*;
use anyhow::Result;
use futures::join;
......@@ -16,11 +17,11 @@ pub async fn monitor_expirations(
let parent_hash = client
.storage()
.fetch(&gdev::storage().system().parent_hash(), None)
.fetch(&runtime::storage().system().parent_hash(), None)
.await?
.unwrap();
let addr_current_block = gdev::storage().system().number();
let addr_current_session = gdev::storage().session().current_index();
let addr_current_block = runtime::storage().system().number();
let addr_current_session = runtime::storage().session().current_index();
let (current_block, current_session) = join!(
client
.storage()
......@@ -51,7 +52,7 @@ pub async fn monitor_expirations(
let mut must_rotate_keys_before_iter = client
.storage()
.iter(
gdev::storage()
runtime::storage()
.authority_members()
.must_rotate_keys_before(0),
10,
......@@ -85,7 +86,7 @@ pub async fn monitor_expirations(
let mut basic_certs_iter = client
.storage()
.iter(
gdev::storage().cert().storage_certs_removable_on(0),
runtime::storage().cert().storage_certs_removable_on(0),
10,
Some(parent_hash),
)
......@@ -101,7 +102,7 @@ pub async fn monitor_expirations(
let mut smith_certs_iter = client
.storage()
.iter(
gdev::storage().smith_cert().storage_certs_removable_on(0),
runtime::storage().smith_cert().storage_certs_removable_on(0),
10,
Some(parent_hash),
)
......@@ -143,7 +144,7 @@ pub async fn monitor_expirations(
let mut basic_membership_iter = client
.storage()
.iter(
gdev::storage().membership().memberships_expire_on(0),
runtime::storage().membership().memberships_expire_on(0),
10,
Some(parent_hash),
)
......@@ -162,7 +163,7 @@ pub async fn monitor_expirations(
let mut smith_membership_iter = client
.storage()
.iter(
gdev::storage().smith_membership().memberships_expire_on(0),
runtime::storage().smith_membership().memberships_expire_on(0),
10,
Some(parent_hash),
)
......
use crate::*;
use crate::indexer::*;
use crate::gdev::runtime_types::common_runtime::entities::IdtyData;
use crate::gdev::runtime_types::pallet_identity::types::*;
use crate::runtime::runtime_types::common_runtime::entities::IdtyData;
use crate::runtime::runtime_types::pallet_identity::types::*;
use anyhow::{anyhow, Result};
use sp_core::{crypto::AccountId32, sr25519::Pair};
use std::str::FromStr;
......@@ -85,7 +85,7 @@ pub async fn get_idty_index_by_account_id(
Ok(client
.storage()
.fetch(
&gdev::storage().identity().identity_index_of(account_id),
&runtime::storage().identity().identity_index_of(account_id),
None,
)
.await?)
......@@ -97,7 +97,7 @@ pub async fn get_identity_by_index(
) -> Result<Option<IdtyValue<u32, AccountId32, IdtyData>>> {
Ok(client
.storage()
.fetch(&gdev::storage().identity().identities(idty_index), None)
.fetch(&runtime::storage().identity().identities(idty_index), None)
.await?)
}
......@@ -105,7 +105,7 @@ pub async fn create_identity(pair: Pair, client: Client, target: AccountId32) ->
Ok(client
.tx()
.sign_and_submit_then_watch(
&gdev::tx().identity().create_identity(target),
&runtime::tx().identity().create_identity(target),
&PairSigner::new(pair),
BaseExtrinsicParamsBuilder::new(),
)
......@@ -116,7 +116,7 @@ pub async fn confirm_identity(pair: Pair, client: Client, name: String) -> Resul
Ok(client
.tx()
.sign_and_submit_then_watch(
&gdev::tx().identity().confirm_identity(name),
&runtime::tx().identity().confirm_identity(name),
&PairSigner::new(pair),
BaseExtrinsicParamsBuilder::new(),
)
......
use crate::{gdev, Client, GdevConfig};
use crate::*;
use anyhow::{anyhow, Result};
use sp_core::{crypto::AccountId32, sr25519::Pair, DeriveJunction, Pair as _};
......@@ -36,7 +36,7 @@ pub async fn repart(
if let Some(pair_i_account) = client
.storage()
.fetch(
&gdev::storage().system().account(&pair_i.public().into()),
&runtime::storage().system().account(&pair_i.public().into()),
None,
)
.await?
......@@ -51,7 +51,7 @@ pub async fn repart(
pub async fn spam_roll(pair: Pair, client: Client, actual_repart: usize) -> Result<()> {
let mut nonce = 0;
let mut pairs =
Vec::<(PairSigner<GdevConfig, Pair>, AccountId32)>::with_capacity(actual_repart);
Vec::<(PairSigner<Runtime, Pair>, AccountId32)>::with_capacity(actual_repart);
for i in 0..actual_repart {
let pair_i = pair
.derive(std::iter::once(DeriveJunction::hard::<u32>(i as u32)), None)
......@@ -68,7 +68,7 @@ pub async fn spam_roll(pair: Pair, client: Client, actual_repart: usize) -> Resu
let watcher = client
.tx()
.create_signed_with_nonce(
&gdev::tx().balances().transfer(MultiAddress::Id(dest), 1),
&runtime::tx().balances().transfer(MultiAddress::Id(dest), 1),
&pairs[i].0,
nonce,
BaseExtrinsicParamsBuilder::new(),
......@@ -83,7 +83,7 @@ pub async fn spam_roll(pair: Pair, client: Client, actual_repart: usize) -> Resu
let watcher = client
.tx()
.sign_and_submit_then_watch(
&gdev::tx().balances().transfer(MultiAddress::Id(dest), 1),
&runtime::tx().balances().transfer(MultiAddress::Id(dest), 1),
&pairs[actual_repart - 1].0,
BaseExtrinsicParamsBuilder::new(),
)
......
use crate::{gdev, Client};
use crate::*;
use anyhow::Result;
use sp_core::{crypto::AccountId32, sr25519::Pair};
......@@ -13,7 +13,7 @@ pub async fn create_oneshot_account(
client
.tx()
.sign_and_submit_then_watch(
&gdev::tx()
&runtime::tx()
.oneshot_account()
.create_oneshot_account(dest.into(), balance),
&PairSigner::new(pair),
......@@ -32,20 +32,20 @@ pub async fn consume_oneshot_account(
) -> Result<()> {
let number = client
.storage()
.fetch(&gdev::storage().system().number(), None)
.fetch(&runtime::storage().system().number(), None)
.await?
.unwrap();
client
.tx()
.sign_and_submit_then_watch(
&gdev::tx().oneshot_account().consume_oneshot_account(
&runtime::tx().oneshot_account().consume_oneshot_account(
number,
if dest_oneshot {
gdev::runtime_types::pallet_oneshot_account::types::Account::Oneshot(
runtime::runtime_types::pallet_oneshot_account::types::Account::Oneshot(
dest.into(),
)
} else {
gdev::runtime_types::pallet_oneshot_account::types::Account::Normal(dest.into())
runtime::runtime_types::pallet_oneshot_account::types::Account::Normal(dest.into())
},
),
&PairSigner::new(pair),
......@@ -67,31 +67,31 @@ pub async fn consume_oneshot_account_with_remaining(
) -> Result<()> {
let number = client
.storage()
.fetch(&gdev::storage().system().number(), None)
.fetch(&runtime::storage().system().number(), None)
.await?
.unwrap();
client
.tx()
.sign_and_submit_then_watch(
&gdev::tx()
&runtime::tx()
.oneshot_account()
.consume_oneshot_account_with_remaining(
number,
if dest_oneshot {
gdev::runtime_types::pallet_oneshot_account::types::Account::Oneshot(
runtime::runtime_types::pallet_oneshot_account::types::Account::Oneshot(
dest.into(),
)
} else {
gdev::runtime_types::pallet_oneshot_account::types::Account::Normal(
runtime::runtime_types::pallet_oneshot_account::types::Account::Normal(
dest.into(),
)
},
if remaining_to_oneshot {
gdev::runtime_types::pallet_oneshot_account::types::Account::Oneshot(
runtime::runtime_types::pallet_oneshot_account::types::Account::Oneshot(
remaining_to.into(),
)
} else {
gdev::runtime_types::pallet_oneshot_account::types::Account::Normal(
runtime::runtime_types::pallet_oneshot_account::types::Account::Normal(
remaining_to.into(),
)
},
......@@ -111,7 +111,7 @@ pub async fn oneshot_account_balance(client: Client, account: AccountId32) -> Re
client
.storage()
.fetch(
&gdev::storage().oneshot_account().oneshot_accounts(&account),
&runtime::storage().oneshot_account().oneshot_accounts(&account),
None
)
.await?
......
use crate::{gdev, Client};
use crate::*;
use anyhow::Result;
use futures::join;
......@@ -6,8 +6,8 @@ use sp_core::{sr25519::Pair, Encode, Pair as _};
pub async fn gen_revoc_doc(api: &Client, pair: &Pair) -> Result<()> {
let account_id: sp_core::crypto::AccountId32 = pair.public().into();
let addr_idty_index = gdev::storage().identity().identity_index_of(&account_id);
let addr_block_hash = gdev::storage().system().block_hash(0);
let addr_idty_index = runtime::storage().identity().identity_index_of(&account_id);
let addr_block_hash = runtime::storage().system().block_hash(0);
let (idty_index, genesis_hash) = join!(
api.storage().fetch(&addr_idty_index, None,),
api.storage().fetch(&addr_block_hash, None)
......
......@@ -22,7 +22,7 @@ pub async fn set_session_keys(pair: Pair, client: Client, session_keys: SessionK
client
.tx()
.sign_and_submit_then_watch(
&gdev::tx()
&runtime::tx()
.authority_members()
.set_session_keys(session_keys),
&PairSigner::new(pair),
......@@ -42,7 +42,7 @@ pub async fn go_online(pair: Pair, client: Client) -> Result<()> {
if client
.storage()
.fetch(
&gdev::storage()
&runtime::storage()
.session()
.next_keys(AccountId32::from(pair.public())),
None,
......@@ -56,7 +56,7 @@ pub async fn go_online(pair: Pair, client: Client) -> Result<()> {
client
.tx()
.sign_and_submit_then_watch(
&gdev::tx().authority_members().go_online(),
&runtime::tx().authority_members().go_online(),
&PairSigner::new(pair),
BaseExtrinsicParamsBuilder::new(),
)
......@@ -69,7 +69,7 @@ pub async fn go_offline(pair: Pair, client: Client) -> Result<()> {
client
.tx()
.sign_and_submit_then_watch(
&gdev::tx().authority_members().go_offline(),
&runtime::tx().authority_members().go_offline(),
&PairSigner::new(pair),
BaseExtrinsicParamsBuilder::new(),
)
......@@ -81,7 +81,7 @@ pub async fn go_offline(pair: Pair, client: Client) -> Result<()> {
pub async fn online(client: Client, args: &Args) -> Result<()> {
let parent_hash = client
.storage()
.fetch(&gdev::storage().system().parent_hash(), None)
.fetch(&runtime::storage().system().parent_hash(), None)
.await?
.unwrap();
......@@ -104,7 +104,7 @@ pub async fn online(client: Client, args: &Args) -> Result<()> {
let online_authorities = client
.storage()
.fetch(
&gdev::storage().authority_members().online_authorities(),
&runtime::storage().authority_members().online_authorities(),
Some(parent_hash),
)
.await?
......@@ -124,7 +124,7 @@ pub async fn online(client: Client, args: &Args) -> Result<()> {
let incoming_authorities = client
.storage()
.fetch(
&gdev::storage().authority_members().incoming_authorities(),
&runtime::storage().authority_members().incoming_authorities(),
Some(parent_hash),
)
.await?
......@@ -144,7 +144,7 @@ pub async fn online(client: Client, args: &Args) -> Result<()> {
let outgoing_authorities = client
.storage()
.fetch(
&gdev::storage().authority_members().outgoing_authorities(),
&runtime::storage().authority_members().outgoing_authorities(),
Some(parent_hash),
)
.await?
......@@ -198,7 +198,7 @@ async fn cert(client: Client, pair: Pair, issuer: u32, receiver: u32) -> Result<
let mut progress = client
.tx()
.sign_and_submit_then_watch(
&gdev::tx().smith_cert().add_cert(issuer, receiver),
&runtime::tx().smith_cert().add_cert(issuer, receiver),
&PairSigner::new(pair),
BaseExtrinsicParamsBuilder::new(),
)
......@@ -222,8 +222,8 @@ async fn cert(client: Client, pair: Pair, issuer: u32, receiver: u32) -> Result<
// get the block events and return if ExtrinsicFailed
let events = in_block.wait_for_success().await?;
// look for the expected event
let new_cert_event = events.find_first::<gdev::smith_cert::events::NewCert>()?;
let renew_cert_event = events.find_first::<gdev::smith_cert::events::RenewedCert>()?;
let new_cert_event = events.find_first::<runtime::smith_cert::events::NewCert>()?;
let renew_cert_event = events.find_first::<runtime::smith_cert::events::RenewedCert>()?;
if let Some(event) = new_cert_event {
println!("{event:?}");
......
use crate::{gdev, Client};
use crate::*;
use anyhow::Result;
use sp_core::{crypto::AccountId32, sr25519::Pair};
......@@ -8,7 +8,7 @@ pub async fn set_key(pair: Pair, client: Client, new_key: AccountId32) -> Result
client
.tx()
.sign_and_submit_then_watch(
&gdev::tx().sudo().set_key(new_key.into()),
&runtime::tx().sudo().set_key(new_key.into()),
&PairSigner::new(pair),
BaseExtrinsicParamsBuilder::new(),
)
......
use crate::{gdev, Client};
use crate::*;
use anyhow::Result;
use sp_core::{crypto::AccountId32, sr25519::Pair};
use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner};
type Call = gdev::runtime_types::gdev_runtime::RuntimeCall;
type BalancesCall = gdev::runtime_types::pallet_balances::pallet::Call;
type Call = runtime::runtime_types::gdev_runtime::RuntimeCall;
type BalancesCall = runtime::runtime_types::pallet_balances::pallet::Call;
pub async fn transfer(
pair: Pair,
......@@ -18,7 +18,7 @@ pub async fn transfer(
client
.tx()
.sign_and_submit_then_watch(
&gdev::tx().balances().transfer(dest.into(), balance),
&runtime::tx().balances().transfer(dest.into(), balance),
&PairSigner::new(pair),
BaseExtrinsicParamsBuilder::new(),
)
......@@ -27,7 +27,7 @@ pub async fn transfer(
client
.tx()
.sign_and_submit_then_watch(
&gdev::tx()
&runtime::tx()
.balances()
.transfer_keep_alive(dest.into(), balance),
&PairSigner::new(pair),
......@@ -60,7 +60,7 @@ pub async fn transfer_multiple(
client
.tx()
.sign_and_submit_then_watch(
&gdev::tx().utility().batch(transactions),
&runtime::tx().utility().batch(transactions),
&PairSigner::new(pair.clone()),
BaseExtrinsicParamsBuilder::new(),
)
......
......@@ -9,16 +9,17 @@ use keys::*;
use sp_core::sr25519::Pair;
use sp_core::H256;
#[cfg(feature = "dev")]
#[subxt::subxt(runtime_metadata_path = "res/metadata.scale")]
pub mod gdev {}
pub mod runtime {}
pub type Client = subxt::OnlineClient<GdevConfig>;
pub type Client = subxt::OnlineClient<Runtime>;
pub type AccountId = subxt::ext::sp_runtime::AccountId32;
pub type TxInBlock = subxt::tx::TxInBlock<GdevConfig, Client>;
pub type TxProgress = subxt::tx::TxProgress<GdevConfig, Client>;
pub type TxInBlock = subxt::tx::TxInBlock<Runtime, Client>;
pub type TxProgress = subxt::tx::TxProgress<Runtime, Client>;
pub enum GdevConfig {}
impl subxt::config::Config for GdevConfig {
pub enum Runtime {}
impl subxt::config::Config for Runtime {
type Index = u32;
type BlockNumber = u32;
type Hash = sp_core::H256;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment