Skip to content

Commit

Permalink
it's compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
haerdib committed Sep 11, 2024
1 parent 068fe93 commit df6f431
Show file tree
Hide file tree
Showing 33 changed files with 325 additions and 281 deletions.
308 changes: 153 additions & 155 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions examples/async/examples/benchmark_bulk_xt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,34 @@
use sp_keyring::AccountKeyring;
use substrate_api_client::{
ac_primitives::{
DefaultRuntimeConfig, ExtrinsicSigner as GenericExtrinsicSigner, SignExtrinsic,
Config, ExtrinsicSigner as GenericExtrinsicSigner, SignExtrinsic, WestendRuntimeConfig,
},
rpc::JsonrpseeClient,
Api, SubmitExtrinsic,
};
use westend_runtime::{AccountId, BalancesCall, RuntimeCall};
use westend_runtime::{BalancesCall, RuntimeCall};

// Define an extrinsic signer type which sets the generic types of the `GenericExtrinsicSigner`.
// This way, the types don't have to be reassigned with every usage of this type and makes
// the code better readable.
type ExtrinsicSigner = GenericExtrinsicSigner<DefaultRuntimeConfig>;
type ExtrinsicSigner = GenericExtrinsicSigner<WestendRuntimeConfig>;

// To access the ExtrinsicAddress type of the Signer, we need to do this via the trait `SignExtrinsic`.
// For better code readability, we define a simple type here and, at the same time, assign the
// AccountId type of the `SignExtrinsic` trait.
type ExtrinsicAddressOf<Signer> = <Signer as SignExtrinsic<AccountId>>::ExtrinsicAddress;

// AccountId type of westend runtime.
type AccountId = <WestendRuntimeConfig as Config>::AccountId;

#[tokio::main]
async fn main() {
env_logger::init();

// Initialize api and set the signer (sender) that is used to sign the extrinsics.
let signer = AccountKeyring::Alice.pair();
let client = JsonrpseeClient::with_default_url().await.unwrap();
let mut api = Api::<DefaultRuntimeConfig, _>::new(client).await.unwrap();
let mut api = Api::<WestendRuntimeConfig, _>::new(client).await.unwrap();
api.set_signer(signer.into());

let recipient: ExtrinsicAddressOf<ExtrinsicSigner> = AccountKeyring::Bob.to_account_id().into();
Expand Down
8 changes: 4 additions & 4 deletions examples/async/examples/check_extrinsic_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use sp_keyring::AccountKeyring;
use substrate_api_client::{
ac_node_api::RawEventDetails,
ac_primitives::{Config, DefaultRuntimeConfig},
ac_primitives::{Config, WestendRuntimeConfig},
extrinsic::BalancesExtrinsics,
rpc::JsonrpseeClient,
Api, GetAccountInformation, SubmitAndWatch, TransactionStatus, XtStatus,
Expand All @@ -25,9 +25,9 @@ use substrate_api_client::{
// To test this example with CI we run it against the Substrate kitchensink node, which uses the asset pallet.
// Therefore, we need to use the `AssetRuntimeConfig` in this example.
// ! However, most Substrate runtimes do not use the asset pallet at all. So if you run an example against your own node
// you most likely should use `DefaultRuntimeConfig` instead.
// you most likely should use `WestendRuntimeConfig` instead.

type Hash = <DefaultRuntimeConfig as Config>::Hash;
type Hash = <WestendRuntimeConfig as Config>::Hash;

#[tokio::main]
async fn main() {
Expand All @@ -36,7 +36,7 @@ async fn main() {
// Initialize api and set the signer (sender) that is used to sign the extrinsics.
let alice_signer = AccountKeyring::Alice.pair();
let client = JsonrpseeClient::with_default_url().await.unwrap();
let mut api = Api::<DefaultRuntimeConfig, _>::new(client).await.unwrap();
let mut api = Api::<WestendRuntimeConfig, _>::new(client).await.unwrap();
api.set_signer(alice_signer.into());

let alice = AccountKeyring::Alice.to_account_id();
Expand Down
29 changes: 13 additions & 16 deletions examples/async/examples/compose_extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,27 @@ use sp_runtime::{generic::Era, MultiAddress};
use substrate_api_client::{
ac_compose_macros::{compose_call, compose_extrinsic_offline},
ac_primitives::{
config::Config, AssetTip, DefaultRuntimeConfig, ExtrinsicParams, ExtrinsicSigner,
GenericAdditionalParams, SignExtrinsic,
config::Config, ExtrinsicParams, ExtrinsicSigner, GenericAdditionalParams, PlainTip,
SignExtrinsic, WestendRuntimeConfig,
},
rpc::JsonrpseeClient,
Api, GetChainInfo, SubmitAndWatch, XtStatus,
};
use westend_runtime::{BalancesCall, RuntimeCall};
use westend_runtime::{Address, BalancesCall, RuntimeCall};

type AssetExtrinsicSigner = <DefaultRuntimeConfig as Config>::ExtrinsicSigner;
type AccountId = <DefaultRuntimeConfig as Config>::AccountId;
type DefaultExtrinsicSigner = <WestendRuntimeConfig as Config>::ExtrinsicSigner;
type AccountId = <WestendRuntimeConfig as Config>::AccountId;
type ExtrinsicAddressOf<Signer> = <Signer as SignExtrinsic<AccountId>>::ExtrinsicAddress;

type Hash = <DefaultRuntimeConfig as Config>::Hash;
type Hash = <WestendRuntimeConfig as Config>::Hash;
/// Get the balance type from your node runtime and adapt it if necessary.
type Balance = <DefaultRuntimeConfig as Config>::Balance;
/// We need AssetTip here, because the kitchensink runtime uses the asset pallet. Change to PlainTip if your node uses the balance pallet only.
type AdditionalParams = GenericAdditionalParams<AssetTip<Balance>, Hash>;

type Address = <DefaultRuntimeConfig as Config>::Address;
type Balance = <WestendRuntimeConfig as Config>::Balance;
type AdditionalParams = GenericAdditionalParams<PlainTip<Balance>, Hash>;

// To test this example with CI we run it against the Substrate kitchensink node, which uses the asset pallet.
// Therefore, we need to use the `AssetRuntimeConfig` in this example.
// ! However, most Substrate runtimes do not use the asset pallet at all. So if you run an example against your own node
// you most likely should use `DefaultRuntimeConfig` instead.
// you most likely should use `WestendRuntimeConfig` instead.

#[tokio::main]
async fn main() {
Expand All @@ -56,8 +53,8 @@ async fn main() {
let signer = AccountKeyring::Alice.pair();
let client = JsonrpseeClient::with_default_url().await.unwrap();

let mut api = Api::<DefaultRuntimeConfig, _>::new(client).await.unwrap();
let extrinsic_signer = ExtrinsicSigner::<DefaultRuntimeConfig>::new(signer);
let mut api = Api::<WestendRuntimeConfig, _>::new(client).await.unwrap();
let extrinsic_signer = ExtrinsicSigner::<WestendRuntimeConfig>::new(signer);
// Signer is needed to set the nonce and sign the extrinsic.
api.set_signer(extrinsic_signer.clone());

Expand All @@ -84,12 +81,12 @@ async fn main() {
let signer_nonce = api.get_nonce().await.unwrap();
println!("[+] Alice's Account Nonce is {}", signer_nonce);

let recipients_extrinsic_address: ExtrinsicAddressOf<AssetExtrinsicSigner> =
let recipients_extrinsic_address: ExtrinsicAddressOf<DefaultExtrinsicSigner> =
recipient.clone().into();

// Construct an extrinsic using only functionality available in no_std
let xt = {
let extrinsic_params = <DefaultRuntimeConfig as Config>::ExtrinsicParams::new(
let extrinsic_params = <WestendRuntimeConfig as Config>::ExtrinsicParams::new(
spec_version,
transaction_version,
signer_nonce,
Expand Down
6 changes: 3 additions & 3 deletions examples/async/examples/custom_nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use sp_keyring::AccountKeyring;
use sp_runtime::{generic::Era, MultiAddress};
use substrate_api_client::{
ac_primitives::{DefaultRuntimeConfig, GenericAdditionalParams},
ac_primitives::{GenericAdditionalParams, WestendRuntimeConfig},
rpc::JsonrpseeClient,
Api, Error, GetChainInfo, SubmitAndWatch, UnexpectedTxStatus, XtStatus,
};
Expand All @@ -28,7 +28,7 @@ use westend_runtime::{BalancesCall, RuntimeCall};
// To test this example with CI we run it against the Substrate kitchensink node, which uses the asset pallet.
// Therefore, we need to use the `AssetRuntimeConfig` in this example.
// ! However, most Substrate runtimes do not use the asset pallet at all. So if you run an example against your own node
// you most likely should use `DefaultRuntimeConfig` instead.
// you most likely should use `WestendRuntimeConfig` instead.

#[tokio::main]
async fn main() {
Expand All @@ -37,7 +37,7 @@ async fn main() {
// Initialize api and set the signer (sender) that is used to sign the extrinsics.
let signer = AccountKeyring::Alice.pair();
let client = JsonrpseeClient::with_default_url().await.unwrap();
let mut api = Api::<DefaultRuntimeConfig, _>::new(client).await.unwrap();
let mut api = Api::<WestendRuntimeConfig, _>::new(client).await.unwrap();
api.set_signer(signer.into());

// Information for Era for mortal transactions.
Expand Down
6 changes: 3 additions & 3 deletions examples/async/examples/get_account_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sp_core::{crypto::Pair, H256};
use sp_keyring::AccountKeyring;
use substrate_api_client::{
ac_compose_macros::compose_extrinsic,
ac_primitives::{DefaultRuntimeConfig, UncheckedExtrinsicV4},
ac_primitives::{UncheckedExtrinsicV4, WestendRuntimeConfig},
rpc::JsonrpseeClient,
Api, GetStorage, SubmitAndWatch, XtStatus,
};
Expand All @@ -36,7 +36,7 @@ type IdentityInformation<T> = <T as pallet_identity::Config>::IdentityInformatio
// To test this example with CI we run it against the Substrate kitchensink node, which uses the asset pallet.
// Therefore, we need to use the `AssetRuntimeConfig` in this example.
// ! However, most Substrate runtimes do not use the asset pallet at all. So if you run an example against your own node
// you most likely should use `DefaultRuntimeConfig` instead.
// you most likely should use `WestendRuntimeConfig` instead.

#[tokio::main]
async fn main() {
Expand All @@ -45,7 +45,7 @@ async fn main() {
// Create the node-api client and set the signer.
let client = JsonrpseeClient::with_default_url().await.unwrap();
let signer = AccountKeyring::Alice.pair();
let mut api = Api::<DefaultRuntimeConfig, _>::new(client).await.unwrap();
let mut api = Api::<WestendRuntimeConfig, _>::new(client).await.unwrap();
api.set_signer(signer.clone().into());

// Fill Identity storage.
Expand Down
6 changes: 3 additions & 3 deletions examples/async/examples/get_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
//! To compile this example for async you need to set the `--no-default-features` flag

use substrate_api_client::{
ac_primitives::DefaultRuntimeConfig,
ac_primitives::WestendRuntimeConfig,
rpc::{HandleSubscription, JsonrpseeClient},
Api, GetChainInfo, SubscribeChain,
};

// To test this example with CI we run it against the Substrate kitchensink node, which uses the asset pallet.
// Therefore, we need to use the `AssetRuntimeConfig` in this example.
// ! However, most Substrate runtimes do not use the asset pallet at all. So if you run an example against your own node
// you most likely should use `DefaultRuntimeConfig` instead.
// you most likely should use `WestendRuntimeConfig` instead.

#[tokio::main]
async fn main() {
env_logger::init();

// Initialize the api.
let client = JsonrpseeClient::with_default_url().await.unwrap();
let api = Api::<DefaultRuntimeConfig, _>::new(client).await.unwrap();
let api = Api::<WestendRuntimeConfig, _>::new(client).await.unwrap();

let (genesis_block, header_hash, signed_block) = tokio::try_join!(
api.get_genesis_block(),
Expand Down
14 changes: 7 additions & 7 deletions examples/async/examples/get_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ use frame_system::AccountInfo as GenericAccountInfo;
use pallet_staking::Exposure;
use sp_keyring::AccountKeyring;
use substrate_api_client::{
ac_primitives::{Config, DefaultRuntimeConfig},
ac_primitives::{Config, WestendRuntimeConfig},
rpc::JsonrpseeClient,
Api, GetAccountInformation, GetStorage,
};
use westend_runtime::AccountId;

// To test this example with CI we run it against the Substrate kitchensink node, which uses the asset pallet.
// Therefore, we need to use the `AssetRuntimeConfig` in this example.
// ! However, most Substrate runtimes do not use the asset pallet at all. So if you run an example against your own node
// you most likely should use `DefaultRuntimeConfig` instead.
// you most likely should use `WestendRuntimeConfig` instead.

type AccountInfo = GenericAccountInfo<
<DefaultRuntimeConfig as Config>::Index,
<DefaultRuntimeConfig as Config>::AccountData,
<WestendRuntimeConfig as Config>::Index,
<WestendRuntimeConfig as Config>::AccountData,
>;

type Balance = <DefaultRuntimeConfig as Config>::Balance;
type Balance = <WestendRuntimeConfig as Config>::Balance;
type AccountId = <WestendRuntimeConfig as Config>::AccountId;

#[tokio::main]
async fn main() {
env_logger::init();

// Initialize the api.
let client = JsonrpseeClient::with_default_url().await.unwrap();
let mut api = Api::<DefaultRuntimeConfig, _>::new(client).await.unwrap();
let mut api = Api::<WestendRuntimeConfig, _>::new(client).await.unwrap();

// Get some plain storage values.
let (maybe_balance, proof) = tokio::try_join!(
Expand Down
6 changes: 3 additions & 3 deletions examples/async/examples/new_json_rpc_api_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sp_core::Bytes;
use sp_keyring::AccountKeyring;
use substrate_api_client::{
ac_compose_macros::rpc_params,
ac_primitives::DefaultRuntimeConfig,
ac_primitives::WestendRuntimeConfig,
extrinsic::BalancesExtrinsics,
rpc::{HandleSubscription, JsonrpseeClient, Request, Subscribe},
Api,
Expand All @@ -31,7 +31,7 @@ use substrate_api_client::{
// To test this example with CI we run it against the Substrate kitchensink node, which uses the asset pallet.
// Therefore, we need to use the `AssetRuntimeConfig` in this example.
// ! However, most Substrate runtimes do not use the asset pallet at all. So if you run an example against your own node
// you most likely should use `DefaultRuntimeConfig` instead.
// you most likely should use `WestendRuntimeConfig` instead.

#[tokio::main]
async fn main() {
Expand All @@ -40,7 +40,7 @@ async fn main() {
// Initialize api and set the signer (sender) that is used to sign the extrinsics.
let signer = AccountKeyring::Alice.pair();
let client = JsonrpseeClient::with_default_url().await.unwrap();
let mut api = Api::<DefaultRuntimeConfig, _>::new(client).await.unwrap();
let mut api = Api::<WestendRuntimeConfig, _>::new(client).await.unwrap();
api.set_signer(signer.into());

// Retrieve all available rpc methods:
Expand Down
6 changes: 3 additions & 3 deletions examples/async/examples/print_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
//! debugging tool.

use substrate_api_client::{
ac_primitives::DefaultRuntimeConfig, api_client::UpdateRuntime, rpc::JsonrpseeClient, Api,
ac_primitives::WestendRuntimeConfig, api_client::UpdateRuntime, rpc::JsonrpseeClient, Api,
};

// To test this example with CI we run it against the Substrate kitchensink node, which uses the asset pallet.
// Therefore, we need to use the `AssetRuntimeConfig` in this example.
// ! However, most Substrate runtimes do not use the asset pallet at all. So if you run an example against your own node
// you most likely should use `DefaultRuntimeConfig` instead.
// you most likely should use `WestendRuntimeConfig` instead.

#[tokio::main]
async fn main() {
env_logger::init();

// Initialize the api, which retrieves the metadata from the node upon initialization.
let client = JsonrpseeClient::with_default_url().await.unwrap();
let mut api = Api::<DefaultRuntimeConfig, _>::new(client).await.unwrap();
let mut api = Api::<WestendRuntimeConfig, _>::new(client).await.unwrap();

let meta = api.metadata().clone();

Expand Down
6 changes: 3 additions & 3 deletions examples/async/examples/query_runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use codec::Encode;
use sp_core::sr25519;
use sp_keyring::AccountKeyring;
use substrate_api_client::{
ac_primitives::DefaultRuntimeConfig,
ac_primitives::WestendRuntimeConfig,
extrinsic::BalancesExtrinsics,
rpc::JsonrpseeClient,
runtime_api::{AuthorityDiscoveryApi, CoreApi, MetadataApi, RuntimeApi, TransactionPaymentApi},
Expand All @@ -29,15 +29,15 @@ use substrate_api_client::{
// To test this example with CI we run it against the Substrate kitchensink node, which uses the asset pallet.
// Therefore, we need to use the `AssetRuntimeConfig` in this example.
// ! However, most Substrate runtimes do not use the asset pallet at all. So if you run an example against your own node
// you most likely should use `DefaultRuntimeConfig` instead.
// you most likely should use `WestendRuntimeConfig` instead.

#[tokio::main]
async fn main() {
env_logger::init();

// Initialize the api, which retrieves the metadata from the node upon initialization.
let client = JsonrpseeClient::with_default_url().await.unwrap();
let mut api = Api::<DefaultRuntimeConfig, _>::new(client).await.unwrap();
let mut api = Api::<WestendRuntimeConfig, _>::new(client).await.unwrap();
let alice_pair = AccountKeyring::Alice.pair();
api.set_signer(alice_pair.into());
let runtime_api = api.runtime_api();
Expand Down
10 changes: 5 additions & 5 deletions examples/async/examples/runtime_update_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use sp_keyring::AccountKeyring;
use sp_weights::Weight;
use substrate_api_client::{
ac_compose_macros::{compose_call, compose_extrinsic},
ac_primitives::{Config, DefaultRuntimeConfig},
ac_primitives::{Config, WestendRuntimeConfig},
api_client::UpdateRuntime,
rpc::JsonrpseeClient,
rpc_api::RuntimeUpdateDetector,
Expand All @@ -25,15 +25,15 @@ use substrate_api_client::{
use tokio::select;
use tokio_util::sync::CancellationToken;

type Hash = <AssetRuntimeConfig as Config>::Hash;
type Hash = <WestendRuntimeConfig as Config>::Hash;

#[tokio::main]
async fn main() {
env_logger::init();

// Initialize the api.
let client = JsonrpseeClient::with_default_url().await.unwrap();
let mut api = Api::<DefaultRuntimeConfig, _>::new(client).await.unwrap();
let mut api = Api::<WestendRuntimeConfig, _>::new(client).await.unwrap();
let sudoer = AccountKeyring::Alice.pair();
api.set_signer(sudoer.into());

Expand Down Expand Up @@ -75,9 +75,9 @@ async fn main() {
}

pub async fn send_code_update_extrinsic(
api: &substrate_api_client::Api<DefaultRuntimeConfig, JsonrpseeClient>,
api: &substrate_api_client::Api<WestendRuntimeConfig, JsonrpseeClient>,
) {
let new_wasm: &[u8] = include_bytes!("westend_runtime.compact.compressed.wasm");
let new_wasm: &[u8] = include_bytes!("kitchensink_runtime.compact.compressed.wasm");

// this call can only be called by sudo
let call = compose_call!(api.metadata(), "System", "set_code", new_wasm.to_vec()).unwrap();
Expand Down
Loading

0 comments on commit df6f431

Please sign in to comment.