From a4f42d6dae091178581c5d2271a68b027c9c5b90 Mon Sep 17 00:00:00 2001 From: Claudiu-Marcel Bruda Date: Thu, 15 Sep 2022 15:23:31 +0300 Subject: [PATCH 1/3] add missing substitution rules, reorganize, typo --- .../src/preprocessing/substitution_list.rs | 51 +++++++++++++------ .../multi_value_managed_vec_counted.rs | 2 +- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/elrond-wasm-derive/src/preprocessing/substitution_list.rs b/elrond-wasm-derive/src/preprocessing/substitution_list.rs index 0090cb96ab..13eb215272 100644 --- a/elrond-wasm-derive/src/preprocessing/substitution_list.rs +++ b/elrond-wasm-derive/src/preprocessing/substitution_list.rs @@ -36,32 +36,51 @@ fn add_managed_type_with_generics( } fn add_managed_types(substitutions: &mut SubstitutionsMap) { + // types::io + add_managed_type(substitutions, "e!(ManagedSCError)); + + // types::interaction + add_managed_type(substitutions, "e!(AsyncCall)); + + // types::managed::basic + add_managed_type(substitutions, "e!(BigFloat)); add_managed_type(substitutions, "e!(BigInt)); add_managed_type(substitutions, "e!(BigUint)); - add_managed_type(substitutions, "e!(BigFloat)); - add_managed_type(substitutions, "e!(ManagedBuffer)); + add_managed_type(substitutions, "e!(EllipticCurveComponents)); add_managed_type(substitutions, "e!(EllipticCurve)); - add_managed_type(substitutions, "e!(ManagedAddress)); - add_managed_type(substitutions, "e!(TokenIdentifier)); - add_managed_type(substitutions, "e!(EgldOrEsdtTokenIdentifier)); - add_managed_type(substitutions, "e!(ManagedSCError)); - add_managed_type(substitutions, "e!(AsyncCall)); + add_managed_type(substitutions, "e!(ManagedBuffer)); + + // types::managed::multi-value add_managed_type(substitutions, "e!(ManagedAsyncCallError)); - add_managed_type(substitutions, "e!(EsdtTokenPayment)); + add_managed_type_with_generics(substitutions, "e!(ManagedAsyncCallResult)); + add_managed_type(substitutions, "e!(EsdtTokenPaymentMultiArg)); add_managed_type(substitutions, "e!(EsdtTokenPaymentMultiValue)); - - add_managed_type_with_generics(substitutions, "e!(ManagedOption)); - add_managed_type_with_generics(substitutions, "e!(ManagedVec)); - add_managed_type_with_generics(substitutions, "e!(ManagedVecOwnedIterator)); - add_managed_type_with_generics(substitutions, "e!(ManagedMultiValue)); + add_managed_type_with_generics(substitutions, "e!(MultiValueEncodedIterator)); + add_managed_type_with_generics(substitutions, "e!(MultiValueEncoded)); add_managed_type_with_generics(substitutions, "e!(ManagedVarArgs)); add_managed_type_with_generics(substitutions, "e!(ManagedMultiResultVec)); - add_managed_type_with_generics(substitutions, "e!(ManagedAsyncCallResult)); - add_managed_type_with_generics(substitutions, "e!(MultiValueEncoded)); - add_managed_type_with_generics(substitutions, "e!(MultiValueManagedVec)); add_managed_type_with_generics(substitutions, "e!(MultiValueManagedVecCounted)); add_managed_type_with_generics(substitutions, "e!(ManagedCountedVarArgs)); add_managed_type_with_generics(substitutions, "e!(ManagedCountedMultiResultVec)); + add_managed_type_with_generics(substitutions, "e!(MultiValueManagedVec)); + + // types::managed::wrapped + add_managed_type(substitutions, "e!(EgldOrEsdtTokenIdentifier)); + add_managed_type(substitutions, "e!(EgldOrEsdtTokenPayment)); + add_managed_type(substitutions, "e!(EsdtTokenData)); + add_managed_type(substitutions, "e!(EsdtTokenPayment)); + add_managed_type(substitutions, "e!(ManagedAddress)); + add_managed_type(substitutions, "e!(ManagedBufferCachedBuilder)); + add_managed_type_with_generics(substitutions, "e!(ManagedByteArray)); + add_managed_type_with_generics(substitutions, "e!(ManagedOption)); + add_managed_type_with_generics(substitutions, "e!(ManagedRef)); + add_managed_type_with_generics(substitutions, "e!(ManagedVecOwnedIterator)); + add_managed_type_with_generics(substitutions, "e!(ManagedVecRefIterator)); + add_managed_type_with_generics(substitutions, "e!(ManagedVecRef)); + add_managed_type_with_generics(substitutions, "e!(ManagedVec)); + add_managed_type_with_generics(substitutions, "e!(PreloadedManagedBuffer)); + add_managed_type_with_generics(substitutions, "e!(RandomnessSource)); + add_managed_type(substitutions, "e!(TokenIdentifier)); } fn add_storage_mapper_single_generic_arg( diff --git a/elrond-wasm/src/types/managed/multi_value/multi_value_managed_vec_counted.rs b/elrond-wasm/src/types/managed/multi_value/multi_value_managed_vec_counted.rs index 5d13ac3772..8f0b7bf5e8 100644 --- a/elrond-wasm/src/types/managed/multi_value/multi_value_managed_vec_counted.rs +++ b/elrond-wasm/src/types/managed/multi_value/multi_value_managed_vec_counted.rs @@ -10,7 +10,7 @@ use elrond_codec::{ /// Argument or result that is made up of the argument count, followed by the arguments themselves. /// Think of it as a `VarArgs` preceded by the count. -/// Unlike `ManagedMultiValue` it deserializes eagerly. +/// Unlike `MultiValueManagedVec` it deserializes eagerly. #[derive(Clone, Default)] pub struct MultiValueManagedVecCounted where From b59f94e0ba252fe7e3dbb19067c43392a5bca2f8 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Fri, 16 Sep 2022 14:19:31 +0300 Subject: [PATCH 2/3] managed ref preprocessor test --- .../basic-features/src/managed_vec_features.rs | 7 +++++++ .../src/types/managed/wrapped/managed_ref.rs | 15 --------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/contracts/feature-tests/basic-features/src/managed_vec_features.rs b/contracts/feature-tests/basic-features/src/managed_vec_features.rs index 196c211cf4..21203abc58 100644 --- a/contracts/feature-tests/basic-features/src/managed_vec_features.rs +++ b/contracts/feature-tests/basic-features/src/managed_vec_features.rs @@ -76,4 +76,11 @@ pub trait ManagedVecFeatures { mv.push(item); mv } + + #[endpoint] + fn managed_ref_explicit(&self, mv: ManagedVec, index: usize) -> BigUint { + let value: ManagedRef = mv.get(index); + let with_explicit_lifetime: ManagedRef<'_, BigUint> = value; + with_explicit_lifetime.clone() + } } diff --git a/elrond-wasm/src/types/managed/wrapped/managed_ref.rs b/elrond-wasm/src/types/managed/wrapped/managed_ref.rs index 373686cd87..d94cb56c23 100644 --- a/elrond-wasm/src/types/managed/wrapped/managed_ref.rs +++ b/elrond-wasm/src/types/managed/wrapped/managed_ref.rs @@ -49,21 +49,6 @@ where } } -impl<'a, M, T> Clone for ManagedRef<'a, M, T> -where - M: ManagedTypeApi, - T: ManagedType, -{ - #[inline] - fn clone(&self) -> Self { - Self { - _phantom_m: PhantomData, - _phantom_t: PhantomData, - handle: self.handle.clone(), - } - } -} - impl<'a, M, T> Deref for ManagedRef<'a, M, T> where M: ManagedTypeApi, From 3ef8f863cd75bc09866cedf3d11756d0a9ef425c Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Fri, 16 Sep 2022 16:37:05 +0300 Subject: [PATCH 3/3] managed ref clone fix --- .../basic-features/src/managed_vec_features.rs | 2 +- .../src/types/managed/wrapped/managed_ref.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/contracts/feature-tests/basic-features/src/managed_vec_features.rs b/contracts/feature-tests/basic-features/src/managed_vec_features.rs index 21203abc58..7b396e0044 100644 --- a/contracts/feature-tests/basic-features/src/managed_vec_features.rs +++ b/contracts/feature-tests/basic-features/src/managed_vec_features.rs @@ -81,6 +81,6 @@ pub trait ManagedVecFeatures { fn managed_ref_explicit(&self, mv: ManagedVec, index: usize) -> BigUint { let value: ManagedRef = mv.get(index); let with_explicit_lifetime: ManagedRef<'_, BigUint> = value; - with_explicit_lifetime.clone() + (*with_explicit_lifetime).clone() } } diff --git a/elrond-wasm/src/types/managed/wrapped/managed_ref.rs b/elrond-wasm/src/types/managed/wrapped/managed_ref.rs index d94cb56c23..373686cd87 100644 --- a/elrond-wasm/src/types/managed/wrapped/managed_ref.rs +++ b/elrond-wasm/src/types/managed/wrapped/managed_ref.rs @@ -49,6 +49,21 @@ where } } +impl<'a, M, T> Clone for ManagedRef<'a, M, T> +where + M: ManagedTypeApi, + T: ManagedType, +{ + #[inline] + fn clone(&self) -> Self { + Self { + _phantom_m: PhantomData, + _phantom_t: PhantomData, + handle: self.handle.clone(), + } + } +} + impl<'a, M, T> Deref for ManagedRef<'a, M, T> where M: ManagedTypeApi,