Skip to content

Commit

Permalink
Make ExtrinsicParams more flexible, and introduce signed extensions (#…
Browse files Browse the repository at this point in the history
…1107)

* WIP new SignedExtensions

* Integrate new signex extension stuff, update docs, remove Static wrapper

* remove impl Into in tx_client to avoid type inference annoyances

* clippy and fix example

* Fix book links

* clippy

* book tweaks

* fmt: remove spaces

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* re-expose Era in utils, and tweak wasm-example

* clippy; remove useless conversion

---------

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
  • Loading branch information
jsdw and niklasad1 authored Aug 8, 2023
1 parent 9cfac4e commit 9b86b55
Show file tree
Hide file tree
Showing 20 changed files with 1,099 additions and 617 deletions.
88 changes: 44 additions & 44 deletions examples/wasm-example/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 17 additions & 12 deletions examples/wasm-example/src/routes/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use subxt::tx::SubmittableExtrinsic;
use subxt::tx::TxPayload;
use subxt::utils::{AccountId32, MultiSignature};

use crate::services::{extension_signature_for_partial_extrinsic, get_accounts, polkadot, Account};
use crate::services::{extension_signature_for_extrinsic, get_accounts, polkadot, Account};
use web_sys::HtmlInputElement;
use yew::prelude::*;

Expand Down Expand Up @@ -139,23 +139,28 @@ impl Component for SigningExamplesComponent {
ctx.link()
.send_future(
async move {
let partial_extrinsic =
match api.tx().create_partial_signed(&remark_call, &account_id, Default::default()).await {
Ok(partial_extrinsic) => partial_extrinsic,
Err(err) => {
return Message::Error(anyhow!("could not create partial extrinsic:\n{:?}", err));
}
};

let Ok(signature) = extension_signature_for_partial_extrinsic(&partial_extrinsic, &api, &account_id, account_source, account_address).await else {
let Ok(account_nonce) = api.tx().account_nonce(&account_id).await else {
return Message::Error(anyhow!("Fetching account nonce failed"));
};

let Ok(call_data) = api.tx().call_data(&remark_call) else {
return Message::Error(anyhow!("could not encode call data"));
};

let Ok(signature) = extension_signature_for_extrinsic(&call_data, &api, account_nonce, account_source, account_address).await else {
return Message::Error(anyhow!("Signing via extension failed"));
};

let Ok(multi_signature) = MultiSignature::decode(&mut &signature[..]) else {
return Message::Error(anyhow!("MultiSignature Decoding"));
};

let signed_extrinsic = partial_extrinsic.sign_with_address_and_signature(&account_id.into(), &multi_signature);
let Ok(partial_signed) = api.tx().create_partial_signed_with_nonce(&remark_call, account_nonce, Default::default()) else {
return Message::Error(anyhow!("PartialExtrinsic creation failed"));
};

// Apply the signature
let signed_extrinsic = partial_signed.sign_with_address_and_signature(&account_id.into(), &multi_signature);

// do a dry run (to debug in the js console if the extrinsic would work)
let dry_res = signed_extrinsic.dry_run(None).await;
Expand Down Expand Up @@ -193,7 +198,7 @@ impl Component for SigningExamplesComponent {
match submit_wait_finalized_and_get_extrinsic_success_event(
signed_extrinsic,
)
.await
.await
{
Ok(remark_event) => Message::ExtrinsicFinalized { remark_event },
Err(err) => Message::ExtrinsicFailed(err),
Expand Down
Loading

0 comments on commit 9b86b55

Please sign in to comment.