mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 16:08:08 +00:00
adjust signed extension examples
This commit is contained in:
Generated
+1
@@ -4531,6 +4531,7 @@ dependencies = [
|
||||
"subxt-lightclient",
|
||||
"subxt-macro",
|
||||
"subxt-metadata",
|
||||
"subxt-signer",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ sp-core = { workspace = true }
|
||||
sp-keyring = { workspace = true }
|
||||
sp-runtime = { workspace = true }
|
||||
assert_matches = { workspace = true }
|
||||
# subxt-signer = { path = "../signer" } // todo!() revert this, but rust analyzer blows up on cyclic dep
|
||||
subxt-signer = { path = "../signer" }
|
||||
# Tracing subscriber is useful for light-client examples to ensure that
|
||||
# the `bootNodes` and chain spec are configured correctly. If all is fine, then
|
||||
# the light-client wlll emit INFO logs with
|
||||
|
||||
@@ -40,7 +40,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.await?;
|
||||
let current_header = rpc.chain_get_header(None).await?.unwrap();
|
||||
|
||||
let ext_params = Params::new().mortal(¤t_header, 8).build();
|
||||
let ext_params = Params::new().mortal(¤t_header, 8).nonce(current_nonce).build();
|
||||
|
||||
let balance_transfer = polkadot::tx()
|
||||
.balances()
|
||||
@@ -48,7 +48,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let ext_hash = api
|
||||
.tx()
|
||||
.create_signed_with_nonce(&balance_transfer, &alice, current_nonce, ext_params)?
|
||||
.create_signed(&balance_transfer, &alice, ext_params).await?
|
||||
.submit()
|
||||
.await?;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#![allow(missing_docs)]
|
||||
use codec::Encode;
|
||||
use subxt::client::OfflineClientT;
|
||||
use subxt::config::{Config, ExtrinsicParams, ExtrinsicParamsEncoder, ExtrinsicParamsError};
|
||||
use subxt::config::{Config, ExtrinsicParams, ExtrinsicParamsEncoder, ExtrinsicParamsError, BaseParams, FromBaseParams};
|
||||
use subxt_signer::sr25519::dev;
|
||||
|
||||
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale")]
|
||||
@@ -51,18 +51,23 @@ impl CustomExtrinsicParamsBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> FromBaseParams<T> for CustomExtrinsicParamsBuilder{
|
||||
fn from_base_params(params: &BaseParams<T>) -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
// Describe how to fetch and then encode the params:
|
||||
impl<T: Config> ExtrinsicParams<T> for CustomExtrinsicParams<T> {
|
||||
type Params = CustomExtrinsicParamsBuilder;
|
||||
|
||||
// Gather together all of the params we will need to encode:
|
||||
fn new<Client: OfflineClientT<T>>(
|
||||
_nonce: u64,
|
||||
client: Client,
|
||||
fn new(
|
||||
base_params: &BaseParams<T>,
|
||||
other_params: Self::Params,
|
||||
) -> Result<Self, ExtrinsicParamsError> {
|
||||
Ok(Self {
|
||||
genesis_hash: client.genesis_hash(),
|
||||
genesis_hash: base_params.client.genesis_hash(),
|
||||
tip: other_params.tip,
|
||||
foo: other_params.foo,
|
||||
})
|
||||
|
||||
@@ -6,7 +6,7 @@ use subxt::client::OfflineClientT;
|
||||
use subxt::config::signed_extensions;
|
||||
use subxt::config::{
|
||||
Config, DefaultExtrinsicParamsBuilder, ExtrinsicParams, ExtrinsicParamsEncoder,
|
||||
ExtrinsicParamsError,
|
||||
ExtrinsicParamsError, BaseParams
|
||||
};
|
||||
use subxt_signer::sr25519::dev;
|
||||
|
||||
@@ -60,11 +60,7 @@ impl<T: Config> signed_extensions::SignedExtension<T> for CustomSignedExtension
|
||||
impl<T: Config> ExtrinsicParams<T> for CustomSignedExtension {
|
||||
type Params = ();
|
||||
|
||||
fn new<Client: OfflineClientT<T>>(
|
||||
_nonce: u64,
|
||||
_client: Client,
|
||||
_other_params: Self::Params,
|
||||
) -> Result<Self, ExtrinsicParamsError> {
|
||||
fn new( base_params: &BaseParams<T>, _params: Self::Params) -> Result<Self, ExtrinsicParamsError> {
|
||||
Ok(CustomSignedExtension)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,12 @@ impl<T: Config> DefaultExtrinsicParamsBuilder<T> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Provide a specific nonce for the submitter of the extrinsic
|
||||
pub fn nonce(mut self, nonce: u64) -> Self {
|
||||
self.nonce = Some(nonce);
|
||||
self
|
||||
}
|
||||
|
||||
/// Provide a tip to the block author using the token denominated by the `asset_id` provided. This
|
||||
/// is not applicable on chains which don't use the `ChargeAssetTxPayment` signed extension; in this
|
||||
/// case, no tip will be given.
|
||||
|
||||
Reference in New Issue
Block a user