Skip to content

Commit

Permalink
Cleanup of merging of the two examples (compose_extrinsic_offline.rs …
Browse files Browse the repository at this point in the history
…and compose_extrinsic_no_std.rs)
  • Loading branch information
Niederb committed Nov 28, 2023
1 parent 962fb8c commit c4a570e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ jobs:
os: [ ubuntu-latest ]
example: [
benchmark_bulk_xt,
compose_extrinsic_offline,
compose_extrinsic,
custom_nonce,
check_extrinsic_events,
get_account_identity,
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ The following examples can be found in the [examples](/examples/examples) folder

* [benchmark_bulk_xt](/examples/examples/benchmark_bulk_xt.rs): Float the node with a series of transactions.
* [check_extrinsic_events](/examples/examples/check_extrinsic_events.rs): Check and react according to events associated to an extrinsic.
* [compose_extrinsic_offline](/examples/examples/compose_extrinsic_offline.rs): Compose an extrinsic without interacting with the node.
* [compose_extrinsic](/examples/examples/compose_extrinsic.rs): Compose an extrinsic without interacting with the node or in no_std mode.
* [custom_nonce](/examples/examples/custom_nonce.rs): Compose an with a custom nonce.
* [contract_instantiate_with_code](/examples/examples/contract_instantiate_with_code.rs): Instantiate a contract on the chain.
* [custom_nonce](/examples/examples/custom_nonce.rs): Compose an with a custom nonce.
* [get_account_identity](/examples/examples/get_account_identity.rs): Create an custom Unchecked Extrinsic to set an account identity and retrieve it afterwards with a getter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
limitations under the License.
*/

//! This example shows how to use the compose_extrinsic_offline macro which generates an extrinsic
//! This example shows two special ways to create an extrinsic:
//! - Use the compose_extrinsic_offline macro which generates an extrinsic
//! without asking the node for nonce and does not need to know the metadata
//! - Compose an extrinsic in a no_std environment
use codec::Compact;
use kitchensink_runtime::{BalancesCall, RuntimeCall};
Expand All @@ -23,24 +25,29 @@ use sp_runtime::{generic::Era, MultiAddress};
use substrate_api_client::{
ac_compose_macros::{compose_call, compose_extrinsic_offline},
ac_primitives::{
config::Config, AssetTip, ExtrinsicParams, ExtrinsicSigner, GenericAdditionalParams,
SignExtrinsic, SubstrateKitchensinkConfig,
config::Config, AssetRuntimeConfig, AssetTip, ExtrinsicParams, ExtrinsicSigner,
GenericAdditionalParams, SignExtrinsic,
},
rpc::JsonrpseeClient,
Api, GetChainInfo, SubmitAndWatch, XtStatus,
};

type KitchensinkExtrinsicSigner = <SubstrateKitchensinkConfig as Config>::ExtrinsicSigner;
type AccountId = <SubstrateKitchensinkConfig as Config>::AccountId;
type AssetExtrinsicSigner = <AssetRuntimeConfig as Config>::ExtrinsicSigner;
type AccountId = <AssetRuntimeConfig as Config>::AccountId;
type ExtrinsicAddressOf<Signer> = <Signer as SignExtrinsic<AccountId>>::ExtrinsicAddress;

type Hash = <SubstrateKitchensinkConfig as Config>::Hash;
type Hash = <AssetRuntimeConfig as Config>::Hash;
/// Get the balance type from your node runtime and adapt it if necessary.
type Balance = <SubstrateKitchensinkConfig as Config>::Balance;
type Balance = <AssetRuntimeConfig 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 = <SubstrateKitchensinkConfig as Config>::Address;
type Address = <AssetRuntimeConfig as Config>::Address;

// 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.

#[tokio::main]
async fn main() {
Expand All @@ -55,8 +62,8 @@ async fn main() {
//
// ! Careful: AssetTipExtrinsicParams is used here, because the substrate kitchensink runtime uses assets as tips. But for most
// runtimes, the PlainTipExtrinsicParams needs to be used.
let mut api = Api::<SubstrateKitchensinkConfig, _>::new(client).unwrap();
let extrinsic_signer = ExtrinsicSigner::<_>::new(signer);
let mut api = Api::<AssetRuntimeConfig, _>::new(client).unwrap();
let extrinsic_signer = ExtrinsicSigner::<AssetRuntimeConfig>::new(signer);
// Signer is needed to set the nonce and sign the extrinsic.
api.set_signer(extrinsic_signer.clone());

Expand Down Expand Up @@ -85,15 +92,15 @@ async fn main() {
let genesis_hash = api.genesis_hash();
let metadata = api.metadata();

let extrinsic_params = <SubstrateKitchensinkConfig as Config>::ExtrinsicParams::new(
let extrinsic_params = <AssetRuntimeConfig as Config>::ExtrinsicParams::new(
spec_version,
transaction_version,
signer_nonce,
genesis_hash,
additional_extrinsic_params,
);

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

let call = compose_call!(
Expand Down
76 changes: 0 additions & 76 deletions examples/examples/compose_extrinsic_offline.rs

This file was deleted.

0 comments on commit c4a570e

Please sign in to comment.