pub use self::{pair_signer::PairSigner, tx_output::TxOutput};
use crate::{Api, backtrace::Backtrace, config::GearConfig, result::Result};
use sp_core::{Pair as PairT, sr25519::Pair};
use sp_keyring::AccountKeyring;
use sp_runtime::AccountId32;
use std::sync::Arc;
mod calls;
mod pair_signer;
mod rpc;
mod storage;
mod tx_output;
mod utils;
pub type Signer = PairSigner<GearConfig, Pair>;
#[derive(derive_more::Debug, Clone, derive_more::Into, derive_more::AsRef, derive_more::Deref)]
pub struct SignedApi {
#[into]
#[as_ref]
#[deref]
api: Api,
#[debug("<signer>")]
signer: Arc<PairSigner<GearConfig, Pair>>,
nonce: Option<u64>,
backtrace: Backtrace,
}
impl Api {
pub fn signed(self, suri: &str, passwd: Option<&str>) -> Result<SignedApi> {
SignedApi::new(self, suri, passwd)
}
pub fn signed_dev(self, account: AccountKeyring) -> SignedApi {
SignedApi::with_pair(self, account.pair())
}
pub fn signed_as_alice(self) -> SignedApi {
self.signed_dev(AccountKeyring::Alice)
}
}
impl SignedApi {
pub fn with_pair(api: Api, pair: Pair) -> Self {
Self {
api,
signer: PairSigner::new(pair).into(),
nonce: None,
backtrace: Backtrace::default(),
}
}
pub fn new(api: Api, suri: &str, passwd: Option<&str>) -> Result<Self> {
Ok(Self::with_pair(api, Pair::from_string(suri, passwd)?))
}
pub fn unsigned(&self) -> &Api {
&self.api
}
pub fn signer(&self) -> &Signer {
&self.signer
}
pub fn account_id(&self) -> &AccountId32 {
self.signer.account_id()
}
pub fn backtrace(&self) -> &Backtrace {
&self.backtrace
}
pub fn set_nonce(&mut self, nonce: u64) {
self.nonce = Some(nonce);
}
}