Add 'Static' type and improve type substitution codegen to accept it (#886)

* Add Static type which defers to Encode/Decode and impls EncodeAsType/DecodeAsType

* rename to static_type and impl Deref/Mut

* Improve type substitution in codegen so that concrete types can be swapped in

* A couple of comment tweaks and no need for a macro export

* Extend type substitution logic to work recursively on destination type

* cargo fmt

* Fix a couple of comments

* update ui test outpuot

* Add docs and missing_docs lint

* Add test for replacing multiple of Ident

* Update codegen/src/error.rs

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

* update copyright year and fix ui test

* simplify another error

---------

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
James Wilson
2023-03-31 16:56:19 +01:00
committed by GitHub
parent 42bcddeecb
commit a2b8dde5e6
132 changed files with 5810 additions and 5442 deletions
+3 -2
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2022 Parity Technologies (UK) Ltd.
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
@@ -21,7 +21,8 @@ pub use crate::rpc::types::StorageKey;
/// entry lives and how to properly decode it.
pub mod address {
pub use super::storage_address::{
dynamic, dynamic_root, Address, DynamicAddress, StaticStorageMapKey, StorageAddress, Yes,
dynamic, dynamic_root, make_static_storage_map_key, Address, DynamicAddress,
StaticStorageMapKey, StorageAddress, Yes,
};
}
+7 -20
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2022 Parity Technologies (UK) Ltd.
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
@@ -6,6 +6,7 @@ use crate::{
dynamic::{DecodedValueThunk, Value},
error::{Error, StorageAddressError},
metadata::{DecodeWithMetadata, EncodeWithMetadata, Metadata},
utils::{Encoded, Static},
};
use frame_metadata::{StorageEntryType, StorageHasher};
use scale_info::TypeDef;
@@ -211,26 +212,12 @@ where
/// A static storage key; this is some pre-encoded bytes
/// likely provided by the generated interface.
pub struct StaticStorageMapKey(pub Vec<u8>);
pub type StaticStorageMapKey = Static<Encoded>;
impl StaticStorageMapKey {
/// Create a new [`StaticStorageMapKey`] by pre-encoding static data.
pub fn new<Encodable: codec::Encode>(value: Encodable) -> StaticStorageMapKey {
Self(value.encode())
}
}
impl EncodeWithMetadata for StaticStorageMapKey {
fn encode_with_metadata(
&self,
_type_id: u32,
_metadata: &Metadata,
bytes: &mut Vec<u8>,
) -> Result<(), Error> {
// We just use the already-encoded bytes for a static storage key:
bytes.extend(&self.0);
Ok(())
}
// Used in codegen to construct the above.
#[doc(hidden)]
pub fn make_static_storage_map_key<T: codec::Encode>(t: T) -> StaticStorageMapKey {
Static(Encoded(t.encode()))
}
/// Construct a new dynamic storage lookup to the root of some entry.
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2022 Parity Technologies (UK) Ltd.
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2022 Parity Technologies (UK) Ltd.
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2019-2022 Parity Technologies (UK) Ltd.
// Copyright 2019-2023 Parity Technologies (UK) Ltd.
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.