difftreelog
fix change sponsor to OptioCrossAddress
in: master
9 files changed
crates/evm-coder/src/abi/impls.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi/impls.rs
+++ b/crates/evm-coder/src/abi/impls.rs
@@ -181,11 +181,6 @@
}
}
-macro_rules! count {
- () => (0usize);
- ( $x:tt $($xs:tt)* ) => (1usize + count!($($xs)*));
-}
-
macro_rules! impl_tuples {
($($ident:ident)+) => {
impl<$($ident: AbiType,)+> AbiType for ($($ident,)+)
pallets/common/src/eth.rsdiffbeforeafterboth--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -122,6 +122,13 @@
}
}
+/// Ethereum representation of Optional value with CrossAddress.
+#[derive(Debug, Default, AbiCoder)]
+pub struct OptionCrossAddress {
+ pub status: bool,
+ pub value: CrossAddress,
+}
+
/// Cross account struct
#[derive(Debug, Default, AbiCoder)]
pub struct CrossAddress {
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -25,6 +25,7 @@
types::*,
ToLog,
};
+use pallet_common::eth;
use pallet_evm::{
ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure, PrecompileHandle,
account::CrossAccountId,
@@ -174,12 +175,17 @@
///
/// @param contractAddress The contract for which a sponsor is requested.
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
- fn sponsor(&self, contract_address: address) -> Result<pallet_common::eth::CrossAddress> {
- Ok(
- pallet_common::eth::CrossAddress::from_sub_cross_account::<T>(
- &Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?,
- ),
- )
+ fn sponsor(&self, contract_address: address) -> Result<eth::OptionCrossAddress> {
+ Ok(match Pallet::<T>::get_sponsor(contract_address) {
+ Some(ref value) => eth::OptionCrossAddress {
+ status: true,
+ value: eth::CrossAddress::from_sub_cross_account::<T>(value),
+ },
+ None => eth::OptionCrossAddress {
+ status: false,
+ value: Default::default(),
+ },
+ })
}
/// Check tat contract has confirmed sponsor.
pallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/evm-contract-helpers/src/stubs/ContractHelpers.soldiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
+++ b/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
@@ -96,11 +96,11 @@
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
/// @dev EVM selector for this function is: 0x766c4f37,
/// or in textual repr: sponsor(address)
- function sponsor(address contractAddress) public view returns (CrossAddress memory) {
+ function sponsor(address contractAddress) public view returns (OptionCrossAddress memory) {
require(false, stub_error);
contractAddress;
dummy;
- return CrossAddress(0x0000000000000000000000000000000000000000, 0);
+ return OptionCrossAddress(false, CrossAddress(0x0000000000000000000000000000000000000000, 0));
}
/// Check tat contract has confirmed sponsor.
@@ -270,3 +270,9 @@
address eth;
uint256 sub;
}
+
+/// @dev Ethereum representation of Optional value with CrossAddress.
+struct OptionCrossAddress {
+ bool status;
+ CrossAddress value;
+}
pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -74,7 +74,7 @@
extern crate alloc;
use frame_support::{
- decl_module, decl_storage, decl_error, decl_event,
+ decl_module, decl_storage, decl_error,
dispatch::DispatchResult,
ensure, fail,
weights::{Weight},
tests/src/eth/abi/contractHelpers.jsondiffbeforeafterboth222 "name": "sponsor",222 "name": "sponsor",223 "outputs": [223 "outputs": [224 {224 {225 "components": [226 { "internalType": "bool", "name": "status", "type": "bool" },227 {225 "components": [228 "components": [226 { "internalType": "address", "name": "eth", "type": "address" },229 { "internalType": "address", "name": "eth", "type": "address" },227 { "internalType": "uint256", "name": "sub", "type": "uint256" }230 { "internalType": "uint256", "name": "sub", "type": "uint256" }228 ],231 ],229 "internalType": "struct CrossAddress",232 "internalType": "struct CrossAddress",233 "name": "value",234 "type": "tuple"235 }236 ],237 "internalType": "struct OptionCrossAddress",230 "name": "",238 "name": "",231 "type": "tuple"239 "type": "tuple"232 }240 }tests/src/eth/api/ContractHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/ContractHelpers.sol
+++ b/tests/src/eth/api/ContractHelpers.sol
@@ -69,7 +69,7 @@
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
/// @dev EVM selector for this function is: 0x766c4f37,
/// or in textual repr: sponsor(address)
- function sponsor(address contractAddress) external view returns (CrossAddress memory);
+ function sponsor(address contractAddress) external view returns (OptionCrossAddress memory);
/// Check tat contract has confirmed sponsor.
///
@@ -171,6 +171,12 @@
function toggleAllowlist(address contractAddress, bool enabled) external;
}
+/// @dev Ethereum representation of Optional value with CrossAddress.
+struct OptionCrossAddress {
+ bool status;
+ CrossAddress value;
+}
+
/// @dev Cross account struct
struct CrossAddress {
address eth;
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -42,7 +42,9 @@
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
// 1.1 Can get sponsor using methods.sponsor:
- const actualSponsor = await helpers.methods.sponsor(flipper.options.address).call();
+ const actualSponsorOpt = await helpers.methods.sponsor(flipper.options.address).call();
+ expect(actualSponsorOpt.status).to.be.true;
+ const actualSponsor = actualSponsorOpt.value;
expect(actualSponsor.eth).to.eq(flipper.options.address);
expect(actualSponsor.sub).to.eq('0');
@@ -151,7 +153,9 @@
expect(await helpers.methods.hasSponsor(flipper.options.address).call()).to.be.true;
// 1.1 Can get sponsor using methods.sponsor:
- const actualSponsor = await helpers.methods.sponsor(flipper.options.address).call();
+ const actualSponsorOpt = await helpers.methods.sponsor(flipper.options.address).call();
+ expect(actualSponsorOpt.status).to.be.true;
+ const actualSponsor = actualSponsorOpt.value;
expect(actualSponsor.eth).to.eq(sponsor);
expect(actualSponsor.sub).to.eq('0');