From da77d2bc53838e6c08cffc7ae17d7128e37b5aa7 Mon Sep 17 00:00:00 2001 From: James Brown Date: Tue, 28 Aug 2018 13:19:01 +1000 Subject: [PATCH 1/3] Add 'approve' functionality to ERC875 --- ERCTokenImplementation.sol | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/ERCTokenImplementation.sol b/ERCTokenImplementation.sol index fff4718..c3ee623 100644 --- a/ERCTokenImplementation.sol +++ b/ERCTokenImplementation.sol @@ -19,6 +19,8 @@ contract Token is ERC { uint totalTickets; mapping(address => uint256[]) inventory; + // Owner of account approves the transfer of specific indices by another account + mapping(address => mapping (address => uint256[])) allowed; uint16 ticketIndex = 0; //to track mapping in tickets uint expiryTimeStamp; address owner; // the address that calls selfdestruct() and takes fees @@ -31,6 +33,7 @@ contract Token is ERC event Transfer(address indexed _from, address indexed _to, uint256[] tokenIndices); event TransferFrom(address indexed _from, address indexed _to, uint _value); + event Approval(address indexed owner, address indexed _approved, uint indexed ticketCount); modifier adminOnly() { @@ -177,20 +180,46 @@ contract Token is ERC } } - function transferFrom(address _from, address _to, uint256[] tokenIndices) - adminOnly public + function transferFrom(address _from, address _to, uint256[] tokenIndices) public { bool isadmin = msg.sender == admin; for(uint i = 0; i < tokenIndices.length; i++) { require(inventory[_from][i] != 0 || isadmin); + require(allowed[_from][msg.sender][i] == tokenIndices[i] || isadmin); //pushes each element with ordering uint index = uint(tokenIndices[i]); inventory[_to].push(inventory[msg.sender][index]); inventory[_from][index] = 0; + delete allowed[_from][msg.sender][i]; } } + // Function can be used by external smart contract to ensure it is allowed to move NFTs + function checkAllowed(address owner, address proxy) public view returns (uint16[]) + { + return allowed[owner][proxy]; + } + + // This function approves specific NTFs to be available for use in an external contract + // See transferFromContract() above. + function approve(address _approved, uint256[] tokenIndices) public + { + // allow caller to cancel approval - each approval call resets previous approval + // putting 0 indices resets approval + delete allowed[msg.sender][_approved]; + + for(uint i = 0; i < tokenIndices.length; i++) + { + uint index = uint(tokenIndices[i]); + //check token ownership, abort function and revert changes if any problems + if(inventory[msg.sender][index] == 0) revert("No token at index"); + } + //Confirmed that msg.sender owns these tokens; can now allow external contract to move them + allowed[msg.sender][_approved] = ticketIndices; + emit Approval(msg.sender, _approved, ticketIndices.length); + } + function endContract() public { if(msg.sender == owner) From 5fd648c9dfe30a8ede60de9ddad51f95e2ec3622 Mon Sep 17 00:00:00 2001 From: James Brown Date: Tue, 28 Aug 2018 13:38:47 +1000 Subject: [PATCH 2/3] Update ERC875 to change ticket to token --- ERCTokenImplementation.sol | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ERCTokenImplementation.sol b/ERCTokenImplementation.sol index c3ee623..05363a5 100644 --- a/ERCTokenImplementation.sol +++ b/ERCTokenImplementation.sol @@ -17,11 +17,11 @@ contract ERC pragma solidity ^0.4.17; contract Token is ERC { - uint totalTickets; + uint totalTokenss; mapping(address => uint256[]) inventory; // Owner of account approves the transfer of specific indices by another account mapping(address => mapping (address => uint256[])) allowed; - uint16 ticketIndex = 0; //to track mapping in tickets + uint16 tokenIndex = 0; uint expiryTimeStamp; address owner; // the address that calls selfdestruct() and takes fees address admin; @@ -29,11 +29,11 @@ contract Token is ERC uint numOfTransfers = 0; string public name; string public symbol; - uint8 public constant decimals = 0; //no decimals as tickets cannot be split + uint8 public constant decimals = 0; //no decimals as tokens cannot be split event Transfer(address indexed _from, address indexed _to, uint256[] tokenIndices); event TransferFrom(address indexed _from, address indexed _to, uint _value); - event Approval(address indexed owner, address indexed _approved, uint indexed ticketCount); + event Approval(address indexed owner, address indexed _approved, uint indexed tokenCount); modifier adminOnly() { @@ -51,8 +51,8 @@ contract Token is ERC string eventSymbol, address adminAddr) public { - totalTickets = numberOfTokens.length; - //assign some tickets to event admin + totalTokenss = numberOfTokens.length; + //assign some tokens to event admin expiryTimeStamp = expiry; owner = msg.sender; admin = adminAddr; @@ -85,11 +85,11 @@ contract Token is ERC address seller = ecrecover(message, v, r, s); for(uint i = 0; i < tokenIndices.length; i++) - { // transfer each individual tickets in the ask order + { // transfer each individual tokenss in the ask order uint index = uint(tokenIndices[i]); - require((inventory[seller][index] > 0)); // 0 means ticket sold. + require((inventory[seller][index] > 0)); // 0 means token sold. inventory[msg.sender].push(inventory[seller][index]); - inventory[seller][index] = 0; // 0 means ticket sold. + inventory[seller][index] = 0; // 0 means token sold. } seller.transfer(msg.value); } @@ -216,8 +216,8 @@ contract Token is ERC if(inventory[msg.sender][index] == 0) revert("No token at index"); } //Confirmed that msg.sender owns these tokens; can now allow external contract to move them - allowed[msg.sender][_approved] = ticketIndices; - emit Approval(msg.sender, _approved, ticketIndices.length); + allowed[msg.sender][_approved] = tokenIndices; + emit Approval(msg.sender, _approved, tokenIndices.length); } function endContract() public From 6f14188f6512f7f2f6213b53aa2debdf222b3819 Mon Sep 17 00:00:00 2001 From: James Brown Date: Fri, 5 Oct 2018 14:51:24 +0800 Subject: [PATCH 3/3] Update ERCTokenImplementation.sol --- ERCTokenImplementation.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ERCTokenImplementation.sol b/ERCTokenImplementation.sol index 05363a5..6b450c3 100644 --- a/ERCTokenImplementation.sol +++ b/ERCTokenImplementation.sol @@ -17,7 +17,7 @@ contract ERC pragma solidity ^0.4.17; contract Token is ERC { - uint totalTokenss; + uint totalTokens; mapping(address => uint256[]) inventory; // Owner of account approves the transfer of specific indices by another account mapping(address => mapping (address => uint256[])) allowed; @@ -51,7 +51,7 @@ contract Token is ERC string eventSymbol, address adminAddr) public { - totalTokenss = numberOfTokens.length; + totalTokens = numberOfTokens.length; //assign some tokens to event admin expiryTimeStamp = expiry; owner = msg.sender;