git.delta.rocks / unique-network / refs/commits / 9871bd2fd605

difftreelog

feat balanceOfCross for RFT token

Trubnikov Sergey2023-04-18parent: #fc48e60.patch.diff
in: master

7 files changed

modifiedpallets/refungible/src/erc_token.rsdiffbeforeafterboth
284 Ok(true)284 Ok(true)
285 }285 }
286
287 /// @notice Balance of account
288 /// @param owner An cross address for whom to query the balance
289 /// @return The number of fingibles owned by `owner`, possibly zero
290 fn balance_of_cross(&self, owner: CrossAddress) -> Result<U256> {
291 self.consume_store_reads(1)?;
292 let balance = <Balance<T>>::get((self.id, self.1, owner.into_sub_cross_account::<T>()?));
293 Ok(balance.into())
294 }
295
286 /// @dev Function that changes total amount of the tokens.296 /// @dev Function that changes total amount of the tokens.
287 /// Throws if `msg.sender` doesn't owns all of the tokens.297 /// Throws if `msg.sender` doesn't owns all of the tokens.
modifiedpallets/refungible/src/stubs/UniqueRefungibleToken.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/stubs/UniqueRefungibleToken.soldiffbeforeafterboth
36 }36 }
37}37}
3838
39/// @dev the ERC-165 identifier for this interface is 0x01d536fc39/// @dev the ERC-165 identifier for this interface is 0xedd3a564
40contract ERC20UniqueExtensions is Dummy, ERC165 {40contract ERC20UniqueExtensions is Dummy, ERC165 {
41 /// @dev Function to check the amount of tokens that an owner allowed to a spender.41 /// @dev Function to check the amount of tokens that an owner allowed to a spender.
42 /// @param owner crossAddress The address which owns the funds.42 /// @param owner crossAddress The address which owns the funds.
97 return false;97 return false;
98 }98 }
99
100 /// @notice Balance of account
101 /// @param owner An cross address for whom to query the balance
102 /// @return The number of fingibles owned by `owner`, possibly zero
103 /// @dev EVM selector for this function is: 0xec069398,
104 /// or in textual repr: balanceOfCross((address,uint256))
105 function balanceOfCross(CrossAddress memory owner) public view returns (uint256) {
106 require(false, stub_error);
107 owner;
108 dummy;
109 return 0;
110 }
99111
100 /// @dev Function that changes total amount of the tokens.112 /// @dev Function that changes total amount of the tokens.
101 /// Throws if `msg.sender` doesn't owns all of the tokens.113 /// Throws if `msg.sender` doesn't owns all of the tokens.
modifiedruntime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth
343 ERC165Call(_, _) => None,343 ERC165Call(_, _) => None,
344344
345 // Not sponsored345 // Not sponsored
346 AllowanceCross { .. } | BurnFrom { .. } | BurnFromCross { .. } | Repartition { .. } => {346 AllowanceCross { .. }
347 | BalanceOfCross { .. }
348 | BurnFrom { .. }
349 | BurnFromCross { .. }
347 None350 | Repartition { .. } => None,
348 }
349351
350 TransferCross { .. } | TransferFromCross { .. } => {352 TransferCross { .. } | TransferFromCross { .. } => {
351 let RefungibleTokenHandle(handle, token_id) = token;353 let RefungibleTokenHandle(handle, token_id) = token;
modifiedtests/src/eth/abi/reFungibleToken.jsondiffbeforeafterboth
122 "stateMutability": "view",122 "stateMutability": "view",
123 "type": "function"123 "type": "function"
124 },124 },
125 {
126 "inputs": [
127 {
128 "components": [
129 { "internalType": "address", "name": "eth", "type": "address" },
130 { "internalType": "uint256", "name": "sub", "type": "uint256" }
131 ],
132 "internalType": "struct CrossAddress",
133 "name": "owner",
134 "type": "tuple"
135 }
136 ],
137 "name": "balanceOfCross",
138 "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
139 "stateMutability": "view",
140 "type": "function"
141 },
125 {142 {
126 "inputs": [143 "inputs": [
127 {144 {
modifiedtests/src/eth/api/UniqueRefungibleToken.soldiffbeforeafterboth
23 function parentTokenId() external view returns (uint256);23 function parentTokenId() external view returns (uint256);
24}24}
2525
26/// @dev the ERC-165 identifier for this interface is 0x01d536fc26/// @dev the ERC-165 identifier for this interface is 0xedd3a564
27interface ERC20UniqueExtensions is Dummy, ERC165 {27interface ERC20UniqueExtensions is Dummy, ERC165 {
28 /// @dev Function to check the amount of tokens that an owner allowed to a spender.28 /// @dev Function to check the amount of tokens that an owner allowed to a spender.
29 /// @param owner crossAddress The address which owns the funds.29 /// @param owner crossAddress The address which owns the funds.
60 /// or in textual repr: approveCross((address,uint256),uint256)60 /// or in textual repr: approveCross((address,uint256),uint256)
61 function approveCross(CrossAddress memory spender, uint256 amount) external returns (bool);61 function approveCross(CrossAddress memory spender, uint256 amount) external returns (bool);
62
63 /// @notice Balance of account
64 /// @param owner An cross address for whom to query the balance
65 /// @return The number of fingibles owned by `owner`, possibly zero
66 /// @dev EVM selector for this function is: 0xec069398,
67 /// or in textual repr: balanceOfCross((address,uint256))
68 function balanceOfCross(CrossAddress memory owner) external view returns (uint256);
6269
63 /// @dev Function that changes total amount of the tokens.70 /// @dev Function that changes total amount of the tokens.
64 /// Throws if `msg.sender` doesn't owns all of the tokens.71 /// Throws if `msg.sender` doesn't owns all of the tokens.
modifiedtests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth
467 }467 }
468 });468 });
469
470 itEth('Check balanceOfCross()', async ({helper}) => {
471 const collection = await helper.rft.mintCollection(alice, {});
472 const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
473 const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner.eth});
474 const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
475 const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner.eth);
476
477 expect(BigInt(await tokenContract.methods.balanceOfCross(owner).call({from: owner.eth})) === 200n).to.be.true;
478
479 for (let i = 1n; i < 100n; i++) {
480 await tokenContract.methods.repartition(i).send({from: owner.eth});
481 expect(BigInt(await tokenContract.methods.balanceOfCross(owner).call({from: owner.eth})) === i).to.be.true;
482 }
483 });
469});484});
470485
471describe('Refungible: Fees', () => {486describe('Refungible: Fees', () => {