Skip to content
Snippets Groups Projects
  • Benjamin Gallois's avatar
    31a25023
    Upgrade to Polkadot v0.9.42 (!172) · 31a25023
    Benjamin Gallois authored and Hugo Trentesaux's avatar Hugo Trentesaux committed
    * allow clippy needless_pass_by_ref_mut
    
    * fix clippy
    
    °_°
    
    * fix provider behavior
    
    * fix build errors
    
    * change behavior of going below ED
    
    * fix provider initialization
    
    * add mock epoch change
    
    * add session number test
    
    * add session number test
    
    * WIP fix tests
    
    * fix time-based ud test
    
    * update metadata
    
    * FIX apply all fix from flash branch
    
    * partial fix clippy
    
    other suggestions are not legit
    
    * fix metadata and end2end test
    
    * fix build tests
    
    * fix build and clippy
    
    * remove benchmark of upgrade_accounts
    
    this happens in substrate dependency
    I also updated other packages because why not :D
    and I removed a useless implementation in mock
    but the test do not compile with feature runtime benchmarks anyway
    
    * test_total_issuance_vs_monetary_mass
    
    * proofreading comment
    
    * fix total issuance differently
    
    this actually fixes total issuance at genesis
    instead of creating duplicate account data
    
    * fix test scenario
    
    the thing tested here was not the ability to call the function,
    but the impossibility of deleting the account
    
    * add comment to explain test
    
    * fix providers and sufficients counts
    
    * fix initial balance
    
    * fix initial TotalIssuance
    
    * fix clippy warnings and optimization
    
    * fix xtask
    
    * update docs
    
    * add DustHandle
    
    * fix pallets config
    
    * fix tests
    
    * fix pallet_balance genesis config
    
    * wip: fix end2end-test
    
    * fix manual and instant sealing
    
    * fix live-tests
    
    * fix offences after rebase
    
    * generate all weights
    
    * add rust toolchain file
    
    * fix benchmarks
    
    Pallet balances benchmarks need https://github.com/duniter/substrate/commit/c36ab4f32454318a47777b24b6533c44121fc10b because pallet duniter-account add another provider.
    
    * fix babe-worker
    
    * fix subxt dependency
    
    * fix ImplicitCallIndex and Weight::from_ref_time deprecation
    
    * fix consensus_babe dependency
    
    * regenerate weights
    
    Regenerate all weights except for pallet-balance failing on one extrinsic
    
    * workaround pallet_duniter_account
    
    Workaround to be able to pass https://github.com/paritytech/substrate/blob/6ef184e33f6ce0f56999ae84b212ea6148c0624d/frame/balances/src/benchmarking.rs#L271 in the benchmark.
    ExtraFlags is private and Default is always new_logic not suitable for the benchmark.
    
    * wip fix node errors
    
    * wip fix runtime errors
    
    * fix pallet-duniter-account errors
    
    * fix pallet-balance errors
    
    * fix pallet-identity errors
    
    * fix pallet-duniter-account errors
    
    * upgrade Cargo files
    
    * update docs
    31a25023
    History
    Upgrade to Polkadot v0.9.42 (!172)
    Benjamin Gallois authored and Hugo Trentesaux's avatar Hugo Trentesaux committed
    * allow clippy needless_pass_by_ref_mut
    
    * fix clippy
    
    °_°
    
    * fix provider behavior
    
    * fix build errors
    
    * change behavior of going below ED
    
    * fix provider initialization
    
    * add mock epoch change
    
    * add session number test
    
    * add session number test
    
    * WIP fix tests
    
    * fix time-based ud test
    
    * update metadata
    
    * FIX apply all fix from flash branch
    
    * partial fix clippy
    
    other suggestions are not legit
    
    * fix metadata and end2end test
    
    * fix build tests
    
    * fix build and clippy
    
    * remove benchmark of upgrade_accounts
    
    this happens in substrate dependency
    I also updated other packages because why not :D
    and I removed a useless implementation in mock
    but the test do not compile with feature runtime benchmarks anyway
    
    * test_total_issuance_vs_monetary_mass
    
    * proofreading comment
    
    * fix total issuance differently
    
    this actually fixes total issuance at genesis
    instead of creating duplicate account data
    
    * fix test scenario
    
    the thing tested here was not the ability to call the function,
    but the impossibility of deleting the account
    
    * add comment to explain test
    
    * fix providers and sufficients counts
    
    * fix initial balance
    
    * fix initial TotalIssuance
    
    * fix clippy warnings and optimization
    
    * fix xtask
    
    * update docs
    
    * add DustHandle
    
    * fix pallets config
    
    * fix tests
    
    * fix pallet_balance genesis config
    
    * wip: fix end2end-test
    
    * fix manual and instant sealing
    
    * fix live-tests
    
    * fix offences after rebase
    
    * generate all weights
    
    * add rust toolchain file
    
    * fix benchmarks
    
    Pallet balances benchmarks need https://github.com/duniter/substrate/commit/c36ab4f32454318a47777b24b6533c44121fc10b because pallet duniter-account add another provider.
    
    * fix babe-worker
    
    * fix subxt dependency
    
    * fix ImplicitCallIndex and Weight::from_ref_time deprecation
    
    * fix consensus_babe dependency
    
    * regenerate weights
    
    Regenerate all weights except for pallet-balance failing on one extrinsic
    
    * workaround pallet_duniter_account
    
    Workaround to be able to pass https://github.com/paritytech/substrate/blob/6ef184e33f6ce0f56999ae84b212ea6148c0624d/frame/balances/src/benchmarking.rs#L271 in the benchmark.
    ExtraFlags is private and Default is always new_logic not suitable for the benchmark.
    
    * wip fix node errors
    
    * wip fix runtime errors
    
    * fix pallet-duniter-account errors
    
    * fix pallet-balance errors
    
    * fix pallet-identity errors
    
    * fix pallet-duniter-account errors
    
    * upgrade Cargo files
    
    * update docs
identity.rs 3.71 KiB
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Substrate-Libre-Currency is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.

use super::gdev;
use super::gdev::runtime_types::pallet_identity;
use super::*;
use crate::DuniterWorld;
use sp_keyring::AccountKeyring;
use subxt::tx::PairSigner;

type BlockNumber = u32;
type AccountId = subxt::utils::AccountId32;
type IdtyData = gdev::runtime_types::common_runtime::entities::IdtyData;
type IdtyValue =
    gdev::runtime_types::pallet_identity::types::IdtyValue<BlockNumber, AccountId, IdtyData>;

// submit extrinsics

pub async fn create_identity(
    client: &Client,
    from: AccountKeyring,
    to: AccountKeyring,
) -> Result<()> {
    let from = PairSigner::new(from.pair());
    let to = to.to_account_id();

    let _events = create_block_with_extrinsic(
        client,
        client
            .tx()
            .create_signed(
                &gdev::tx().identity().create_identity(to.into()),
                &from,
                BaseExtrinsicParamsBuilder::new(),
            )
            .await?,
    )
    .await?;

    Ok(())
}

pub async fn confirm_identity(client: &Client, from: AccountKeyring, pseudo: String) -> Result<()> {
    let from = PairSigner::new(from.pair());

    let _events = create_block_with_extrinsic(
        client,
        client
            .tx()
            .create_signed(
                &gdev::tx().identity().confirm_identity(pseudo),
                &from,
                BaseExtrinsicParamsBuilder::new(),
            )
            .await?,
    )
    .await?;

    Ok(())
}

pub async fn validate_identity(client: &Client, from: AccountKeyring, to: u32) -> Result<()> {
    let from = PairSigner::new(from.pair());

    let _events = create_block_with_extrinsic(
        client,
        client
            .tx()
            .create_signed(
                &gdev::tx().identity().validate_identity(to),
                &from,
                BaseExtrinsicParamsBuilder::new(),
            )
            .await
            .unwrap(),
    )
    .await
    .unwrap();

    Ok(())
}

// get identity index from account keyring name
pub async fn get_identity_index(world: &DuniterWorld, account: String) -> Result<u32> {
    let account: AccountId = AccountKeyring::from_str(&account)
        .expect("unknown account")
        .to_account_id()
        .into();

    let identity_index = world
        .read(&gdev::storage().identity().identity_index_of(&account))
        .await
        .await?
        .ok_or_else(|| anyhow::anyhow!("identity {} has no associated index", account))
        .unwrap();

    Ok(identity_index)
}
// get identity value from account keyring name
pub async fn get_identity_value(world: &DuniterWorld, account: String) -> Result<IdtyValue> {
    let identity_index = get_identity_index(world, account).await.unwrap();

    let identity_value = world
        .read(&gdev::storage().identity().identities(identity_index))
        .await
        .await?
        .ok_or_else(|| {
            anyhow::anyhow!(
                "indentity index {} does not have associated value",
                identity_index
            )
        })?;

    Ok(identity_value)
}