difftreelog
feat impl balance_of_cross
in: master
5 files changed
pallets/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);
pallets/balances-adapter/src/stubs/UniqueNativeFungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/balances-adapter/src/stubs/UniqueNativeFungible.soldiffbeforeafterboth1// SPDX-License-Identifier: OTHER2// This code is automatically generated34pragma solidity >=0.8.0 <0.9.0;56/// @dev common stubs holder7contract Dummy {8 uint8 dummy;9 string stub_error = "this contract is implemented in native";10}1112contract ERC165 is Dummy {13 function supportsInterface(bytes4 interfaceID) external view returns (bool) {14 require(false, stub_error);15 interfaceID;16 return true;17 }18}1920/// @dev the ERC-165 identifier for this interface is 0x1313556c21contract ERC20UniqueExtensions is Dummy, ERC165 {22 /// @dev EVM selector for this function is: 0xec069398,23 /// or in textual repr: balanceOfCross((address,uint256))24 function balanceOfCross(CrossAddress memory owner) public view returns (uint256) {25 require(false, stub_error);26 owner;27 dummy;28 return 0;29 }3031 /// @dev EVM selector for this function is: 0x2ada85ff,32 /// or in textual repr: transferCross((address,uint256),uint256)33 function transferCross(CrossAddress memory to, uint256 amount) public returns (bool) {34 require(false, stub_error);35 to;36 amount;37 dummy = 0;38 return false;39 }4041 /// @dev EVM selector for this function is: 0xd5cf430b,42 /// or in textual repr: transferFromCross((address,uint256),(address,uint256),uint256)43 function transferFromCross(44 CrossAddress memory from,45 CrossAddress memory to,46 uint256 amount47 ) public returns (bool) {48 require(false, stub_error);49 from;50 to;51 amount;52 dummy = 0;53 return false;54 }55}5657/// Cross account struct58struct CrossAddress {59 address eth;60 uint256 sub;61}6263/// @dev inlined interface64contract ERC20Events {65 event Transfer(address indexed from, address indexed to, uint256 value);66 event Approval(address indexed owner, address indexed spender, uint256 value);67}6869/// @dev the ERC-165 identifier for this interface is 0x942e8b2270contract ERC20 is Dummy, ERC165, ERC20Events {71 /// @dev EVM selector for this function is: 0xdd62ed3e,72 /// or in textual repr: allowance(address,address)73 function allowance(address owner, address spender) public view returns (uint256) {74 require(false, stub_error);75 owner;76 spender;77 dummy;78 return 0;79 }8081 /// @dev EVM selector for this function is: 0x095ea7b3,82 /// or in textual repr: approve(address,uint256)83 function approve(address spender, uint256 amount) public returns (bool) {84 require(false, stub_error);85 spender;86 amount;87 dummy = 0;88 return false;89 }9091 /// @dev EVM selector for this function is: 0x70a08231,92 /// or in textual repr: balanceOf(address)93 function balanceOf(address owner) public view returns (uint256) {94 require(false, stub_error);95 owner;96 dummy;97 return 0;98 }99100 /// @dev EVM selector for this function is: 0x313ce567,101 /// or in textual repr: decimals()102 function decimals() public view returns (uint8) {103 require(false, stub_error);104 dummy;105 return 0;106 }107108 /// @dev EVM selector for this function is: 0x06fdde03,109 /// or in textual repr: name()110 function name() public view returns (string memory) {111 require(false, stub_error);112 dummy;113 return "";114 }115116 /// @dev EVM selector for this function is: 0x95d89b41,117 /// or in textual repr: symbol()118 function symbol() public view returns (string memory) {119 require(false, stub_error);120 dummy;121 return "";122 }123124 /// @dev EVM selector for this function is: 0x18160ddd,125 /// or in textual repr: totalSupply()126 function totalSupply() public view returns (uint256) {127 require(false, stub_error);128 dummy;129 return 0;130 }131132 /// @dev EVM selector for this function is: 0xa9059cbb,133 /// or in textual repr: transfer(address,uint256)134 function transfer(address to, uint256 amount) public returns (bool) {135 require(false, stub_error);136 to;137 amount;138 dummy = 0;139 return false;140 }141142 /// @dev EVM selector for this function is: 0x23b872dd,143 /// or in textual repr: transferFrom(address,address,uint256)144 function transferFrom(145 address from,146 address to,147 uint256 amount148 ) public returns (bool) {149 require(false, stub_error);150 from;151 to;152 amount;153 dummy = 0;154 return false;155 }156}157158contract UniqueNativeFungible is Dummy, ERC165, ERC20, ERC20UniqueExtensions {}tests/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" }],
tests/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);