difftreelog
added repartition method to refungible erc20 extensions
in: master
7 files changed
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -1,3 +1,19 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
extern crate alloc;
use evm_coder::{generate_stubgen, solidity_interface, types::*};
pallets/refungible/src/erc_token.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc_token.rs
+++ b/pallets/refungible/src/erc_token.rs
@@ -149,6 +149,15 @@
.map_err(dispatch_to_evm::<T>)?;
Ok(true)
}
+
+ #[weight(<SelfWeightOf<T>>::repartition_item())]
+ fn repartition(&mut self, caller: caller, amount: uint256) -> Result<bool> {
+ let caller = T::CrossAccountId::from_eth(caller);
+ let amount = amount.try_into().map_err(|_| "amount overflow")?;
+
+ <Pallet<T>>::repartition(self, &caller, self.1, amount).map_err(dispatch_to_evm::<T>)?;
+ Ok(true)
+ }
}
impl<T: Config> RefungibleTokenHandle<T> {
pallets/refungible/src/stubs/UniqueRefungibleToken.rawdiffbeforeafterbothbinary blob — no preview
pallets/refungible/src/stubs/UniqueRefungibleToken.soldiffbeforeafterboth--- a/pallets/refungible/src/stubs/UniqueRefungibleToken.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungibleToken.sol
@@ -31,18 +31,6 @@
);
}
-// Selector: 79cc6790
-contract ERC20UniqueExtensions is Dummy, ERC165 {
- // Selector: burnFrom(address,uint256) 79cc6790
- function burnFrom(address from, uint256 amount) public returns (bool) {
- require(false, stub_error);
- from;
- amount;
- dummy = 0;
- return false;
- }
-}
-
// Selector: 942e8b22
contract ERC20 is Dummy, ERC165, ERC20Events {
// Selector: name() 06fdde03
@@ -127,4 +115,24 @@
}
}
+// Selector: ab8deb37
+contract ERC20UniqueExtensions is Dummy, ERC165 {
+ // Selector: burnFrom(address,uint256) 79cc6790
+ function burnFrom(address from, uint256 amount) public returns (bool) {
+ require(false, stub_error);
+ from;
+ amount;
+ dummy = 0;
+ return false;
+ }
+
+ // Selector: repartition(uint256) d2418ca7
+ function repartition(uint256 amount) public returns (bool) {
+ require(false, stub_error);
+ amount;
+ dummy = 0;
+ return false;
+ }
+}
+
contract UniqueRefungibleToken is Dummy, ERC165, ERC20, ERC20UniqueExtensions {}
tests/src/eth/api/UniqueRefungibleToken.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRefungibleToken.sol
+++ b/tests/src/eth/api/UniqueRefungibleToken.sol
@@ -22,12 +22,6 @@
);
}
-// Selector: 79cc6790
-interface ERC20UniqueExtensions is Dummy, ERC165 {
- // Selector: burnFrom(address,uint256) 79cc6790
- function burnFrom(address from, uint256 amount) external returns (bool);
-}
-
// Selector: 942e8b22
interface ERC20 is Dummy, ERC165, ERC20Events {
// Selector: name() 06fdde03
@@ -65,6 +59,15 @@
returns (uint256);
}
+// Selector: ab8deb37
+interface ERC20UniqueExtensions is Dummy, ERC165 {
+ // Selector: burnFrom(address,uint256) 79cc6790
+ function burnFrom(address from, uint256 amount) external returns (bool);
+
+ // Selector: repartition(uint256) d2418ca7
+ function repartition(uint256 amount) external returns (bool);
+}
+
interface UniqueRefungibleToken is
Dummy,
ERC165,
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth211 }211 }212 });212 });213214 itWeb3('Can perform repartition()', async ({web3, api, privateKeyWrapper}) => {215 const alice = privateKeyWrapper('//Alice');216217 const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;218219 const owner = createEthAccount(web3);220 await transferBalanceToEth(api, alice, owner);221222 const receiver = createEthAccount(web3);223 await transferBalanceToEth(api, alice, receiver);224225 const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;226227 const address = tokenIdToAddress(collectionId, tokenId);228 const contract = new web3.eth.Contract(reFungibleTokenAbi as any, address, {from: owner, ...GAS_ARGS});229230 await contract.methods.repartition(200).send({from: owner});231 expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);232 await contract.methods.transfer(receiver, 110).send({from: owner});233 expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(90);234 expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(110);235 236 await expect(contract.methods.repartition(80).send({from: owner})).to.eventually.be.rejected;237238 await contract.methods.transfer(receiver, 90).send({from: owner});239 expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(0);240 expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(200);241242 await contract.methods.repartition(150).send({from: receiver});243 await expect(contract.methods.transfer(owner, 160).send({from: receiver})).to.eventually.be.rejected;244 expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(150);245 });213});246});214247215describe('Refungible: Fees', () => {248describe('Refungible: Fees', () => {tests/src/eth/reFungibleTokenAbi.jsondiffbeforeafterboth--- a/tests/src/eth/reFungibleTokenAbi.json
+++ b/tests/src/eth/reFungibleTokenAbi.json
@@ -104,6 +104,15 @@
},
{
"inputs": [
+ { "internalType": "uint256", "name": "amount", "type": "uint256" }
+ ],
+ "name": "repartition",
+ "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }
],
"name": "supportsInterface",