Skip to content
Snippets Groups Projects
Verified Commit d8ba05d3 authored by Pascal Engélibert's avatar Pascal Engélibert :bicyclist:
Browse files

feat: create-identity, confirm-identity

parent 264e9b72
No related branches found
No related tags found
No related merge requests found
...@@ -29,8 +29,8 @@ pub async fn monitor_expirations( ...@@ -29,8 +29,8 @@ pub async fn monitor_expirations(
.storage() .storage()
.fetch(&addr_current_session, Some(parent_hash),) .fetch(&addr_current_session, Some(parent_hash),)
); );
let current_block = current_block?.unwrap(); let current_block = current_block?.unwrap_or_default();
let current_session = current_session?.unwrap(); let current_session = current_session?.unwrap_or_default();
let end_block = current_block + blocks; let end_block = current_block + blocks;
let end_session = current_session + sessions; let end_session = current_session + sessions;
...@@ -152,6 +152,9 @@ pub async fn monitor_expirations( ...@@ -152,6 +152,9 @@ pub async fn monitor_expirations(
while let Some((k, v)) = basic_membership_iter.next().await? { while let Some((k, v)) = basic_membership_iter.next().await? {
let block_number = u32::from_le_bytes(k.as_ref()[40..44].try_into().unwrap()); let block_number = u32::from_le_bytes(k.as_ref()[40..44].try_into().unwrap());
if block_number < end_block { if block_number < end_block {
if block_number < current_block {
dbg!((block_number, current_block));
}
basic_memberships.insert(block_number - current_block, v); basic_memberships.insert(block_number - current_block, v);
} }
} }
......
use crate::{gdev, indexer::*, Args, Client}; use crate::{gdev, indexer::*, Args, Client};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use sp_core::crypto::AccountId32; use sp_core::{crypto::AccountId32, sr25519::Pair};
use std::str::FromStr; use std::str::FromStr;
use subxt::tx::{BaseExtrinsicParamsBuilder, PairSigner};
pub async fn get_identity( pub async fn get_identity(
client: Client, client: Client,
...@@ -87,3 +88,29 @@ pub async fn get_identity( ...@@ -87,3 +88,29 @@ pub async fn get_identity(
Ok(()) Ok(())
} }
pub async fn create_identity(pair: Pair, client: Client, target: AccountId32) -> Result<()> {
client
.tx()
.sign_and_submit_then_watch(
&gdev::tx().identity().create_identity(target),
&PairSigner::new(pair),
BaseExtrinsicParamsBuilder::new(),
)
.await?;
Ok(())
}
pub async fn confirm_identity(pair: Pair, client: Client, name: String) -> Result<()> {
client
.tx()
.sign_and_submit_then_watch(
&gdev::tx().identity().confirm_identity(name),
&PairSigner::new(pair),
BaseExtrinsicParamsBuilder::new(),
)
.await?;
Ok(())
}
...@@ -82,6 +82,18 @@ pub struct Args { ...@@ -82,6 +82,18 @@ pub struct Args {
#[derive(Debug, clap::Subcommand)] #[derive(Debug, clap::Subcommand)]
pub enum Subcommand { pub enum Subcommand {
/// Confirm an identity
///
/// To be called by the certified not-yet-member account, to become member.
ConfirmIdentity {
name: String,
},
/// Create and certify an identity
///
/// Caller must be member, and the target account must exist.
CreateIdentity {
target: sp_core::crypto::AccountId32,
},
CreateOneshot { CreateOneshot {
balance: u64, balance: u64,
dest: sp_core::crypto::AccountId32, dest: sp_core::crypto::AccountId32,
...@@ -196,6 +208,36 @@ async fn main() -> Result<()> { ...@@ -196,6 +208,36 @@ async fn main() -> Result<()> {
}*/ }*/
match args.subcommand { match args.subcommand {
Subcommand::ConfirmIdentity { name } => {
commands::identity::confirm_identity(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
Client::from_url(&args.url).await.unwrap(),
name,
)
.await?
}
Subcommand::CreateIdentity { target } => {
commands::identity::create_identity(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
Client::from_url(&args.url).await.unwrap(),
target,
)
.await?
}
Subcommand::CreateOneshot { balance, dest } => { Subcommand::CreateOneshot { balance, dest } => {
commands::oneshot::create_oneshot_account( commands::oneshot::create_oneshot_account(
get_keys( get_keys(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment