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

Do not require extrinsic params #410

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 3 additions & 3 deletions examples/examples/batch_payout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use serde_json::Value;
use sp_keyring::AccountKeyring;
use sp_runtime::{app_crypto::Ss58Codec, AccountId32};
use substrate_api_client::{
rpc::JsonrpseeClient, Api, GetStorage, PlainTipExtrinsicParams, SubmitAndWatch, XtStatus,
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GetStorage, SubmitAndWatch, XtStatus,
};

const MAX_BATCHED_TRANSACTION: u32 = 9;
Expand Down Expand Up @@ -46,7 +46,7 @@ async fn main() {
// Initialize api and set the signer (sender) that is used to sign the extrinsics.
let alice = AccountKeyring::Alice.pair();
let client = JsonrpseeClient::with_default_url().unwrap();
let mut api = Api::<_, _, PlainTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
api.set_signer(alice);

// Give a valid validator account address, given one is westend chain validator account.
Expand Down Expand Up @@ -120,7 +120,7 @@ pub fn get_last_reward(
api: &substrate_api_client::Api<
sp_core::sr25519::Pair,
JsonrpseeClient,
PlainTipExtrinsicParams<Runtime>,
AssetTipExtrinsicParams<Runtime>,
Runtime,
>,
) -> u32 {
Expand Down
4 changes: 2 additions & 2 deletions examples/examples/contract_instantiate_with_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use codec::{Decode, Encode};
use kitchensink_runtime::Runtime;
use sp_keyring::AccountKeyring;
use substrate_api_client::{
rpc::JsonrpseeClient, AccountId, Api, PlainTipExtrinsicParams, StaticEvent, SubmitAndWatch,
rpc::JsonrpseeClient, AccountId, Api, AssetTipExtrinsicParams, StaticEvent, SubmitAndWatch,
SubscribeEvents, SubscribeFrameSystem, XtStatus,
};

Expand All @@ -44,7 +44,7 @@ async fn main() {
let client = JsonrpseeClient::with_default_url().unwrap();
// ! 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::<_, _, PlainTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
api.set_signer(signer);

println!("[+] Alice's Account Nonce is {}", api.get_nonce().unwrap());
Expand Down
3 changes: 1 addition & 2 deletions examples/examples/event_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ async fn main() {

// Initialize the api.
let client = JsonrpseeClient::with_default_url().unwrap();
let api =
Api::<sr25519::Pair, _, PlainTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
let api = Api::<(), _, (), Runtime>::new(client).unwrap();

println!("Subscribe to events");
let mut subscription = api.subscribe_system_events().unwrap();
Expand Down
3 changes: 1 addition & 2 deletions examples/examples/get_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ async fn main() {

// Initialize the api.
let client = JsonrpseeClient::with_default_url().unwrap();
let api =
Api::<sr25519::Pair, _, PlainTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
let api = Api::<(), _, (), Runtime>::new(client).unwrap();

println!("Genesis block: \n {:?} \n", api.get_block_by_num(Some(0)).unwrap());

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/get_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async fn main() {

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

// get some plain storage value
let result: u128 = api.get_storage_value("Balances", "TotalIssuance", None).unwrap().unwrap();
Expand Down
3 changes: 1 addition & 2 deletions examples/examples/print_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ async fn main() {

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

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

Expand Down
21 changes: 21 additions & 0 deletions primitives/src/extrinsic_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use codec::{Decode, Encode};
use core::{hash::Hash as HashTrait, marker::PhantomData};
use sp_core::H256;
use sp_runtime::{
generic::Era,
traits::{BlakeTwo256, Hash},
Expand Down Expand Up @@ -291,3 +292,23 @@ impl From<AssetTip<u128>> for u128 {
tip.tip
}
}

/// Emtpy implementation in case no ExtrinsicParams are needed, such as unsigned extrinsics or getter calls.
impl ExtrinsicParams<u32, H256> for () {
type OtherParams = ();
type SignedExtra = ();
type AdditionalSigned = ();

fn new(
_spec_version: u32,
_transaction_version: u32,
_nonce: u32,
_genesis_hash: H256,
_other_params: Self::OtherParams,
) -> Self {
}

fn signed_extra(&self) -> Self::SignedExtra {}

fn additional_signed(&self) -> Self::AdditionalSigned {}
}