Skip to content

Commit 454b89b

Browse files
add signer
wohoo fix most finally compiling make clippy happy remove unused comment update comment Fix documentation for running an example (#417) Also some minor typos clean up imports of macors Remove thiserror and use more specific Error names (#419) * small result clean up * lets not overcomplicate * remove thiserror * remove unused errors fix build Bump tokio from 1.23.0 to 1.23.1 (#427) Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.23.0 to 1.23.1. - [Release notes](https://github.com/tokio-rs/tokio/releases) - [Commits](tokio-rs/tokio@tokio-1.23.0...tokio-1.23.1) --- updated-dependencies: - dependency-name: tokio dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent e675ec8 commit 454b89b

27 files changed

+393
-236
lines changed

compose-macros/src/lib.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ macro_rules! compose_extrinsic_offline {
6464
($signer: expr,
6565
$call: expr,
6666
$params: expr) => {{
67-
use $crate::{
68-
primitives::{ExtrinsicParams, GenericAddress, SignedPayload, UncheckedExtrinsicV4},
69-
sp_core::{crypto::Pair, Public},
70-
sp_runtime::{generic::Era, traits::IdentifyAccount, MultiSigner},
67+
use $crate::primitives::{
68+
ExtrinsicParams, SignExtrinsic, SignedPayload, UncheckedExtrinsicV4,
7169
};
7270

7371
let extra = $params.signed_extra();
@@ -76,14 +74,7 @@ macro_rules! compose_extrinsic_offline {
7674

7775
let signature = raw_payload.using_encoded(|payload| $signer.sign(payload));
7876

79-
let multi_signer: MultiSigner = $signer.public().into();
80-
81-
UncheckedExtrinsicV4::new_signed(
82-
$call,
83-
GenericAddress::from(multi_signer.into_account()),
84-
signature.into(),
85-
extra,
86-
)
77+
UncheckedExtrinsicV4::new_signed($call, $signer.extrinsic_address(), signature, extra)
8778
}};
8879
}
8980

@@ -102,11 +93,8 @@ macro_rules! compose_extrinsic {
10293
$call: expr
10394
$(, $args: expr) *) => {
10495
{
105-
#[allow(unused_imports)] // For when extrinsic does not use Compact
106-
use $crate::codec::Compact;
10796
use $crate::log::debug;
10897
use $crate::primitives::UncheckedExtrinsicV4;
109-
use $crate::sp_runtime::generic::Era;
11098

11199
debug!("Composing generic extrinsic for module {:?} and call {:?}", $module, $call);
112100
let call = $crate::compose_call!($api.metadata().clone(), $module, $call $(, ($args)) *);
@@ -117,10 +105,7 @@ macro_rules! compose_extrinsic {
117105
$api.extrinsic_params($api.get_nonce().unwrap())
118106
)
119107
} else {
120-
UncheckedExtrinsicV4 {
121-
signature: None,
122-
function: call.clone(),
123-
}
108+
UncheckedExtrinsicV4::new_unsigned(call.clone())
124109
}
125110
}
126111
};

examples/examples/batch_payout.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
*/
1313

1414
use codec::{Decode, Encode};
15-
use kitchensink_runtime::Runtime;
15+
use kitchensink_runtime::{Runtime, Signature};
1616
use pallet_staking::{ActiveEraInfo, Exposure};
1717
use serde_json::Value;
1818
use sp_keyring::AccountKeyring;
1919
use sp_runtime::{app_crypto::Ss58Codec, AccountId32};
2020
use substrate_api_client::{
21-
rpc::JsonrpseeClient, Api, GetStorage, PlainTipExtrinsicParams, SubmitAndWatch, XtStatus,
21+
rpc::JsonrpseeClient, Api, ExtrinsicSigner, GetStorage, PlainTipExtrinsicParams,
22+
SubmitAndWatch, XtStatus,
2223
};
2324

2425
const MAX_BATCHED_TRANSACTION: u32 = 9;
@@ -47,7 +48,7 @@ async fn main() {
4748
let alice = AccountKeyring::Alice.pair();
4849
let client = JsonrpseeClient::with_default_url().unwrap();
4950
let mut api = Api::<_, _, PlainTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
50-
api.set_signer(alice);
51+
api.set_signer(ExtrinsicSigner::<_, Signature, Runtime>::new(alice));
5152

5253
// Give a valid validator account address, given one is westend chain validator account.
5354
let account =
@@ -118,7 +119,7 @@ async fn main() {
118119
pub fn get_last_reward(
119120
account: &AccountId32,
120121
api: &substrate_api_client::Api<
121-
sp_core::sr25519::Pair,
122+
ExtrinsicSigner<sp_core::sr25519::Pair, Signature, Runtime>,
122123
JsonrpseeClient,
123124
PlainTipExtrinsicParams<Runtime>,
124125
Runtime,

examples/examples/benchmark_bulk_xt.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818
// run this against test node with
1919
// > substrate-test-node --dev --execution native --ws-port 9979 -ltxpool=debug
2020

21-
use kitchensink_runtime::{BalancesCall, Runtime, RuntimeCall};
21+
use kitchensink_runtime::{AccountId, BalancesCall, Runtime, RuntimeCall, Signature};
22+
use sp_core::sr25519::Pair;
2223
use sp_keyring::AccountKeyring;
2324
use substrate_api_client::{
24-
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GenericAddress, SubmitExtrinsic,
25+
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner, SignExtrinsic,
26+
SubmitExtrinsic,
2527
};
2628

29+
type MyExtrinsicSigner = ExtrinsicSigner<Pair, Signature, Runtime>;
30+
2731
#[tokio::main]
2832
async fn main() {
2933
env_logger::init();
@@ -34,9 +38,10 @@ async fn main() {
3438
// ! Careful: AssetTipExtrinsicParams is used here, because the substrate kitchensink runtime uses assets as tips. But for most
3539
// runtimes, the PlainTipExtrinsicParams needs to be used.
3640
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
37-
api.set_signer(signer);
41+
api.set_signer(MyExtrinsicSigner::new(signer));
3842

39-
let recipient = AccountKeyring::Bob.to_account_id();
43+
let recipient: <MyExtrinsicSigner as SignExtrinsic<AccountId>>::ExtrinsicAddress =
44+
AccountKeyring::Bob.to_account_id().into();
4045
// We use a manual nonce input here, because otherwise the api retrieves the nonce via getter and needs
4146
// to wait for the response of the node (and the actual execution of the previous extrinsic).
4247
// But because we want to spam the node with extrinsic, we simple monotonically increase the nonce, without
@@ -46,7 +51,7 @@ async fn main() {
4651
while nonce < first_nonce + 500 {
4752
// Compose a balance extrinsic.
4853
let call = RuntimeCall::Balances(BalancesCall::transfer {
49-
dest: GenericAddress::Id(recipient.clone()),
54+
dest: recipient.clone(),
5055
value: 1_000_000,
5156
});
5257
let xt = api.compose_extrinsic_offline(call, nonce);

examples/examples/compose_extrinsic_offline.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
//! This example shows how to use the compose_extrinsic_offline macro which generates an extrinsic
1717
//! without asking the node for nonce and does not need to know the metadata
1818
19-
use kitchensink_runtime::{BalancesCall, Runtime, RuntimeCall};
19+
use kitchensink_runtime::{BalancesCall, Runtime, RuntimeCall, Signature};
2020
use sp_keyring::AccountKeyring;
2121
use sp_runtime::{generic::Era, MultiAddress};
2222
use substrate_api_client::{
23-
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GenericAdditionalParams, GetHeader,
24-
SubmitAndWatch, XtStatus,
23+
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner, GenericAdditionalParams,
24+
GetHeader, SubmitAndWatch, XtStatus,
2525
};
2626

2727
#[tokio::main]
@@ -38,7 +38,7 @@ async fn main() {
3838
// ! Careful: AssetTipExtrinsicParams is used here, because the substrate kitchensink runtime uses assets as tips. But for most
3939
// runtimes, the PlainTipExtrinsicParams needs to be used.
4040
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
41-
api.set_signer(signer);
41+
api.set_signer(ExtrinsicSigner::<_, Signature, Runtime>::new(signer));
4242

4343
// Information for Era for mortal transactions (online).
4444
let last_finalized_header_hash = api.get_finalized_head().unwrap().unwrap();

examples/examples/contract_instantiate_with_code.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
//! This example is community maintained and not CI tested, therefore it may not work as is.
1717
1818
use codec::Decode;
19-
use kitchensink_runtime::Runtime;
19+
use kitchensink_runtime::{AccountId, Runtime, Signature};
2020
use sp_keyring::AccountKeyring;
2121
use substrate_api_client::{
22-
rpc::JsonrpseeClient, AccountId, Api, PlainTipExtrinsicParams, StaticEvent, SubmitAndWatch,
23-
SubmitAndWatchUntilSuccess, XtStatus,
22+
rpc::JsonrpseeClient, Api, ExtrinsicSigner, PlainTipExtrinsicParams, StaticEvent,
23+
SubmitAndWatch, SubscribeEvents, SubscribeFrameSystem, XtStatus,
2424
};
2525

2626
#[allow(unused)]
@@ -45,7 +45,7 @@ async fn main() {
4545
// ! Careful: AssetTipExtrinsicParams is used here, because the substrate kitchensink runtime uses assets as tips. But for most
4646
// runtimes, the PlainTipExtrinsicParams needs to be used.
4747
let mut api = Api::<_, _, PlainTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
48-
api.set_signer(signer);
48+
api.set_signer(ExtrinsicSigner::<_, Signature, Runtime>::new(signer));
4949

5050
println!("[+] Alice's Account Nonce is {}", api.get_nonce().unwrap());
5151

examples/examples/custom_nonce.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
//! This example shows how to use the compose_extrinsic_offline macro which generates an extrinsic
1717
//! without asking the node for nonce and does not need to know the metadata
1818
19-
use kitchensink_runtime::{BalancesCall, Runtime, RuntimeCall};
19+
use kitchensink_runtime::{BalancesCall, Runtime, RuntimeCall, Signature};
2020
use sp_keyring::AccountKeyring;
2121
use sp_runtime::{generic::Era, MultiAddress};
2222
use substrate_api_client::{
23-
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, Error, GenericAdditionalParams, GetHeader,
24-
SubmitAndWatch, UnexpectedTxStatus, XtStatus,
23+
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, Error, ExtrinsicSigner,
24+
GenericAdditionalParams, GetHeader, SubmitAndWatch, UnexpectedTxStatus, XtStatus,
2525
};
2626

2727
#[tokio::main]
@@ -34,7 +34,7 @@ async fn main() {
3434
// ! Careful: AssetTipExtrinsicParams is used here, because the substrate kitchensink runtime uses assets as tips. But for most
3535
// runtimes, the PlainTipExtrinsicParams needs to be used.
3636
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
37-
api.set_signer(signer);
37+
api.set_signer(ExtrinsicSigner::<_, Signature, Runtime>::new(signer));
3838

3939
// Information for Era for mortal transactions.
4040
let last_finalized_header_hash = api.get_finalized_head().unwrap().unwrap();

examples/examples/event_callback.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use codec::Decode;
1919
use kitchensink_runtime::Runtime;
2020
use log::debug;
21-
use sp_core::{sr25519, H256 as Hash};
21+
use sp_core::H256 as Hash;
2222
use substrate_api_client::{
2323
rpc::{HandleSubscription, JsonrpseeClient},
2424
Api, PlainTipExtrinsicParams, SubscribeFrameSystem,
@@ -35,8 +35,7 @@ async fn main() {
3535

3636
// Initialize the api.
3737
let client = JsonrpseeClient::with_default_url().unwrap();
38-
let api =
39-
Api::<sr25519::Pair, _, PlainTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
38+
let api = Api::<(), _, PlainTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
4039

4140
println!("Subscribe to events");
4241
let mut subscription = api.subscribe_system_events().unwrap();

examples/examples/event_error_details.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
*/
1515

1616
use codec::Decode;
17-
use kitchensink_runtime::Runtime;
17+
use kitchensink_runtime::{Runtime, Signature};
1818
use sp_keyring::AccountKeyring;
1919
use sp_runtime::{AccountId32 as AccountId, MultiAddress};
2020
use substrate_api_client::{
21-
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GetAccountInformation, StaticEvent,
22-
SubmitAndWatchUntilSuccess,
21+
rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner, GetAccountInformation,
22+
Result, StaticEvent, SubmitAndWatch, SubscribeEvents, SubscribeFrameSystem, XtStatus,
2323
};
2424

2525
#[derive(Decode)]
@@ -44,7 +44,7 @@ async fn main() {
4444
// ! Careful: AssetTipExtrinsicParams is used here, because the substrate kitchensink runtime uses assets as tips. But for most
4545
// runtimes, the PlainTipExtrinsicParams needs to be used.
4646
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
47-
api.set_signer(alice_signer);
47+
api.set_signer(ExtrinsicSigner::<_, Signature, Runtime>::new(alice_signer));
4848

4949
let alice = AccountKeyring::Alice.to_account_id();
5050
let balance_of_alice = api.get_account_data(&alice).unwrap().unwrap().free;

examples/examples/get_account_identity.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
//! Example to show how to get the account identity display name from the identity pallet.
1717
1818
use frame_support::traits::Currency;
19-
use kitchensink_runtime::Runtime as KitchensinkRuntime;
19+
use kitchensink_runtime::{Runtime as KitchensinkRuntime, Signature};
2020
use pallet_identity::{Data, IdentityInfo, Registration};
2121
use sp_core::{crypto::Pair, H256};
2222
use sp_keyring::AccountKeyring;
2323
use substrate_api_client::{
24-
compose_extrinsic, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, GetStorage,
25-
SubmitAndWatch, UncheckedExtrinsicV4, XtStatus,
24+
compose_extrinsic, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner,
25+
GetStorage, SubmitAndWatch, UncheckedExtrinsicV4, XtStatus,
2626
};
2727

2828
type BalanceOf<T> = <<T as pallet_identity::Config>::Currency as Currency<
@@ -43,7 +43,7 @@ async fn main() {
4343
let mut api =
4444
Api::<_, _, AssetTipExtrinsicParams<KitchensinkRuntime>, KitchensinkRuntime>::new(client)
4545
.unwrap();
46-
api.set_signer(signer.clone());
46+
api.set_signer(ExtrinsicSigner::<_, Signature, KitchensinkRuntime>::new(signer.clone()));
4747

4848
// Fill Identity storage.
4949
let info = IdentityInfo::<MaxAdditionalFieldsOf<KitchensinkRuntime>> {
@@ -58,7 +58,7 @@ async fn main() {
5858
twitter: Data::None,
5959
};
6060

61-
let xt: UncheckedExtrinsicV4<_, _> =
61+
let xt: UncheckedExtrinsicV4<_, _, _, _> =
6262
compose_extrinsic!(&api, "Identity", "set_identity", Box::new(info.clone()));
6363
println!("[+] Composed Extrinsic:\n {:?}\n", xt);
6464

examples/examples/get_storage.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
//! Very simple example that shows how to get some simple storage values.
1717
1818
use frame_system::AccountInfo as GenericAccountInfo;
19-
use kitchensink_runtime::Runtime;
19+
use kitchensink_runtime::{Runtime, Signature};
2020
use sp_keyring::AccountKeyring;
21-
use substrate_api_client::{rpc::JsonrpseeClient, Api, GetStorage, PlainTipExtrinsicParams};
21+
use substrate_api_client::{
22+
rpc::JsonrpseeClient, Api, ExtrinsicSigner, GetStorage, PlainTipExtrinsicParams,
23+
};
2224

2325
type IndexFor<T> = <T as frame_system::Config>::Index;
2426
type AccountDataFor<T> = <T as frame_system::Config>::AccountData;
@@ -54,7 +56,7 @@ async fn main() {
5456

5557
// get Alice's AccountNonce with api.get_nonce()
5658
let signer = AccountKeyring::Alice.pair();
57-
api.set_signer(signer);
59+
api.set_signer(ExtrinsicSigner::<_, Signature, Runtime>::new(signer));
5860
println!("[+] Alice's Account Nonce is {}", api.get_nonce().unwrap());
5961

6062
// Get an vector of storage keys, numbering up to the given max keys and that start with the (optionally) given storage key prefix.

examples/examples/sudo.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717
//! module, whereas the desired module and call are supplied as a string.
1818
1919
use codec::Compact;
20-
use kitchensink_runtime::Runtime;
20+
use kitchensink_runtime::{AccountId, Runtime, Signature};
21+
use sp_core::sr25519::Pair;
2122
use sp_keyring::AccountKeyring;
2223
use substrate_api_client::{
2324
compose_call, compose_extrinsic, rpc::JsonrpseeClient, Api, AssetTipExtrinsicParams,
24-
GenericAddress, GetAccountInformation, SubmitAndWatch, UncheckedExtrinsicV4, XtStatus,
25+
ExtrinsicSigner, GetAccountInformation, SignExtrinsic, SubmitAndWatch, UncheckedExtrinsicV4,
26+
XtStatus,
2527
};
2628

29+
type MyExtrinsicSigner = ExtrinsicSigner<Pair, Signature, Runtime>;
30+
2731
#[tokio::main]
2832
async fn main() {
2933
env_logger::init();
@@ -32,7 +36,7 @@ async fn main() {
3236
let sudoer = AccountKeyring::Alice.pair();
3337
let client = JsonrpseeClient::with_default_url().unwrap();
3438
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
35-
api.set_signer(sudoer);
39+
api.set_signer(MyExtrinsicSigner::new(sudoer));
3640

3741
// Set the recipient of newly issued funds.
3842
let recipient = AccountKeyring::Bob.to_account_id();
@@ -42,17 +46,18 @@ async fn main() {
4246
println!("[+] Recipients's Free Balance is now {}\n", recipient_balance);
4347

4448
// Compose a call that should only be executable via Sudo.
49+
let recipients_extrinsic_address: <MyExtrinsicSigner as SignExtrinsic<AccountId>>::ExtrinsicAddress = recipient.clone().into();
4550
let new_balance = recipient_balance + 100;
4651
let call = compose_call!(
4752
api.metadata(),
4853
"Balances",
4954
"set_balance",
50-
GenericAddress::Id(recipient.clone()),
55+
recipients_extrinsic_address,
5156
Compact(new_balance),
5257
Compact(new_balance)
5358
);
5459

55-
let xt: UncheckedExtrinsicV4<_, _> = compose_extrinsic!(&api, "Sudo", "sudo", call);
60+
let xt: UncheckedExtrinsicV4<_, _, _, _> = compose_extrinsic!(&api, "Sudo", "sudo", call);
5661

5762
// Send and watch extrinsic until in block.
5863
let block_hash = api

examples/examples/transfer_with_tungstenite_client.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515

1616
//! Very simple example that shows how to use a predefined extrinsic from the extrinsic module.
1717
18-
use kitchensink_runtime::Runtime;
18+
use kitchensink_runtime::{Runtime, Signature};
1919
use sp_core::{
2020
crypto::{Pair, Ss58Codec},
2121
sr25519,
2222
};
2323
use sp_runtime::MultiAddress;
2424
use substrate_api_client::{
25-
rpc::TungsteniteRpcClient, Api, AssetTipExtrinsicParams, GetAccountInformation, SubmitAndWatch,
26-
XtStatus,
25+
rpc::TungsteniteRpcClient, Api, AssetTipExtrinsicParams, ExtrinsicSigner,
26+
GetAccountInformation, SubmitAndWatch, XtStatus,
2727
};
2828

2929
fn main() {
@@ -40,7 +40,7 @@ fn main() {
4040
// Initialize api and set the signer (sender) that is used to sign the extrinsics.
4141
let client = TungsteniteRpcClient::with_default_url(100);
4242
let mut api = Api::<_, _, AssetTipExtrinsicParams<Runtime>, Runtime>::new(client).unwrap();
43-
api.set_signer(alice.clone());
43+
api.set_signer(ExtrinsicSigner::<_, Signature, Runtime>::new(alice.clone()));
4444

4545
// Retrieve bobs current balance.
4646
let bob = sr25519::Public::from_ss58check("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty")

0 commit comments

Comments
 (0)