-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Turn registration into NFT #76
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c2efb14
Turn registration into NFT
niklr 46fba08
Fix module exports
niklr 1bf8b61
Fix lint errors
niklr 6273167
Remove Utils.toPayable function
niklr 02968e1
Merge ConferenceTicket into AbstractConference contract
niklr 8cdcc78
Merge branch 'master' into bounty-nft
niklr 40674b9
Remove ConferenceTicket contract
niklr 077e57c
Merge branch 'bounty-nft' of https://github.com/niklr/kickback-contra…
niklr bca17be
Unit test nonexistent token
niklr 857681d
Pass deployerAddress instead of baseTokenUri when deploying a conference
niklr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module.exports = { | ||
mnemonic: 'mnemonic', | ||
infuraKey: 'infuraKey', | ||
maticKey: 'maticKey', | ||
etherscanApiKey: 'etherscanApiKey' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,12 @@ pragma solidity ^0.5.11; | |
|
||
import './GroupAdmin.sol'; | ||
import './Conference.sol'; | ||
import './Deployer.sol'; | ||
import { Utils } from './Utils.sol'; | ||
import 'openzeppelin-solidity/contracts/math/SafeMath.sol'; | ||
import 'openzeppelin-solidity/contracts/token/ERC721/ERC721.sol'; | ||
|
||
contract AbstractConference is Conference, GroupAdmin { | ||
contract AbstractConference is Conference, GroupAdmin, ERC721 { | ||
using SafeMath for uint256; | ||
|
||
string public name; | ||
|
@@ -24,6 +27,8 @@ contract AbstractConference is Conference, GroupAdmin { | |
uint256 public lastSent = 0; | ||
uint256 public withdrawn = 0; | ||
|
||
Deployer public deployer; | ||
|
||
mapping (address => Participant) public participants; | ||
mapping (uint256 => address) public participantsIndex; | ||
|
||
|
@@ -70,15 +75,17 @@ contract AbstractConference is Conference, GroupAdmin { | |
* @param _limitOfParticipants The number of participant. The default is set to 20. The number can be changed by the owner of the event. | ||
* @param _coolingPeriod The period participants should withdraw their deposit after the event ends. After the cooling period, the event owner can claim the remining deposits. | ||
* @param _owner The owner of the event | ||
* @param _clearFee the fee for _clearAndSend function in per-mille (e.g. _clearFee = 10 means 1% fees, _clearFee = 1 means 0.1% fees) | ||
* @param _clearFee the fee for _clearAndSend function in per-mille (e.g. _clearFee = 10 means 1% fees, _clearFee = 1 means 0.1% fees) | ||
* @param _deployerAddress The address of the Deployer contract. | ||
*/ | ||
constructor ( | ||
string memory _name, | ||
uint256 _deposit, | ||
uint256 _limitOfParticipants, | ||
uint256 _coolingPeriod, | ||
address payable _owner, | ||
uint256 _clearFee | ||
uint256 _clearFee, | ||
address _deployerAddress | ||
) public { | ||
require(_owner != address(0), 'owner address is required'); | ||
owner = _owner; | ||
|
@@ -87,6 +94,7 @@ contract AbstractConference is Conference, GroupAdmin { | |
limitOfParticipants = _limitOfParticipants; | ||
coolingPeriod = _coolingPeriod; | ||
clearFee = _clearFee; | ||
deployer = Deployer(_deployerAddress); | ||
} | ||
|
||
|
||
|
@@ -102,6 +110,8 @@ contract AbstractConference is Conference, GroupAdmin { | |
participantsIndex[registered] = msg.sender; | ||
participants[msg.sender] = Participant(registered, msg.sender, false); | ||
|
||
mint(msg.sender, registered); | ||
|
||
emit RegisterEvent(msg.sender, registered); | ||
} | ||
|
||
|
@@ -324,4 +334,45 @@ contract AbstractConference is Conference, GroupAdmin { | |
revert('tokenAddress must be impelmented in the child class'); | ||
} | ||
|
||
/* ERC721 implementation start */ | ||
|
||
function tokenURI(uint256 tokenId) public view returns (string memory) { | ||
return string(abi.encodePacked(deployer.baseTokenUri(), Utils.addr2str(address(this)), '/', _tokenURI(tokenId))); | ||
} | ||
|
||
/** | ||
* @dev Internal returns an URI for a given token ID. | ||
* Throws if the token ID does not exist. May return an empty string. | ||
* @param tokenId uint256 ID of the token to query | ||
*/ | ||
function _tokenURI(uint256 tokenId) internal view returns (string memory) { | ||
require(_exists(tokenId), 'ERC721Metadata: URI query for nonexistent token'); | ||
return Utils.uint2str(tokenId); | ||
} | ||
|
||
/** | ||
* @dev Mints a new token. | ||
* @param to The address that will own the minted token | ||
* @param tokenId uint256 ID of the token to be minted | ||
*/ | ||
function mint(address to, uint256 tokenId) internal { | ||
_mint(to, tokenId); | ||
} | ||
|
||
function transferFrom(address from, address to, uint256 tokenId) public onlyActive { | ||
require(!isRegistered(to), 'already registered'); | ||
super.transferFrom(from, to, tokenId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we use the |
||
|
||
Participant memory participant = participants[from]; | ||
participantsIndex[participant.index] = to; | ||
participants[from] = Participant(0, address(0), false); | ||
participants[to] = Participant(participant.index, address(uint160(to)), participant.paid); | ||
} | ||
|
||
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public { | ||
transferFrom(from, to, tokenId); | ||
require(super._checkOnERC721Received(from, to, tokenId, _data), 'ERC721: transfer to non ERC721Receiver implementer'); | ||
} | ||
|
||
/* ERC721 implementation end */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
pragma solidity ^0.5.11; | ||
|
||
library Utils { | ||
function uint2str(uint256 _i) | ||
internal | ||
pure | ||
returns (string memory _uintAsString) | ||
{ | ||
if (_i == 0) { | ||
return '0'; | ||
} | ||
uint256 j = _i; | ||
uint256 len; | ||
while (j != 0) { | ||
len++; | ||
j /= 10; | ||
} | ||
bytes memory bstr = new bytes(len); | ||
uint256 k = len - 1; | ||
while (_i != 0) { | ||
bstr[k--] = bytes1(uint8(48 + (_i % 10))); | ||
_i /= 10; | ||
} | ||
return string(bstr); | ||
} | ||
|
||
function addr2str(address _address) internal pure returns (string memory) { | ||
return bytes2str(abi.encodePacked(_address)); | ||
} | ||
|
||
function bytes2str(bytes memory _data) internal pure returns (string memory) { | ||
bytes memory alphabet = '0123456789abcdef'; | ||
|
||
bytes memory str = new bytes(2 + _data.length * 2); | ||
str[0] = '0'; | ||
str[1] = 'x'; | ||
for (uint256 i = 0; i < _data.length; i++) { | ||
str[2 + i * 2] = alphabet[uint256(uint8(_data[i] >> 4))]; | ||
str[3 + i * 2] = alphabet[uint256(uint8(_data[i] & 0x0f))]; | ||
} | ||
return string(str); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you rename
transferFrom
to_beforeTokenTransfer
you don't need to overridesafeTransferFrom(address from, address to, uint256 tokenId)
norsafeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.openzeppelin.com/contracts/4.x/api/token/erc721#ERC721-_beforeTokenTransfer-address-address-uint256-
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v2.5 does not have
_beforeTokenTransfer
according to https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC721/ERC721.solThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, is it because we still use the old version of the solidity? Ok, then let's leave it as is.