Skip to content

Commit 8959088

Browse files
authoredFeb 26, 2024
Custom errors, etc (#619)
* custom error for extensions * contract publisher * legacy contracts * custom error for CurrencyTransferLib * efficient hash function MerkleProof * Pack without forwarder * fix test * fix tests * fix btt tests * extension tests * extension tests * test pack * more btt * more tests * drop prebuilt tests * fix lint
1 parent effd208 commit 8959088

File tree

81 files changed

+1049
-741
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1049
-741
lines changed
 

‎contracts/extension/BatchMintMetadata.sol

+21-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ pragma solidity ^0.8.0;
1111
*/
1212

1313
contract BatchMintMetadata {
14+
/// @dev Invalid index for batch
15+
error BatchMintInvalidBatchId(uint256 index);
16+
17+
/// @dev Invalid token
18+
error BatchMintInvalidTokenId(uint256 tokenId);
19+
20+
/// @dev Metadata frozen
21+
error BatchMintMetadataFrozen(uint256 batchId);
22+
1423
/// @dev Largest tokenId of each batch of tokens with the same baseURI + 1 {ex: batchId 100 at position 0 includes tokens 0-99}
1524
uint256[] private batchIds;
1625

@@ -46,7 +55,7 @@ contract BatchMintMetadata {
4655
*/
4756
function getBatchIdAtIndex(uint256 _index) public view returns (uint256) {
4857
if (_index >= getBaseURICount()) {
49-
revert("Invalid index");
58+
revert BatchMintInvalidBatchId(_index);
5059
}
5160
return batchIds[_index];
5261
}
@@ -65,7 +74,7 @@ contract BatchMintMetadata {
6574
}
6675
}
6776

68-
revert("Invalid tokenId");
77+
revert BatchMintInvalidTokenId(_tokenId);
6978
}
7079

7180
/// @dev Returns the baseURI for a token. The intended metadata URI for the token is baseURI + tokenId.
@@ -78,7 +87,8 @@ contract BatchMintMetadata {
7887
return baseURI[indices[i]];
7988
}
8089
}
81-
revert("Invalid tokenId");
90+
91+
revert BatchMintInvalidTokenId(_tokenId);
8292
}
8393

8494
/// @dev returns the starting tokenId of a given batchId.
@@ -94,20 +104,25 @@ contract BatchMintMetadata {
94104
return 0;
95105
}
96106
}
97-
revert("Invalid batchId");
107+
108+
revert BatchMintInvalidBatchId(_batchID);
98109
}
99110

100111
/// @dev Sets the base URI for the batch of tokens with the given batchId.
101112
function _setBaseURI(uint256 _batchId, string memory _baseURI) internal {
102-
require(!batchFrozen[_batchId], "Batch frozen");
113+
if (batchFrozen[_batchId]) {
114+
revert BatchMintMetadataFrozen(_batchId);
115+
}
103116
baseURI[_batchId] = _baseURI;
104117
emit BatchMetadataUpdate(_getBatchStartId(_batchId), _batchId);
105118
}
106119

107120
/// @dev Freezes the base URI for the batch of tokens with the given batchId.
108121
function _freezeBaseURI(uint256 _batchId) internal {
109122
string memory baseURIForBatch = baseURI[_batchId];
110-
require(bytes(baseURIForBatch).length > 0, "Invalid batch");
123+
if (bytes(baseURIForBatch).length == 0) {
124+
revert BatchMintInvalidBatchId(_batchId);
125+
}
111126
batchFrozen[_batchId] = true;
112127
emit MetadataFrozen();
113128
}

‎contracts/extension/ContractMetadata.sol

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import "./interface/IContractMetadata.sol";
1313
*/
1414

1515
abstract contract ContractMetadata is IContractMetadata {
16+
/// @dev The sender is not authorized to perform the action
17+
error ContractMetadataUnauthorized();
18+
1619
/// @notice Returns the contract metadata URI.
1720
string public override contractURI;
1821

@@ -26,7 +29,7 @@ abstract contract ContractMetadata is IContractMetadata {
2629
*/
2730
function setContractURI(string memory _uri) external override {
2831
if (!_canSetContractURI()) {
29-
revert("Not authorized");
32+
revert ContractMetadataUnauthorized();
3033
}
3134

3235
_setupContractURI(_uri);

0 commit comments

Comments
 (0)