Introduce Metadata type (#974)

* WIP new Metadata type

* Finish basic Metadata impl inc hashing and validation

* remove caching from metadata; can add that higher up

* remove caches

* update retain to use Metadata

* clippy fixes

* update codegen to use Metadata

* clippy

* WIP fixing subxt lib

* WIP fixing tests, rebuild artifacts, fix OrderedMap::retain

* get --all-targets compiling

* move DispatchError type lookup back to being optional

* cargo clippy

* fix docs

* re-use VariantIndex to get variants

* add docs and enforce docs on metadata crate

* fix docs

* add test and fix docs

* cargo fmt

* address review comments

* update lockfiles

* ExactSizeIter so we can ask for len() of things (and hopefully soon is_empty()
This commit is contained in:
James Wilson
2023-05-25 10:35:21 +01:00
committed by GitHub
parent f344d0dd4d
commit b9f5419095
64 changed files with 6818 additions and 5719 deletions
+10 -8
View File
@@ -11,7 +11,7 @@ use sp_core_hashing::blake2_256;
use crate::{
client::{OfflineClientT, OnlineClientT},
config::{Config, ExtrinsicParams, Hasher},
error::Error,
error::{Error, MetadataError},
tx::{Signer as SignerT, TxPayload, TxProgress},
utils::{Encoded, PhantomDataSendSync},
};
@@ -47,14 +47,16 @@ impl<T: Config, C: OfflineClientT<T>> TxClient<T, C> {
Call: TxPayload,
{
if let Some(details) = call.validation_details() {
let metadata = self.client.metadata();
let expected_hash = metadata.call_hash(details.pallet_name, details.call_name)?;
let expected_hash = self
.client
.metadata()
.pallet_by_name(details.pallet_name)
.ok_or_else(|| MetadataError::PalletNameNotFound(details.pallet_name.to_owned()))?
.call_hash(details.call_name)
.ok_or_else(|| MetadataError::CallNameNotFound(details.call_name.to_owned()))?;
if details.hash != expected_hash {
return Err(crate::metadata::MetadataError::IncompatibleCallMetadata(
details.pallet_name.into(),
details.call_name.into(),
)
.into());
return Err(MetadataError::IncompatibleCodegen.into());
}
}
Ok(())
+13 -5
View File
@@ -5,7 +5,11 @@
//! This module contains the trait and types used to represent
//! transactions that can be submitted.
use crate::{dynamic::Value, error::Error, metadata::Metadata};
use crate::{
dynamic::Value,
error::{Error, MetadataError},
metadata::Metadata,
};
use codec::Encode;
use scale_encode::EncodeAsFields;
use scale_value::{Composite, ValueDef, Variant};
@@ -137,17 +141,21 @@ impl Payload<Composite<()>> {
impl<CallData: EncodeAsFields> TxPayload for Payload<CallData> {
fn encode_call_data_to(&self, metadata: &Metadata, out: &mut Vec<u8>) -> Result<(), Error> {
let pallet = metadata.pallet(&self.pallet_name)?;
let call = pallet.call(&self.call_name)?;
let pallet = metadata
.pallet_by_name(&self.pallet_name)
.ok_or_else(|| MetadataError::PalletNameNotFound((*self.pallet_name).to_owned()))?;
let call = pallet
.call_variant_by_name(&self.call_name)
.ok_or_else(|| MetadataError::CallNameNotFound((*self.call_name).to_owned()))?;
let pallet_index = pallet.index();
let call_index = call.index();
let call_index = call.index;
pallet_index.encode_to(out);
call_index.encode_to(out);
self.call_data
.encode_as_fields_to(call.fields(), metadata.types(), out)?;
.encode_as_fields_to(&call.fields, metadata.types(), out)?;
Ok(())
}