#![warn(missing_docs)]
#![feature(auto_traits)]
#![feature(negative_impls)]
use std::str::FromStr;
use anyhow::anyhow;
pub use contract_transcode;
pub use subxt::ext::{codec, sp_core, sp_core::Pair, sp_runtime};
use subxt::{
ext::sp_core::{ed25519, sr25519, H256},
OnlineClient, PolkadotConfig, SubstrateConfig,
};
use crate::api::runtime_types::aleph_runtime::RuntimeCall as Call;
#[cfg(not(feature = "liminal"))]
#[allow(clippy::all)]
#[doc(hidden)]
mod aleph_zero;
#[cfg(feature = "liminal")]
#[path = "./aleph_zero_liminal.rs"]
#[allow(clippy::all)]
#[doc(hidden)]
mod aleph_zero;
mod connections;
pub mod contract;
pub mod pallets;
mod runtime_types;
pub mod utility;
pub mod waiting;
pub use aleph_zero::api;
pub use runtime_types::*;
pub type Balance = u128;
pub type BlockNumber = u32;
pub type SessionCount = u32;
pub type SessionIndex = u32;
pub type EraIndex = u32;
pub type Version = u32;
pub const MILLISECS_PER_BLOCK: u64 = 1000;
pub type AlephKeyPair = ed25519::Pair;
pub type RawKeyPair = sr25519::Pair;
pub type AccountId = subxt::ext::sp_core::crypto::AccountId32;
pub type CodeHash = H256;
pub type BlockHash = H256;
pub type TxHash = H256;
pub type SubxtClient = OnlineClient<AlephConfig>;
pub use connections::{
AsConnection, AsSigned, Connection, ConnectionApi, RootConnection, SignedConnection,
SignedConnectionApi, SudoCall, TxInfo,
};
type AlephConfig = PolkadotConfig;
type ParamsBuilder = subxt::tx::PolkadotExtrinsicParamsBuilder<SubstrateConfig>;
type PairSigner = subxt::tx::PairSigner<AlephConfig, RawKeyPair>;
pub struct KeyPair {
inner: PairSigner,
}
impl Clone for KeyPair {
fn clone(&self) -> Self {
KeyPair::new(self.inner.signer().clone())
}
}
impl FromStr for KeyPair {
type Err = anyhow::Error;
fn from_str(s: &str) -> anyhow::Result<Self> {
let pair = sr25519::Pair::from_string(s, None)
.map_err(|e| anyhow!("Can't create pair from seed value: {:?}", e))?;
Ok(KeyPair::new(pair))
}
}
impl KeyPair {
pub fn new(keypair: RawKeyPair) -> Self {
KeyPair {
inner: PairSigner::new(keypair),
}
}
pub fn signer(&self) -> &RawKeyPair {
self.inner.signer()
}
pub fn account_id(&self) -> &AccountId {
self.inner.account_id()
}
}
#[derive(Copy, Clone)]
pub enum TxStatus {
InBlock,
Finalized,
Submitted,
}
pub fn keypair_from_string(seed: &str) -> KeyPair {
let pair = sr25519::Pair::from_string(seed, None).expect("Can't create pair from seed value");
KeyPair::new(pair)
}
pub fn raw_keypair_from_string(seed: &str) -> RawKeyPair {
sr25519::Pair::from_string(seed, None).expect("Can't create pair from seed value")
}
pub fn aleph_keypair_from_string(seed: &str) -> AlephKeyPair {
ed25519::Pair::from_string(seed, None).expect("Can't create pair from seed value")
}
pub fn account_from_keypair<P>(keypair: &P) -> AccountId
where
P: Pair,
AccountId: From<<P as Pair>::Public>,
{
AccountId::from(keypair.public())
}