From 2e64f808d8b6d1276286f1927d2a53d68b867a1d Mon Sep 17 00:00:00 2001 From: haerdib Date: Wed, 11 Jan 2023 17:35:59 +0100 Subject: [PATCH 01/22] add CreateBalancesExtrinsic trait --- examples/examples/event_error_details.rs | 4 +- .../transfer_with_tungstenite_client.rs | 4 +- examples/examples/transfer_with_ws_client.rs | 4 +- src/extrinsic/balances.rs | 86 +++++++++++-------- src/extrinsic/mod.rs | 2 + src/lib.rs | 1 + testing/examples/author_tests.rs | 6 +- .../pallet_transaction_payment_tests.rs | 4 +- 8 files changed, 65 insertions(+), 46 deletions(-) diff --git a/examples/examples/event_error_details.rs b/examples/examples/event_error_details.rs index 020fadfc9..e6efd0812 100644 --- a/examples/examples/event_error_details.rs +++ b/examples/examples/event_error_details.rs @@ -18,8 +18,8 @@ use kitchensink_runtime::{Runtime, Signature}; use sp_keyring::AccountKeyring; use sp_runtime::{AccountId32 as AccountId, MultiAddress}; use substrate_api_client::{ - rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner, GetAccountInformation, - StaticEvent, SubmitAndWatchUntilSuccess, + rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, CreateBalancesExtrinsic, ExtrinsicSigner, + GetAccountInformation, StaticEvent, SubmitAndWatchUntilSuccess, }; #[derive(Decode)] diff --git a/examples/examples/transfer_with_tungstenite_client.rs b/examples/examples/transfer_with_tungstenite_client.rs index a5d568923..ef8a9eed3 100755 --- a/examples/examples/transfer_with_tungstenite_client.rs +++ b/examples/examples/transfer_with_tungstenite_client.rs @@ -22,8 +22,8 @@ use sp_core::{ }; use sp_runtime::MultiAddress; use substrate_api_client::{ - rpc::TungsteniteRpcClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner, - GetAccountInformation, SubmitAndWatch, XtStatus, + rpc::TungsteniteRpcClient, Api, AssetTipExtrinsicParams, CreateBalancesExtrinsic, + ExtrinsicSigner, GetAccountInformation, SubmitAndWatch, XtStatus, }; fn main() { diff --git a/examples/examples/transfer_with_ws_client.rs b/examples/examples/transfer_with_ws_client.rs index fbe93f8f5..88ed6d5f7 100755 --- a/examples/examples/transfer_with_ws_client.rs +++ b/examples/examples/transfer_with_ws_client.rs @@ -22,8 +22,8 @@ use sp_core::{ }; use sp_runtime::MultiAddress; use substrate_api_client::{ - rpc::WsRpcClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner, GetAccountInformation, - SubmitAndWatch, XtStatus, + rpc::WsRpcClient, Api, AssetTipExtrinsicParams, CreateBalancesExtrinsic, ExtrinsicSigner, + GetAccountInformation, SubmitAndWatch, XtStatus, }; fn main() { diff --git a/src/extrinsic/balances.rs b/src/extrinsic/balances.rs index d4de4fe84..34765ec41 100644 --- a/src/extrinsic/balances.rs +++ b/src/extrinsic/balances.rs @@ -25,59 +25,75 @@ use ac_primitives::{ use alloc::borrow::ToOwned; use codec::{Compact, Encode}; use serde::de::DeserializeOwned; -use sp_runtime::traits::GetRuntimeBlockType; -pub const BALANCES_MODULE: &str = "Balances"; -pub const BALANCES_TRANSFER: &str = "transfer"; -pub const BALANCES_SET_BALANCE: &str = "set_balance"; +pub const MODULE: &str = "Balances"; +pub const TRANSFER: &str = "transfer"; +pub const SET_BALANCE: &str = "set_balance"; -pub type BalanceTransferFn = (CallIndex, Address, Compact); -pub type BalanceSetBalanceFn = +pub type BalanceTransferCall = (CallIndex, Address, Compact); +pub type BalanceSetBalanceCall = (CallIndex, Address, Compact, Compact); -pub type BalanceTransferXt = - UncheckedExtrinsicV4, Signature, SignedExtra>; -pub type BalanceSetBalanceXt = - UncheckedExtrinsicV4, Signature, SignedExtra>; +type AddressFor = ::Address; +type SignatureFor = ::Signature; +type SignedExtraFor = ::SignedExtra; -impl Api +type ExtrinsicFor = + UncheckedExtrinsicV4, Call, SignatureFor, SignedExtraFor>; + +pub trait CreateBalancesExtrinsic { + type Balance; + type Address; + type Signature; + type SignedExtra; + + fn balance_transfer( + &self, + to: Self::Address, + amount: Self::Balance, + ) -> ExtrinsicFor>; + + fn balance_set_balance( + &self, + who: Self::Address, + free_balance: Self::Balance, + reserved_balance: Self::Balance, + ) -> ExtrinsicFor>; +} + +impl CreateBalancesExtrinsic + for Api where Signer: SignExtrinsic, Client: Request, - Runtime: GetRuntimeBlockType + BalancesConfig, + Runtime: BalancesConfig, Params: ExtrinsicParams, Compact: Encode, Runtime::Header: DeserializeOwned, - Runtime::RuntimeBlock: DeserializeOwned, { - pub fn balance_transfer( + type Balance = Runtime::Balance; + type Address = Signer::ExtrinsicAddress; + type Signature = Signer::Signature; + type SignedExtra = Params::SignedExtra; + + fn balance_transfer( &self, - to: Signer::ExtrinsicAddress, - amount: Runtime::Balance, - ) -> BalanceTransferXt< - Signer::ExtrinsicAddress, - Runtime::Balance, - Signer::Signature, - Params::SignedExtra, - > { - compose_extrinsic!(self, BALANCES_MODULE, BALANCES_TRANSFER, to, Compact(amount)) + to: Self::Address, + amount: Self::Balance, + ) -> ExtrinsicFor> { + compose_extrinsic!(self, MODULE, TRANSFER, to, Compact(amount)) } - pub fn balance_set_balance( + fn balance_set_balance( &self, - who: Signer::ExtrinsicAddress, - free_balance: Runtime::Balance, - reserved_balance: Runtime::Balance, - ) -> BalanceSetBalanceXt< - Signer::ExtrinsicAddress, - Runtime::Balance, - Signer::Signature, - Params::SignedExtra, - > { + who: Self::Address, + free_balance: Self::Balance, + reserved_balance: Self::Balance, + ) -> ExtrinsicFor> { compose_extrinsic!( self, - BALANCES_MODULE, - BALANCES_SET_BALANCE, + MODULE, + SET_BALANCE, who, Compact(free_balance), Compact(reserved_balance) diff --git a/src/extrinsic/mod.rs b/src/extrinsic/mod.rs index d08ae5d31..4e8e27c11 100644 --- a/src/extrinsic/mod.rs +++ b/src/extrinsic/mod.rs @@ -17,6 +17,8 @@ //! Offers some predefined extrinsics for common runtime modules. +pub use balances::CreateBalancesExtrinsic; + pub mod balances; pub mod common; pub mod contracts; diff --git a/src/lib.rs b/src/lib.rs index fe0cb777f..65114e4d4 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,6 +23,7 @@ pub use ac_compose_macros::*; pub use ac_node_api::*; pub use ac_primitives::*; pub use api::*; +pub use extrinsic::CreateBalancesExtrinsic; pub mod api; pub mod extrinsic; diff --git a/testing/examples/author_tests.rs b/testing/examples/author_tests.rs index 7d21ba3b8..20ac007f8 100644 --- a/testing/examples/author_tests.rs +++ b/testing/examples/author_tests.rs @@ -21,9 +21,9 @@ use sp_keyring::AccountKeyring; use std::{thread, time::Duration}; use substrate_api_client::{ rpc::{HandleSubscription, JsonrpseeClient}, - Api, AssetTipExtrinsicParams, EventDetails, ExtrinsicSigner as GenericExtrinsicSigner, - SignExtrinsic, SubmitAndWatch, SubmitAndWatchUntilSuccess, SubmitExtrinsic, TransactionStatus, - XtStatus, + Api, AssetTipExtrinsicParams, CreateBalancesExtrinsic, EventDetails, + ExtrinsicSigner as GenericExtrinsicSigner, SignExtrinsic, SubmitAndWatch, + SubmitAndWatchUntilSuccess, SubmitExtrinsic, TransactionStatus, XtStatus, }; type ExtrinsicSigner = GenericExtrinsicSigner; diff --git a/testing/examples/pallet_transaction_payment_tests.rs b/testing/examples/pallet_transaction_payment_tests.rs index 4354d3a44..add069847 100644 --- a/testing/examples/pallet_transaction_payment_tests.rs +++ b/testing/examples/pallet_transaction_payment_tests.rs @@ -19,8 +19,8 @@ use codec::Encode; use kitchensink_runtime::{Runtime, Signature}; use sp_keyring::AccountKeyring; use substrate_api_client::{ - rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner, GetBlock, - GetTransactionPayment, + rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, CreateBalancesExtrinsic, ExtrinsicSigner, + GetBlock, GetTransactionPayment, }; #[tokio::main] From 789e46394b59f9a43a4e08f491f85303c5ac3b89 Mon Sep 17 00:00:00 2001 From: haerdib Date: Wed, 11 Jan 2023 18:03:42 +0100 Subject: [PATCH 02/22] introuce AssignExtrinsicTypes trait --- src/extrinsic/balances.rs | 34 +++++++++------------------------- src/extrinsic/mod.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/extrinsic/balances.rs b/src/extrinsic/balances.rs index 34765ec41..fd35648b2 100644 --- a/src/extrinsic/balances.rs +++ b/src/extrinsic/balances.rs @@ -17,48 +17,36 @@ //! Extrinsics for `pallet-balances`. +use super::{AssignExtrinsicTypes, ExtrinsicFor}; use crate::{api::Api, rpc::Request}; use ac_compose_macros::compose_extrinsic; -use ac_primitives::{ - BalancesConfig, CallIndex, ExtrinsicParams, SignExtrinsic, UncheckedExtrinsicV4, -}; +use ac_primitives::{BalancesConfig, CallIndex, ExtrinsicParams, SignExtrinsic}; use alloc::borrow::ToOwned; use codec::{Compact, Encode}; -use serde::de::DeserializeOwned; pub const MODULE: &str = "Balances"; pub const TRANSFER: &str = "transfer"; pub const SET_BALANCE: &str = "set_balance"; -pub type BalanceTransferCall = (CallIndex, Address, Compact); -pub type BalanceSetBalanceCall = +pub type TransferCall = (CallIndex, Address, Compact); +pub type SetBalanceCall = (CallIndex, Address, Compact, Compact); -type AddressFor = ::Address; -type SignatureFor = ::Signature; -type SignedExtraFor = ::SignedExtra; - -type ExtrinsicFor = - UncheckedExtrinsicV4, Call, SignatureFor, SignedExtraFor>; - -pub trait CreateBalancesExtrinsic { +pub trait CreateBalancesExtrinsic: AssignExtrinsicTypes { type Balance; - type Address; - type Signature; - type SignedExtra; fn balance_transfer( &self, to: Self::Address, amount: Self::Balance, - ) -> ExtrinsicFor>; + ) -> ExtrinsicFor>; fn balance_set_balance( &self, who: Self::Address, free_balance: Self::Balance, reserved_balance: Self::Balance, - ) -> ExtrinsicFor>; + ) -> ExtrinsicFor>; } impl CreateBalancesExtrinsic @@ -69,18 +57,14 @@ where Runtime: BalancesConfig, Params: ExtrinsicParams, Compact: Encode, - Runtime::Header: DeserializeOwned, { type Balance = Runtime::Balance; - type Address = Signer::ExtrinsicAddress; - type Signature = Signer::Signature; - type SignedExtra = Params::SignedExtra; fn balance_transfer( &self, to: Self::Address, amount: Self::Balance, - ) -> ExtrinsicFor> { + ) -> ExtrinsicFor> { compose_extrinsic!(self, MODULE, TRANSFER, to, Compact(amount)) } @@ -89,7 +73,7 @@ where who: Self::Address, free_balance: Self::Balance, reserved_balance: Self::Balance, - ) -> ExtrinsicFor> { + ) -> ExtrinsicFor> { compose_extrinsic!( self, MODULE, diff --git a/src/extrinsic/mod.rs b/src/extrinsic/mod.rs index 4e8e27c11..3b9ac8f3a 100644 --- a/src/extrinsic/mod.rs +++ b/src/extrinsic/mod.rs @@ -26,3 +26,30 @@ pub mod offline_extrinsic; #[cfg(feature = "staking-xt")] pub mod staking; pub mod utility; + +use crate::Api; +use ac_primitives::{ExtrinsicParams, FrameSystemConfig, SignExtrinsic, UncheckedExtrinsicV4}; + +type AddressFor = ::Address; +type SignatureFor = ::Signature; +type SignedExtraFor = ::SignedExtra; + +type ExtrinsicFor = + UncheckedExtrinsicV4, Call, SignatureFor, SignedExtraFor>; + +pub trait AssignExtrinsicTypes { + type Address; + type Signature; + type SignedExtra; +} + +impl AssignExtrinsicTypes for Api +where + Signer: SignExtrinsic, + Runtime: FrameSystemConfig, + Params: ExtrinsicParams, +{ + type Address = Signer::ExtrinsicAddress; + type Signature = Signer::Signature; + type SignedExtra = Params::SignedExtra; +} From c3fff637203839f0d17ac72df3737734fdcbe847 Mon Sep 17 00:00:00 2001 From: haerdib Date: Wed, 11 Jan 2023 18:25:43 +0100 Subject: [PATCH 03/22] change contracts --- src/extrinsic/contracts.rs | 186 +++++++++++++++++++------------------ 1 file changed, 95 insertions(+), 91 deletions(-) diff --git a/src/extrinsic/contracts.rs b/src/extrinsic/contracts.rs index e06003089..fe62ecded 100644 --- a/src/extrinsic/contracts.rs +++ b/src/extrinsic/contracts.rs @@ -18,68 +18,81 @@ //! Extrinsics for `pallet-contract`. //! Contracts module is community maintained and not CI tested, therefore it may not work as is. +use super::{AssignExtrinsicTypes, ExtrinsicFor}; use crate::{api::Api, rpc::Request}; use ac_compose_macros::compose_extrinsic; use ac_primitives::{ BalancesConfig, CallIndex, ContractsConfig, ExtrinsicParams, FrameSystemConfig, SignExtrinsic, - UncheckedExtrinsicV4, }; use alloc::vec::Vec; use codec::{Compact, Encode}; use serde::de::DeserializeOwned; use sp_runtime::traits::GetRuntimeBlockType; -pub const CONTRACTS_MODULE: &str = "Contracts"; -pub const CONTRACTS_PUT_CODE: &str = "put_code"; -pub const CONTRACTS_INSTANTIATE: &str = "instantiate"; -pub const CONTRACTS_INSTANTIATE_WITH_CODE: &str = "instantiate_with_code"; -pub const CONTRACTS_CALL: &str = "call"; - -type Gas = u64; -type Data = Vec; -type Code = Vec; -type Salt = Vec; - -type GasLimit = Compact; -type Endowment = Compact; -type Value = Compact; - -pub type ContractPutCodeFn = (CallIndex, GasLimit, Data); -pub type ContractInstantiateFn = - (CallIndex, Endowment, GasLimit, Hash, Data); -pub type ContractInstantiateWithCodeFn = - (CallIndex, Endowment, GasLimit, Code, Data, Salt); -pub type ContractCallFn = (CallIndex, Address, Value, GasLimit, Data); - -pub type ContractPutCodeXt = - UncheckedExtrinsicV4; -pub type ContractInstantiateXt = - UncheckedExtrinsicV4, Signature, SignedExtra>; -pub type ContractInstantiateWithCodeXt = - UncheckedExtrinsicV4, Signature, SignedExtra>; -pub type ContractCallXt = - UncheckedExtrinsicV4, Signature, SignedExtra>; +pub const MODULE: &str = "Contracts"; +pub const PUT_CODE: &str = "put_code"; +pub const INSTANTIATE: &str = "instantiate"; +pub const INSTANTIATE_WITH_CODE: &str = "instantiate_with_code"; +pub const CALL: &str = "call"; + +pub type PutCodeCall = (CallIndex, Compact, Data); +pub type InstantiateCall = + (CallIndex, Compact, Compact, Hash, Data); +pub type InstantiateWithCodeCall = + (CallIndex, Compact, Compact, Code, Data, Salt); +pub type CallCall = + (CallIndex, Address, Compact, Compact, Data); + +pub trait CreateContractsExtrinsic: AssignExtrinsicTypes { + type Gas; + type Currency; + type Hash; + type Data; + type Salt; + + fn contract_put_code( + &self, + gas_limit: Self::Gas, + code: Self::Data, + ) -> ExtrinsicFor>; + + fn contract_instantiate( + &self, + endowment: Self::Currency, + gas_limit: Self::Gas, + code_hash: Self::Hash, + data: Self::Data, + ) -> ExtrinsicFor>; + + fn contract_instantiate_with_code( + &self, + endowment: Self::Currency, + gas_limit: Self::Gas, + code: Self::Data, + data: Self::Data, + salt: Self::Salt, + ) -> ExtrinsicFor< + Self, + InstantiateWithCodeCall, + >; + + fn contract_call( + &self, + dest: Self::Address, + value: Self::Currency, + gas_limit: Self::Gas, + data: Self::Data, + ) -> ExtrinsicFor>; +} #[cfg(feature = "std")] type BalanceOf = <::Currency as frame_support::traits::Currency< ::AccountId, >>::Balance; -type ExtrinsicAddressOf = >::ExtrinsicAddress; -type SignatureOf = >::Signature; -type HashOf = ::Hash; -type AccountIdOf = ::AccountId; - -#[cfg(feature = "std")] -type ContractInstantiateXtOf = ContractInstantiateXt< - ExtrinsicAddressOf>, - SignatureOf>, - SignedExtra, - BalanceOf, - HashOf, ->; #[cfg(feature = "std")] -impl Api +impl CreateContractsExtrinsic + for Api where Signer: SignExtrinsic, Client: Request, @@ -90,25 +103,31 @@ where Runtime::Header: DeserializeOwned, Runtime::RuntimeBlock: DeserializeOwned, { - pub fn contract_put_code( + type Gas = u64; + type Currency = BalanceOf; + type Hash = Runtime::Hash; + type Data = Vec; + type Salt = Vec; + + fn contract_put_code( &self, - gas_limit: Gas, - code: Data, - ) -> ContractPutCodeXt { - compose_extrinsic!(self, CONTRACTS_MODULE, CONTRACTS_PUT_CODE, Compact(gas_limit), code) + gas_limit: Self::Gas, + code: Self::Data, + ) -> ExtrinsicFor> { + compose_extrinsic!(self, MODULE, PUT_CODE, Compact(gas_limit), code) } - pub fn contract_instantiate( + fn contract_instantiate( &self, - endowment: BalanceOf, - gas_limit: Gas, - code_hash: Runtime::Hash, - data: Data, - ) -> ContractInstantiateXtOf { + endowment: Self::Currency, + gas_limit: Self::Gas, + code_hash: Self::Hash, + data: Self::Data, + ) -> ExtrinsicFor> { compose_extrinsic!( self, - CONTRACTS_MODULE, - CONTRACTS_INSTANTIATE, + MODULE, + INSTANTIATE, Compact(endowment), Compact(gas_limit), code_hash, @@ -116,23 +135,21 @@ where ) } - pub fn contract_instantiate_with_code( + fn contract_instantiate_with_code( &self, - endowment: BalanceOf, - gas_limit: Gas, - code: Data, - data: Data, - salt: Data, - ) -> ContractInstantiateWithCodeXt< - Signer::ExtrinsicAddress, - Signer::Signature, - Params::SignedExtra, - BalanceOf, + endowment: Self::Currency, + gas_limit: Self::Gas, + code: Self::Data, + data: Self::Data, + salt: Self::Salt, + ) -> ExtrinsicFor< + Self, + InstantiateWithCodeCall, > { compose_extrinsic!( self, - CONTRACTS_MODULE, - CONTRACTS_INSTANTIATE_WITH_CODE, + MODULE, + INSTANTIATE_WITH_CODE, Compact(endowment), Compact(gas_limit), code, @@ -141,26 +158,13 @@ where ) } - pub fn contract_call( + fn contract_call( &self, - dest: Signer::ExtrinsicAddress, - value: BalanceOf, - gas_limit: Gas, - data: Data, - ) -> ContractCallXt< - Signer::ExtrinsicAddress, - Signer::Signature, - Params::SignedExtra, - BalanceOf, - > { - compose_extrinsic!( - self, - CONTRACTS_MODULE, - CONTRACTS_CALL, - dest, - Compact(value), - Compact(gas_limit), - data - ) + dest: Self::Address, + value: Self::Currency, + gas_limit: Self::Gas, + data: Self::Data, + ) -> ExtrinsicFor> { + compose_extrinsic!(self, MODULE, CALL, dest, Compact(value), Compact(gas_limit), data) } } From b999f90eca8be0f5e51d390254289dcf6532ab35 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 08:24:28 +0100 Subject: [PATCH 04/22] remove obsolete trait bounds --- src/extrinsic/contracts.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/extrinsic/contracts.rs b/src/extrinsic/contracts.rs index fe62ecded..57e2e4668 100644 --- a/src/extrinsic/contracts.rs +++ b/src/extrinsic/contracts.rs @@ -26,7 +26,6 @@ use ac_primitives::{ }; use alloc::vec::Vec; use codec::{Compact, Encode}; -use serde::de::DeserializeOwned; use sp_runtime::traits::GetRuntimeBlockType; pub const MODULE: &str = "Contracts"; @@ -100,8 +99,6 @@ where Runtime: GetRuntimeBlockType + ContractsConfig + BalancesConfig, Compact>: Encode + Clone, Runtime::Currency: frame_support::traits::Currency, - Runtime::Header: DeserializeOwned, - Runtime::RuntimeBlock: DeserializeOwned, { type Gas = u64; type Currency = BalanceOf; From b44382721365f36e99136e0da3864916a256f2e8 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 08:54:13 +0100 Subject: [PATCH 05/22] fix clippy --- src/extrinsic/contracts.rs | 52 ++++++++++++++++++++++---------------- src/extrinsic/mod.rs | 6 ++--- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/extrinsic/contracts.rs b/src/extrinsic/contracts.rs index 57e2e4668..43f8b3d27 100644 --- a/src/extrinsic/contracts.rs +++ b/src/extrinsic/contracts.rs @@ -18,7 +18,7 @@ //! Extrinsics for `pallet-contract`. //! Contracts module is community maintained and not CI tested, therefore it may not work as is. -use super::{AssignExtrinsicTypes, ExtrinsicFor}; +use super::{AddressFor, AssignExtrinsicTypes, ExtrinsicFor}; use crate::{api::Api, rpc::Request}; use ac_compose_macros::compose_extrinsic; use ac_primitives::{ @@ -34,13 +34,27 @@ pub const INSTANTIATE: &str = "instantiate"; pub const INSTANTIATE_WITH_CODE: &str = "instantiate_with_code"; pub const CALL: &str = "call"; -pub type PutCodeCall = (CallIndex, Compact, Data); -pub type InstantiateCall = - (CallIndex, Compact, Compact, Hash, Data); -pub type InstantiateWithCodeCall = - (CallIndex, Compact, Compact, Code, Data, Salt); -pub type CallCall = - (CallIndex, Address, Compact, Compact, Data); +type GasLimitFor = Compact<::Gas>; +type ValueFor = Compact<::Currency>; +type EndowmentFor = Compact<::Currency>; +type DataFor = ::Data; +type CodeFor = ::Data; +type SaltFor = ::Salt; +type HashFor = ::Hash; + +/// Call for putting code in a contract. +type PutCodeFor = (CallIndex, GasLimitFor, DataFor); + +/// Call for instantiating a contract with the code hash. +type InstantiateWithHashFor = + (CallIndex, EndowmentFor, GasLimitFor, HashFor, DataFor); + +/// Call for instantiating a contract with code and salt. +type InstantiateWithCodeFor = + (CallIndex, EndowmentFor, GasLimitFor, CodeFor, DataFor, SaltFor); + +/// Call for calling a function inside a contract. +type ContractCallFor = (CallIndex, AddressFor, ValueFor, GasLimitFor, DataFor); pub trait CreateContractsExtrinsic: AssignExtrinsicTypes { type Gas; @@ -53,7 +67,7 @@ pub trait CreateContractsExtrinsic: AssignExtrinsicTypes { &self, gas_limit: Self::Gas, code: Self::Data, - ) -> ExtrinsicFor>; + ) -> ExtrinsicFor>; fn contract_instantiate( &self, @@ -61,7 +75,7 @@ pub trait CreateContractsExtrinsic: AssignExtrinsicTypes { gas_limit: Self::Gas, code_hash: Self::Hash, data: Self::Data, - ) -> ExtrinsicFor>; + ) -> ExtrinsicFor>; fn contract_instantiate_with_code( &self, @@ -70,10 +84,7 @@ pub trait CreateContractsExtrinsic: AssignExtrinsicTypes { code: Self::Data, data: Self::Data, salt: Self::Salt, - ) -> ExtrinsicFor< - Self, - InstantiateWithCodeCall, - >; + ) -> ExtrinsicFor>; fn contract_call( &self, @@ -81,7 +92,7 @@ pub trait CreateContractsExtrinsic: AssignExtrinsicTypes { value: Self::Currency, gas_limit: Self::Gas, data: Self::Data, - ) -> ExtrinsicFor>; + ) -> ExtrinsicFor>; } #[cfg(feature = "std")] @@ -110,7 +121,7 @@ where &self, gas_limit: Self::Gas, code: Self::Data, - ) -> ExtrinsicFor> { + ) -> ExtrinsicFor> { compose_extrinsic!(self, MODULE, PUT_CODE, Compact(gas_limit), code) } @@ -120,7 +131,7 @@ where gas_limit: Self::Gas, code_hash: Self::Hash, data: Self::Data, - ) -> ExtrinsicFor> { + ) -> ExtrinsicFor> { compose_extrinsic!( self, MODULE, @@ -139,10 +150,7 @@ where code: Self::Data, data: Self::Data, salt: Self::Salt, - ) -> ExtrinsicFor< - Self, - InstantiateWithCodeCall, - > { + ) -> ExtrinsicFor> { compose_extrinsic!( self, MODULE, @@ -161,7 +169,7 @@ where value: Self::Currency, gas_limit: Self::Gas, data: Self::Data, - ) -> ExtrinsicFor> { + ) -> ExtrinsicFor> { compose_extrinsic!(self, MODULE, CALL, dest, Compact(value), Compact(gas_limit), data) } } diff --git a/src/extrinsic/mod.rs b/src/extrinsic/mod.rs index 3b9ac8f3a..b83f6209e 100644 --- a/src/extrinsic/mod.rs +++ b/src/extrinsic/mod.rs @@ -30,9 +30,9 @@ pub mod utility; use crate::Api; use ac_primitives::{ExtrinsicParams, FrameSystemConfig, SignExtrinsic, UncheckedExtrinsicV4}; -type AddressFor = ::Address; -type SignatureFor = ::Signature; -type SignedExtraFor = ::SignedExtra; +pub type AddressFor = ::Address; +pub type SignatureFor = ::Signature; +pub type SignedExtraFor = ::SignedExtra; type ExtrinsicFor = UncheckedExtrinsicV4, Call, SignatureFor, SignedExtraFor>; From 1730be62179514e7b5d37111e0670249283cb632 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 08:55:15 +0100 Subject: [PATCH 06/22] add some more comments --- src/extrinsic/balances.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/extrinsic/balances.rs b/src/extrinsic/balances.rs index fd35648b2..cc7f1a655 100644 --- a/src/extrinsic/balances.rs +++ b/src/extrinsic/balances.rs @@ -28,7 +28,10 @@ pub const MODULE: &str = "Balances"; pub const TRANSFER: &str = "transfer"; pub const SET_BALANCE: &str = "set_balance"; +/// Call for a balance transfer. pub type TransferCall = (CallIndex, Address, Compact); + +/// Call to the balance of an account. pub type SetBalanceCall = (CallIndex, Address, Compact, Compact); From afec191842b57099b391bd295e310da140ad3cd4 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 08:57:15 +0100 Subject: [PATCH 07/22] shorten const names --- src/extrinsic/staking.rs | 48 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/extrinsic/staking.rs b/src/extrinsic/staking.rs index 395e7c97b..6357be58b 100644 --- a/src/extrinsic/staking.rs +++ b/src/extrinsic/staking.rs @@ -28,20 +28,20 @@ use codec::{Compact, Encode}; use serde::de::DeserializeOwned; use sp_runtime::traits::GetRuntimeBlockType; -const STAKING_MODULE: &str = "Staking"; -const STAKING_BOND: &str = "bond"; -const STAKING_BOND_EXTRA: &str = "bond_extra"; -const STAKING_UNBOND: &str = "unbond"; -const STAKING_REBOND: &str = "rebond"; -const STAKING_WITHDRAW_UNBONDED: &str = "withdraw_unbonded"; -const STAKING_NOMINATE: &str = "nominate"; -const STAKING_CHILL: &str = "chill"; -const STAKING_SET_CONTROLLER: &str = "set_controller"; +const MODULE: &str = "Staking"; +const BOND: &str = "bond"; +const BOND_EXTRA: &str = "bond_extra"; +const UNBOND: &str = "unbond"; +const REBOND: &str = "rebond"; +const WITHDRAW_UNBONDED: &str = "withdraw_unbonded"; +const NOMINATE: &str = "nominate"; +const CHILL: &str = "chill"; +const SET_CONTROLLER: &str = "set_controller"; const PAYOUT_STAKERS: &str = "payout_stakers"; const FORCE_NEW_ERA: &str = "force_new_era"; const FORCE_NEW_ERA_ALWAYS: &str = "force_new_era_always"; const FORCE_NO_ERA: &str = "force_no_era"; -const STAKING_SET_PAYEE: &str = "set_payee"; +const SET_PAYEE: &str = "set_payee"; const SET_VALIDATOR_COUNT: &str = "set_validator_count"; pub type StakingBondFn = @@ -112,7 +112,7 @@ where Params::SignedExtra, Runtime::CurrencyBalance, > { - compose_extrinsic!(self, STAKING_MODULE, STAKING_BOND, controller, Compact(value), payee) + compose_extrinsic!(self, MODULE, BOND, controller, Compact(value), payee) } /// Bonds extra funds from the stash's free balance to the balance for staking. @@ -125,7 +125,7 @@ where Params::SignedExtra, Runtime::CurrencyBalance, > { - compose_extrinsic!(self, STAKING_MODULE, STAKING_BOND_EXTRA, Compact(value)) + compose_extrinsic!(self, MODULE, BOND_EXTRA, Compact(value)) } /// Unbond `value` portion of the stash. @@ -140,7 +140,7 @@ where Params::SignedExtra, Runtime::CurrencyBalance, > { - compose_extrinsic!(self, STAKING_MODULE, STAKING_UNBOND, Compact(value)) + compose_extrinsic!(self, MODULE, UNBOND, Compact(value)) } /// Rebond `value` portion of the current amount that is in the process of unbonding. @@ -153,7 +153,7 @@ where Params::SignedExtra, Runtime::CurrencyBalance, > { - compose_extrinsic!(self, STAKING_MODULE, STAKING_REBOND, Compact(value)) + compose_extrinsic!(self, MODULE, REBOND, Compact(value)) } /// Free the balance of the stash so the stash account can do whatever it wants. @@ -164,7 +164,7 @@ where num_slashing_spans: u32, ) -> StakingWithdrawUnbondedXt { - compose_extrinsic!(self, STAKING_MODULE, STAKING_WITHDRAW_UNBONDED, num_slashing_spans) + compose_extrinsic!(self, MODULE, WITHDRAW_UNBONDED, num_slashing_spans) } /// Nominate `targets` as validators. @@ -173,14 +173,14 @@ where &self, targets: Vec, ) -> StakingNominateXt { - compose_extrinsic!(self, STAKING_MODULE, STAKING_NOMINATE, targets) + compose_extrinsic!(self, MODULE, NOMINATE, targets) } /// Stop nominating por validating. Effects take place in the next era pub fn staking_chill( &self, ) -> StakingChillXt { - compose_extrinsic!(self, STAKING_MODULE, STAKING_CHILL) + compose_extrinsic!(self, MODULE, CHILL) } /// (Re-)set the controller of the stash @@ -190,7 +190,7 @@ where &self, controller: Signer::ExtrinsicAddress, ) -> StakingSetControllerXt { - compose_extrinsic!(self, STAKING_MODULE, STAKING_SET_CONTROLLER, controller) + compose_extrinsic!(self, MODULE, SET_CONTROLLER, controller) } /// Return the payout call for the given era @@ -205,14 +205,14 @@ where Runtime::AccountId, > { let value = PayoutStakers { validator_stash: account, era }; - compose_extrinsic!(self, STAKING_MODULE, PAYOUT_STAKERS, value) + compose_extrinsic!(self, MODULE, PAYOUT_STAKERS, value) } /// For New Era at the end of Next Session. pub fn force_new_era( &self, ) -> StakingForceNewEraXt { - compose_extrinsic!(self, STAKING_MODULE, FORCE_NEW_ERA, ForceEra {}) + compose_extrinsic!(self, MODULE, FORCE_NEW_ERA, ForceEra {}) } /// Force there to be a new era at the end of sessions indefinitely. @@ -220,7 +220,7 @@ where &self, ) -> StakingForceNewEraAlwaysXt { - compose_extrinsic!(self, STAKING_MODULE, FORCE_NEW_ERA_ALWAYS, ForceEra {}) + compose_extrinsic!(self, MODULE, FORCE_NEW_ERA_ALWAYS, ForceEra {}) } /// Force there to be no new eras indefinitely. @@ -228,7 +228,7 @@ where &self, ) -> StakingForceNewEraAlwaysXt { - compose_extrinsic!(self, STAKING_MODULE, FORCE_NO_ERA, ForceEra {}) + compose_extrinsic!(self, MODULE, FORCE_NO_ERA, ForceEra {}) } /// Re-set the payment target for a controller. @@ -236,7 +236,7 @@ where &self, payee: Signer::ExtrinsicAddress, ) -> StakingSetControllerXt { - compose_extrinsic!(self, STAKING_MODULE, STAKING_SET_PAYEE, payee) + compose_extrinsic!(self, MODULE, SET_PAYEE, payee) } /// Sets the number of validators. @@ -245,6 +245,6 @@ where count: u32, ) -> StakingSetValidatorCountXt { - compose_extrinsic!(self, STAKING_MODULE, SET_VALIDATOR_COUNT, count) + compose_extrinsic!(self, MODULE, SET_VALIDATOR_COUNT, count) } } From 885706aabb18f9ccb8577096ae099ea8c34994ea Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 09:16:15 +0100 Subject: [PATCH 08/22] add pub --- src/extrinsic/contracts.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/extrinsic/contracts.rs b/src/extrinsic/contracts.rs index 43f8b3d27..e5df4a031 100644 --- a/src/extrinsic/contracts.rs +++ b/src/extrinsic/contracts.rs @@ -34,27 +34,27 @@ pub const INSTANTIATE: &str = "instantiate"; pub const INSTANTIATE_WITH_CODE: &str = "instantiate_with_code"; pub const CALL: &str = "call"; -type GasLimitFor = Compact<::Gas>; -type ValueFor = Compact<::Currency>; -type EndowmentFor = Compact<::Currency>; -type DataFor = ::Data; -type CodeFor = ::Data; -type SaltFor = ::Salt; -type HashFor = ::Hash; +pub type GasLimitFor = Compact<::Gas>; +pub type ValueFor = Compact<::Currency>; +pub type EndowmentFor = Compact<::Currency>; +pub type DataFor = ::Data; +pub type CodeFor = ::Data; +pub type SaltFor = ::Salt; +pub type HashFor = ::Hash; /// Call for putting code in a contract. -type PutCodeFor = (CallIndex, GasLimitFor, DataFor); +pub type PutCodeFor = (CallIndex, GasLimitFor, DataFor); /// Call for instantiating a contract with the code hash. -type InstantiateWithHashFor = +pub type InstantiateWithHashFor = (CallIndex, EndowmentFor, GasLimitFor, HashFor, DataFor); /// Call for instantiating a contract with code and salt. -type InstantiateWithCodeFor = +pub type InstantiateWithCodeFor = (CallIndex, EndowmentFor, GasLimitFor, CodeFor, DataFor, SaltFor); /// Call for calling a function inside a contract. -type ContractCallFor = (CallIndex, AddressFor, ValueFor, GasLimitFor, DataFor); +pub type ContractCallFor = (CallIndex, AddressFor, ValueFor, GasLimitFor, DataFor); pub trait CreateContractsExtrinsic: AssignExtrinsicTypes { type Gas; From bc88d27049d9239f213a826bc735696275f7c31e Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 09:42:30 +0100 Subject: [PATCH 09/22] remodel staking --- src/extrinsic/common.rs | 8 -- src/extrinsic/staking.rs | 289 +++++++++++++++++++-------------------- 2 files changed, 142 insertions(+), 155 deletions(-) diff --git a/src/extrinsic/common.rs b/src/extrinsic/common.rs index 29a89b200..1b2e4211e 100644 --- a/src/extrinsic/common.rs +++ b/src/extrinsic/common.rs @@ -20,14 +20,6 @@ use alloc::vec::Vec; use codec::{Decode, Encode}; -#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug)] -pub struct PayoutStakers { - pub validator_stash: AccountId, - pub era: u32, -} -#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug)] -pub struct ForceEra {} - #[derive(Clone, Eq, PartialEq, Encode, Decode, Debug)] pub struct Batch { pub calls: Vec, diff --git a/src/extrinsic/staking.rs b/src/extrinsic/staking.rs index 6357be58b..61f8b3627 100644 --- a/src/extrinsic/staking.rs +++ b/src/extrinsic/staking.rs @@ -16,15 +16,15 @@ */ //! Extrinsics for `pallet-staking`. +//! https://polkadot.js.org/docs/substrate/extrinsics#staking -use super::common::*; +use super::{AssignExtrinsicTypes, ExtrinsicFor}; use crate::{rpc::Request, Api}; use ac_compose_macros::compose_extrinsic; use ac_primitives::{ BalancesConfig, CallIndex, ExtrinsicParams, RewardDestination, SignExtrinsic, StakingConfig, - UncheckedExtrinsicV4, }; -use codec::{Compact, Encode}; +use codec::{Compact, Decode, Encode}; use serde::de::DeserializeOwned; use sp_runtime::traits::GetRuntimeBlockType; @@ -44,53 +44,108 @@ const FORCE_NO_ERA: &str = "force_no_era"; const SET_PAYEE: &str = "set_payee"; const SET_VALIDATOR_COUNT: &str = "set_validator_count"; -pub type StakingBondFn = +#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug)] +pub struct PayoutStakers { + pub validator_stash: AccountId, + pub era: u32, +} + +pub type BondCall = (CallIndex, Address, Compact, RewardDestination
); -pub type StakingBondExtraFn = (CallIndex, Compact); -pub type StakingUnbondFn = (CallIndex, Compact); -pub type StakingRebondFn = (CallIndex, Compact); -pub type StakingWithdrawUnbondedFn = (CallIndex, u32); -pub type StakingNominateFn
= (CallIndex, Vec
); -pub type StakingChillFn = CallIndex; -pub type StakingSetControllerFn
= (CallIndex, Address); -pub type StakingPayoutStakersFn = (CallIndex, PayoutStakers); -pub type StakingForceNewEraFn = (CallIndex, ForceEra); -pub type StakingForceNewEraAlwaysFn = (CallIndex, ForceEra); -pub type StakingForceNoEraFn = (CallIndex, ForceEra); -pub type StakingSetPayeeFn
= (CallIndex, Address); -pub type StakingSetValidatorCountFn = (CallIndex, u32); - -pub type StakingBondXt = - UncheckedExtrinsicV4, Signature, SignedExtra>; -pub type StakingBondExtraXt = - UncheckedExtrinsicV4, Signature, SignedExtra>; -pub type StakingUnbondXt = - UncheckedExtrinsicV4, Signature, SignedExtra>; -pub type StakingRebondXt = - UncheckedExtrinsicV4, Signature, SignedExtra>; -pub type StakingWithdrawUnbondedXt = - UncheckedExtrinsicV4; -pub type StakingNominateXt = - UncheckedExtrinsicV4, Signature, SignedExtra>; -pub type StakingChillXt = - UncheckedExtrinsicV4; -pub type StakingSetControllerXt = - UncheckedExtrinsicV4, Signature, SignedExtra>; -pub type StakingPayoutStakersXt = - UncheckedExtrinsicV4, Signature, SignedExtra>; -pub type StakingForceNewEraXt = - UncheckedExtrinsicV4; -pub type StakingForceNewEraAlwaysXt = - UncheckedExtrinsicV4; -pub type StakingForceNoEraXt = - UncheckedExtrinsicV4; -pub type StakingSetPayeeXt = - UncheckedExtrinsicV4, Signature, SignedExtra>; -pub type StakingSetValidatorCountXt = - UncheckedExtrinsicV4; - -// https://polkadot.js.org/docs/substrate/extrinsics#staking -impl Api +pub type BondExtraCall = (CallIndex, Compact); +pub type UnbondCall = (CallIndex, Compact); +pub type RebondCall = (CallIndex, Compact); +pub type WithdrawUnbondedCall = (CallIndex, u32); +pub type NominateCall
= (CallIndex, Vec
); +pub type ChillCall = CallIndex; +pub type SetControllerCall
= (CallIndex, Address); +pub type PayoutStakersCall = (CallIndex, PayoutStakers); +pub type ForceNewEraCall = CallIndex; +pub type ForceNewEraAlwaysCall = CallIndex; +pub type ForceNoEraCall = CallIndex; +pub type SetPayeeCall
= (CallIndex, Address); +pub type SetValidatorCountCall = (CallIndex, u32); + +pub trait CreateStakingExtrinsic: AssignExtrinsicTypes { + type Balance; + type RewardDestination; + type AccountId; + + /// Bond `value` amount to `controller`. + fn staking_bond( + &self, + controller: Self::Address, + value: Self::Balance, + payee: Self::RewardDestination, + ) -> ExtrinsicFor>; + + /// Bonds extra funds from the stash's free balance to the balance for staking. + fn staking_bond_extra( + &self, + value: Self::Balance, + ) -> ExtrinsicFor>; + + /// Unbond `value` portion of the stash. + /// If `value` is less than the minimum required, then the entire amount is unbound. + /// Must be signed by the controller of the stash. + fn staking_unbond(&self, value: Self::Balance) + -> ExtrinsicFor>; + + /// Rebond `value` portion of the current amount that is in the process of unbonding. + fn staking_rebond(&self, value: Self::Balance) + -> ExtrinsicFor>; + + /// Free the balance of the stash so the stash account can do whatever it wants. + /// Must be signed by the controller of the stash and called when EraElectionStatus is Closed. + /// For most users, `num_slashing_spans` should be 0. + fn staking_withdraw_unbonded( + &self, + num_slashing_spans: u32, + ) -> ExtrinsicFor; + + /// Nominate `targets` as validators. + /// Must be signed by the controller of the stash and called when EraElectionStatus is Closed. + fn staking_nominate( + &self, + targets: Vec, + ) -> ExtrinsicFor>; + + /// Stop nominating por validating. Effects take place in the next era + fn staking_chill(&self) -> ExtrinsicFor; + + /// (Re-)set the controller of the stash + /// Effects will be felt at the beginning of the next era. + /// Must be Signed by the stash, not the controller. + fn staking_set_controller( + &self, + controller: Self::Address, + ) -> ExtrinsicFor>; + + /// Return the payout call for the given era + fn payout_stakers( + &self, + era: u32, + account: Self::AccountId, + ) -> ExtrinsicFor>; + + /// For New Era at the end of Next Session. + fn force_new_era(&self) -> ExtrinsicFor; + + /// Force there to be a new era at the end of sessions indefinitely. + fn force_new_era_always(&self) -> ExtrinsicFor; + + /// Force there to be no new eras indefinitely. + fn force_no_era(&self) -> ExtrinsicFor; + + /// Re-set the payment target for a controller. + fn set_payee(&self, payee: Self::Address) -> ExtrinsicFor>; + + /// Sets the number of validators. + fn set_validator_count(&self, count: u32) -> ExtrinsicFor; +} + +impl CreateStakingExtrinsic + for Api where Signer: SignExtrinsic, Client: Request, @@ -100,151 +155,91 @@ where Runtime::Header: DeserializeOwned, Runtime::RuntimeBlock: DeserializeOwned, { - /// Bond `value` amount to `controller` - pub fn staking_bond( + type Balance = Runtime::CurrencyBalance; + type RewardDestination = RewardDestination; + type AccountId = Runtime::AccountId; + + fn staking_bond( &self, - controller: Signer::ExtrinsicAddress, - value: Runtime::CurrencyBalance, - payee: RewardDestination, - ) -> StakingBondXt< - Signer::ExtrinsicAddress, - Signer::Signature, - Params::SignedExtra, - Runtime::CurrencyBalance, - > { + controller: Self::Address, + value: Self::Balance, + payee: Self::RewardDestination, + ) -> ExtrinsicFor> { compose_extrinsic!(self, MODULE, BOND, controller, Compact(value), payee) } - /// Bonds extra funds from the stash's free balance to the balance for staking. - pub fn staking_bond_extra( + fn staking_bond_extra( &self, - value: Runtime::CurrencyBalance, - ) -> StakingBondExtraXt< - Signer::ExtrinsicAddress, - Signer::Signature, - Params::SignedExtra, - Runtime::CurrencyBalance, - > { + value: Self::Balance, + ) -> ExtrinsicFor> { compose_extrinsic!(self, MODULE, BOND_EXTRA, Compact(value)) } - /// Unbond `value` portion of the stash. - /// If `value` is less than the minimum required, then the entire amount is unbound. - /// Must be signed by the controller of the stash. - pub fn staking_unbond( + fn staking_unbond( &self, - value: Runtime::CurrencyBalance, - ) -> StakingUnbondXt< - Signer::ExtrinsicAddress, - Signer::Signature, - Params::SignedExtra, - Runtime::CurrencyBalance, - > { + value: Self::Balance, + ) -> ExtrinsicFor> { compose_extrinsic!(self, MODULE, UNBOND, Compact(value)) } - /// Rebond `value` portion of the current amount that is in the process of unbonding. - pub fn staking_rebond( + fn staking_rebond( &self, - value: Runtime::CurrencyBalance, - ) -> StakingRebondXt< - Signer::ExtrinsicAddress, - Signer::Signature, - Params::SignedExtra, - Runtime::CurrencyBalance, - > { + value: Self::Balance, + ) -> ExtrinsicFor> { compose_extrinsic!(self, MODULE, REBOND, Compact(value)) } - /// Free the balance of the stash so the stash account can do whatever it wants. - /// Must be signed by the controller of the stash and called when EraElectionStatus is Closed. - /// For most users, `num_slashing_spans` should be 0. - pub fn staking_withdraw_unbonded( + fn staking_withdraw_unbonded( &self, num_slashing_spans: u32, - ) -> StakingWithdrawUnbondedXt - { + ) -> ExtrinsicFor { compose_extrinsic!(self, MODULE, WITHDRAW_UNBONDED, num_slashing_spans) } - /// Nominate `targets` as validators. - /// Must be signed by the controller of the stash and called when EraElectionStatus is Closed. - pub fn staking_nominate( + fn staking_nominate( &self, - targets: Vec, - ) -> StakingNominateXt { + targets: Vec, + ) -> ExtrinsicFor> { compose_extrinsic!(self, MODULE, NOMINATE, targets) } - /// Stop nominating por validating. Effects take place in the next era - pub fn staking_chill( - &self, - ) -> StakingChillXt { + fn staking_chill(&self) -> ExtrinsicFor { compose_extrinsic!(self, MODULE, CHILL) } - /// (Re-)set the controller of the stash - /// Effects will be felt at the beginning of the next era. - /// Must be Signed by the stash, not the controller. - pub fn staking_set_controller( + fn staking_set_controller( &self, - controller: Signer::ExtrinsicAddress, - ) -> StakingSetControllerXt { + controller: Self::Address, + ) -> ExtrinsicFor> { compose_extrinsic!(self, MODULE, SET_CONTROLLER, controller) } - /// Return the payout call for the given era - pub fn payout_stakers( + fn payout_stakers( &self, era: u32, - account: Runtime::AccountId, - ) -> StakingPayoutStakersXt< - Signer::ExtrinsicAddress, - Signer::Signature, - Params::SignedExtra, - Runtime::AccountId, - > { + account: Self::AccountId, + ) -> ExtrinsicFor> { let value = PayoutStakers { validator_stash: account, era }; compose_extrinsic!(self, MODULE, PAYOUT_STAKERS, value) } - /// For New Era at the end of Next Session. - pub fn force_new_era( - &self, - ) -> StakingForceNewEraXt { - compose_extrinsic!(self, MODULE, FORCE_NEW_ERA, ForceEra {}) + fn force_new_era(&self) -> ExtrinsicFor { + compose_extrinsic!(self, MODULE, FORCE_NEW_ERA) } - /// Force there to be a new era at the end of sessions indefinitely. - pub fn force_new_era_always( - &self, - ) -> StakingForceNewEraAlwaysXt - { - compose_extrinsic!(self, MODULE, FORCE_NEW_ERA_ALWAYS, ForceEra {}) + fn force_new_era_always(&self) -> ExtrinsicFor { + compose_extrinsic!(self, MODULE, FORCE_NEW_ERA_ALWAYS) } - /// Force there to be no new eras indefinitely. - pub fn force_no_era( - &self, - ) -> StakingForceNewEraAlwaysXt - { - compose_extrinsic!(self, MODULE, FORCE_NO_ERA, ForceEra {}) + fn force_no_era(&self) -> ExtrinsicFor { + compose_extrinsic!(self, MODULE, FORCE_NO_ERA) } - /// Re-set the payment target for a controller. - pub fn set_payee( - &self, - payee: Signer::ExtrinsicAddress, - ) -> StakingSetControllerXt { + fn set_payee(&self, payee: Self::Address) -> ExtrinsicFor> { compose_extrinsic!(self, MODULE, SET_PAYEE, payee) } - /// Sets the number of validators. - pub fn set_validator_count( - &self, - count: u32, - ) -> StakingSetValidatorCountXt - { + fn set_validator_count(&self, count: u32) -> ExtrinsicFor { compose_extrinsic!(self, MODULE, SET_VALIDATOR_COUNT, count) } } From 65ce8481377e4192b148f0d8186fb6ce5856815c Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 10:11:06 +0100 Subject: [PATCH 10/22] clean up files --- src/extrinsic/common.rs | 26 ------------------- src/extrinsic/staking.rs | 10 ++------ src/extrinsic/utility.rs | 54 ++++++++++++++++++++++++---------------- 3 files changed, 34 insertions(+), 56 deletions(-) delete mode 100644 src/extrinsic/common.rs diff --git a/src/extrinsic/common.rs b/src/extrinsic/common.rs deleted file mode 100644 index 1b2e4211e..000000000 --- a/src/extrinsic/common.rs +++ /dev/null @@ -1,26 +0,0 @@ -/* - Copyright 2019 Supercomputing Systems AG - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -*/ - -//! Common types. - -use alloc::vec::Vec; -use codec::{Decode, Encode}; - -#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug)] -pub struct Batch { - pub calls: Vec, -} diff --git a/src/extrinsic/staking.rs b/src/extrinsic/staking.rs index 61f8b3627..362359f5a 100644 --- a/src/extrinsic/staking.rs +++ b/src/extrinsic/staking.rs @@ -21,12 +21,8 @@ use super::{AssignExtrinsicTypes, ExtrinsicFor}; use crate::{rpc::Request, Api}; use ac_compose_macros::compose_extrinsic; -use ac_primitives::{ - BalancesConfig, CallIndex, ExtrinsicParams, RewardDestination, SignExtrinsic, StakingConfig, -}; +use ac_primitives::{CallIndex, ExtrinsicParams, RewardDestination, SignExtrinsic, StakingConfig}; use codec::{Compact, Decode, Encode}; -use serde::de::DeserializeOwned; -use sp_runtime::traits::GetRuntimeBlockType; const MODULE: &str = "Staking"; const BOND: &str = "bond"; @@ -150,10 +146,8 @@ where Signer: SignExtrinsic, Client: Request, Params: ExtrinsicParams, - Runtime: GetRuntimeBlockType + BalancesConfig + StakingConfig, + Runtime: StakingConfig, Compact: Encode, - Runtime::Header: DeserializeOwned, - Runtime::RuntimeBlock: DeserializeOwned, { type Balance = Runtime::CurrencyBalance; type RewardDestination = RewardDestination; diff --git a/src/extrinsic/utility.rs b/src/extrinsic/utility.rs index 3c164b690..268a8e24e 100644 --- a/src/extrinsic/utility.rs +++ b/src/extrinsic/utility.rs @@ -16,45 +16,55 @@ */ //! Extrinsics for `pallet-utility`. +//! https://polkadot.js.org/docs/substrate/extrinsics/#utility -use super::common::Batch; +use super::{AssignExtrinsicTypes, ExtrinsicFor}; use crate::{rpc::Request, Api}; use ac_compose_macros::compose_extrinsic; -use ac_primitives::{ - BalancesConfig, CallIndex, ExtrinsicParams, SignExtrinsic, UncheckedExtrinsicV4, -}; +use ac_primitives::{CallIndex, ExtrinsicParams, FrameSystemConfig, SignExtrinsic}; use alloc::{borrow::ToOwned, vec::Vec}; -use codec::Encode; -use sp_runtime::traits::GetRuntimeBlockType; +use codec::{Decode, Encode}; -const UTILITY_MODULE: &str = "Utility"; -const UTILITY_BATCH: &str = "batch"; -const UTILITY_FORCE_BATCH: &str = "force_batch"; +const MODULE: &str = "Utility"; +const BATCH: &str = "batch"; +const FORCE_BATCH: &str = "force_batch"; -pub type UtilityBatchFn = (CallIndex, Batch); -pub type UtilityBatchXt = - UncheckedExtrinsicV4, Signature, SignedExtra>; +#[derive(Clone, Eq, PartialEq, Encode, Decode, Debug)] +pub struct Batch { + pub calls: Vec, +} + +pub type BatchCall = (CallIndex, Batch); + +pub trait CreateUtilityExtrinsic: AssignExtrinsicTypes { + // Send a batch of dispatch calls. + fn batch(&self, calls: Vec) -> ExtrinsicFor>; -impl Api + // Send a batch of dispatch calls. Unlike batch, it allows errors and won't interrupt. + fn force_batch( + &self, + calls: Vec, + ) -> ExtrinsicFor>; +} + +impl CreateUtilityExtrinsic + for Api where Signer: SignExtrinsic, Client: Request, Params: ExtrinsicParams, - Runtime: GetRuntimeBlockType + BalancesConfig, + Runtime: FrameSystemConfig, { - pub fn batch( - &self, - calls: Vec, - ) -> UtilityBatchXt { + fn batch(&self, calls: Vec) -> ExtrinsicFor> { let calls = Batch { calls }; - compose_extrinsic!(self, UTILITY_MODULE, UTILITY_BATCH, calls) + compose_extrinsic!(self, MODULE, BATCH, calls) } - pub fn force_batch( + fn force_batch( &self, calls: Vec, - ) -> UtilityBatchXt { + ) -> ExtrinsicFor> { let calls = Batch { calls }; - compose_extrinsic!(self, UTILITY_MODULE, UTILITY_FORCE_BATCH, calls) + compose_extrinsic!(self, MODULE, FORCE_BATCH, calls) } } From 8392adc7b43ad7049c604575621fb8781219d37e Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 10:15:25 +0100 Subject: [PATCH 11/22] fix mod.rs --- src/extrinsic/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/extrinsic/mod.rs b/src/extrinsic/mod.rs index b83f6209e..4de45aeb9 100644 --- a/src/extrinsic/mod.rs +++ b/src/extrinsic/mod.rs @@ -18,9 +18,12 @@ //! Offers some predefined extrinsics for common runtime modules. pub use balances::CreateBalancesExtrinsic; +pub use contracts::CreateContractsExtrinsic; +#[cfg(feature = "staking-xt")] +pub use staking::CreateStakingExtrinsic; +pub use utility::CreateUtilityExtrinsic; pub mod balances; -pub mod common; pub mod contracts; pub mod offline_extrinsic; #[cfg(feature = "staking-xt")] From e7c92b423d178a30da1ceaa3d1400dea093f8239 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 10:17:44 +0100 Subject: [PATCH 12/22] fix examples --- examples/examples/contract_instantiate_with_code.rs | 4 ++-- examples/examples/staking_batch_payout.rs | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/examples/contract_instantiate_with_code.rs b/examples/examples/contract_instantiate_with_code.rs index ef927eb64..8c1e41021 100644 --- a/examples/examples/contract_instantiate_with_code.rs +++ b/examples/examples/contract_instantiate_with_code.rs @@ -19,8 +19,8 @@ use codec::Decode; use kitchensink_runtime::{AccountId, Runtime, Signature}; use sp_keyring::AccountKeyring; use substrate_api_client::{ - rpc::JsonrpseeClient, Api, ExtrinsicSigner, PlainTipExtrinsicParams, StaticEvent, - SubmitAndWatch, SubmitAndWatchUntilSuccess, XtStatus, + extrinsic::CreateContractsExtrinsic, rpc::JsonrpseeClient, Api, ExtrinsicSigner, + PlainTipExtrinsicParams, StaticEvent, SubmitAndWatch, SubmitAndWatchUntilSuccess, XtStatus, }; #[allow(unused)] diff --git a/examples/examples/staking_batch_payout.rs b/examples/examples/staking_batch_payout.rs index ee9954681..38751068a 100644 --- a/examples/examples/staking_batch_payout.rs +++ b/examples/examples/staking_batch_payout.rs @@ -17,8 +17,10 @@ use pallet_staking::{ActiveEraInfo, Exposure}; use sp_keyring::AccountKeyring; use sp_runtime::{app_crypto::Ss58Codec, AccountId32}; use substrate_api_client::{ - rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner, GetStorage, - SubmitAndWatch, SubmitAndWatchUntilSuccess, XtStatus, + extrinsic::{CreateStakingExtrinsic, CreateUtilityExtrinsic}, + rpc::JsonrpseeClient, + Api, AssetTipExtrinsicParams, ExtrinsicSigner, GetStorage, SubmitAndWatch, + SubmitAndWatchUntilSuccess, XtStatus, }; const MAX_BATCHED_TRANSACTION: u32 = 9; From f6075800321e07a565673508990dfff00bc0c795 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 10:39:12 +0100 Subject: [PATCH 13/22] remove pub use extrinisc::CreateBalance --- examples/examples/event_error_details.rs | 4 ++-- examples/examples/transfer_with_tungstenite_client.rs | 2 +- examples/examples/transfer_with_ws_client.rs | 4 ++-- src/lib.rs | 1 - testing/examples/author_tests.rs | 7 ++++--- testing/examples/pallet_transaction_payment_tests.rs | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/examples/event_error_details.rs b/examples/examples/event_error_details.rs index e6efd0812..dee08763a 100644 --- a/examples/examples/event_error_details.rs +++ b/examples/examples/event_error_details.rs @@ -18,8 +18,8 @@ use kitchensink_runtime::{Runtime, Signature}; use sp_keyring::AccountKeyring; use sp_runtime::{AccountId32 as AccountId, MultiAddress}; use substrate_api_client::{ - rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, CreateBalancesExtrinsic, ExtrinsicSigner, - GetAccountInformation, StaticEvent, SubmitAndWatchUntilSuccess, + extrinsic::CreateBalancesExtrinsic, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, + ExtrinsicSigner, GetAccountInformation, StaticEvent, SubmitAndWatchUntilSuccess, }; #[derive(Decode)] diff --git a/examples/examples/transfer_with_tungstenite_client.rs b/examples/examples/transfer_with_tungstenite_client.rs index ef8a9eed3..439246225 100755 --- a/examples/examples/transfer_with_tungstenite_client.rs +++ b/examples/examples/transfer_with_tungstenite_client.rs @@ -22,7 +22,7 @@ use sp_core::{ }; use sp_runtime::MultiAddress; use substrate_api_client::{ - rpc::TungsteniteRpcClient, Api, AssetTipExtrinsicParams, CreateBalancesExtrinsic, + extrinsic::CreateBalancesExtrinsic, rpc::TungsteniteRpcClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner, GetAccountInformation, SubmitAndWatch, XtStatus, }; diff --git a/examples/examples/transfer_with_ws_client.rs b/examples/examples/transfer_with_ws_client.rs index 88ed6d5f7..c287947c6 100755 --- a/examples/examples/transfer_with_ws_client.rs +++ b/examples/examples/transfer_with_ws_client.rs @@ -22,8 +22,8 @@ use sp_core::{ }; use sp_runtime::MultiAddress; use substrate_api_client::{ - rpc::WsRpcClient, Api, AssetTipExtrinsicParams, CreateBalancesExtrinsic, ExtrinsicSigner, - GetAccountInformation, SubmitAndWatch, XtStatus, + extrinsic::CreateBalancesExtrinsic, rpc::WsRpcClient, Api, AssetTipExtrinsicParams, + ExtrinsicSigner, GetAccountInformation, SubmitAndWatch, XtStatus, }; fn main() { diff --git a/src/lib.rs b/src/lib.rs index 65114e4d4..fe0cb777f 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,6 @@ pub use ac_compose_macros::*; pub use ac_node_api::*; pub use ac_primitives::*; pub use api::*; -pub use extrinsic::CreateBalancesExtrinsic; pub mod api; pub mod extrinsic; diff --git a/testing/examples/author_tests.rs b/testing/examples/author_tests.rs index 20ac007f8..01a5dd2fe 100644 --- a/testing/examples/author_tests.rs +++ b/testing/examples/author_tests.rs @@ -20,10 +20,11 @@ use sp_core::sr25519::Pair; use sp_keyring::AccountKeyring; use std::{thread, time::Duration}; use substrate_api_client::{ + extrinsic::CreateBalancesExtrinsic, rpc::{HandleSubscription, JsonrpseeClient}, - Api, AssetTipExtrinsicParams, CreateBalancesExtrinsic, EventDetails, - ExtrinsicSigner as GenericExtrinsicSigner, SignExtrinsic, SubmitAndWatch, - SubmitAndWatchUntilSuccess, SubmitExtrinsic, TransactionStatus, XtStatus, + Api, AssetTipExtrinsicParams, EventDetails, ExtrinsicSigner as GenericExtrinsicSigner, + SignExtrinsic, SubmitAndWatch, SubmitAndWatchUntilSuccess, SubmitExtrinsic, TransactionStatus, + XtStatus, }; type ExtrinsicSigner = GenericExtrinsicSigner; diff --git a/testing/examples/pallet_transaction_payment_tests.rs b/testing/examples/pallet_transaction_payment_tests.rs index add069847..e58a5ad01 100644 --- a/testing/examples/pallet_transaction_payment_tests.rs +++ b/testing/examples/pallet_transaction_payment_tests.rs @@ -19,8 +19,8 @@ use codec::Encode; use kitchensink_runtime::{Runtime, Signature}; use sp_keyring::AccountKeyring; use substrate_api_client::{ - rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, CreateBalancesExtrinsic, ExtrinsicSigner, - GetBlock, GetTransactionPayment, + extrinsic::CreateBalancesExtrinsic, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, + ExtrinsicSigner, GetBlock, GetTransactionPayment, }; #[tokio::main] From 5d309e97690f5b5e4c6b839ae731ff5d7f26283c Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 12:45:41 +0100 Subject: [PATCH 14/22] update comments --- src/extrinsic/balances.rs | 3 +++ src/extrinsic/mod.rs | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/extrinsic/balances.rs b/src/extrinsic/balances.rs index cc7f1a655..c9ba8b00a 100644 --- a/src/extrinsic/balances.rs +++ b/src/extrinsic/balances.rs @@ -16,6 +16,7 @@ */ //! Extrinsics for `pallet-balances`. +//! https://polkadot.js.org/docs/substrate/extrinsics/#balances use super::{AssignExtrinsicTypes, ExtrinsicFor}; use crate::{api::Api, rpc::Request}; @@ -38,12 +39,14 @@ pub type SetBalanceCall = pub trait CreateBalancesExtrinsic: AssignExtrinsicTypes { type Balance; + /// Transfer some liquid free balance to another account. fn balance_transfer( &self, to: Self::Address, amount: Self::Balance, ) -> ExtrinsicFor>; + /// Set the balances of a given account. fn balance_set_balance( &self, who: Self::Address, diff --git a/src/extrinsic/mod.rs b/src/extrinsic/mod.rs index 4de45aeb9..9bba27667 100644 --- a/src/extrinsic/mod.rs +++ b/src/extrinsic/mod.rs @@ -37,9 +37,13 @@ pub type AddressFor = ::Address; pub type SignatureFor = ::Signature; pub type SignedExtraFor = ::SignedExtra; -type ExtrinsicFor = +/// Type to summarize and simplify the extrinsic return value. It defines all the types in +/// UncheckedExtrinsicV4 except for the Call, which differs for every extrinsic. +pub type ExtrinsicFor = UncheckedExtrinsicV4, Call, SignatureFor, SignedExtraFor>; +/// Helper trait to assign the types used in every extrinsic. +/// This helps to avoid repeated reassignments in the extrinsic creation traits. pub trait AssignExtrinsicTypes { type Address; type Signature; From 4f5a1af0a98a807ed04a9edcb28eb5f1dfa711a5 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 12:52:13 +0100 Subject: [PATCH 15/22] add code --- src/extrinsic/contracts.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/extrinsic/contracts.rs b/src/extrinsic/contracts.rs index e5df4a031..82976baa7 100644 --- a/src/extrinsic/contracts.rs +++ b/src/extrinsic/contracts.rs @@ -38,7 +38,7 @@ pub type GasLimitFor = Compact<::Gas>; pub type ValueFor = Compact<::Currency>; pub type EndowmentFor = Compact<::Currency>; pub type DataFor = ::Data; -pub type CodeFor = ::Data; +pub type CodeFor = ::Code; pub type SaltFor = ::Salt; pub type HashFor = ::Hash; @@ -60,13 +60,14 @@ pub trait CreateContractsExtrinsic: AssignExtrinsicTypes { type Gas; type Currency; type Hash; + type Code; type Data; type Salt; fn contract_put_code( &self, gas_limit: Self::Gas, - code: Self::Data, + code: Self::Code, ) -> ExtrinsicFor>; fn contract_instantiate( @@ -81,7 +82,7 @@ pub trait CreateContractsExtrinsic: AssignExtrinsicTypes { &self, endowment: Self::Currency, gas_limit: Self::Gas, - code: Self::Data, + code: Self::Code, data: Self::Data, salt: Self::Salt, ) -> ExtrinsicFor>; @@ -114,13 +115,14 @@ where type Gas = u64; type Currency = BalanceOf; type Hash = Runtime::Hash; + type Code = Vec; type Data = Vec; type Salt = Vec; fn contract_put_code( &self, gas_limit: Self::Gas, - code: Self::Data, + code: Self::Code, ) -> ExtrinsicFor> { compose_extrinsic!(self, MODULE, PUT_CODE, Compact(gas_limit), code) } @@ -147,7 +149,7 @@ where &self, endowment: Self::Currency, gas_limit: Self::Gas, - code: Self::Data, + code: Self::Code, data: Self::Data, salt: Self::Salt, ) -> ExtrinsicFor> { From 1bd817af7313ade5aca57aa7f97cf016254d33c3 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 12:54:27 +0100 Subject: [PATCH 16/22] add comments --- src/extrinsic/contracts.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/extrinsic/contracts.rs b/src/extrinsic/contracts.rs index 82976baa7..29f613d17 100644 --- a/src/extrinsic/contracts.rs +++ b/src/extrinsic/contracts.rs @@ -17,6 +17,9 @@ //! Extrinsics for `pallet-contract`. //! Contracts module is community maintained and not CI tested, therefore it may not work as is. +//! https://polkadot.js.org/docs/substrate/extrinsics/#contracts + +// FIXME: This module is currently outdated. See https://github.com/scs/substrate-api-client/issues/435. use super::{AddressFor, AssignExtrinsicTypes, ExtrinsicFor}; use crate::{api::Api, rpc::Request}; From 648cea92fa59222b470dd1710288d601cc516b90 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 12:56:14 +0100 Subject: [PATCH 17/22] add s --- src/extrinsic/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extrinsic/mod.rs b/src/extrinsic/mod.rs index 9bba27667..fb4547792 100644 --- a/src/extrinsic/mod.rs +++ b/src/extrinsic/mod.rs @@ -37,7 +37,7 @@ pub type AddressFor = ::Address; pub type SignatureFor = ::Signature; pub type SignedExtraFor = ::SignedExtra; -/// Type to summarize and simplify the extrinsic return value. It defines all the types in +/// Type to summarize and simplify the extrinsic return values. It defines all the types in /// UncheckedExtrinsicV4 except for the Call, which differs for every extrinsic. pub type ExtrinsicFor = UncheckedExtrinsicV4, Call, SignatureFor, SignedExtraFor>; From 28abdb9955db73b1842fdb4649ec072eb5f23b39 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 14:16:55 +0100 Subject: [PATCH 18/22] define Extrinsic type <3 --- src/extrinsic/balances.rs | 20 ++++++---- src/extrinsic/contracts.rs | 26 ++++++++----- src/extrinsic/mod.rs | 31 --------------- src/extrinsic/staking.rs | 77 +++++++++++++++++++------------------- src/extrinsic/utility.rs | 24 ++++++++---- 5 files changed, 84 insertions(+), 94 deletions(-) diff --git a/src/extrinsic/balances.rs b/src/extrinsic/balances.rs index c9ba8b00a..4f21b15a4 100644 --- a/src/extrinsic/balances.rs +++ b/src/extrinsic/balances.rs @@ -18,10 +18,11 @@ //! Extrinsics for `pallet-balances`. //! https://polkadot.js.org/docs/substrate/extrinsics/#balances -use super::{AssignExtrinsicTypes, ExtrinsicFor}; use crate::{api::Api, rpc::Request}; use ac_compose_macros::compose_extrinsic; -use ac_primitives::{BalancesConfig, CallIndex, ExtrinsicParams, SignExtrinsic}; +use ac_primitives::{ + BalancesConfig, CallIndex, ExtrinsicParams, SignExtrinsic, UncheckedExtrinsicV4, +}; use alloc::borrow::ToOwned; use codec::{Compact, Encode}; @@ -36,15 +37,17 @@ pub type TransferCall = (CallIndex, Address, Compact) pub type SetBalanceCall = (CallIndex, Address, Compact, Compact); -pub trait CreateBalancesExtrinsic: AssignExtrinsicTypes { +pub trait CreateBalancesExtrinsic { type Balance; + type Address; + type Extrinsic; /// Transfer some liquid free balance to another account. fn balance_transfer( &self, to: Self::Address, amount: Self::Balance, - ) -> ExtrinsicFor>; + ) -> Self::Extrinsic>; /// Set the balances of a given account. fn balance_set_balance( @@ -52,7 +55,7 @@ pub trait CreateBalancesExtrinsic: AssignExtrinsicTypes { who: Self::Address, free_balance: Self::Balance, reserved_balance: Self::Balance, - ) -> ExtrinsicFor>; + ) -> Self::Extrinsic>; } impl CreateBalancesExtrinsic @@ -65,12 +68,15 @@ where Compact: Encode, { type Balance = Runtime::Balance; + type Address = Signer::ExtrinsicAddress; + type Extrinsic = + UncheckedExtrinsicV4; fn balance_transfer( &self, to: Self::Address, amount: Self::Balance, - ) -> ExtrinsicFor> { + ) -> Self::Extrinsic> { compose_extrinsic!(self, MODULE, TRANSFER, to, Compact(amount)) } @@ -79,7 +85,7 @@ where who: Self::Address, free_balance: Self::Balance, reserved_balance: Self::Balance, - ) -> ExtrinsicFor> { + ) -> Self::Extrinsic> { compose_extrinsic!( self, MODULE, diff --git a/src/extrinsic/contracts.rs b/src/extrinsic/contracts.rs index 29f613d17..f1f01d87b 100644 --- a/src/extrinsic/contracts.rs +++ b/src/extrinsic/contracts.rs @@ -21,11 +21,11 @@ // FIXME: This module is currently outdated. See https://github.com/scs/substrate-api-client/issues/435. -use super::{AddressFor, AssignExtrinsicTypes, ExtrinsicFor}; use crate::{api::Api, rpc::Request}; use ac_compose_macros::compose_extrinsic; use ac_primitives::{ BalancesConfig, CallIndex, ContractsConfig, ExtrinsicParams, FrameSystemConfig, SignExtrinsic, + UncheckedExtrinsicV4, }; use alloc::vec::Vec; use codec::{Compact, Encode}; @@ -44,6 +44,7 @@ pub type DataFor = ::Data; pub type CodeFor = ::Code; pub type SaltFor = ::Salt; pub type HashFor = ::Hash; +pub type AddressFor = ::Address; /// Call for putting code in a contract. pub type PutCodeFor = (CallIndex, GasLimitFor, DataFor); @@ -59,19 +60,21 @@ pub type InstantiateWithCodeFor = /// Call for calling a function inside a contract. pub type ContractCallFor = (CallIndex, AddressFor, ValueFor, GasLimitFor, DataFor); -pub trait CreateContractsExtrinsic: AssignExtrinsicTypes { +pub trait CreateContractsExtrinsic { type Gas; type Currency; type Hash; type Code; type Data; type Salt; + type Address; + type Extrinsic; fn contract_put_code( &self, gas_limit: Self::Gas, code: Self::Code, - ) -> ExtrinsicFor>; + ) -> Self::Extrinsic>; fn contract_instantiate( &self, @@ -79,7 +82,7 @@ pub trait CreateContractsExtrinsic: AssignExtrinsicTypes { gas_limit: Self::Gas, code_hash: Self::Hash, data: Self::Data, - ) -> ExtrinsicFor>; + ) -> Self::Extrinsic>; fn contract_instantiate_with_code( &self, @@ -88,7 +91,7 @@ pub trait CreateContractsExtrinsic: AssignExtrinsicTypes { code: Self::Code, data: Self::Data, salt: Self::Salt, - ) -> ExtrinsicFor>; + ) -> Self::Extrinsic>; fn contract_call( &self, @@ -96,7 +99,7 @@ pub trait CreateContractsExtrinsic: AssignExtrinsicTypes { value: Self::Currency, gas_limit: Self::Gas, data: Self::Data, - ) -> ExtrinsicFor>; + ) -> Self::Extrinsic>; } #[cfg(feature = "std")] @@ -121,12 +124,15 @@ where type Code = Vec; type Data = Vec; type Salt = Vec; + type Address = Signer::ExtrinsicAddress; + type Extrinsic = + UncheckedExtrinsicV4; fn contract_put_code( &self, gas_limit: Self::Gas, code: Self::Code, - ) -> ExtrinsicFor> { + ) -> Self::Extrinsic> { compose_extrinsic!(self, MODULE, PUT_CODE, Compact(gas_limit), code) } @@ -136,7 +142,7 @@ where gas_limit: Self::Gas, code_hash: Self::Hash, data: Self::Data, - ) -> ExtrinsicFor> { + ) -> Self::Extrinsic> { compose_extrinsic!( self, MODULE, @@ -155,7 +161,7 @@ where code: Self::Code, data: Self::Data, salt: Self::Salt, - ) -> ExtrinsicFor> { + ) -> Self::Extrinsic> { compose_extrinsic!( self, MODULE, @@ -174,7 +180,7 @@ where value: Self::Currency, gas_limit: Self::Gas, data: Self::Data, - ) -> ExtrinsicFor> { + ) -> Self::Extrinsic> { compose_extrinsic!(self, MODULE, CALL, dest, Compact(value), Compact(gas_limit), data) } } diff --git a/src/extrinsic/mod.rs b/src/extrinsic/mod.rs index fb4547792..c3d692fab 100644 --- a/src/extrinsic/mod.rs +++ b/src/extrinsic/mod.rs @@ -29,34 +29,3 @@ pub mod offline_extrinsic; #[cfg(feature = "staking-xt")] pub mod staking; pub mod utility; - -use crate::Api; -use ac_primitives::{ExtrinsicParams, FrameSystemConfig, SignExtrinsic, UncheckedExtrinsicV4}; - -pub type AddressFor = ::Address; -pub type SignatureFor = ::Signature; -pub type SignedExtraFor = ::SignedExtra; - -/// Type to summarize and simplify the extrinsic return values. It defines all the types in -/// UncheckedExtrinsicV4 except for the Call, which differs for every extrinsic. -pub type ExtrinsicFor = - UncheckedExtrinsicV4, Call, SignatureFor, SignedExtraFor>; - -/// Helper trait to assign the types used in every extrinsic. -/// This helps to avoid repeated reassignments in the extrinsic creation traits. -pub trait AssignExtrinsicTypes { - type Address; - type Signature; - type SignedExtra; -} - -impl AssignExtrinsicTypes for Api -where - Signer: SignExtrinsic, - Runtime: FrameSystemConfig, - Params: ExtrinsicParams, -{ - type Address = Signer::ExtrinsicAddress; - type Signature = Signer::Signature; - type SignedExtra = Params::SignedExtra; -} diff --git a/src/extrinsic/staking.rs b/src/extrinsic/staking.rs index 362359f5a..b4b4e9f16 100644 --- a/src/extrinsic/staking.rs +++ b/src/extrinsic/staking.rs @@ -18,10 +18,12 @@ //! Extrinsics for `pallet-staking`. //! https://polkadot.js.org/docs/substrate/extrinsics#staking -use super::{AssignExtrinsicTypes, ExtrinsicFor}; use crate::{rpc::Request, Api}; use ac_compose_macros::compose_extrinsic; -use ac_primitives::{CallIndex, ExtrinsicParams, RewardDestination, SignExtrinsic, StakingConfig}; +use ac_primitives::{ + CallIndex, ExtrinsicParams, RewardDestination, SignExtrinsic, StakingConfig, + UncheckedExtrinsicV4, +}; use codec::{Compact, Decode, Encode}; const MODULE: &str = "Staking"; @@ -62,10 +64,12 @@ pub type ForceNoEraCall = CallIndex; pub type SetPayeeCall
= (CallIndex, Address); pub type SetValidatorCountCall = (CallIndex, u32); -pub trait CreateStakingExtrinsic: AssignExtrinsicTypes { +pub trait CreateStakingExtrinsic { type Balance; type RewardDestination; type AccountId; + type Address; + type Extrinsic; /// Bond `value` amount to `controller`. fn staking_bond( @@ -73,23 +77,21 @@ pub trait CreateStakingExtrinsic: AssignExtrinsicTypes { controller: Self::Address, value: Self::Balance, payee: Self::RewardDestination, - ) -> ExtrinsicFor>; + ) -> Self::Extrinsic>; /// Bonds extra funds from the stash's free balance to the balance for staking. fn staking_bond_extra( &self, value: Self::Balance, - ) -> ExtrinsicFor>; + ) -> Self::Extrinsic>; /// Unbond `value` portion of the stash. /// If `value` is less than the minimum required, then the entire amount is unbound. /// Must be signed by the controller of the stash. - fn staking_unbond(&self, value: Self::Balance) - -> ExtrinsicFor>; + fn staking_unbond(&self, value: Self::Balance) -> Self::Extrinsic>; /// Rebond `value` portion of the current amount that is in the process of unbonding. - fn staking_rebond(&self, value: Self::Balance) - -> ExtrinsicFor>; + fn staking_rebond(&self, value: Self::Balance) -> Self::Extrinsic>; /// Free the balance of the stash so the stash account can do whatever it wants. /// Must be signed by the controller of the stash and called when EraElectionStatus is Closed. @@ -97,17 +99,17 @@ pub trait CreateStakingExtrinsic: AssignExtrinsicTypes { fn staking_withdraw_unbonded( &self, num_slashing_spans: u32, - ) -> ExtrinsicFor; + ) -> Self::Extrinsic; /// Nominate `targets` as validators. /// Must be signed by the controller of the stash and called when EraElectionStatus is Closed. fn staking_nominate( &self, targets: Vec, - ) -> ExtrinsicFor>; + ) -> Self::Extrinsic>; /// Stop nominating por validating. Effects take place in the next era - fn staking_chill(&self) -> ExtrinsicFor; + fn staking_chill(&self) -> Self::Extrinsic; /// (Re-)set the controller of the stash /// Effects will be felt at the beginning of the next era. @@ -115,29 +117,29 @@ pub trait CreateStakingExtrinsic: AssignExtrinsicTypes { fn staking_set_controller( &self, controller: Self::Address, - ) -> ExtrinsicFor>; + ) -> Self::Extrinsic>; /// Return the payout call for the given era fn payout_stakers( &self, era: u32, account: Self::AccountId, - ) -> ExtrinsicFor>; + ) -> Self::Extrinsic>; /// For New Era at the end of Next Session. - fn force_new_era(&self) -> ExtrinsicFor; + fn force_new_era(&self) -> Self::Extrinsic; /// Force there to be a new era at the end of sessions indefinitely. - fn force_new_era_always(&self) -> ExtrinsicFor; + fn force_new_era_always(&self) -> Self::Extrinsic; /// Force there to be no new eras indefinitely. - fn force_no_era(&self) -> ExtrinsicFor; + fn force_no_era(&self) -> Self::Extrinsic; /// Re-set the payment target for a controller. - fn set_payee(&self, payee: Self::Address) -> ExtrinsicFor>; + fn set_payee(&self, payee: Self::Address) -> Self::Extrinsic>; /// Sets the number of validators. - fn set_validator_count(&self, count: u32) -> ExtrinsicFor; + fn set_validator_count(&self, count: u32) -> Self::Extrinsic; } impl CreateStakingExtrinsic @@ -152,59 +154,56 @@ where type Balance = Runtime::CurrencyBalance; type RewardDestination = RewardDestination; type AccountId = Runtime::AccountId; + type Address = Signer::ExtrinsicAddress; + type Extrinsic = + UncheckedExtrinsicV4; fn staking_bond( &self, controller: Self::Address, value: Self::Balance, payee: Self::RewardDestination, - ) -> ExtrinsicFor> { + ) -> Self::Extrinsic> { compose_extrinsic!(self, MODULE, BOND, controller, Compact(value), payee) } fn staking_bond_extra( &self, value: Self::Balance, - ) -> ExtrinsicFor> { + ) -> Self::Extrinsic> { compose_extrinsic!(self, MODULE, BOND_EXTRA, Compact(value)) } - fn staking_unbond( - &self, - value: Self::Balance, - ) -> ExtrinsicFor> { + fn staking_unbond(&self, value: Self::Balance) -> Self::Extrinsic> { compose_extrinsic!(self, MODULE, UNBOND, Compact(value)) } - fn staking_rebond( - &self, - value: Self::Balance, - ) -> ExtrinsicFor> { + fn staking_rebond(&self, value: Self::Balance) -> Self::Extrinsic> { compose_extrinsic!(self, MODULE, REBOND, Compact(value)) } fn staking_withdraw_unbonded( &self, num_slashing_spans: u32, - ) -> ExtrinsicFor { + ) -> Self::Extrinsic { compose_extrinsic!(self, MODULE, WITHDRAW_UNBONDED, num_slashing_spans) } fn staking_nominate( &self, targets: Vec, - ) -> ExtrinsicFor> { + ) -> Self::Extrinsic> { compose_extrinsic!(self, MODULE, NOMINATE, targets) } - fn staking_chill(&self) -> ExtrinsicFor { + fn staking_chill(&self) -> Self::Extrinsic { compose_extrinsic!(self, MODULE, CHILL) } fn staking_set_controller( &self, controller: Self::Address, - ) -> ExtrinsicFor> { + ) -> Self::Extrinsic> { compose_extrinsic!(self, MODULE, SET_CONTROLLER, controller) } @@ -212,28 +211,28 @@ where &self, era: u32, account: Self::AccountId, - ) -> ExtrinsicFor> { + ) -> Self::Extrinsic> { let value = PayoutStakers { validator_stash: account, era }; compose_extrinsic!(self, MODULE, PAYOUT_STAKERS, value) } - fn force_new_era(&self) -> ExtrinsicFor { + fn force_new_era(&self) -> Self::Extrinsic { compose_extrinsic!(self, MODULE, FORCE_NEW_ERA) } - fn force_new_era_always(&self) -> ExtrinsicFor { + fn force_new_era_always(&self) -> Self::Extrinsic { compose_extrinsic!(self, MODULE, FORCE_NEW_ERA_ALWAYS) } - fn force_no_era(&self) -> ExtrinsicFor { + fn force_no_era(&self) -> Self::Extrinsic { compose_extrinsic!(self, MODULE, FORCE_NO_ERA) } - fn set_payee(&self, payee: Self::Address) -> ExtrinsicFor> { + fn set_payee(&self, payee: Self::Address) -> Self::Extrinsic> { compose_extrinsic!(self, MODULE, SET_PAYEE, payee) } - fn set_validator_count(&self, count: u32) -> ExtrinsicFor { + fn set_validator_count(&self, count: u32) -> Self::Extrinsic { compose_extrinsic!(self, MODULE, SET_VALIDATOR_COUNT, count) } } diff --git a/src/extrinsic/utility.rs b/src/extrinsic/utility.rs index 268a8e24e..528dfeb61 100644 --- a/src/extrinsic/utility.rs +++ b/src/extrinsic/utility.rs @@ -18,10 +18,11 @@ //! Extrinsics for `pallet-utility`. //! https://polkadot.js.org/docs/substrate/extrinsics/#utility -use super::{AssignExtrinsicTypes, ExtrinsicFor}; use crate::{rpc::Request, Api}; use ac_compose_macros::compose_extrinsic; -use ac_primitives::{CallIndex, ExtrinsicParams, FrameSystemConfig, SignExtrinsic}; +use ac_primitives::{ + CallIndex, ExtrinsicParams, FrameSystemConfig, SignExtrinsic, UncheckedExtrinsicV4, +}; use alloc::{borrow::ToOwned, vec::Vec}; use codec::{Decode, Encode}; @@ -36,15 +37,17 @@ pub struct Batch { pub type BatchCall = (CallIndex, Batch); -pub trait CreateUtilityExtrinsic: AssignExtrinsicTypes { +pub trait CreateUtilityExtrinsic { + type Extrinsic; + // Send a batch of dispatch calls. - fn batch(&self, calls: Vec) -> ExtrinsicFor>; + fn batch(&self, calls: Vec) -> Self::Extrinsic>; // Send a batch of dispatch calls. Unlike batch, it allows errors and won't interrupt. fn force_batch( &self, calls: Vec, - ) -> ExtrinsicFor>; + ) -> Self::Extrinsic>; } impl CreateUtilityExtrinsic @@ -55,7 +58,14 @@ where Params: ExtrinsicParams, Runtime: FrameSystemConfig, { - fn batch(&self, calls: Vec) -> ExtrinsicFor> { + type Extrinsic = UncheckedExtrinsicV4< + Signer::ExtrinsicAddress, + Call, + Signer::Signature, + Params::SignedExtra, + >; + + fn batch(&self, calls: Vec) -> Self::Extrinsic> { let calls = Batch { calls }; compose_extrinsic!(self, MODULE, BATCH, calls) } @@ -63,7 +73,7 @@ where fn force_batch( &self, calls: Vec, - ) -> ExtrinsicFor> { + ) -> Self::Extrinsic> { let calls = Batch { calls }; compose_extrinsic!(self, MODULE, FORCE_BATCH, calls) } From ad1a8e33c307045a682fe0347912b31058af492d Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 14:24:30 +0100 Subject: [PATCH 19/22] add prefix to const MODULE --- src/extrinsic/balances.rs | 6 +++--- src/extrinsic/contracts.rs | 18 +++++++++++++----- src/extrinsic/staking.rs | 30 +++++++++++++++--------------- src/extrinsic/utility.rs | 6 +++--- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/extrinsic/balances.rs b/src/extrinsic/balances.rs index 4f21b15a4..fdafefc06 100644 --- a/src/extrinsic/balances.rs +++ b/src/extrinsic/balances.rs @@ -26,7 +26,7 @@ use ac_primitives::{ use alloc::borrow::ToOwned; use codec::{Compact, Encode}; -pub const MODULE: &str = "Balances"; +pub const BALANCES_MODULE: &str = "Balances"; pub const TRANSFER: &str = "transfer"; pub const SET_BALANCE: &str = "set_balance"; @@ -77,7 +77,7 @@ where to: Self::Address, amount: Self::Balance, ) -> Self::Extrinsic> { - compose_extrinsic!(self, MODULE, TRANSFER, to, Compact(amount)) + compose_extrinsic!(self, BALANCES_MODULE, TRANSFER, to, Compact(amount)) } fn balance_set_balance( @@ -88,7 +88,7 @@ where ) -> Self::Extrinsic> { compose_extrinsic!( self, - MODULE, + BALANCES_MODULE, SET_BALANCE, who, Compact(free_balance), diff --git a/src/extrinsic/contracts.rs b/src/extrinsic/contracts.rs index f1f01d87b..4d6d57c98 100644 --- a/src/extrinsic/contracts.rs +++ b/src/extrinsic/contracts.rs @@ -31,7 +31,7 @@ use alloc::vec::Vec; use codec::{Compact, Encode}; use sp_runtime::traits::GetRuntimeBlockType; -pub const MODULE: &str = "Contracts"; +pub const CONTRACTS_MODULE: &str = "Contracts"; pub const PUT_CODE: &str = "put_code"; pub const INSTANTIATE: &str = "instantiate"; pub const INSTANTIATE_WITH_CODE: &str = "instantiate_with_code"; @@ -133,7 +133,7 @@ where gas_limit: Self::Gas, code: Self::Code, ) -> Self::Extrinsic> { - compose_extrinsic!(self, MODULE, PUT_CODE, Compact(gas_limit), code) + compose_extrinsic!(self, CONTRACTS_MODULE, PUT_CODE, Compact(gas_limit), code) } fn contract_instantiate( @@ -145,7 +145,7 @@ where ) -> Self::Extrinsic> { compose_extrinsic!( self, - MODULE, + CONTRACTS_MODULE, INSTANTIATE, Compact(endowment), Compact(gas_limit), @@ -164,7 +164,7 @@ where ) -> Self::Extrinsic> { compose_extrinsic!( self, - MODULE, + CONTRACTS_MODULE, INSTANTIATE_WITH_CODE, Compact(endowment), Compact(gas_limit), @@ -181,6 +181,14 @@ where gas_limit: Self::Gas, data: Self::Data, ) -> Self::Extrinsic> { - compose_extrinsic!(self, MODULE, CALL, dest, Compact(value), Compact(gas_limit), data) + compose_extrinsic!( + self, + CONTRACTS_MODULE, + CALL, + dest, + Compact(value), + Compact(gas_limit), + data + ) } } diff --git a/src/extrinsic/staking.rs b/src/extrinsic/staking.rs index b4b4e9f16..a633828ee 100644 --- a/src/extrinsic/staking.rs +++ b/src/extrinsic/staking.rs @@ -26,7 +26,7 @@ use ac_primitives::{ }; use codec::{Compact, Decode, Encode}; -const MODULE: &str = "Staking"; +const STAKING_MODULE: &str = "Staking"; const BOND: &str = "bond"; const BOND_EXTRA: &str = "bond_extra"; const UNBOND: &str = "unbond"; @@ -164,47 +164,47 @@ where value: Self::Balance, payee: Self::RewardDestination, ) -> Self::Extrinsic> { - compose_extrinsic!(self, MODULE, BOND, controller, Compact(value), payee) + compose_extrinsic!(self, STAKING_MODULE, BOND, controller, Compact(value), payee) } fn staking_bond_extra( &self, value: Self::Balance, ) -> Self::Extrinsic> { - compose_extrinsic!(self, MODULE, BOND_EXTRA, Compact(value)) + compose_extrinsic!(self, STAKING_MODULE, BOND_EXTRA, Compact(value)) } fn staking_unbond(&self, value: Self::Balance) -> Self::Extrinsic> { - compose_extrinsic!(self, MODULE, UNBOND, Compact(value)) + compose_extrinsic!(self, STAKING_MODULE, UNBOND, Compact(value)) } fn staking_rebond(&self, value: Self::Balance) -> Self::Extrinsic> { - compose_extrinsic!(self, MODULE, REBOND, Compact(value)) + compose_extrinsic!(self, STAKING_MODULE, REBOND, Compact(value)) } fn staking_withdraw_unbonded( &self, num_slashing_spans: u32, ) -> Self::Extrinsic { - compose_extrinsic!(self, MODULE, WITHDRAW_UNBONDED, num_slashing_spans) + compose_extrinsic!(self, STAKING_MODULE, WITHDRAW_UNBONDED, num_slashing_spans) } fn staking_nominate( &self, targets: Vec, ) -> Self::Extrinsic> { - compose_extrinsic!(self, MODULE, NOMINATE, targets) + compose_extrinsic!(self, STAKING_MODULE, NOMINATE, targets) } fn staking_chill(&self) -> Self::Extrinsic { - compose_extrinsic!(self, MODULE, CHILL) + compose_extrinsic!(self, STAKING_MODULE, CHILL) } fn staking_set_controller( &self, controller: Self::Address, ) -> Self::Extrinsic> { - compose_extrinsic!(self, MODULE, SET_CONTROLLER, controller) + compose_extrinsic!(self, STAKING_MODULE, SET_CONTROLLER, controller) } fn payout_stakers( @@ -213,26 +213,26 @@ where account: Self::AccountId, ) -> Self::Extrinsic> { let value = PayoutStakers { validator_stash: account, era }; - compose_extrinsic!(self, MODULE, PAYOUT_STAKERS, value) + compose_extrinsic!(self, STAKING_MODULE, PAYOUT_STAKERS, value) } fn force_new_era(&self) -> Self::Extrinsic { - compose_extrinsic!(self, MODULE, FORCE_NEW_ERA) + compose_extrinsic!(self, STAKING_MODULE, FORCE_NEW_ERA) } fn force_new_era_always(&self) -> Self::Extrinsic { - compose_extrinsic!(self, MODULE, FORCE_NEW_ERA_ALWAYS) + compose_extrinsic!(self, STAKING_MODULE, FORCE_NEW_ERA_ALWAYS) } fn force_no_era(&self) -> Self::Extrinsic { - compose_extrinsic!(self, MODULE, FORCE_NO_ERA) + compose_extrinsic!(self, STAKING_MODULE, FORCE_NO_ERA) } fn set_payee(&self, payee: Self::Address) -> Self::Extrinsic> { - compose_extrinsic!(self, MODULE, SET_PAYEE, payee) + compose_extrinsic!(self, STAKING_MODULE, SET_PAYEE, payee) } fn set_validator_count(&self, count: u32) -> Self::Extrinsic { - compose_extrinsic!(self, MODULE, SET_VALIDATOR_COUNT, count) + compose_extrinsic!(self, STAKING_MODULE, SET_VALIDATOR_COUNT, count) } } diff --git a/src/extrinsic/utility.rs b/src/extrinsic/utility.rs index 528dfeb61..99123b451 100644 --- a/src/extrinsic/utility.rs +++ b/src/extrinsic/utility.rs @@ -26,7 +26,7 @@ use ac_primitives::{ use alloc::{borrow::ToOwned, vec::Vec}; use codec::{Decode, Encode}; -const MODULE: &str = "Utility"; +const UTILITY_MODULE: &str = "Utility"; const BATCH: &str = "batch"; const FORCE_BATCH: &str = "force_batch"; @@ -67,7 +67,7 @@ where fn batch(&self, calls: Vec) -> Self::Extrinsic> { let calls = Batch { calls }; - compose_extrinsic!(self, MODULE, BATCH, calls) + compose_extrinsic!(self, UTILITY_MODULE, BATCH, calls) } fn force_batch( @@ -75,6 +75,6 @@ where calls: Vec, ) -> Self::Extrinsic> { let calls = Batch { calls }; - compose_extrinsic!(self, MODULE, FORCE_BATCH, calls) + compose_extrinsic!(self, UTILITY_MODULE, FORCE_BATCH, calls) } } From 8593f92fec58fc49a6a47fee7cf5987c10d35931 Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 14:28:03 +0100 Subject: [PATCH 20/22] remove obsolsete trait bounds --- src/extrinsic/contracts.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/extrinsic/contracts.rs b/src/extrinsic/contracts.rs index 4d6d57c98..7b6c594d8 100644 --- a/src/extrinsic/contracts.rs +++ b/src/extrinsic/contracts.rs @@ -24,12 +24,11 @@ use crate::{api::Api, rpc::Request}; use ac_compose_macros::compose_extrinsic; use ac_primitives::{ - BalancesConfig, CallIndex, ContractsConfig, ExtrinsicParams, FrameSystemConfig, SignExtrinsic, + CallIndex, ContractsConfig, ExtrinsicParams, FrameSystemConfig, SignExtrinsic, UncheckedExtrinsicV4, }; use alloc::vec::Vec; use codec::{Compact, Encode}; -use sp_runtime::traits::GetRuntimeBlockType; pub const CONTRACTS_MODULE: &str = "Contracts"; pub const PUT_CODE: &str = "put_code"; @@ -114,7 +113,7 @@ where Signer: SignExtrinsic, Client: Request, Params: ExtrinsicParams, - Runtime: GetRuntimeBlockType + ContractsConfig + BalancesConfig, + Runtime: ContractsConfig, Compact>: Encode + Clone, Runtime::Currency: frame_support::traits::Currency, { From 21f94f218d9814c48609c3bf790d0773269a0f2f Mon Sep 17 00:00:00 2001 From: haerdib Date: Thu, 12 Jan 2023 15:44:35 +0100 Subject: [PATCH 21/22] fix CI --- testing/examples/events_tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/examples/events_tests.rs b/testing/examples/events_tests.rs index 66287990d..ab360ee13 100644 --- a/testing/examples/events_tests.rs +++ b/testing/examples/events_tests.rs @@ -20,8 +20,8 @@ use frame_support::dispatch::DispatchInfo; use kitchensink_runtime::{Runtime, Signature}; use sp_keyring::AccountKeyring; use substrate_api_client::{ - rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, EventDetails, ExtrinsicSigner, FetchEvents, - GetBlock, StaticEvent, SubmitAndWatch, XtStatus, + extrinsic::CreateBalancesExtrinsic, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, + EventDetails, ExtrinsicSigner, FetchEvents, GetBlock, StaticEvent, SubmitAndWatch, XtStatus, }; /// Check out frame_system::Event::ExtrinsicSuccess: From 6a3220e77d6a842ed44ad42e1a4b3fd4a936ecc6 Mon Sep 17 00:00:00 2001 From: haerdib Date: Wed, 18 Jan 2023 11:50:45 +0100 Subject: [PATCH 22/22] rename trait Create..Extrinsic to ..Extrinsics --- .../contract_instantiate_with_code.rs | 2 +- examples/examples/event_error_details.rs | 2 +- examples/examples/staking_batch_payout.rs | 2 +- .../transfer_with_tungstenite_client.rs | 2 +- examples/examples/transfer_with_ws_client.rs | 4 ++-- src/extrinsic/balances.rs | 5 ++--- src/extrinsic/contracts.rs | 21 +++++++++---------- src/extrinsic/mod.rs | 8 +++---- src/extrinsic/staking.rs | 5 ++--- src/extrinsic/utility.rs | 5 ++--- testing/examples/author_tests.rs | 2 +- testing/examples/events_tests.rs | 2 +- .../pallet_transaction_payment_tests.rs | 2 +- 13 files changed, 29 insertions(+), 33 deletions(-) diff --git a/examples/examples/contract_instantiate_with_code.rs b/examples/examples/contract_instantiate_with_code.rs index 8c1e41021..262f26c0b 100644 --- a/examples/examples/contract_instantiate_with_code.rs +++ b/examples/examples/contract_instantiate_with_code.rs @@ -19,7 +19,7 @@ use codec::Decode; use kitchensink_runtime::{AccountId, Runtime, Signature}; use sp_keyring::AccountKeyring; use substrate_api_client::{ - extrinsic::CreateContractsExtrinsic, rpc::JsonrpseeClient, Api, ExtrinsicSigner, + extrinsic::ContractsExtrinsics, rpc::JsonrpseeClient, Api, ExtrinsicSigner, PlainTipExtrinsicParams, StaticEvent, SubmitAndWatch, SubmitAndWatchUntilSuccess, XtStatus, }; diff --git a/examples/examples/event_error_details.rs b/examples/examples/event_error_details.rs index dee08763a..9eb777447 100644 --- a/examples/examples/event_error_details.rs +++ b/examples/examples/event_error_details.rs @@ -18,7 +18,7 @@ use kitchensink_runtime::{Runtime, Signature}; use sp_keyring::AccountKeyring; use sp_runtime::{AccountId32 as AccountId, MultiAddress}; use substrate_api_client::{ - extrinsic::CreateBalancesExtrinsic, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, + extrinsic::BalancesExtrinsics, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner, GetAccountInformation, StaticEvent, SubmitAndWatchUntilSuccess, }; diff --git a/examples/examples/staking_batch_payout.rs b/examples/examples/staking_batch_payout.rs index 38751068a..9be275d24 100644 --- a/examples/examples/staking_batch_payout.rs +++ b/examples/examples/staking_batch_payout.rs @@ -17,7 +17,7 @@ use pallet_staking::{ActiveEraInfo, Exposure}; use sp_keyring::AccountKeyring; use sp_runtime::{app_crypto::Ss58Codec, AccountId32}; use substrate_api_client::{ - extrinsic::{CreateStakingExtrinsic, CreateUtilityExtrinsic}, + extrinsic::{StakingExtrinsics, UtilityExtrinsics}, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner, GetStorage, SubmitAndWatch, SubmitAndWatchUntilSuccess, XtStatus, diff --git a/examples/examples/transfer_with_tungstenite_client.rs b/examples/examples/transfer_with_tungstenite_client.rs index 439246225..73997fb65 100755 --- a/examples/examples/transfer_with_tungstenite_client.rs +++ b/examples/examples/transfer_with_tungstenite_client.rs @@ -22,7 +22,7 @@ use sp_core::{ }; use sp_runtime::MultiAddress; use substrate_api_client::{ - extrinsic::CreateBalancesExtrinsic, rpc::TungsteniteRpcClient, Api, AssetTipExtrinsicParams, + extrinsic::BalancesExtrinsics, rpc::TungsteniteRpcClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner, GetAccountInformation, SubmitAndWatch, XtStatus, }; diff --git a/examples/examples/transfer_with_ws_client.rs b/examples/examples/transfer_with_ws_client.rs index c287947c6..7d99b15c6 100755 --- a/examples/examples/transfer_with_ws_client.rs +++ b/examples/examples/transfer_with_ws_client.rs @@ -22,8 +22,8 @@ use sp_core::{ }; use sp_runtime::MultiAddress; use substrate_api_client::{ - extrinsic::CreateBalancesExtrinsic, rpc::WsRpcClient, Api, AssetTipExtrinsicParams, - ExtrinsicSigner, GetAccountInformation, SubmitAndWatch, XtStatus, + extrinsic::BalancesExtrinsics, rpc::WsRpcClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner, + GetAccountInformation, SubmitAndWatch, XtStatus, }; fn main() { diff --git a/src/extrinsic/balances.rs b/src/extrinsic/balances.rs index fdafefc06..4b1a26d7d 100644 --- a/src/extrinsic/balances.rs +++ b/src/extrinsic/balances.rs @@ -37,7 +37,7 @@ pub type TransferCall = (CallIndex, Address, Compact) pub type SetBalanceCall = (CallIndex, Address, Compact, Compact); -pub trait CreateBalancesExtrinsic { +pub trait BalancesExtrinsics { type Balance; type Address; type Extrinsic; @@ -58,8 +58,7 @@ pub trait CreateBalancesExtrinsic { ) -> Self::Extrinsic>; } -impl CreateBalancesExtrinsic - for Api +impl BalancesExtrinsics for Api where Signer: SignExtrinsic, Client: Request, diff --git a/src/extrinsic/contracts.rs b/src/extrinsic/contracts.rs index 7b6c594d8..cc92e6676 100644 --- a/src/extrinsic/contracts.rs +++ b/src/extrinsic/contracts.rs @@ -36,14 +36,14 @@ pub const INSTANTIATE: &str = "instantiate"; pub const INSTANTIATE_WITH_CODE: &str = "instantiate_with_code"; pub const CALL: &str = "call"; -pub type GasLimitFor = Compact<::Gas>; -pub type ValueFor = Compact<::Currency>; -pub type EndowmentFor = Compact<::Currency>; -pub type DataFor = ::Data; -pub type CodeFor = ::Code; -pub type SaltFor = ::Salt; -pub type HashFor = ::Hash; -pub type AddressFor = ::Address; +pub type GasLimitFor = Compact<::Gas>; +pub type ValueFor = Compact<::Currency>; +pub type EndowmentFor = Compact<::Currency>; +pub type DataFor = ::Data; +pub type CodeFor = ::Code; +pub type SaltFor = ::Salt; +pub type HashFor = ::Hash; +pub type AddressFor = ::Address; /// Call for putting code in a contract. pub type PutCodeFor = (CallIndex, GasLimitFor, DataFor); @@ -59,7 +59,7 @@ pub type InstantiateWithCodeFor = /// Call for calling a function inside a contract. pub type ContractCallFor = (CallIndex, AddressFor, ValueFor, GasLimitFor, DataFor); -pub trait CreateContractsExtrinsic { +pub trait ContractsExtrinsics { type Gas; type Currency; type Hash; @@ -107,8 +107,7 @@ type BalanceOf = <::Currency as frame_support::traits:: >>::Balance; #[cfg(feature = "std")] -impl CreateContractsExtrinsic - for Api +impl ContractsExtrinsics for Api where Signer: SignExtrinsic, Client: Request, diff --git a/src/extrinsic/mod.rs b/src/extrinsic/mod.rs index c3d692fab..74518e1c7 100644 --- a/src/extrinsic/mod.rs +++ b/src/extrinsic/mod.rs @@ -17,11 +17,11 @@ //! Offers some predefined extrinsics for common runtime modules. -pub use balances::CreateBalancesExtrinsic; -pub use contracts::CreateContractsExtrinsic; +pub use balances::BalancesExtrinsics; +pub use contracts::ContractsExtrinsics; #[cfg(feature = "staking-xt")] -pub use staking::CreateStakingExtrinsic; -pub use utility::CreateUtilityExtrinsic; +pub use staking::StakingExtrinsics; +pub use utility::UtilityExtrinsics; pub mod balances; pub mod contracts; diff --git a/src/extrinsic/staking.rs b/src/extrinsic/staking.rs index a633828ee..492b1c67f 100644 --- a/src/extrinsic/staking.rs +++ b/src/extrinsic/staking.rs @@ -64,7 +64,7 @@ pub type ForceNoEraCall = CallIndex; pub type SetPayeeCall
= (CallIndex, Address); pub type SetValidatorCountCall = (CallIndex, u32); -pub trait CreateStakingExtrinsic { +pub trait StakingExtrinsics { type Balance; type RewardDestination; type AccountId; @@ -142,8 +142,7 @@ pub trait CreateStakingExtrinsic { fn set_validator_count(&self, count: u32) -> Self::Extrinsic; } -impl CreateStakingExtrinsic - for Api +impl StakingExtrinsics for Api where Signer: SignExtrinsic, Client: Request, diff --git a/src/extrinsic/utility.rs b/src/extrinsic/utility.rs index 99123b451..df4d74efc 100644 --- a/src/extrinsic/utility.rs +++ b/src/extrinsic/utility.rs @@ -37,7 +37,7 @@ pub struct Batch { pub type BatchCall = (CallIndex, Batch); -pub trait CreateUtilityExtrinsic { +pub trait UtilityExtrinsics { type Extrinsic; // Send a batch of dispatch calls. @@ -50,8 +50,7 @@ pub trait CreateUtilityExtrinsic { ) -> Self::Extrinsic>; } -impl CreateUtilityExtrinsic - for Api +impl UtilityExtrinsics for Api where Signer: SignExtrinsic, Client: Request, diff --git a/testing/examples/author_tests.rs b/testing/examples/author_tests.rs index 01a5dd2fe..2c577e3a2 100644 --- a/testing/examples/author_tests.rs +++ b/testing/examples/author_tests.rs @@ -20,7 +20,7 @@ use sp_core::sr25519::Pair; use sp_keyring::AccountKeyring; use std::{thread, time::Duration}; use substrate_api_client::{ - extrinsic::CreateBalancesExtrinsic, + extrinsic::BalancesExtrinsics, rpc::{HandleSubscription, JsonrpseeClient}, Api, AssetTipExtrinsicParams, EventDetails, ExtrinsicSigner as GenericExtrinsicSigner, SignExtrinsic, SubmitAndWatch, SubmitAndWatchUntilSuccess, SubmitExtrinsic, TransactionStatus, diff --git a/testing/examples/events_tests.rs b/testing/examples/events_tests.rs index ab360ee13..69d52744a 100644 --- a/testing/examples/events_tests.rs +++ b/testing/examples/events_tests.rs @@ -20,7 +20,7 @@ use frame_support::dispatch::DispatchInfo; use kitchensink_runtime::{Runtime, Signature}; use sp_keyring::AccountKeyring; use substrate_api_client::{ - extrinsic::CreateBalancesExtrinsic, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, + extrinsic::BalancesExtrinsics, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, EventDetails, ExtrinsicSigner, FetchEvents, GetBlock, StaticEvent, SubmitAndWatch, XtStatus, }; diff --git a/testing/examples/pallet_transaction_payment_tests.rs b/testing/examples/pallet_transaction_payment_tests.rs index e58a5ad01..232c298ee 100644 --- a/testing/examples/pallet_transaction_payment_tests.rs +++ b/testing/examples/pallet_transaction_payment_tests.rs @@ -19,7 +19,7 @@ use codec::Encode; use kitchensink_runtime::{Runtime, Signature}; use sp_keyring::AccountKeyring; use substrate_api_client::{ - extrinsic::CreateBalancesExtrinsic, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, + extrinsic::BalancesExtrinsics, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner, GetBlock, GetTransactionPayment, };