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 40 41 42 43 44 45 46 47 48 49 50 51 52 | 1x 1x 1x 17x 2x 15x 1x 14x 2x 12x | import { ContractSchema } from "../contractSchema";
import { Generator, ind } from "../generator";
import { Feature } from "../../types";
export class PatchFuncGen implements Generator {
gen(schema: ContractSchema): string {
if (schema.features.some((feature: Feature) => feature === Feature.PATCH)) {
return ind(4,`` +
`function mintPatch(address owner, PatchTarget memory target) external payable returns (uint256 tokenId) {\n` +
` if (msg.sender != _manager) {\n` +
` return IPatchworkProtocol(_manager).patch{value: msg.value}(owner, target.addr, target.tokenId, address(this));\n` +
` }\n` +
` // require inherited ownership\n` +
` if (IERC721(target.addr).ownerOf(target.tokenId) != owner) {\n` +
` revert IPatchworkProtocol.NotAuthorized(owner);\n` +
` }\n` +
` tokenId = _nextTokenId++;\n` +
` _storePatch(tokenId, target);\n` +
` _safeMint(owner, tokenId);\n` +
` _metadataStorage[tokenId] = new uint256[](${schema.slots()});\n` +
` return tokenId;\n` +
`}\n\n`);
}
if (schema.features.some((feature: Feature) => feature === Feature['1155PATCH'])) {
return ind(4,`` +
`function mintPatch(address owner, PatchTarget memory target) external payable returns (uint256 tokenId) {\n` +
` if (msg.sender != _manager) {\n` +
` return IPatchworkProtocol(_manager).patch1155{value: msg.value}(owner, target.addr, target.tokenId, target.account, address(this));\n` +
` }\n` +
` tokenId = _nextTokenId++;\n` +
` _storePatch(tokenId, target);\n` +
` _safeMint(owner, tokenId);\n` +
` _metadataStorage[tokenId] = new uint256[](${schema.slots()});\n` +
` return tokenId;\n` +
`}\n\n`);
}
if (schema.features.some((feature: Feature) => feature === Feature.ACCOUNTPATCH)) {
return ind(4,`` +
`function mintPatch(address owner, address target) external payable returns (uint256 tokenId) {\n` +
` if (msg.sender != _manager) {\n` +
` return IPatchworkProtocol(_manager).patchAccount{value: msg.value}(owner, target, address(this));\n` +
` }\n` +
` tokenId = _nextTokenId++;\n` +
` _storePatch(tokenId, target);\n` +
` _safeMint(owner, tokenId);\n` +
` _metadataStorage[tokenId] = new uint256[](${schema.slots()});\n` +
` return tokenId;\n` +
`}\n\n`);
}
return "";
}
} |