start fixing examples and cleaning up interface

This commit is contained in:
Tadeo hepperle
2024-02-02 16:50:41 +01:00
parent 4e2d3fd9cf
commit fce85c4af0
20 changed files with 48 additions and 95 deletions
+2 -5
View File
@@ -11,11 +11,8 @@ use crate::client::ClientBase;
use super::Config;
use crate::ExtrinsicParamsError;
use alloc::string::String;
use alloc::vec::Vec;
use core::fmt::Debug;
use derive_more::Display;
use alloc::vec::Vec;
/// This trait allows you to configure the "signed extra" and
/// "additional" parameters that are a part of the transaction payload
@@ -29,7 +26,7 @@ pub trait ExtrinsicParams<T: Config>: ExtrinsicParamsEncoder + Sized + 'static {
/// Construct a new instance of our [`ExtrinsicParams`].
fn new(
nonce: u64,
client: &ClientBase<T>,
client: ClientBase<T>,
other_params: Self::OtherParams,
) -> Result<Self, ExtrinsicParamsError>;
}
+9 -9
View File
@@ -45,7 +45,7 @@ impl<T: Config> ExtrinsicParams<T> for CheckSpecVersion {
fn new(
_nonce: u64,
client: &ClientBase<T>,
client: ClientBase<T>,
_other_params: Self::OtherParams,
) -> Result<Self, ExtrinsicParamsError> {
Ok(CheckSpecVersion(client.runtime_version().spec_version))
@@ -73,7 +73,7 @@ impl<T: Config> ExtrinsicParams<T> for CheckNonce {
fn new(
nonce: u64,
_client: &ClientBase<T>,
_client: ClientBase<T>,
_other_params: Self::OtherParams,
) -> Result<Self, ExtrinsicParamsError> {
Ok(CheckNonce(Compact(nonce)))
@@ -101,7 +101,7 @@ impl<T: Config> ExtrinsicParams<T> for CheckTxVersion {
fn new(
_nonce: u64,
client: &ClientBase<T>,
client: ClientBase<T>,
_other_params: Self::OtherParams,
) -> Result<Self, ExtrinsicParamsError> {
Ok(CheckTxVersion(client.runtime_version().transaction_version))
@@ -129,7 +129,7 @@ impl<T: Config> ExtrinsicParams<T> for CheckGenesis<T> {
fn new(
_nonce: u64,
client: &ClientBase<T>,
client: ClientBase<T>,
_other_params: Self::OtherParams,
) -> Result<Self, ExtrinsicParamsError> {
Ok(CheckGenesis(client.genesis_hash()))
@@ -195,7 +195,7 @@ impl<T: Config> ExtrinsicParams<T> for CheckMortality<T> {
fn new(
_nonce: u64,
client: &ClientBase<T>,
client: ClientBase<T>,
other_params: Self::OtherParams,
) -> Result<Self, ExtrinsicParamsError> {
Ok(CheckMortality {
@@ -286,7 +286,7 @@ impl<T: Config> ExtrinsicParams<T> for ChargeAssetTxPayment<T> {
fn new(
_nonce: u64,
_client: &ClientBase<T>,
_client: ClientBase<T>,
other_params: Self::OtherParams,
) -> Result<Self, ExtrinsicParamsError> {
Ok(ChargeAssetTxPayment {
@@ -344,7 +344,7 @@ impl<T: Config> ExtrinsicParams<T> for ChargeTransactionPayment {
fn new(
_nonce: u64,
_client: &ClientBase<T>,
_client: ClientBase<T>,
other_params: Self::OtherParams,
) -> Result<Self, ExtrinsicParamsError> {
Ok(ChargeTransactionPayment {
@@ -388,7 +388,7 @@ macro_rules! impl_tuples {
fn new(
nonce: u64,
client: &ClientBase<T>,
client: ClientBase<T>,
other_params: Self::OtherParams,
) -> Result<Self, ExtrinsicParamsError> {
let metadata = client.metadata();
@@ -405,7 +405,7 @@ macro_rules! impl_tuples {
}
// Break and record as soon as we find a match:
if $ident::matches(e.identifier(), e.extra_ty(), types) {
let ext = $ident::new(nonce, client, other_params.$index)?;
let ext = $ident::new(nonce, client.clone(), other_params.$index)?;
let boxed_ext: Box<dyn ExtrinsicParamsEncoder> = Box::new(ext);
exts_by_index.insert(idx, boxed_ext);
break
+1 -5
View File
@@ -6,7 +6,6 @@
use super::{Config, DefaultExtrinsicParams, DefaultExtrinsicParamsBuilder, Hasher, Header};
pub use crate::utils::{AccountId32, MultiAddress, MultiSignature};
use alloc::string::String;
use alloc::vec::Vec;
use codec::{Decode, Encode};
pub use primitive_types::{H256, U256};
@@ -289,10 +288,7 @@ impl From<U256> for NumberOrHex {
}
}
/// A quick helper to encode some bytes to hex.
fn to_hex(bytes: impl AsRef<[u8]>) -> String {
alloc::format!("0x{}", hex::encode(bytes.as_ref()))
}
#[cfg(test)]
mod test {
+1 -1
View File
@@ -52,7 +52,7 @@ pub fn get_constant<Address: ConstantAddress>(
let value = <Address::Target as DecodeWithMetadata>::decode_with_metadata(
&mut constant.value(),
constant.ty(),
&metadata,
metadata,
)?;
Ok(value)
}
+1 -1
View File
@@ -51,7 +51,7 @@ pub fn get_custom_value<Address: CustomValueAddress<IsDecodable = Yes> + ?Sized>
let value = <Address::Target as DecodeWithMetadata>::decode_with_metadata(
&mut custom_value.bytes(),
custom_value.type_id(),
&metadata,
metadata,
)?;
Ok(value)
}
+1 -7
View File
@@ -33,14 +33,8 @@ pub use config::{
pub use metadata::Metadata;
pub use signer::Signer;
pub use storage::StorageAddress;
pub use utils::{AccountId32, MultiAddress, MultiSignature, H160, H256, H512};
pub use utils::{AccountId32, MultiAddress, MultiSignature, H160, H256, H512, Yes, to_hex};
#[macro_use]
mod macros;
mod marker {
/// A unit marker struct signalling that some property is true
pub struct Yes;
}
pub use marker::Yes;
+8
View File
@@ -78,3 +78,11 @@ unsafe impl<T> Sync for PhantomDataSendSync<T> {}
/// with collections like BTreeMap. This has the same type params
/// as `BTreeMap` which allows us to easily swap the two during codegen.
pub type KeyedVec<K, V> = Vec<(K, V)>;
/// A unit marker struct signalling that some property is true
pub struct Yes;
/// A quick helper to encode some bytes to hex.
pub fn to_hex(bytes: impl AsRef<[u8]>) -> String {
alloc::format!("0x{}", hex::encode(bytes.as_ref()))
}