Skip to content

Commit

Permalink
updates contract to include fee login
Browse files Browse the repository at this point in the history
  • Loading branch information
victorrseloy committed May 27, 2019
1 parent d960cf4 commit 76f65b5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
10 changes: 8 additions & 2 deletions build/contracts/DeveryERC721Token.json
Original file line number Diff line number Diff line change
Expand Up @@ -33546,11 +33546,17 @@
"version": "0.4.24+commit.e67f0147.Emscripten.clang"
},
"networks": {
"1": {
"events": {},
"links": {},
"address": "0x032ef0359eb068d3dddd6e91021c02f397afce5a",
"transactionHash": "0xe587090839ddabeada37d07d34c2b3ff5e1ee2b620b2fbfed49bf433ba8d09a3"
},
"3": {
"events": {},
"links": {},
"address": "0x2230ee6c3807d79153F35654F256bFFAF1916c8A",
"transactionHash": "0xd7396f35bf8f58372e46d5f3b2ffc07afa06b62de6a252e0bd2a568d25fd2ccf"
"address": "0x3353c9a20fae5113b194169b0c24611665a46e2e",
"transactionHash": "0xfb23e035d99cb60fa512afddbee1deaa82ec39924c5e03482bf3ccd5586bc77d"
}
},
"schemaVersion": "2.0.1",
Expand Down
35 changes: 32 additions & 3 deletions contracts/DeveryERC721Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,15 @@ contract DeveryERC721Token is ERC721Enumerable,Admined {
mapping(address => uint) public totalAllowedProducts;
mapping(address => uint) public totalMintedProducts;
DeveryRegistry deveryRegistry;
ERC20Interface public token;

event TokenUpdated(address indexed oldToken, address indexed newToken);


function setToken(address _token) public onlyAdmin {
TokenUpdated(address(token), _token);
token = ERC20Interface(_token);
}

/**
* @dev modifier to enforce that only the brand that created a given product can change it
Expand Down Expand Up @@ -684,15 +693,35 @@ contract DeveryERC721Token is ERC721Enumerable,Admined {
}

/**
* @dev mint a new ERC721 token for a given product and assing it to the original product brand;
*/
* @dev mint a new ERC721 token for a given product and assing it to the original product brand;
*/
function claimProduct(address _productAddress,uint _quantity) external payable brandOwnerOnly(_productAddress) {
require(totalAllowedProducts[_productAddress] == 0 || totalAllowedProducts[_productAddress] >= totalMintedProducts[_productAddress] + _quantity);
totalMintedProducts[_productAddress]+=_quantity;
//********************************************************************charges the fee****************************************
address productBrandAddress;
address appAccountAddress;
address appFeeAccount;
address deveryFeeAccount;
uint appFee;
uint deveryFee;
(,productBrandAddress,,,,,) = deveryRegistry.products(_productAddress);
(,appAccountAddress,,) = deveryRegistry.brands(productBrandAddress);
(,,appFeeAccount,appFee,) = deveryRegistry.apps(appAccountAddress);
deveryFee = deveryRegistry.fee();
deveryFeeAccount = deveryRegistry.feeAccount();
if (appFee > 0) {
token.transferFrom(productBrandAddress, appFeeAccount, appFee*_quantity);
}
if (deveryFee > 0) {
token.transferFrom(productBrandAddress, deveryFeeAccount, deveryFee*_quantity);
}
//********************************************************************charges the fee****************************************
for(uint i = 0;i<_quantity;i++){
uint nextId = tokenIdToProduct.push(_productAddress) - 1;
_mint(msg.sender,nextId);
}

totalMintedProducts[_productAddress]+=_quantity;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devery/devery",
"version": "0.1.23",
"version": "0.1.24",
"description": "Build decentralised apps on the Devery Protocol using Javascript",
"main": "./dist/index.js",
"scripts": {
Expand Down

0 comments on commit 76f65b5

Please sign in to comment.