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
before · tests/src/eth/abi/nativeFungible.json
1[2  {3    "anonymous": false,4    "inputs": [5      {6        "indexed": true,7        "internalType": "address",8        "name": "owner",9        "type": "address"10      },11      {12        "indexed": true,13        "internalType": "address",14        "name": "spender",15        "type": "address"16      },17      {18        "indexed": false,19        "internalType": "uint256",20        "name": "value",21        "type": "uint256"22      }23    ],24    "name": "Approval",25    "type": "event"26  },27  {28    "anonymous": false,29    "inputs": [30      {31        "indexed": true,32        "internalType": "address",33        "name": "from",34        "type": "address"35      },36      {37        "indexed": true,38        "internalType": "address",39        "name": "to",40        "type": "address"41      },42      {43        "indexed": false,44        "internalType": "uint256",45        "name": "value",46        "type": "uint256"47      }48    ],49    "name": "Transfer",50    "type": "event"51  },52  {53    "inputs": [54      { "internalType": "address", "name": "owner", "type": "address" },55      { "internalType": "address", "name": "spender", "type": "address" }56    ],57    "name": "allowance",58    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],59    "stateMutability": "view",60    "type": "function"61  },62  {63    "inputs": [64      { "internalType": "address", "name": "spender", "type": "address" },65      { "internalType": "uint256", "name": "amount", "type": "uint256" }66    ],67    "name": "approve",68    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],69    "stateMutability": "nonpayable",70    "type": "function"71  },72  {73    "inputs": [74      { "internalType": "address", "name": "owner", "type": "address" }75    ],76    "name": "balanceOf",77    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],78    "stateMutability": "view",79    "type": "function"80  },81  {82    "inputs": [],83    "name": "decimals",84    "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }],85    "stateMutability": "view",86    "type": "function"87  },88  {89    "inputs": [],90    "name": "name",91    "outputs": [{ "internalType": "string", "name": "", "type": "string" }],92    "stateMutability": "view",93    "type": "function"94  },95  {96    "inputs": [97      { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }98    ],99    "name": "supportsInterface",100    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],101    "stateMutability": "view",102    "type": "function"103  },104  {105    "inputs": [],106    "name": "symbol",107    "outputs": [{ "internalType": "string", "name": "", "type": "string" }],108    "stateMutability": "view",109    "type": "function"110  },111  {112    "inputs": [],113    "name": "totalSupply",114    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],115    "stateMutability": "view",116    "type": "function"117  },118  {119    "inputs": [120      { "internalType": "address", "name": "to", "type": "address" },121      { "internalType": "uint256", "name": "amount", "type": "uint256" }122    ],123    "name": "transfer",124    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],125    "stateMutability": "nonpayable",126    "type": "function"127  },128  {129    "inputs": [130      {131        "components": [132          { "internalType": "address", "name": "eth", "type": "address" },133          { "internalType": "uint256", "name": "sub", "type": "uint256" }134        ],135        "internalType": "struct CrossAddress",136        "name": "to",137        "type": "tuple"138      },139      { "internalType": "uint256", "name": "amount", "type": "uint256" }140    ],141    "name": "transferCross",142    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],143    "stateMutability": "nonpayable",144    "type": "function"145  },146  {147    "inputs": [148      { "internalType": "address", "name": "from", "type": "address" },149      { "internalType": "address", "name": "to", "type": "address" },150      { "internalType": "uint256", "name": "amount", "type": "uint256" }151    ],152    "name": "transferFrom",153    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],154    "stateMutability": "nonpayable",155    "type": "function"156  },157  {158    "inputs": [159      {160        "components": [161          { "internalType": "address", "name": "eth", "type": "address" },162          { "internalType": "uint256", "name": "sub", "type": "uint256" }163        ],164        "internalType": "struct CrossAddress",165        "name": "from",166        "type": "tuple"167      },168      {169        "components": [170          { "internalType": "address", "name": "eth", "type": "address" },171          { "internalType": "uint256", "name": "sub", "type": "uint256" }172        ],173        "internalType": "struct CrossAddress",174        "name": "to",175        "type": "tuple"176      },177      { "internalType": "uint256", "name": "amount", "type": "uint256" }178    ],179    "name": "transferFromCross",180    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],181    "stateMutability": "nonpayable",182    "type": "function"183  }184]
after · tests/src/eth/abi/nativeFungible.json
1[2  {3    "anonymous": false,4    "inputs": [5      {6        "indexed": true,7        "internalType": "address",8        "name": "owner",9        "type": "address"10      },11      {12        "indexed": true,13        "internalType": "address",14        "name": "spender",15        "type": "address"16      },17      {18        "indexed": false,19        "internalType": "uint256",20        "name": "value",21        "type": "uint256"22      }23    ],24    "name": "Approval",25    "type": "event"26  },27  {28    "anonymous": false,29    "inputs": [30      {31        "indexed": true,32        "internalType": "address",33        "name": "from",34        "type": "address"35      },36      {37        "indexed": true,38        "internalType": "address",39        "name": "to",40        "type": "address"41      },42      {43        "indexed": false,44        "internalType": "uint256",45        "name": "value",46        "type": "uint256"47      }48    ],49    "name": "Transfer",50    "type": "event"51  },52  {53    "inputs": [54      { "internalType": "address", "name": "owner", "type": "address" },55      { "internalType": "address", "name": "spender", "type": "address" }56    ],57    "name": "allowance",58    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],59    "stateMutability": "view",60    "type": "function"61  },62  {63    "inputs": [64      { "internalType": "address", "name": "spender", "type": "address" },65      { "internalType": "uint256", "name": "amount", "type": "uint256" }66    ],67    "name": "approve",68    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],69    "stateMutability": "nonpayable",70    "type": "function"71  },72  {73    "inputs": [74      { "internalType": "address", "name": "owner", "type": "address" }75    ],76    "name": "balanceOf",77    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],78    "stateMutability": "view",79    "type": "function"80  },81  {82    "inputs": [83      {84        "components": [85          { "internalType": "address", "name": "eth", "type": "address" },86          { "internalType": "uint256", "name": "sub", "type": "uint256" }87        ],88        "internalType": "struct CrossAddress",89        "name": "owner",90        "type": "tuple"91      }92    ],93    "name": "balanceOfCross",94    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],95    "stateMutability": "view",96    "type": "function"97  },98  {99    "inputs": [],100    "name": "decimals",101    "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }],102    "stateMutability": "view",103    "type": "function"104  },105  {106    "inputs": [],107    "name": "name",108    "outputs": [{ "internalType": "string", "name": "", "type": "string" }],109    "stateMutability": "view",110    "type": "function"111  },112  {113    "inputs": [114      { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }115    ],116    "name": "supportsInterface",117    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],118    "stateMutability": "view",119    "type": "function"120  },121  {122    "inputs": [],123    "name": "symbol",124    "outputs": [{ "internalType": "string", "name": "", "type": "string" }],125    "stateMutability": "view",126    "type": "function"127  },128  {129    "inputs": [],130    "name": "totalSupply",131    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],132    "stateMutability": "view",133    "type": "function"134  },135  {136    "inputs": [137      { "internalType": "address", "name": "to", "type": "address" },138      { "internalType": "uint256", "name": "amount", "type": "uint256" }139    ],140    "name": "transfer",141    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],142    "stateMutability": "nonpayable",143    "type": "function"144  },145  {146    "inputs": [147      {148        "components": [149          { "internalType": "address", "name": "eth", "type": "address" },150          { "internalType": "uint256", "name": "sub", "type": "uint256" }151        ],152        "internalType": "struct CrossAddress",153        "name": "to",154        "type": "tuple"155      },156      { "internalType": "uint256", "name": "amount", "type": "uint256" }157    ],158    "name": "transferCross",159    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],160    "stateMutability": "nonpayable",161    "type": "function"162  },163  {164    "inputs": [165      { "internalType": "address", "name": "from", "type": "address" },166      { "internalType": "address", "name": "to", "type": "address" },167      { "internalType": "uint256", "name": "amount", "type": "uint256" }168    ],169    "name": "transferFrom",170    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],171    "stateMutability": "nonpayable",172    "type": "function"173  },174  {175    "inputs": [176      {177        "components": [178          { "internalType": "address", "name": "eth", "type": "address" },179          { "internalType": "uint256", "name": "sub", "type": "uint256" }180        ],181        "internalType": "struct CrossAddress",182        "name": "from",183        "type": "tuple"184      },185      {186        "components": [187          { "internalType": "address", "name": "eth", "type": "address" },188          { "internalType": "uint256", "name": "sub", "type": "uint256" }189        ],190        "internalType": "struct CrossAddress",191        "name": "to",192        "type": "tuple"193      },194      { "internalType": "uint256", "name": "amount", "type": "uint256" }195    ],196    "name": "transferFromCross",197    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],198    "stateMutability": "nonpayable",199    "type": "function"200  }201]
modifiedtests/src/eth/api/UniqueNativeFungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueNativeFungible.sol
+++ b/tests/src/eth/api/UniqueNativeFungible.sol
@@ -12,8 +12,12 @@
 	function supportsInterface(bytes4 interfaceID) external view returns (bool);
 }
 
-/// @dev the ERC-165 identifier for this interface is 0xff15c6f4
+/// @dev the ERC-165 identifier for this interface is 0x1313556c
 interface ERC20UniqueExtensions is Dummy, ERC165 {
+	/// @dev EVM selector for this function is: 0xec069398,
+	///  or in textual repr: balanceOfCross((address,uint256))
+	function balanceOfCross(CrossAddress memory owner) external view returns (uint256);
+
 	/// @dev EVM selector for this function is: 0x2ada85ff,
 	///  or in textual repr: transferCross((address,uint256),uint256)
 	function transferCross(CrossAddress memory to, uint256 amount) external returns (bool);