Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
.github
.vscode
dist
package-lock.json
package.json
README.md
tsconfig.json
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": false,
"printWidth": 80,
"tabWidth": 2,
"bracketSpacing": true
}
4 changes: 2 additions & 2 deletions bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function copyFiles(args: Args) {
copyBlockchainFeatures(
args.directory,
TEMPLATE_DIR_NAME,
blockchainFeatures
blockchainFeatures,
);
}
copyAppletHandlers(args.directory, TEMPLATE_DIR_NAME, appletHandlers);
Expand Down Expand Up @@ -73,7 +73,7 @@ function logWelcomeMessage() {
\\ /\\___ \\ / __ \\| |_> > |_> >
\\/\\_//____ > (____ / __/| __/
\\/ \\/|__| |__|
`)
`);
}

function logFinalMessage(args: Args) {
Expand Down
12 changes: 11 additions & 1 deletion bin/meow-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const cli: Result<Flags> = meow(
--binding, -b Include an onchain device registration and binding template
--erc20, -e Include an ERC20 token template
--erc721, -n Include an ERC721 token template
--sbt, -t Include a soul bound token template
--erc1155, -f Include an ERC1155 token template
--help, -h Display this message
--minimal, -m Create a minimal applet without any tests and utils
-y Skip prompts and use yes as the answer for all prompts
Expand Down Expand Up @@ -43,6 +45,14 @@ const cli: Result<Flags> = meow(
type: "boolean",
shortFlag: "n",
},
sbt: {
type: "boolean",
shortFlag: "t",
},
erc1155: {
type: "boolean",
shortFlag: "f",
},
minimal: {
type: "boolean",
shortFlag: "m",
Expand All @@ -56,7 +66,7 @@ const cli: Result<Flags> = meow(
shortFlag: "y",
},
},
}
},
);

export default cli;
2 changes: 1 addition & 1 deletion bin/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ${c.bold("npm start")}

export const blockchainInstructions = (args: Args) => `
${c.cyan(
"🔗 To get started with onchain functionallity, type the following commands:"
"🔗 To get started with onchain functionallity, type the following commands:",
)}
cd ${args.directory}/blockchain
touch .env ${c.dim("// and add your IoTeX Private Key to .env file")}
Expand Down
10 changes: 10 additions & 0 deletions bin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export type Flags = {
type: "boolean";
shortFlag: "n";
};
sbt: {
type: "boolean";
shortFlag: "t";
};
erc1155: {
type: "boolean";
shortFlag: "f";
};
minimal: {
type: "boolean";
shortFlag: "m";
Expand All @@ -34,6 +42,8 @@ export type Args = {
binding: boolean | undefined;
erc20: boolean | undefined;
erc721: boolean | undefined;
erc1155: boolean | undefined;
sbt: boolean | undefined;
simulator: boolean | undefined;
minimal: boolean | undefined;
yes: boolean | undefined;
Expand Down
30 changes: 18 additions & 12 deletions bin/utils/copy-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
export function copyTemplates(
projectPath: string,
templatePath: string,
subdirs: { [key: string]: string }
subdirs: { [key: string]: string },
) {
for (const [subdir, template] of Object.entries(subdirs)) {
const templateSubdirPath = path.join(__dirname, templatePath, template);
Expand All @@ -19,14 +19,14 @@ export function copyTemplates(
export function copyBlockchainFeatures(
projectPath: string,
templatePath: string,
blockchainFeatures: string[]
blockchainFeatures: string[],
) {
blockchainFeatures.forEach((feature) => {
const templateSubdirPath = path.join(
__dirname,
templatePath,
"extensions",
feature
feature,
);
const projectSubdirPath = path.join(projectPath, "blockchain");
copyBlockchainFeature(templateSubdirPath, projectSubdirPath);
Expand All @@ -38,15 +38,15 @@ export function copyBlockchainFeatures(
export function copyAppletHandlers(
projectPath: string,
templatePath: string,
appletHandlers: string[]
appletHandlers: string[],
) {
appletHandlers.forEach((handler) => {
const templateSubdirPath = path.join(
__dirname,
templatePath,
"extensions",
"applet",
handler
handler,
);

const projectSubdirPath = path.join(projectPath, "applet", "assembly");
Expand All @@ -59,7 +59,7 @@ export function copyAppletHandlers(

function copyBlockchainFeature(
templateSubdirPath: string,
projectSubdirPath: string
projectSubdirPath: string,
) {
const subdirs = ["contracts", "test", "tasks", "deploy"];

Expand All @@ -73,7 +73,7 @@ function copyBlockchainFeature(

function copyAppletHandler(
templateSubdirPath: string,
projectSubdirPath: string
projectSubdirPath: string,
) {
fs.copySync(templateSubdirPath, projectSubdirPath);
}
Expand All @@ -92,14 +92,20 @@ function addHandlerToIndex(projectSubdirPath: string, handler: string) {
}

function addFeatureTaskToIndex(projectSubdirPath: string, feature: string) {
const taskIndex = path.join(projectSubdirPath, "tasks", "index.js");
const taskIndex = path.join(projectSubdirPath, "tasks", "index.ts");
if (feature === "binding") {
fs.appendFileSync(taskIndex, `\nrimport "./binding";`);
}
if (feature === "sbt") {
fs.appendFileSync(taskIndex, `\nimport "./sbt";`);
}
if (feature === "erc20") {
fs.appendFileSync(taskIndex, `\nrequire("./erc20");`);
fs.appendFileSync(taskIndex, `\nimport "./erc20";`);
}
if (feature === "erc721") {
fs.appendFileSync(taskIndex, `\nrequire("./nft");`);
fs.appendFileSync(taskIndex, `\nimport "./nft";`);
}
if (feature === "binding") {
fs.appendFileSync(taskIndex, `\nrequire("./binding");`);
if (feature === "erc1155") {
fs.appendFileSync(taskIndex, `\nimport "./rewards";`);
}
}
8 changes: 7 additions & 1 deletion bin/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function extractSubdirsAndFeatures(args: Args): {
const appletPath = args.minimal ? path.join("light", "applet") : "applet";
subdirs.applet = appletPath;

if (args.binding || args.erc20 || args.erc721) {
if (args.binding || args.erc20 || args.erc721 || args.erc1155 || args.sbt) {
subdirs.blockchain = "blockchain";
addBlockchainFeatures(args, blockchainFeatures);
}
Expand Down Expand Up @@ -44,6 +44,12 @@ function addBlockchainFeatures(args: Args, blockchainFeatures: string[]) {
if (args.erc721) {
pushStringToArray(blockchainFeatures, "erc721");
}
if (args.erc1155) {
pushStringToArray(blockchainFeatures, "erc1155");
}
if (args.sbt) {
pushStringToArray(blockchainFeatures, "sbt");
}
}

function pushStringToArray(subdirs: string[], template: string) {
Expand Down
16 changes: 15 additions & 1 deletion bin/utils/normalize-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ function setFlagsValue(cli: Result<Flags>, value: boolean) {
cli.flags.binding = value;
cli.flags.erc20 = value;
cli.flags.erc721 = value;
cli.flags.erc1155 = value;
cli.flags.sbt = value;
cli.flags.simulator = value;
}

Expand All @@ -66,7 +68,9 @@ function isAnyOfTheFlagsTrue(cli: Result<Flags>) {
cli.flags.binding ||
cli.flags.erc20 ||
cli.flags.erc721 ||
cli.flags.simulator
cli.flags.simulator ||
cli.flags.sbt ||
cli.flags.erc1155
);
}

Expand All @@ -75,6 +79,8 @@ async function promtAllFlags(cli: Result<Flags>) {
cli.flags.erc721 = await promtConfirmation("erc721");
cli.flags.binding = await promtConfirmation("binding");
cli.flags.simulator = await promtConfirmation("simulator");
cli.flags.sbt = await promtConfirmation("sbt");
cli.flags.erc1155 = await promtConfirmation("erc1155");
}

async function promtConfirmation(tmpName: string) {
Expand All @@ -96,10 +102,14 @@ function buildMessage(tmpName: string) {
return `${emoji} include a device ${tmpName} template?`;
case "binding":
return `${emoji} include an onchain device registration and binding template?`;
case "sbt":
return `${emoji} include an ${tmpName} template?`;
case "erc20":
return `${emoji} include an ${tmpName} token template?`;
case "erc721":
return `${emoji} include an ${tmpName} token template?`;
case "erc1155":
return `${emoji} include an ${tmpName} token template?`;
default:
return "";
}
Expand All @@ -115,6 +125,10 @@ function selectEmoji(tmpName: string) {
return "🖼️ ";
case "simulator":
return "🤖";
case "sbt":
return "👤";
case "erc1155":
return "🎟️";
default:
return "";
}
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"devDependencies": {
"@types/fs-extra": "^11.0.1",
"@types/node": "^20.1.0",
"prettier": "^3.0.3",
"typescript": "^5.0.4"
}
}
2 changes: 1 addition & 1 deletion templates/applet/as-pect.asconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
},
"extends": "./asconfig.json",
"entries": ["./node_modules/@as-pect/assembly/assembly/index.ts"]
}
}
2 changes: 1 addition & 1 deletion templates/applet/asconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"options": {
"bindings": "esm"
}
}
}
22 changes: 10 additions & 12 deletions templates/applet/assembly/utils/__tests__/build-tx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,33 @@ import { buildTxData } from "../build-tx";
const TX_DATA =
"0x40c10f1900000000000000000000000036f075ef0437b5fe95a7d0293823f1e085416ddf0000000000000000000000000000000000000000000000003782dace9d900000";
const TX_DATA_2 =
"0x40c10f1900000000000000000000000036f075ef0437b5fe95a7d0293823f1e085416ddf000000000000000000000000000000000000000000000001dd6559bdb1700000"
"0x40c10f1900000000000000000000000036f075ef0437b5fe95a7d0293823f1e085416ddf000000000000000000000000000000000000000000000001dd6559bdb1700000";
const TX_DATA_3 =
"0x40c10f1900000000000000000000000036f075ef0437b5fe95a7d0293823f1e085416ddf0000000000000000000000000000000000000000000422e5a5eed78714500000"
"0x40c10f1900000000000000000000000036f075ef0437b5fe95a7d0293823f1e085416ddf0000000000000000000000000000000000000000000422e5a5eed78714500000";

const RECIPIENT_ADDR = "0x36f075ef0437b5fe95a7d0293823f1e085416ddf";
const FUNCTION_ADDR = "40c10f19";

test("tx data builder", () => {
it("should build a tx data string with amount as a string", () => {
expect<string>(buildTxData(FUNCTION_ADDR, RECIPIENT_ADDR, "4")).toBe(
TX_DATA
TX_DATA,
);
expect<string>(buildTxData(FUNCTION_ADDR, RECIPIENT_ADDR, "34.4")).toBe(
TX_DATA_2
TX_DATA_2,
);
expect<string>(buildTxData(FUNCTION_ADDR, RECIPIENT_ADDR, "5000500")).toBe(
TX_DATA_3
)
TX_DATA_3,
);
});
it("should build a tx data string with amount as a number", () => {
expect<string>(buildTxData(FUNCTION_ADDR, RECIPIENT_ADDR, 4)).toBe(
TX_DATA
);
expect<string>(buildTxData(FUNCTION_ADDR, RECIPIENT_ADDR, 4)).toBe(TX_DATA);
expect<string>(buildTxData(FUNCTION_ADDR, RECIPIENT_ADDR, 34.4)).toBe(
TX_DATA_2
TX_DATA_2,
);
expect<string>(buildTxData(FUNCTION_ADDR, RECIPIENT_ADDR, 5000500)).toBe(
TX_DATA_3
)
TX_DATA_3,
);
});
itThrows("should throw an error if amount is not a number", () => {
buildTxData(FUNCTION_ADDR, RECIPIENT_ADDR, "a");
Expand Down
Loading