Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 1x 1x 1x 17x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 16x | import { ContractSchema } from "../contractSchema";
import { Generator, ind } from "../generator";
import { cleanAndCapitalizeFirstLetter } from "../utils";
import { Feature } from "../../types";
export class MintFuncGen implements Generator {
gen(schema: ContractSchema): string {
if (schema.features.some((feature: Feature) => feature === Feature.MINTABLE)) {
let out = ``;
out += `function mint(address to, bytes calldata data) public payable returns (uint256 tokenId) {\n`;
out += ` if (msg.sender != _manager) {\n`;
out += ` return IPatchworkProtocol(_manager).mint{value: msg.value}(to, address(this), data);\n`;
out += ` }\n`;
out += ` return _mintSingle(to, data);\n`;
out += `}\n`;
out += `\n`;
out += `function mintBatch(address to, bytes calldata data, uint256 quantity) public payable returns (uint256[] memory tokenIds) {\n`;
out += ` if (msg.sender != _manager) {\n`;
out += ` return IPatchworkProtocol(_manager).mintBatch{value: msg.value}(to, address(this), data, quantity);\n`;
out += ` }\n`;
out += ` tokenIds = new uint256[](quantity);\n`;
out += ` for (uint256 i = 0; i < quantity; i++) {\n`;
out += ` tokenIds[i] = _mintSingle(to, data);\n`;
out += ` }\n`;
out += `}\n`;
out += `\n`;
out += `function _mintSingle(address to, bytes calldata /* data */) internal returns (uint256) {\n`;
out += ` uint256 tokenId = _nextTokenId;\n`;
out += ` _metadataStorage[tokenId] = new uint256[](${schema.slots()});\n`;
out += ` _nextTokenId++;\n`;
out += ` _safeMint(to, tokenId);\n`;
out += ` return tokenId;\n`;
out += `}\n`;
out += `\n`;
return ind(4, out);
}
return "";
}
} |