git.delta.rocks / unique-network / refs/commits / d3a59ede1ff6

difftreelog

feat impl balance_of_cross

Trubnikov Sergey2023-04-21parent: #ec349b0.patch.diff
in: master

5 files changed

modifiedpallets/balances-adapter/src/erc.rsdiffbeforeafterboth
--- a/pallets/balances-adapter/src/erc.rs
+++ b/pallets/balances-adapter/src/erc.rs
@@ -58,6 +58,7 @@
 		// self.consume_store_reads(1)?;
 		Err("Approve not supported now".into())
 	}
+
 	fn balance_of(&self, owner: Address) -> Result<U256> {
 		// self.consume_store_reads(1)?;
 		let owner = T::CrossAccountId::from_eth(owner);
@@ -141,6 +142,13 @@
 where
 	T::AccountId: From<[u8; 32]>,
 {
+	fn balance_of_cross(&self, owner: CrossAddress) -> Result<U256> {
+		// self.consume_store_reads(1)?;
+		let owner = owner.into_sub_cross_account::<T>()?;
+		let balance = <T as Config>::Currency::free_balance(owner.as_sub());
+		Ok(balance.into())
+	}
+
 	// #[weight(<SelfWeightOf<T>>::transfer())]
 	fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {
 		let caller = T::CrossAccountId::from_eth(caller);
modifiedpallets/balances-adapter/src/stubs/UniqueNativeFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/balances-adapter/src/stubs/UniqueNativeFungible.soldiffbeforeafterboth
--- a/pallets/balances-adapter/src/stubs/UniqueNativeFungible.sol
+++ b/pallets/balances-adapter/src/stubs/UniqueNativeFungible.sol
@@ -17,8 +17,17 @@
 	}
 }
 
-/// @dev the ERC-165 identifier for this interface is 0xff15c6f4
+/// @dev the ERC-165 identifier for this interface is 0x1313556c
 contract ERC20UniqueExtensions is Dummy, ERC165 {
+	/// @dev EVM selector for this function is: 0xec069398,
+	///  or in textual repr: balanceOfCross((address,uint256))
+	function balanceOfCross(CrossAddress memory owner) public view returns (uint256) {
+		require(false, stub_error);
+		owner;
+		dummy;
+		return 0;
+	}
+
 	/// @dev EVM selector for this function is: 0x2ada85ff,
 	///  or in textual repr: transferCross((address,uint256),uint256)
 	function transferCross(CrossAddress memory to, uint256 amount) public returns (bool) {
modifiedtests/src/eth/abi/nativeFungible.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/nativeFungible.json
+++ b/tests/src/eth/abi/nativeFungible.json
@@ -79,6 +79,23 @@
     "type": "function"
   },
   {
+    "inputs": [
+      {
+        "components": [
+          { "internalType": "address", "name": "eth", "type": "address" },
+          { "internalType": "uint256", "name": "sub", "type": "uint256" }
+        ],
+        "internalType": "struct CrossAddress",
+        "name": "owner",
+        "type": "tuple"
+      }
+    ],
+    "name": "balanceOfCross",
+    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
     "inputs": [],
     "name": "decimals",
     "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }],
modifiedtests/src/eth/api/UniqueNativeFungible.soldiffbeforeafterboth
before · tests/src/eth/api/UniqueNativeFungible.sol
1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56/// @dev common stubs holder7interface Dummy {89}1011interface ERC165 is Dummy {12	function supportsInterface(bytes4 interfaceID) external view returns (bool);13}1415/// @dev the ERC-165 identifier for this interface is 0xff15c6f416interface ERC20UniqueExtensions is Dummy, ERC165 {17	/// @dev EVM selector for this function is: 0x2ada85ff,18	///  or in textual repr: transferCross((address,uint256),uint256)19	function transferCross(CrossAddress memory to, uint256 amount) external returns (bool);2021	/// @dev EVM selector for this function is: 0xd5cf430b,22	///  or in textual repr: transferFromCross((address,uint256),(address,uint256),uint256)23	function transferFromCross(24		CrossAddress memory from,25		CrossAddress memory to,26		uint256 amount27	) external returns (bool);28}2930/// Cross account struct31struct CrossAddress {32	address eth;33	uint256 sub;34}3536/// @dev inlined interface37interface ERC20Events {38	event Transfer(address indexed from, address indexed to, uint256 value);39	event Approval(address indexed owner, address indexed spender, uint256 value);40}4142/// @dev the ERC-165 identifier for this interface is 0x942e8b2243interface ERC20 is Dummy, ERC165, ERC20Events {44	/// @dev EVM selector for this function is: 0xdd62ed3e,45	///  or in textual repr: allowance(address,address)46	function allowance(address owner, address spender) external view returns (uint256);4748	/// @dev EVM selector for this function is: 0x095ea7b3,49	///  or in textual repr: approve(address,uint256)50	function approve(address spender, uint256 amount) external returns (bool);5152	/// @dev EVM selector for this function is: 0x70a08231,53	///  or in textual repr: balanceOf(address)54	function balanceOf(address owner) external view returns (uint256);5556	/// @dev EVM selector for this function is: 0x313ce567,57	///  or in textual repr: decimals()58	function decimals() external view returns (uint8);5960	/// @dev EVM selector for this function is: 0x06fdde03,61	///  or in textual repr: name()62	function name() external view returns (string memory);6364	/// @dev EVM selector for this function is: 0x95d89b41,65	///  or in textual repr: symbol()66	function symbol() external view returns (string memory);6768	/// @dev EVM selector for this function is: 0x18160ddd,69	///  or in textual repr: totalSupply()70	function totalSupply() external view returns (uint256);7172	/// @dev EVM selector for this function is: 0xa9059cbb,73	///  or in textual repr: transfer(address,uint256)74	function transfer(address to, uint256 amount) external returns (bool);7576	/// @dev EVM selector for this function is: 0x23b872dd,77	///  or in textual repr: transferFrom(address,address,uint256)78	function transferFrom(79		address from,80		address to,81		uint256 amount82	) external returns (bool);83}8485interface UniqueNativeFungible is Dummy, ERC165, ERC20, ERC20UniqueExtensions {}
after · tests/src/eth/api/UniqueNativeFungible.sol
1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56/// @dev common stubs holder7interface Dummy {89}1011interface ERC165 is Dummy {12	function supportsInterface(bytes4 interfaceID) external view returns (bool);13}1415/// @dev the ERC-165 identifier for this interface is 0x1313556c16interface ERC20UniqueExtensions is Dummy, ERC165 {17	/// @dev EVM selector for this function is: 0xec069398,18	///  or in textual repr: balanceOfCross((address,uint256))19	function balanceOfCross(CrossAddress memory owner) external view returns (uint256);2021	/// @dev EVM selector for this function is: 0x2ada85ff,22	///  or in textual repr: transferCross((address,uint256),uint256)23	function transferCross(CrossAddress memory to, uint256 amount) external returns (bool);2425	/// @dev EVM selector for this function is: 0xd5cf430b,26	///  or in textual repr: transferFromCross((address,uint256),(address,uint256),uint256)27	function transferFromCross(28		CrossAddress memory from,29		CrossAddress memory to,30		uint256 amount31	) external returns (bool);32}3334/// Cross account struct35struct CrossAddress {36	address eth;37	uint256 sub;38}3940/// @dev inlined interface41interface ERC20Events {42	event Transfer(address indexed from, address indexed to, uint256 value);43	event Approval(address indexed owner, address indexed spender, uint256 value);44}4546/// @dev the ERC-165 identifier for this interface is 0x942e8b2247interface ERC20 is Dummy, ERC165, ERC20Events {48	/// @dev EVM selector for this function is: 0xdd62ed3e,49	///  or in textual repr: allowance(address,address)50	function allowance(address owner, address spender) external view returns (uint256);5152	/// @dev EVM selector for this function is: 0x095ea7b3,53	///  or in textual repr: approve(address,uint256)54	function approve(address spender, uint256 amount) external returns (bool);5556	/// @dev EVM selector for this function is: 0x70a08231,57	///  or in textual repr: balanceOf(address)58	function balanceOf(address owner) external view returns (uint256);5960	/// @dev EVM selector for this function is: 0x313ce567,61	///  or in textual repr: decimals()62	function decimals() external view returns (uint8);6364	/// @dev EVM selector for this function is: 0x06fdde03,65	///  or in textual repr: name()66	function name() external view returns (string memory);6768	/// @dev EVM selector for this function is: 0x95d89b41,69	///  or in textual repr: symbol()70	function symbol() external view returns (string memory);7172	/// @dev EVM selector for this function is: 0x18160ddd,73	///  or in textual repr: totalSupply()74	function totalSupply() external view returns (uint256);7576	/// @dev EVM selector for this function is: 0xa9059cbb,77	///  or in textual repr: transfer(address,uint256)78	function transfer(address to, uint256 amount) external returns (bool);7980	/// @dev EVM selector for this function is: 0x23b872dd,81	///  or in textual repr: transferFrom(address,address,uint256)82	function transferFrom(83		address from,84		address to,85		uint256 amount86	) external returns (bool);87}8889interface UniqueNativeFungible is Dummy, ERC165, ERC20, ERC20UniqueExtensions {}