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 53 | 1x 1x 1x 1x 17x 17x 4x 17x 1x 17x 17x 4x 4x 2x 2x 1x 1x 17x 17x 17x 2x 17x 1x 17x 2x 17x 1x 17x 4x 17x 8x 17x | import { ContractSchema } from "../contractSchema";
import { Generator, ind } from "../generator";
import { cleanAndCapitalizeFirstLetter } from "../utils";
import { Feature } from "../../types";
export class ContractStartGen implements Generator {
gen(schema: ContractSchema): string {
let inheritance = this.getBaseInheritance(schema.features);
if (schema.hasLiteRef()) {
inheritance.push("PatchworkLiteRef");
}
if (schema.features.some((feature: Feature) => feature === Feature.MINTABLE)) {
inheritance.push("IPatchworkMintable");
}
let out = `abstract contract ${cleanAndCapitalizeFirstLetter(schema.name)}Generated is ${inheritance.join(", ")} {\n`;
if (schema.hasLiteRef()) {
out += `\n`;
if (schema.liteRefArrayLength(0) == 0) {
out += ind(4, `error AlreadyLoaded();\nerror NotFound();\nerror StorageIntegrityError();\nerror UnsupportedMetadataId();\n`);
} else if (schema.liteRefArrayLength(0) == 1) {
out += ind(4, `error NoReferenceSlotsAvailable();\nerror TooManyReferences();\nerror NoReference();\nerror UnsupportedMetadataId();\n`);
} else {
out += ind(4, `error NoReferenceSlotsAvailable();\nerror TooManyReferences();\nerror NoReference();\nerror UnsupportedMetadataId();\nerror AlreadyHaveReferences();\n`);
}
}
return out;
}
getBaseInheritance(features: Feature[]): string[] {
let inheritance: string[] = [];
if (features.some((feature: Feature) => feature === Feature.PATCH)) {
inheritance.push(`PatchworkPatch`);
}
if (features.some((feature: Feature) => feature === Feature['1155PATCH'])) {
inheritance.push(`Patchwork1155Patch`);
}
if (features.some((feature: Feature) => feature === Feature.ACCOUNTPATCH)) {
inheritance.push(`PatchworkAccountPatch`);
}
if (features.some((feature: Feature) => feature === Feature.FRAGMENTMULTI)) {
inheritance.push(`PatchworkFragmentMulti`);
}
if (features.some((feature: Feature) => feature === Feature.FRAGMENTSINGLE)) {
inheritance.push(`PatchworkFragmentSingle`);
}
// If no specific feature is found, default to Patchwork721
if (inheritance.length === 0) {
inheritance.push(`Patchwork721`);
}
return inheritance;
}
} |