-
Notifications
You must be signed in to change notification settings - Fork 25
Refactor token ID handling in ERC20FixedDenomination and ERC404NullOw… #147
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -90,8 +90,7 @@ contract ERC20FixedDenomination is ERC404NullOwnerCappedUpgradeable { | |||||||||||||||||||||||||
| _transferERC20(from, to, units()); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Transfer the specific NFT using the proper function | ||||||||||||||||||||||||||
| uint256 id = ID_ENCODING_PREFIX + nftId; | ||||||||||||||||||||||||||
| _transferERC721(from, to, id); | ||||||||||||||||||||||||||
| _transferERC721(from, to, nftId); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // ============================================================= | ||||||||||||||||||||||||||
|
|
@@ -154,25 +153,14 @@ contract ERC20FixedDenomination is ERC404NullOwnerCappedUpgradeable { | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /// @notice Returns metadata URI for NFT tokens | ||||||||||||||||||||||||||
| /// @dev Returns a data URI with JSON metadata fetched from the main Ethscriptions contract | ||||||||||||||||||||||||||
| function tokenURI(uint256 id_) public view virtual override returns (string memory) { | ||||||||||||||||||||||||||
| // This will revert InvalidTokenId / NotFound on bad ids | ||||||||||||||||||||||||||
| ownerOf(id_); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| uint256 mintId = id_ & ~ID_ENCODING_PREFIX; | ||||||||||||||||||||||||||
| function tokenURI(uint256 mintId) public view virtual override returns (string memory) { | ||||||||||||||||||||||||||
| _validateTokenId(mintId); | ||||||||||||||||||||||||||
| ownerOf(mintId); // reverts on invalid / nonexistent | ||||||||||||||||||||||||||
|
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. Bug: Missing fallback for zero ethscriptionId in tokenURIThe |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Get the ethscriptionId for this mintId from the manager | ||||||||||||||||||||||||||
| ERC20FixedDenominationManager mgr = ERC20FixedDenominationManager(manager); | ||||||||||||||||||||||||||
| bytes32 ethscriptionId = mgr.getMintEthscriptionId(deployEthscriptionId, mintId); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| // If no ethscription is found, return default metadata | |
| if (ethscriptionId == bytes32(0)) { | |
| string memory json = string.concat( | |
| '{"name":"', name(), ' Token #', mintId.toString(), '"', | |
| ',"description":"Fixed denomination token for ', mintAmount().toString(), ' ', symbol(), ' tokens"', | |
| ',"ethscription_id":"0x0"', | |
| '}' | |
| ); | |
| return string.concat("data:application/json;base64,", Base64.encode(bytes(json))); | |
| } |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -69,16 +69,15 @@ abstract contract ERC404NullOwnerCappedUpgradeable is | |||
| /// keccak256(abi.encode(uint256(keccak256("ethscriptions.storage.ERC404NullOwnerCapped")) - 1)) & ~bytes32(uint256(0xff)) | ||||
| bytes32 private constant STORAGE_LOCATION = 0x8a0c9d8e5f7b3a2c1d4e6f8a9b7c5d3e2f1a4b6c8d9e7f5a3b2c1d4e6f8a9b00; | ||||
|
|
||||
| /// @dev Constant for token id encoding | ||||
| uint256 public constant ID_ENCODING_PREFIX = 1 << 255; | ||||
|
|
||||
| // ============================================================= | ||||
| // EVENTS | ||||
| // ============================================================= | ||||
|
|
||||
| // ERC20 Events are inherited from IERC20 (Transfer, Approval) | ||||
|
|
||||
| // ERC721 Events (using different names to avoid conflicts with ERC20) | ||||
| // event Transfer(address indexed from, address indexed to, uint256 value); | ||||
| event ERC20Transfer(address indexed from, address indexed to, uint256 value); | ||||
|
||||
| event ERC20Transfer(address indexed from, address indexed to, uint256 value); |
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.
The
_validateTokenIdcall on line 157 is redundant sinceownerOfon line 158 also calls_validateTokenIdinternally and will revert if the token doesn't exist. Remove the duplicate validation call.