Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add api traits #363

Merged
merged 22 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ serde = { version = "1.0.136", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.79", default-features = false }
thiserror = { version = "1.0.30", optional = true }
tungstenite = { version = "0.18.0", optional = true, features = ["native-tls"] }
url = { verson = "2.0.0", optional = true }
url = { version = "2.0.0", optional = true }
ws = { version = "0.9.2", optional = true, features = ["ssl"] }


Expand Down
2 changes: 1 addition & 1 deletion compose-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ macro_rules! compose_extrinsic_offline {
$params: expr) => {{
use $crate::{
primitives::{ExtrinsicParams, GenericAddress, SignedPayload, UncheckedExtrinsicV4},
sp_core::crypto::Pair,
sp_core::{crypto::Pair, Public},
sp_runtime::{generic::Era, traits::IdentifyAccount, MultiSigner},
};

Expand Down
4 changes: 3 additions & 1 deletion examples/batch_payout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use sp_keyring::AccountKeyring;
#[cfg(feature = "staking-xt")]
use sp_runtime::{app_crypto::Ss58Codec, AccountId32};
#[cfg(feature = "staking-xt")]
use substrate_api_client::{rpc::JsonrpseeClient, Api, PlainTipExtrinsicParams, XtStatus};
use substrate_api_client::{
rpc::JsonrpseeClient, Api, GetStorage, PlainTipExtrinsicParams, SubmitAndWatch, XtStatus,
};

#[cfg(feature = "staking-xt")]
#[tokio::main]
Expand Down
3 changes: 2 additions & 1 deletion examples/benchmark_bulk_xt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
use kitchensink_runtime::{BalancesCall, Runtime, RuntimeCall};
use sp_keyring::AccountKeyring;
use substrate_api_client::{
compose_extrinsic_offline, Api, AssetTipExtrinsicParams, JsonrpseeClient, UncheckedExtrinsicV4,
compose_extrinsic_offline, Api, AssetTipExtrinsicParams, JsonrpseeClient, SubmitExtrinsic,
UncheckedExtrinsicV4,
};

#[tokio::main]
Expand Down
4 changes: 2 additions & 2 deletions examples/compose_extrinsic_offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use kitchensink_runtime::{BalancesCall, Header, Runtime, RuntimeCall};
use sp_keyring::AccountKeyring;
use sp_runtime::{generic::Era, MultiAddress};
use substrate_api_client::{
compose_extrinsic_offline, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams,
UncheckedExtrinsicV4, XtStatus,
compose_extrinsic_offline, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GetHeader,
SubmitAndWatch, UncheckedExtrinsicV4, XtStatus,
};

#[tokio::main]
Expand Down
5 changes: 3 additions & 2 deletions examples/contract_instantiate_with_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use codec::Decode;
use kitchensink_runtime::Runtime;
use sp_keyring::AccountKeyring;
use substrate_api_client::{
rpc::JsonrpseeClient, AccountId, Api, PlainTipExtrinsicParams, StaticEvent, XtStatus,
rpc::JsonrpseeClient, AccountId, Api, PlainTipExtrinsicParams, StaticEvent, SubmitAndWatch,
SubscribeEvents, SubscribeFrameSystem, XtStatus,
};

#[allow(unused)]
Expand Down Expand Up @@ -55,7 +56,7 @@ async fn main() {
"#;
let wasm = wabt::wat2wasm(CONTRACT).expect("invalid wabt");

let mut subscription = api.subscribe_events().expect("cannot subscribe to events");
let mut subscription = api.subscribe_system_events().expect("cannot subscribe to events");

let xt = api.contract_instantiate_with_code(
1_000_000_000_000_000,
Expand Down
4 changes: 2 additions & 2 deletions examples/custom_nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use kitchensink_runtime::{BalancesCall, Runtime, RuntimeCall};
use sp_keyring::AccountKeyring;
use sp_runtime::{generic::Era, MultiAddress};
use substrate_api_client::{
compose_extrinsic_offline, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams,
UncheckedExtrinsicV4, XtStatus,
compose_extrinsic_offline, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GetHeader,
SubmitAndWatch, UncheckedExtrinsicV4, XtStatus,
};

#[tokio::main]
Expand Down
8 changes: 4 additions & 4 deletions examples/event_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use codec::Decode;
use kitchensink_runtime::Runtime;
use log::debug;
use sp_core::{sr25519, H256 as Hash};
use substrate_api_client::HandleSubscription;

use substrate_api_client::{rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams};
use substrate_api_client::{
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, HandleSubscription, SubscribeFrameSystem,
};

// This module depends on node_runtime.
// To avoid dependency collisions, node_runtime has been removed from the substrate-api-client library.
Expand All @@ -38,7 +38,7 @@ async fn main() {
Api::<sr25519::Pair, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();

println!("Subscribe to events");
let mut subscription = api.subscribe_events().unwrap();
let mut subscription = api.subscribe_system_events().unwrap();
haerdib marked this conversation as resolved.
Show resolved Hide resolved

for _ in 0..5 {
let event_bytes = subscription.next().unwrap().unwrap().changes[0].1.clone().unwrap().0;
Expand Down
5 changes: 3 additions & 2 deletions examples/event_error_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use sp_core::crypto::Pair;
use sp_keyring::AccountKeyring;
use sp_runtime::{AccountId32 as AccountId, MultiAddress};
use substrate_api_client::{
rpc::JsonrpseeClient, Api, ApiResult, AssetTipExtrinsicParams, StaticEvent, XtStatus,
rpc::JsonrpseeClient, Api, ApiResult, AssetTipExtrinsicParams, GetAccountInformation,
StaticEvent, SubmitAndWatch, SubscribeEvents, SubscribeFrameSystem, XtStatus,
};

#[derive(Decode)]
Expand Down Expand Up @@ -81,7 +82,7 @@ async fn main() {
println!("[+] Transaction got included into the TxPool.");

// Transfer should fail as Alice wants to transfer all her balance. She does not have enough money to pay the fees.
let mut subscription = api.subscribe_events().unwrap();
let mut subscription = api.subscribe_system_events().unwrap();
let args: ApiResult<TransferEventArgs> = api.wait_for_event(&mut subscription);
match args {
Ok(_transfer) => {
Expand Down
5 changes: 3 additions & 2 deletions examples/generic_event_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use sp_keyring::AccountKeyring;
use sp_runtime::{AccountId32 as AccountId, MultiAddress};
use std::thread;
use substrate_api_client::{
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, StaticEvent, XtStatus,
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, StaticEvent, SubmitAndWatch,
SubscribeEvents, SubscribeFrameSystem, XtStatus,
};

// Look at the how the transfer event looks like in in the metadata
Expand Down Expand Up @@ -52,7 +53,7 @@ async fn main() {

let api2 = api.clone();
let thread_output = thread::spawn(move || {
let mut subscription = api2.subscribe_events().unwrap();
let mut subscription = api2.subscribe_system_events().unwrap();
let args: TransferEventArgs =
api2.wait_for_event::<TransferEventArgs>(&mut subscription).unwrap();
args
Expand Down
2 changes: 1 addition & 1 deletion examples/generic_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use kitchensink_runtime::Runtime;
use sp_keyring::AccountKeyring;
use substrate_api_client::{
compose_extrinsic, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GenericAddress,
UncheckedExtrinsicV4, XtStatus,
SubmitAndWatch, UncheckedExtrinsicV4, XtStatus,
};

#[tokio::main]
Expand Down
4 changes: 2 additions & 2 deletions examples/get_account_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use pallet_identity::{Data, IdentityInfo, Registration};
use sp_core::{crypto::Pair, H256};
use sp_keyring::AccountKeyring;
use substrate_api_client::{
compose_extrinsic, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, UncheckedExtrinsicV4,
XtStatus,
compose_extrinsic, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GetStorage,
SubmitAndWatch, UncheckedExtrinsicV4, XtStatus,
};

type BalanceOf<T> = <<T as pallet_identity::Config>::Currency as Currency<
Expand Down
3 changes: 2 additions & 1 deletion examples/get_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
use kitchensink_runtime::Runtime;
use sp_core::sr25519;
use substrate_api_client::{
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, HandleSubscription,
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GetBlock, GetHeader, HandleSubscription,
SubscribeChain,
};

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion examples/get_existential_deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.

use kitchensink_runtime::Runtime;
use sp_runtime::app_crypto::sp_core::sr25519;
use substrate_api_client::{rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams};
use substrate_api_client::{rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GetBalance};

#[tokio::main]
async fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/get_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use frame_system::AccountInfo as GenericAccountInfo;
use kitchensink_runtime::Runtime;
use sp_keyring::AccountKeyring;
use substrate_api_client::{rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams};
use substrate_api_client::{rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GetStorage};

type IndexFor<T> = <T as frame_system::Config>::Index;
type AccountDataFor<T> = <T as frame_system::Config>::AccountData;
Expand Down
4 changes: 3 additions & 1 deletion examples/staking_payout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use sp_keyring::AccountKeyring;
#[cfg(feature = "staking-xt")]
use sp_runtime::{app_crypto::Ss58Codec, AccountId32};
#[cfg(feature = "staking-xt")]
use substrate_api_client::{rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, XtStatus};
use substrate_api_client::{
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GetStorage, SubmitAndWatch, XtStatus,
};

#[cfg(feature = "staking-xt")]
#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion examples/sudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use kitchensink_runtime::Runtime;
use sp_keyring::AccountKeyring;
use substrate_api_client::{
compose_call, compose_extrinsic, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams,
GenericAddress, UncheckedExtrinsicV4, XtStatus,
GenericAddress, SubmitAndWatch, UncheckedExtrinsicV4, XtStatus,
};

#[tokio::main]
Expand Down
5 changes: 4 additions & 1 deletion examples/transfer_using_seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ use sp_core::{
sr25519,
};
use sp_runtime::MultiAddress;
use substrate_api_client::{rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, XtStatus};
use substrate_api_client::{
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GetAccountInformation, SubmitAndWatch,
XtStatus,
};

#[tokio::main]
async fn main() {
Expand Down
5 changes: 4 additions & 1 deletion examples/transfer_with_tungstenite_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ use sp_core::{
sr25519,
};
use sp_runtime::MultiAddress;
use substrate_api_client::{rpc::TungsteniteRpcClient, Api, AssetTipExtrinsicParams, XtStatus};
use substrate_api_client::{
rpc::TungsteniteRpcClient, Api, AssetTipExtrinsicParams, GetAccountInformation, SubmitAndWatch,
XtStatus,
};

fn main() {
env_logger::init();
Expand Down
4 changes: 3 additions & 1 deletion examples/transfer_with_ws_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ use sp_core::{
sr25519,
};
use sp_runtime::MultiAddress;
use substrate_api_client::{rpc::WsRpcClient, Api, AssetTipExtrinsicParams, XtStatus};
use substrate_api_client::{
rpc::WsRpcClient, Api, AssetTipExtrinsicParams, GetAccountInformation, SubmitAndWatch, XtStatus,
};

fn main() {
env_logger::init();
Expand Down
2 changes: 1 addition & 1 deletion node-api/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//!
//! This file is mostly subxt.

use crate::{alloc::borrow::ToOwned, storage::GetStorage, Encoded};
use crate::{alloc::borrow::ToOwned, storage::GetStorageTypes, Encoded};
use codec::{Decode, Encode, Error as CodecError};
use frame_metadata::{
PalletConstantMetadata, RuntimeMetadata, RuntimeMetadataLastVersion, RuntimeMetadataPrefixed,
Expand Down
4 changes: 2 additions & 2 deletions node-api/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<K: Encode, Q: Encode> StorageDoubleMap<K, Q> {
}

/// trait to extract the storage based on the [`StorageEntryMetadata`].
pub trait GetStorage {
pub trait GetStorageTypes {
fn get_double_map<K: Encode, Q: Encode>(
&self,
pallet_prefix: &str,
Expand All @@ -85,7 +85,7 @@ pub trait GetStorage {
fn get_value(&self, pallet_prefix: &str) -> Result<StorageValue, MetadataError>;
}

impl GetStorage for StorageEntryMetadata<PortableForm> {
impl GetStorageTypes for StorageEntryMetadata<PortableForm> {
fn get_double_map<K: Encode, Q: Encode>(
&self,
pallet_prefix: &str,
Expand Down
13 changes: 4 additions & 9 deletions primitives/src/pallet_traits/frame_system_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.

*/
use codec::{Codec, EncodeLike, FullCodec, MaxEncodedLen};
use codec::{Codec, Decode, EncodeLike, FullCodec, MaxEncodedLen};
use core::fmt::Debug;
use scale_info::TypeInfo;
use sp_runtime::traits::{
Expand All @@ -37,18 +37,13 @@ pub trait FrameSystemConfig {
+ TypeInfo
+ Dispatchable<RuntimeOrigin = Self::RuntimeOrigin>
+ Debug;
type Index: Codec
+ EncodeLike
+ Clone
+ Eq
+ Debug
+ TypeInfo
+ MaybeSerializeDeserialize
type Index: MaybeSerializeDeserialize
+ Debug
+ Default
+ AtLeast32Bit
+ Copy
+ MaxEncodedLen;
+ MaxEncodedLen
+ Decode;
type BlockNumber: Codec
+ EncodeLike
+ Clone
Expand Down
Loading