@patchworkdev/common
Version:
Patchwork Development Kit
55 lines (54 loc) • 2.99 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PatchFuncGen = void 0;
const generator_1 = require("../generator");
const types_1 = require("../../types");
class PatchFuncGen {
gen(schema) {
if (schema.features.some((feature) => feature === types_1.Feature.PATCH)) {
return (0, generator_1.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 === types_1.Feature['1155PATCH'])) {
return (0, generator_1.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 === types_1.Feature.ACCOUNTPATCH)) {
return (0, generator_1.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 "";
}
}
exports.PatchFuncGen = PatchFuncGen;