mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +00:00
New substrate signing API, srml -> paint rename (#33)
* Update jsonrpc to align with substrate * Update to new substrate signing * Default to MultiSignature * Add missing event type sizes * Rename TakeFees check to ChargeTransactionPayment * Fix extrinsic Signature * Ignore AuthorityList type size * Rename srml to paint (#32)
This commit is contained in:
+6
-6
@@ -19,15 +19,15 @@ futures = "0.1.28"
|
||||
jsonrpc-core-client = { version = "14.0", features = ["ws"] }
|
||||
num-traits = { version = "0.2", default-features = false }
|
||||
parity-scale-codec = { version = "1.0", default-features = false, features = ["derive", "full"] }
|
||||
runtime_metadata = { git = "https://github.com/paritytech/substrate/", package = "srml-metadata" }
|
||||
runtime_support = { git = "https://github.com/paritytech/substrate/", package = "srml-support" }
|
||||
runtime_metadata = { git = "https://github.com/paritytech/substrate/", package = "paint-metadata" }
|
||||
runtime_support = { git = "https://github.com/paritytech/substrate/", package = "paint-support" }
|
||||
runtime_primitives = { git = "https://github.com/paritytech/substrate/", package = "sr-primitives" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
sr-version = { git = "https://github.com/paritytech/substrate/", package = "sr-version" }
|
||||
srml-system = { git = "https://github.com/paritytech/substrate/", package = "srml-system" }
|
||||
srml-balances = { git = "https://github.com/paritytech/substrate/", package = "srml-balances" }
|
||||
srml-contracts = { git = "https://github.com/paritytech/substrate/", package = "srml-contracts" }
|
||||
srml-indices = { git = "https://github.com/paritytech/substrate/", package = "srml-indices" }
|
||||
paint-system = { git = "https://github.com/paritytech/substrate/", package = "paint-system" }
|
||||
paint-balances = { git = "https://github.com/paritytech/substrate/", package = "paint-balances" }
|
||||
paint-contracts = { git = "https://github.com/paritytech/substrate/", package = "paint-contracts" }
|
||||
paint-indices = { git = "https://github.com/paritytech/substrate/", package = "paint-indices" }
|
||||
substrate-rpc-api = { git = "https://github.com/paritytech/substrate/", package = "substrate-rpc-api" }
|
||||
substrate-rpc-primitives = { git = "https://github.com/paritytech/substrate/", package = "substrate-rpc-primitives" }
|
||||
substrate-primitives = { git = "https://github.com/paritytech/substrate/", package = "substrate-primitives" }
|
||||
|
||||
+6
-2
@@ -20,7 +20,7 @@ use crate::{
|
||||
Metadata,
|
||||
MetadataError,
|
||||
},
|
||||
srml::balances::Balances,
|
||||
paint::balances::Balances,
|
||||
System,
|
||||
SystemEvent,
|
||||
};
|
||||
@@ -34,7 +34,7 @@ use parity_scale_codec::{
|
||||
Input,
|
||||
Output,
|
||||
};
|
||||
use srml_system::Phase;
|
||||
use paint_system::Phase;
|
||||
use std::{
|
||||
collections::{
|
||||
HashMap,
|
||||
@@ -113,8 +113,12 @@ impl<T: System + Balances + 'static> TryFrom<Metadata> for EventsDecoder<T> {
|
||||
// Ignore these unregistered types, which are not fixed size primitives
|
||||
decoder.check_missing_type_sizes(vec![
|
||||
"DispatchError",
|
||||
"Result<(), DispatchError>",
|
||||
"OpaqueTimeSlot",
|
||||
"rstd::marker::PhantomData<(AccountId, Event)>",
|
||||
// FIXME: determine type size for the following if necessary/possible
|
||||
"IdentificationTuple",
|
||||
"AuthorityList",
|
||||
])?;
|
||||
Ok(decoder)
|
||||
}
|
||||
|
||||
+18
-12
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::srml::{
|
||||
use crate::paint::{
|
||||
balances::Balances,
|
||||
system::System,
|
||||
};
|
||||
@@ -29,14 +29,18 @@ use runtime_primitives::{
|
||||
SignedPayload,
|
||||
UncheckedExtrinsic,
|
||||
},
|
||||
traits::SignedExtension,
|
||||
traits::{
|
||||
Verify,
|
||||
IdentifyAccount,
|
||||
SignedExtension,
|
||||
},
|
||||
transaction_validity::TransactionValidityError,
|
||||
};
|
||||
use std::marker::PhantomData;
|
||||
use substrate_primitives::Pair;
|
||||
|
||||
/// SignedExtra checks copied from substrate, in order to remove requirement to implement
|
||||
/// substrate's `srml_system::Trait`
|
||||
/// substrate's `paint_system::Trait`
|
||||
|
||||
/// Ensure the runtime version registered in the transaction is the same as at present.
|
||||
///
|
||||
@@ -168,9 +172,9 @@ where
|
||||
/// Require the transactor pay for themselves and maybe include a tip to gain additional priority
|
||||
/// in the queue.
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq, Debug)]
|
||||
pub struct TakeFees<T: Balances>(#[codec(compact)] T::Balance);
|
||||
pub struct ChargeTransactionPayment<T: Balances>(#[codec(compact)] T::Balance);
|
||||
|
||||
impl<T> SignedExtension for TakeFees<T>
|
||||
impl<T> SignedExtension for ChargeTransactionPayment<T>
|
||||
where
|
||||
T: Balances + Send + Sync,
|
||||
{
|
||||
@@ -234,7 +238,7 @@ impl<T: System + Balances + Send + Sync> SignedExtra<T> for DefaultExtra<T> {
|
||||
CheckEra<T>,
|
||||
CheckNonce<T>,
|
||||
CheckWeight<T>,
|
||||
TakeFees<T>,
|
||||
ChargeTransactionPayment<T>,
|
||||
CheckBlockGasLimit<T>,
|
||||
);
|
||||
|
||||
@@ -245,7 +249,7 @@ impl<T: System + Balances + Send + Sync> SignedExtra<T> for DefaultExtra<T> {
|
||||
CheckEra((Era::Immortal, PhantomData), self.genesis_hash),
|
||||
CheckNonce(self.nonce),
|
||||
CheckWeight(PhantomData),
|
||||
TakeFees(<T as Balances>::Balance::default()),
|
||||
ChargeTransactionPayment(<T as Balances>::Balance::default()),
|
||||
CheckBlockGasLimit(PhantomData),
|
||||
)
|
||||
}
|
||||
@@ -265,28 +269,30 @@ impl<T: System + Balances + Send + Sync> SignedExtension for DefaultExtra<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_and_sign<T: System + Send + Sync, C, P, E>(
|
||||
pub fn create_and_sign<T: System + Send + Sync, C, P, S, E>(
|
||||
signer: P,
|
||||
call: C,
|
||||
extra: E,
|
||||
) -> Result<
|
||||
UncheckedExtrinsic<T::Address, C, P::Signature, <E as SignedExtra<T>>::Extra>,
|
||||
UncheckedExtrinsic<T::Address, C, S, <E as SignedExtra<T>>::Extra>,
|
||||
TransactionValidityError,
|
||||
>
|
||||
where
|
||||
P: Pair,
|
||||
P::Public: Into<T::Address>,
|
||||
P::Signature: Codec,
|
||||
S: Verify + Codec + From<P::Signature>,
|
||||
S::Signer: From<P::Public> + IdentifyAccount<AccountId = T::AccountId>,
|
||||
C: Encode,
|
||||
E: SignedExtra<T> + SignedExtension,
|
||||
T::Address: From<T::AccountId>,
|
||||
{
|
||||
let raw_payload = SignedPayload::new(call, extra.extra())?;
|
||||
let signature = raw_payload.using_encoded(|payload| signer.sign(payload));
|
||||
let (call, extra, _) = raw_payload.deconstruct();
|
||||
let account_id = S::Signer::from(signer.public()).into_account();
|
||||
|
||||
Ok(UncheckedExtrinsic::new_signed(
|
||||
call,
|
||||
signer.public().into(),
|
||||
account_id.into(),
|
||||
signature.into(),
|
||||
extra,
|
||||
))
|
||||
|
||||
+46
-37
@@ -32,7 +32,14 @@ use parity_scale_codec::{
|
||||
Codec,
|
||||
Decode,
|
||||
};
|
||||
use runtime_primitives::generic::UncheckedExtrinsic;
|
||||
use runtime_primitives::{
|
||||
generic::UncheckedExtrinsic,
|
||||
traits::{
|
||||
Verify,
|
||||
IdentifyAccount,
|
||||
},
|
||||
MultiSignature,
|
||||
};
|
||||
use sr_version::RuntimeVersion;
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
@@ -61,7 +68,7 @@ use crate::{
|
||||
MapStream,
|
||||
Rpc,
|
||||
},
|
||||
srml::{
|
||||
paint::{
|
||||
balances::Balances,
|
||||
system::{
|
||||
System,
|
||||
@@ -79,25 +86,25 @@ mod extrinsic;
|
||||
mod metadata;
|
||||
mod rpc;
|
||||
mod runtimes;
|
||||
mod srml;
|
||||
mod paint;
|
||||
|
||||
pub use error::Error;
|
||||
pub use events::RawEvent;
|
||||
pub use rpc::ExtrinsicSuccess;
|
||||
pub use runtimes::*;
|
||||
pub use srml::*;
|
||||
pub use paint::*;
|
||||
|
||||
fn connect<T: System>(url: &Url) -> impl Future<Item = Rpc<T>, Error = Error> {
|
||||
ws::connect(url).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// ClientBuilder for constructing a Client.
|
||||
pub struct ClientBuilder<T: System> {
|
||||
_marker: std::marker::PhantomData<T>,
|
||||
pub struct ClientBuilder<T: System, S = MultiSignature> {
|
||||
_marker: std::marker::PhantomData<(T, S)>,
|
||||
url: Option<Url>,
|
||||
}
|
||||
|
||||
impl<T: System> ClientBuilder<T> {
|
||||
impl<T: System, S> ClientBuilder<T, S> {
|
||||
/// Creates a new ClientBuilder.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
@@ -113,7 +120,7 @@ impl<T: System> ClientBuilder<T> {
|
||||
}
|
||||
|
||||
/// Creates a new Client.
|
||||
pub fn build(self) -> impl Future<Item = Client<T>, Error = Error> {
|
||||
pub fn build(self) -> impl Future<Item = Client<T, S>, Error = Error> {
|
||||
let url = self.url.unwrap_or_else(|| {
|
||||
Url::parse("ws://127.0.0.1:9944").expect("Is valid url; qed")
|
||||
});
|
||||
@@ -126,6 +133,7 @@ impl<T: System> ClientBuilder<T> {
|
||||
genesis_hash,
|
||||
metadata,
|
||||
runtime_version,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -133,25 +141,28 @@ impl<T: System> ClientBuilder<T> {
|
||||
}
|
||||
|
||||
/// Client to interface with a substrate node.
|
||||
pub struct Client<T: System> {
|
||||
pub struct Client<T: System, S = MultiSignature> {
|
||||
url: Url,
|
||||
genesis_hash: T::Hash,
|
||||
metadata: Metadata,
|
||||
runtime_version: RuntimeVersion,
|
||||
_marker: PhantomData<fn() -> S>,
|
||||
}
|
||||
|
||||
impl<T: System> Clone for Client<T> {
|
||||
impl<T: System, S> Clone for Client<T, S> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
url: self.url.clone(),
|
||||
genesis_hash: self.genesis_hash.clone(),
|
||||
metadata: self.metadata.clone(),
|
||||
runtime_version: self.runtime_version.clone(),
|
||||
_marker:PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: System + Balances + 'static> Client<T> {
|
||||
impl<T: System + Balances + 'static, S: 'static> Client<T, S>
|
||||
{
|
||||
fn connect(&self) -> impl Future<Item = Rpc<T>, Error = Error> {
|
||||
connect(&self.url)
|
||||
}
|
||||
@@ -234,16 +245,18 @@ impl<T: System + Balances + 'static> Client<T> {
|
||||
&self,
|
||||
signer: P,
|
||||
nonce: Option<T::Index>,
|
||||
) -> impl Future<Item = XtBuilder<T, P>, Error = Error>
|
||||
) -> impl Future<Item = XtBuilder<T, P, S>, Error = Error>
|
||||
where
|
||||
P: Pair,
|
||||
P::Public: Into<T::AccountId> + Into<T::Address>,
|
||||
P::Signature: Codec,
|
||||
S: Verify,
|
||||
S::Signer: From<P::Public> + IdentifyAccount<AccountId = T::AccountId>,
|
||||
{
|
||||
let client = self.clone();
|
||||
let account_id = S::Signer::from(signer.public()).into_account();
|
||||
match nonce {
|
||||
Some(nonce) => Either::A(future::ok(nonce)),
|
||||
None => Either::B(self.account_nonce(signer.public().into())),
|
||||
None => Either::B(self.account_nonce(account_id)),
|
||||
}
|
||||
.map(|nonce| {
|
||||
let genesis_hash = client.genesis_hash.clone();
|
||||
@@ -267,8 +280,8 @@ pub enum Valid {}
|
||||
pub enum Invalid {}
|
||||
|
||||
/// Transaction builder.
|
||||
pub struct XtBuilder<T: System, P, V = Invalid> {
|
||||
client: Client<T>,
|
||||
pub struct XtBuilder<T: System, P, S, V = Invalid> {
|
||||
client: Client<T, S>,
|
||||
nonce: T::Index,
|
||||
runtime_version: RuntimeVersion,
|
||||
genesis_hash: T::Hash,
|
||||
@@ -277,7 +290,7 @@ pub struct XtBuilder<T: System, P, V = Invalid> {
|
||||
marker: PhantomData<fn() -> V>,
|
||||
}
|
||||
|
||||
impl<T: System + Balances + 'static, P, V> XtBuilder<T, P, V>
|
||||
impl<T: System + Balances + 'static, P, S: 'static, V> XtBuilder<T, P, S, V>
|
||||
where
|
||||
P: Pair,
|
||||
{
|
||||
@@ -292,19 +305,19 @@ where
|
||||
}
|
||||
|
||||
/// Sets the nonce to a new value.
|
||||
pub fn set_nonce(&mut self, nonce: T::Index) -> &mut XtBuilder<T, P, V> {
|
||||
pub fn set_nonce(&mut self, nonce: T::Index) -> &mut XtBuilder<T, P, S, V> {
|
||||
self.nonce = nonce;
|
||||
self
|
||||
}
|
||||
|
||||
/// Increment the nonce
|
||||
pub fn increment_nonce(&mut self) -> &mut XtBuilder<T, P, V> {
|
||||
pub fn increment_nonce(&mut self) -> &mut XtBuilder<T, P, S, V> {
|
||||
self.set_nonce(self.nonce() + 1.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the module call to a new value
|
||||
pub fn set_call<F>(&self, module: &'static str, f: F) -> XtBuilder<T, P, Valid>
|
||||
pub fn set_call<F>(&self, module: &'static str, f: F) -> XtBuilder<T, P, S, Valid>
|
||||
where
|
||||
F: FnOnce(ModuleCalls<T, P>) -> Result<Encoded, MetadataError>,
|
||||
{
|
||||
@@ -326,11 +339,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: System + Balances + Send + Sync + 'static, P> XtBuilder<T, P, Valid>
|
||||
impl<T: System + Balances + Send + Sync + 'static, P, S: 'static> XtBuilder<T, P, S, Valid>
|
||||
where
|
||||
P: Pair,
|
||||
P::Public: Into<T::Address>,
|
||||
P::Signature: Codec,
|
||||
S: Verify + Codec + From<P::Signature>,
|
||||
S::Signer: From<P::Public> + IdentifyAccount<AccountId = T::AccountId>,
|
||||
T::Address: From<T::AccountId>,
|
||||
{
|
||||
/// Creates and signs an Extrinsic for the supplied `Call`
|
||||
pub fn create_and_sign(
|
||||
@@ -339,15 +353,11 @@ where
|
||||
UncheckedExtrinsic<
|
||||
T::Address,
|
||||
Encoded,
|
||||
P::Signature,
|
||||
S,
|
||||
<DefaultExtra<T> as SignedExtra<T>>::Extra,
|
||||
>,
|
||||
Error,
|
||||
>
|
||||
where
|
||||
P: Pair,
|
||||
P::Public: Into<T::Address>,
|
||||
P::Signature: Codec,
|
||||
{
|
||||
let signer = self.signer.clone();
|
||||
let account_nonce = self.nonce.clone();
|
||||
@@ -365,7 +375,7 @@ where
|
||||
);
|
||||
|
||||
let extra = extrinsic::DefaultExtra::new(version, account_nonce, genesis_hash);
|
||||
let xt = extrinsic::create_and_sign(signer, call, extra)?;
|
||||
let xt = extrinsic::create_and_sign::<_, _, _, S, _>(signer, call, extra)?;
|
||||
Ok(xt)
|
||||
}
|
||||
|
||||
@@ -405,7 +415,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::srml::{
|
||||
use crate::paint::{
|
||||
balances::{
|
||||
Balances,
|
||||
BalancesStore,
|
||||
@@ -420,7 +430,6 @@ mod tests {
|
||||
use substrate_keyring::AccountKeyring;
|
||||
use substrate_primitives::{
|
||||
storage::StorageKey,
|
||||
Pair,
|
||||
};
|
||||
|
||||
type Index = <Runtime as System>::Index;
|
||||
@@ -444,7 +453,7 @@ mod tests {
|
||||
let signer = AccountKeyring::Alice.pair();
|
||||
let mut xt = rt.block_on(client.xt(signer, None)).unwrap();
|
||||
|
||||
let dest = AccountKeyring::Bob.pair().public();
|
||||
let dest = AccountKeyring::Bob.to_account_id();
|
||||
let transfer = xt
|
||||
.balances(|calls| calls.transfer(dest.clone().into(), 10_000))
|
||||
.submit();
|
||||
@@ -515,7 +524,7 @@ mod tests {
|
||||
fn test_state_read_free_balance() {
|
||||
let (mut rt, client) = test_setup();
|
||||
|
||||
let account = AccountKeyring::Alice.pair().public();
|
||||
let account = AccountKeyring::Alice.to_account_id();
|
||||
rt.block_on(client.free_balance(account.into())).unwrap();
|
||||
}
|
||||
|
||||
@@ -547,11 +556,11 @@ mod tests {
|
||||
let (_, client) = test_setup();
|
||||
|
||||
let balances = client.metadata().module("Balances").unwrap();
|
||||
let dest = substrate_keyring::AccountKeyring::Bob.pair().public();
|
||||
let dest = substrate_keyring::AccountKeyring::Bob.to_account_id();
|
||||
let address: Address = dest.clone().into();
|
||||
let amount: Balance = 10_000;
|
||||
|
||||
let transfer = srml_balances::Call::transfer(address.clone(), amount);
|
||||
let transfer = paint_balances::Call::transfer(address.clone(), amount);
|
||||
let call = node_runtime::Call::Balances(transfer);
|
||||
let call2 = balances
|
||||
.call("transfer", (address, codec::compact(amount)))
|
||||
@@ -559,7 +568,7 @@ mod tests {
|
||||
assert_eq!(call.encode().to_vec(), call2.0);
|
||||
|
||||
let free_balance =
|
||||
<srml_balances::FreeBalance<node_runtime::Runtime>>::hashed_key_for(&dest);
|
||||
<paint_balances::FreeBalance<node_runtime::Runtime>>::hashed_key_for(&dest);
|
||||
let free_balance_key = StorageKey(free_balance);
|
||||
let free_balance_key2 = balances
|
||||
.storage("FreeBalance")
|
||||
@@ -570,7 +579,7 @@ mod tests {
|
||||
assert_eq!(free_balance_key, free_balance_key2);
|
||||
|
||||
let account_nonce =
|
||||
<srml_system::AccountNonce<node_runtime::Runtime>>::hashed_key_for(&dest);
|
||||
<paint_system::AccountNonce<node_runtime::Runtime>>::hashed_key_for(&dest);
|
||||
let account_nonce_key = StorageKey(account_nonce);
|
||||
let account_nonce_key2 = client
|
||||
.metadata()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Implements support for the srml_balances module.
|
||||
//! Implements support for the paint_balances module.
|
||||
use crate::{
|
||||
codec::{
|
||||
compact,
|
||||
@@ -6,7 +6,7 @@ use crate::{
|
||||
},
|
||||
error::Error,
|
||||
metadata::MetadataError,
|
||||
srml::{
|
||||
paint::{
|
||||
system::System,
|
||||
ModuleCalls,
|
||||
},
|
||||
@@ -23,12 +23,14 @@ use runtime_primitives::traits::{
|
||||
MaybeSerialize,
|
||||
Member,
|
||||
SimpleArithmetic,
|
||||
Verify,
|
||||
IdentifyAccount,
|
||||
};
|
||||
use runtime_support::Parameter;
|
||||
use substrate_primitives::Pair;
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// The subset of the `srml_balances::Trait` that a client must implement.
|
||||
/// The subset of the `paint_balances::Trait` that a client must implement.
|
||||
pub trait Balances: System {
|
||||
/// The balance of an account.
|
||||
type Balance: Parameter
|
||||
@@ -43,9 +45,9 @@ pub trait Balances: System {
|
||||
}
|
||||
|
||||
/// Blanket impl for using existing runtime types
|
||||
impl<T: srml_system::Trait + srml_balances::Trait + Debug> Balances for T
|
||||
impl<T: paint_system::Trait + paint_balances::Trait + Debug> Balances for T
|
||||
where
|
||||
<T as srml_system::Trait>::Header: serde::de::DeserializeOwned,
|
||||
<T as paint_system::Trait>::Header: serde::de::DeserializeOwned,
|
||||
{
|
||||
type Balance = T::Balance;
|
||||
}
|
||||
@@ -74,7 +76,7 @@ pub trait BalancesStore {
|
||||
) -> Box<dyn Future<Item = <Self::Balances as Balances>::Balance, Error = Error> + Send>;
|
||||
}
|
||||
|
||||
impl<T: Balances + 'static> BalancesStore for Client<T> {
|
||||
impl<T: Balances + 'static, S: 'static> BalancesStore for Client<T, S> {
|
||||
type Balances = T;
|
||||
|
||||
fn free_balance(
|
||||
@@ -105,23 +107,28 @@ pub trait BalancesXt {
|
||||
type Balances: Balances;
|
||||
/// Keypair type
|
||||
type Pair: Pair;
|
||||
/// Signature type
|
||||
type Signature: Verify;
|
||||
|
||||
/// Create a call for the srml balances module
|
||||
fn balances<F>(&self, f: F) -> XtBuilder<Self::Balances, Self::Pair, Valid>
|
||||
/// Create a call for the paint balances module
|
||||
fn balances<F>(&self, f: F) -> XtBuilder<Self::Balances, Self::Pair, Self::Signature, Valid>
|
||||
where
|
||||
F: FnOnce(
|
||||
ModuleCalls<Self::Balances, Self::Pair>,
|
||||
) -> Result<Encoded, MetadataError>;
|
||||
}
|
||||
|
||||
impl<T: Balances + 'static, P, V> BalancesXt for XtBuilder<T, P, V>
|
||||
impl<T: Balances + 'static, P, S: 'static, V> BalancesXt for XtBuilder<T, P, S, V>
|
||||
where
|
||||
P: Pair,
|
||||
S: Verify,
|
||||
S::Signer: From<P::Public> + IdentifyAccount<AccountId = T::AccountId>,
|
||||
{
|
||||
type Balances = T;
|
||||
type Pair = P;
|
||||
type Signature = S;
|
||||
|
||||
fn balances<F>(&self, f: F) -> XtBuilder<T, P, Valid>
|
||||
fn balances<F>(&self, f: F) -> XtBuilder<T, P, S, Valid>
|
||||
where
|
||||
F: FnOnce(
|
||||
ModuleCalls<Self::Balances, Self::Pair>,
|
||||
@@ -1,11 +1,11 @@
|
||||
//! Implements support for the srml_contracts module.
|
||||
//! Implements support for the paint_contracts module.
|
||||
use crate::{
|
||||
codec::{
|
||||
compact,
|
||||
Encoded,
|
||||
},
|
||||
metadata::MetadataError,
|
||||
srml::{
|
||||
paint::{
|
||||
balances::Balances,
|
||||
system::System,
|
||||
ModuleCalls,
|
||||
@@ -13,24 +13,28 @@ use crate::{
|
||||
Valid,
|
||||
XtBuilder,
|
||||
};
|
||||
use runtime_primitives::traits::{
|
||||
IdentifyAccount,
|
||||
Verify,
|
||||
};
|
||||
use substrate_primitives::Pair;
|
||||
|
||||
/// Gas units are chosen to be represented by u64 so that gas metering
|
||||
/// instructions can operate on them efficiently.
|
||||
pub type Gas = u64;
|
||||
|
||||
/// The subset of the `srml_contracts::Trait` that a client must implement.
|
||||
/// The subset of the `paint_contracts::Trait` that a client must implement.
|
||||
pub trait Contracts: System + Balances {}
|
||||
|
||||
/// Blanket impl for using existing runtime types
|
||||
impl<
|
||||
T: srml_contracts::Trait
|
||||
+ srml_system::Trait
|
||||
+ srml_balances::Trait
|
||||
T: paint_contracts::Trait
|
||||
+ paint_system::Trait
|
||||
+ paint_balances::Trait
|
||||
+ std::fmt::Debug,
|
||||
> Contracts for T
|
||||
where
|
||||
<T as srml_system::Trait>::Header: serde::de::DeserializeOwned,
|
||||
<T as paint_system::Trait>::Header: serde::de::DeserializeOwned,
|
||||
{
|
||||
}
|
||||
|
||||
@@ -40,23 +44,28 @@ pub trait ContractsXt {
|
||||
type Contracts: Contracts;
|
||||
/// Key Pair Type
|
||||
type Pair: Pair;
|
||||
/// Signature type
|
||||
type Signature: Verify;
|
||||
|
||||
/// Create a call for the srml contracts module
|
||||
fn contracts<F>(&self, f: F) -> XtBuilder<Self::Contracts, Self::Pair, Valid>
|
||||
/// Create a call for the paint contracts module
|
||||
fn contracts<F>(&self, f: F) -> XtBuilder<Self::Contracts, Self::Pair, Self::Signature, Valid>
|
||||
where
|
||||
F: FnOnce(
|
||||
ModuleCalls<Self::Contracts, Self::Pair>,
|
||||
) -> Result<Encoded, MetadataError>;
|
||||
}
|
||||
|
||||
impl<T: Contracts + 'static, P, V> ContractsXt for XtBuilder<T, P, V>
|
||||
impl<T: Contracts + 'static, P, S: 'static, V> ContractsXt for XtBuilder<T, P, S, V>
|
||||
where
|
||||
P: Pair,
|
||||
S: Verify,
|
||||
S::Signer: From<P::Public> + IdentifyAccount<AccountId = T::AccountId>,
|
||||
{
|
||||
type Contracts = T;
|
||||
type Pair = P;
|
||||
type Signature = S;
|
||||
|
||||
fn contracts<F>(&self, f: F) -> XtBuilder<T, P, Valid>
|
||||
fn contracts<F>(&self, f: F) -> XtBuilder<T, P, S, Valid>
|
||||
where
|
||||
F: FnOnce(
|
||||
ModuleCalls<Self::Contracts, Self::Pair>,
|
||||
@@ -1,9 +1,9 @@
|
||||
//! Implements support for the srml_system module.
|
||||
//! Implements support for the paint_system module.
|
||||
use crate::{
|
||||
codec::Encoded,
|
||||
error::Error,
|
||||
metadata::MetadataError,
|
||||
srml::{
|
||||
paint::{
|
||||
balances::Balances,
|
||||
ModuleCalls,
|
||||
},
|
||||
@@ -21,6 +21,7 @@ use runtime_primitives::traits::{
|
||||
CheckEqual,
|
||||
Hash,
|
||||
Header,
|
||||
IdentifyAccount,
|
||||
MaybeDisplay,
|
||||
MaybeSerialize,
|
||||
MaybeSerializeDeserialize,
|
||||
@@ -28,13 +29,14 @@ use runtime_primitives::traits::{
|
||||
SimpleArithmetic,
|
||||
SimpleBitOps,
|
||||
StaticLookup,
|
||||
Verify,
|
||||
};
|
||||
use runtime_support::Parameter;
|
||||
use serde::de::DeserializeOwned;
|
||||
use substrate_primitives::Pair;
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// The subset of the `srml_system::Trait` that a client must implement.
|
||||
/// The subset of the `paint::Trait` that a client must implement.
|
||||
pub trait System: 'static + Eq + Clone + Debug {
|
||||
/// Account index (aka nonce) type. This stores the number of previous
|
||||
/// transactions associated with a sender account.
|
||||
@@ -85,7 +87,7 @@ pub trait System: 'static + Eq + Clone + Debug {
|
||||
+ Ord
|
||||
+ Default;
|
||||
|
||||
/// The address type. This instead of `<srml_system::Trait::Lookup as StaticLookup>::Source`.
|
||||
/// The address type. This instead of `<paint_system::Trait::Lookup as StaticLookup>::Source`.
|
||||
type Address: Codec + Clone + PartialEq + Debug;
|
||||
|
||||
/// The block header.
|
||||
@@ -95,9 +97,9 @@ pub trait System: 'static + Eq + Clone + Debug {
|
||||
}
|
||||
|
||||
/// Blanket impl for using existing runtime types
|
||||
impl<T: srml_system::Trait + Debug> System for T
|
||||
impl<T: paint_system::Trait + Debug> System for T
|
||||
where
|
||||
<T as srml_system::Trait>::Header: serde::de::DeserializeOwned,
|
||||
<T as paint_system::Trait>::Header: serde::de::DeserializeOwned,
|
||||
{
|
||||
type Index = T::Index;
|
||||
type BlockNumber = T::BlockNumber;
|
||||
@@ -120,7 +122,7 @@ pub trait SystemStore {
|
||||
) -> Box<dyn Future<Item = <Self::System as System>::Index, Error = Error> + Send>;
|
||||
}
|
||||
|
||||
impl<T: System + Balances + 'static> SystemStore for Client<T> {
|
||||
impl<T: System + Balances + 'static, S: 'static> SystemStore for Client<T, S> {
|
||||
type System = T;
|
||||
|
||||
fn account_nonce(
|
||||
@@ -149,23 +151,28 @@ pub trait SystemXt {
|
||||
type System: System;
|
||||
/// Keypair type
|
||||
type Pair: Pair;
|
||||
/// Signature type
|
||||
type Signature: Verify;
|
||||
|
||||
/// Create a call for the srml system module
|
||||
fn system<F>(&self, f: F) -> XtBuilder<Self::System, Self::Pair, Valid>
|
||||
/// Create a call for the paint system module
|
||||
fn system<F>(&self, f: F) -> XtBuilder<Self::System, Self::Pair, Self::Signature, Valid>
|
||||
where
|
||||
F: FnOnce(
|
||||
ModuleCalls<Self::System, Self::Pair>,
|
||||
) -> Result<Encoded, MetadataError>;
|
||||
}
|
||||
|
||||
impl<T: System + Balances + 'static, P, V> SystemXt for XtBuilder<T, P, V>
|
||||
impl<T: System + Balances + 'static, P, S: 'static, V> SystemXt for XtBuilder<T, P, S, V>
|
||||
where
|
||||
P: Pair,
|
||||
S: Verify,
|
||||
S::Signer: From<P::Public> + IdentifyAccount<AccountId = T::AccountId>,
|
||||
{
|
||||
type System = T;
|
||||
type Pair = P;
|
||||
type Signature = S;
|
||||
|
||||
fn system<F>(&self, f: F) -> XtBuilder<T, P, Valid>
|
||||
fn system<F>(&self, f: F) -> XtBuilder<T, P, S, Valid>
|
||||
where
|
||||
F: FnOnce(
|
||||
ModuleCalls<Self::System, Self::Pair>,
|
||||
+3
-3
@@ -21,7 +21,7 @@ use crate::{
|
||||
RuntimeEvent,
|
||||
},
|
||||
metadata::Metadata,
|
||||
srml::{
|
||||
paint::{
|
||||
balances::Balances,
|
||||
system::System,
|
||||
},
|
||||
@@ -161,9 +161,9 @@ use txpool::watcher::Status;
|
||||
|
||||
use crate::{
|
||||
events::RawEvent,
|
||||
srml::system::SystemEvent,
|
||||
paint::system::SystemEvent,
|
||||
};
|
||||
use srml_system::Phase;
|
||||
use paint_system::Phase;
|
||||
|
||||
type MapClosure<T> = Box<dyn Fn(T) -> T + Send>;
|
||||
pub type MapStream<T> = stream::Map<TypedSubscriptionStream<T>, MapClosure<T>>;
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::srml::{
|
||||
use crate::paint::{
|
||||
balances::Balances,
|
||||
contracts::Contracts,
|
||||
system::System,
|
||||
@@ -43,7 +43,7 @@ impl System for DefaultNodeRuntime {
|
||||
type Hash = substrate_primitives::H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = <AnySignature as Verify>::Signer;
|
||||
type Address = srml_indices::address::Address<Self::AccountId, u32>;
|
||||
type Address = paint_indices::address::Address<Self::AccountId, u32>;
|
||||
type Header = Header<Self::BlockNumber, BlakeTwo256>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user