substrate_api_client/extrinsic/
offline_extrinsic.rs

1/*
2   Copyright 2019 Supercomputing Systems AG
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8	   http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15
16*/
17
18//! Helper function to easily create extrinsics offline (without getter calls to the node).
19
20use crate::Api;
21use ac_compose_macros::compose_extrinsic_offline;
22use ac_primitives::{
23	config::Config, extrinsic_params::ExtrinsicParams, Preamble, SignExtrinsic, UncheckedExtrinsic,
24};
25use codec::Encode;
26
27type ExtrinsicAddress<T> =
28	<<T as Config>::ExtrinsicSigner as SignExtrinsic<<T as Config>::AccountId>>::ExtrinsicAddress;
29type Signature<T> =
30	<<T as Config>::ExtrinsicSigner as SignExtrinsic<<T as Config>::AccountId>>::Signature;
31type TxExtension<T> = <<T as Config>::ExtrinsicParams as ExtrinsicParams<
32	<T as Config>::Index,
33	<T as Config>::Hash,
34>>::TxExtension;
35
36impl<T: Config, Client> Api<T, Client> {
37	/// Wrapper around the `compose_extrinsic_offline!` macro to be less verbose.
38	pub fn compose_extrinsic_offline<Call: Encode + Clone>(
39		&self,
40		call: Call,
41		nonce: T::Index,
42	) -> UncheckedExtrinsic<ExtrinsicAddress<T>, Call, Signature<T>, TxExtension<T>> {
43		match self.signer() {
44			Some(signer) => compose_extrinsic_offline!(signer, call, self.extrinsic_params(nonce)),
45			None => UncheckedExtrinsic { preamble: Preamble::Bare(5), function: call },
46		}
47	}
48}