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.soldiffbeforeafterboth96 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.96 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.97 /// @dev EVM selector for this function is: 0x766c4f37,97 /// @dev EVM selector for this function is: 0x766c4f37,98 /// or in textual repr: sponsor(address)98 /// or in textual repr: sponsor(address)99 function sponsor(address contractAddress) public view returns (CrossAddress memory) {99 function sponsor(address contractAddress) public view returns (OptionCrossAddress memory) {100 require(false, stub_error);100 require(false, stub_error);101 contractAddress;101 contractAddress;102 dummy;102 dummy;103 return CrossAddress(0x0000000000000000000000000000000000000000, 0);103 return OptionCrossAddress(false, CrossAddress(0x0000000000000000000000000000000000000000, 0));104 }104 }105105106 /// Check tat contract has confirmed sponsor.106 /// Check tat contract has confirmed sponsor.271 uint256 sub;271 uint256 sub;272}272}273274/// @dev Ethereum representation of Optional value with CrossAddress.275struct OptionCrossAddress {276 bool status;277 CrossAddress value;278}273279pallets/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.jsondiffbeforeafterboth--- a/tests/src/eth/abi/contractHelpers.json
+++ b/tests/src/eth/abi/contractHelpers.json
@@ -223,10 +223,18 @@
"outputs": [
{
"components": [
- { "internalType": "address", "name": "eth", "type": "address" },
- { "internalType": "uint256", "name": "sub", "type": "uint256" }
+ { "internalType": "bool", "name": "status", "type": "bool" },
+ {
+ "components": [
+ { "internalType": "address", "name": "eth", "type": "address" },
+ { "internalType": "uint256", "name": "sub", "type": "uint256" }
+ ],
+ "internalType": "struct CrossAddress",
+ "name": "value",
+ "type": "tuple"
+ }
],
- "internalType": "struct CrossAddress",
+ "internalType": "struct OptionCrossAddress",
"name": "",
"type": "tuple"
}
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');