Skip to content

feat: initial implementation of ERC1046#933

Merged
shrugs merged 6 commits into
OpenZeppelin:masterfrom
shrugs:feat/erc-1046-proposal
Jun 17, 2018
Merged

feat: initial implementation of ERC1046#933
shrugs merged 6 commits into
OpenZeppelin:masterfrom
shrugs:feat/erc-1046-proposal

Conversation

@shrugs

@shrugs shrugs commented May 6, 2018

Copy link
Copy Markdown
Contributor

🚀 Description

This is the initial implementation of ERC1046, which adds (optional) tokenURI to ERC20 tokens to allow them to exist on-par with ERC721 tokens.

https://eips.ethereum.org/EIPS/eip-1046

  • 📘 I've reviewed the OpenZeppelin Contributor Guidelines
  • ✅ I've added tests where applicable to test my new functionality.
  • 📖 I've made sure that my contracts are well-documented.
  • 🎨 I've run the JS/Solidity linters and fixed any issues (npm run lint:all:fix).

* @dev TODO - update https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/token/ERC721/ERC721.sol#L17 when 1046 is finalized
*/
contract ERC20TokenMetadata is ERC20 {
function tokenURI() public view returns (string);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this interface is public here rather than external as in the draft.

Are the minor gas savings worth it? https://ethereum.stackexchange.com/questions/19380/external-vs-public-best-practices


function tokenURI() public view returns (string) {
// in the effort of minimum-effort compatibility,
// tokenURI MUST throw if not exists https://eips.ethereum.org/EIPS/eip-721

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we feel about this interpretation?

function ERC20WithMetadata(string _tokenURI)
public
{
tokenURI_ = _tokenURI;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using a state variable with explicit getter for extensibility

@tomasienrbc

Copy link
Copy Markdown

👍

@tomasienrbc tomasienrbc left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks right to me

@shrugs shrugs force-pushed the feat/erc-1046-proposal branch from b3b65d4 to 2e3ed3c Compare May 30, 2018 22:49
@shrugs shrugs force-pushed the feat/erc-1046-proposal branch from 2e3ed3c to eda22e5 Compare June 6, 2018 20:34
@shrugs shrugs force-pushed the feat/erc-1046-proposal branch from 36e088a to fcd5486 Compare June 15, 2018 19:18
@shrugs shrugs requested a review from frangio June 16, 2018 17:23

@frangio frangio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM save for the revert in tokenURI. 🙂


function tokenURI() external view returns (string) {
// in the effort of minimum-effort compatibility,
// tokenURI MUST throw if not exists https://eips.ethereum.org/EIPS/eip-721

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how this is about compatibility. ER721 "throws if _tokenId is not a valid NFT". There's no _tokenId argument here, but as I understand it there is an implicit token id which is the token address, which sounds like a "valid token" under any interpretation.

I guess an empty string can never be a valid URI though. If that is the reason though, IMO we should check this in the setter of tokenURI_ and not when returning it. Or not check it at all, because we're not going to validate that it's a valid URI anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right, this check doesn't really make sense. Will update

@shrugs shrugs force-pushed the feat/erc-1046-proposal branch from 59eb8bb to 4da5e11 Compare June 16, 2018 23:22
const invalidMetadataURI = '';

describe('ERC20WithMetadata', function () {
context('invalid metadata', function () {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last commit removed the need for testing for invalid metadata.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, that's what I get for letting travis do my testing for me 😅

this.token.tokenURI()
);
});
before(async function () {

@frangio frangio Jun 17, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1021. I'm fine with merging and fixing afterwards though because there is only one test here.

@shrugs shrugs merged commit f18c3bc into OpenZeppelin:master Jun 17, 2018
@shrugs shrugs deleted the feat/erc-1046-proposal branch June 17, 2018 23:21
nventuro pushed a commit to nventuro/openzeppelin-contracts that referenced this pull request Jun 18, 2018
* feat: initial implementation of ERC1046
@shrugs shrugs removed the review label Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants