Crate xcm_calls[][src]

Expand description

Support for generically creating XCM calls that are used within Xcm::Transact

Receiving chains will decode incoming XCM calls based on their native types, therefore the encoding of Xcm::Transact is runtime agnostic.

This crate provides a set of abstractions for commonly used pallets. To create chain agnostic bindings for pallets, a few things are required.

First, an exact replica of the pallet’s call enum, but not bound to T: Config, but with generic types. like for pallet_staking:

pub enum StakingCall<Source, Balance, AccountId> {
  Bond(/* -snip */ ),
  UnBond(/* -snip */ ),
  BondExtra(/* -snip */ ),
}

each enum variant represents the corresponding extrinsic of the pallet.

All the pallet’s type that would be configured as part of Config trait and are part of the public interface are now generics: <Source, Balance, AccountId>.

In the event that bindings for different runtimes are required for the pallet, we may still need to support different types, e.g. RuntimeA::Balance = u128; and RuntimeB::Balance = u64;.

Instead of maintaining multiple configs of StakingCall with different types, we maintain a config with a single type configuration, preferably those from our local chain’s frame_system::Config, and then provide a separate encoder, that handle encoding context aware, for example a CurrencyId or AssetId.

For that we configure the pallet’s PalletCallEncoder trait according to the set of different runtime configs.

For the pallet_staking that is StakingCallEncoder that can be configured with encoders for all the StakingCall’s generic types

use xcm_calls::{PalletCallEncoder, PassthroughCompactEncoder, PassthroughEncoder};
use xcm_calls::staking::StakingCallEncoder;
// native types
type AssetId = u64;
type Balance = u128;
type AccountId = u64;
type AccountLookupSource =  sp_runtime::MultiAddress<AccountId, ()>;
 /// The encoder to use when transacting `pallet_staking` calls
 pub struct PalletStakingEncoder;
 impl StakingCallEncoder<AccountLookupSource, Balance, AccountId> for PalletStakingEncoder {
    // encode the `Balance` as the same type as configured but compactly
 	type CompactBalanceEncoder = PassthroughCompactEncoder<Balance, AssetId>;
    // encode the `AccountLookupSource` as the same type as configured
 	type SourceEncoder = PassthroughEncoder<AccountLookupSource, AssetId>;
    // encode the `AccountId` as the same type as configured
 	type AccountIdEncoder = PassthroughEncoder<AccountId, AssetId>;
 }

// Implement the `PalletCallEncoder` that determines whether a call can be encoded based
// on the context
impl PalletCallEncoder for PalletStakingEncoder {
	type Context = AssetId;
	fn can_encode(_ctx: &Self::Context) -> bool {
		// allow all calls
        // handling this separately here allows us to eventually support additional chains
        // without runtime upgrades
		true
	}
}

Modules

Xcm support for pallet_assets calls.

Xcm support for dispatching pallet_proxy pallet calls

Xcm support for pallet_staking calls.

Xcm support for dispatching pallet_utility pallet calls

Structs

Helps encoding the inner call based on the context used.

Wrapper around something to encode with additional context

Encodes an AccountId as Multiaddress regardless of the asset id

Encodes the type as it is but compact

Encodes the type as it is

Represents an extrinsic of a pallet configured inside a runtime

Traits

A helper to encode an item using the provided context

Abstraction over a dispatchable call in a pallet

Common trait for encoders of pallet calls