mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 18:41:01 +00:00
adjust signed extension examples
This commit is contained in:
Generated
+1
@@ -4531,6 +4531,7 @@ dependencies = [
|
|||||||
"subxt-lightclient",
|
"subxt-lightclient",
|
||||||
"subxt-macro",
|
"subxt-macro",
|
||||||
"subxt-metadata",
|
"subxt-metadata",
|
||||||
|
"subxt-signer",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
|
|||||||
+1
-1
@@ -115,7 +115,7 @@ sp-core = { workspace = true }
|
|||||||
sp-keyring = { workspace = true }
|
sp-keyring = { workspace = true }
|
||||||
sp-runtime = { workspace = true }
|
sp-runtime = { workspace = true }
|
||||||
assert_matches = { 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
|
# 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 `bootNodes` and chain spec are configured correctly. If all is fine, then
|
||||||
# the light-client wlll emit INFO logs with
|
# the light-client wlll emit INFO logs with
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.await?;
|
.await?;
|
||||||
let current_header = rpc.chain_get_header(None).await?.unwrap();
|
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()
|
let balance_transfer = polkadot::tx()
|
||||||
.balances()
|
.balances()
|
||||||
@@ -48,7 +48,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
let ext_hash = api
|
let ext_hash = api
|
||||||
.tx()
|
.tx()
|
||||||
.create_signed_with_nonce(&balance_transfer, &alice, current_nonce, ext_params)?
|
.create_signed(&balance_transfer, &alice, ext_params).await?
|
||||||
.submit()
|
.submit()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
use codec::Encode;
|
use codec::Encode;
|
||||||
use subxt::client::OfflineClientT;
|
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;
|
use subxt_signer::sr25519::dev;
|
||||||
|
|
||||||
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale")]
|
#[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:
|
// Describe how to fetch and then encode the params:
|
||||||
impl<T: Config> ExtrinsicParams<T> for CustomExtrinsicParams<T> {
|
impl<T: Config> ExtrinsicParams<T> for CustomExtrinsicParams<T> {
|
||||||
type Params = CustomExtrinsicParamsBuilder;
|
type Params = CustomExtrinsicParamsBuilder;
|
||||||
|
|
||||||
// Gather together all of the params we will need to encode:
|
// Gather together all of the params we will need to encode:
|
||||||
fn new<Client: OfflineClientT<T>>(
|
fn new(
|
||||||
_nonce: u64,
|
base_params: &BaseParams<T>,
|
||||||
client: Client,
|
|
||||||
other_params: Self::Params,
|
other_params: Self::Params,
|
||||||
) -> Result<Self, ExtrinsicParamsError> {
|
) -> Result<Self, ExtrinsicParamsError> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
genesis_hash: client.genesis_hash(),
|
genesis_hash: base_params.client.genesis_hash(),
|
||||||
tip: other_params.tip,
|
tip: other_params.tip,
|
||||||
foo: other_params.foo,
|
foo: other_params.foo,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use subxt::client::OfflineClientT;
|
|||||||
use subxt::config::signed_extensions;
|
use subxt::config::signed_extensions;
|
||||||
use subxt::config::{
|
use subxt::config::{
|
||||||
Config, DefaultExtrinsicParamsBuilder, ExtrinsicParams, ExtrinsicParamsEncoder,
|
Config, DefaultExtrinsicParamsBuilder, ExtrinsicParams, ExtrinsicParamsEncoder,
|
||||||
ExtrinsicParamsError,
|
ExtrinsicParamsError, BaseParams
|
||||||
};
|
};
|
||||||
use subxt_signer::sr25519::dev;
|
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 {
|
impl<T: Config> ExtrinsicParams<T> for CustomSignedExtension {
|
||||||
type Params = ();
|
type Params = ();
|
||||||
|
|
||||||
fn new<Client: OfflineClientT<T>>(
|
fn new( base_params: &BaseParams<T>, _params: Self::Params) -> Result<Self, ExtrinsicParamsError> {
|
||||||
_nonce: u64,
|
|
||||||
_client: Client,
|
|
||||||
_other_params: Self::Params,
|
|
||||||
) -> Result<Self, ExtrinsicParamsError> {
|
|
||||||
Ok(CustomSignedExtension)
|
Ok(CustomSignedExtension)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,12 @@ impl<T: Config> DefaultExtrinsicParamsBuilder<T> {
|
|||||||
self
|
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
|
/// 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
|
/// is not applicable on chains which don't use the `ChargeAssetTxPayment` signed extension; in this
|
||||||
/// case, no tip will be given.
|
/// case, no tip will be given.
|
||||||
|
|||||||
Reference in New Issue
Block a user