From 10cd44aa51c8d2dc84507d86c5d9392c103c62bb Mon Sep 17 00:00:00 2001 From: Shunsuke Watanabe Date: Fri, 28 Apr 2023 14:04:11 +0900 Subject: [PATCH 1/5] reorganize folder structure as prep --- packages/cli/src/commands/contract/compile.ts | 2 +- packages/cli/src/commands/contract/test.ts | 3 +- packages/cli/src/commands/init/index.ts | 1 + packages/core/src/lib/command-utils.ts | 28 +++++-------------- packages/core/src/lib/consts.ts | 7 +---- .../ask/blank/test/index.test.ts.hbs | 4 +-- .../ask/erc20token/test/index.test.ts.hbs | 4 +-- .../ink/blank/test/index.test.ts.hbs | 4 +-- .../ink/flipper/test/index.test.ts.hbs | 4 +-- .../ink/psp22/test/index.test.ts.hbs | 4 +-- 10 files changed, 22 insertions(+), 39 deletions(-) diff --git a/packages/cli/src/commands/contract/compile.ts b/packages/cli/src/commands/contract/compile.ts index 124377f8..361b1350 100644 --- a/packages/cli/src/commands/contract/compile.ts +++ b/packages/cli/src/commands/contract/compile.ts @@ -154,7 +154,7 @@ export class CompileContract extends Command { await fs.remove(path.resolve(artifactsPath, `${contractName}.wasm`)); } - const typedContractDestPath = path.resolve("test", contractName, "typedContract"); + const typedContractDestPath = path.resolve("typedContracts", contractName); await spinner.runCommand( async () => await generateTypes(artifactsPath, contractName, typedContractDestPath), `Generating ${contractName} contract ts types`, diff --git a/packages/cli/src/commands/contract/test.ts b/packages/cli/src/commands/contract/test.ts index 25e47a77..e3145bb3 100644 --- a/packages/cli/src/commands/contract/test.ts +++ b/packages/cli/src/commands/contract/test.ts @@ -52,6 +52,7 @@ export class TestContract extends Command { const projectDir = path.resolve(); const testDir = path.resolve("test"); + const typedContractsDir = path.resolve("typedCotracts") for (const contractName of contractNames) { const contractInfo = config.contracts[contractName]; if (!contractInfo.build) { @@ -86,7 +87,7 @@ export class TestContract extends Command { mocha.addFile(test); }); - global.contractTypesPath = path.resolve(testDir, contractName, "typedContract"); + global.contractTypesPath = path.resolve(typedContractsDir, contractName); shell.cd(`${testDir}/${contractName}`); try { diff --git a/packages/cli/src/commands/init/index.ts b/packages/cli/src/commands/init/index.ts index 5e9b9336..56734f37 100644 --- a/packages/cli/src/commands/init/index.ts +++ b/packages/cli/src/commands/init/index.ts @@ -116,6 +116,7 @@ export class Init extends Command { } await ensureDir(path.resolve(projectPath, "artifacts", answers.contractName)); + await ensureDir(path.resolve(projectPath, "typedContracts", answers.contractName)); await ensureDir(path.resolve(projectPath, "test", answers.contractName)); await spinner.runCommand( diff --git a/packages/core/src/lib/command-utils.ts b/packages/core/src/lib/command-utils.ts index 52d5c348..d92d69d0 100644 --- a/packages/core/src/lib/command-utils.ts +++ b/packages/core/src/lib/command-utils.ts @@ -4,7 +4,7 @@ import path = require("node:path"); import { DEFAULT_NETWORK_URL, STORED_ARTIFACTS_PATH } from "./consts.js"; import { BuildData, SwankyConfig } from "../types"; import { Abi } from "@polkadot/api-contract"; -import { TEMP_ARTIFACTS_PATH, TEMP_TYPED_CONTRACT_PATH } from "./consts"; +import { TEMP_ARTIFACTS_PATH } from "./consts"; export async function commandStdoutOrNull(command: string): Promise { try { @@ -69,21 +69,6 @@ export async function storeArtifacts( `${buildData.artifactsPath}/${contractName}.json` ), ]); - // move both to test/contract_name/artifacts - const testArtifacts = path.resolve("test", contractName, "artifacts"); - await fs.ensureDir(testArtifacts); - await Promise.all([ - fs.move( - path.resolve(artifactsPath, `${contractName}.contract`), - `${testArtifacts}/${contractName}.contract`, - { overwrite: true } - ), - fs.move( - path.resolve(artifactsPath, `${contractName}.json`), - `${testArtifacts}/${contractName}.json`, - { overwrite: true } - ), - ]); } catch (e) { console.error(e); } @@ -134,7 +119,7 @@ export async function printContractInfo(metadataPath: string) { } } -export async function generateTypes(inputAbsPath: string, contractName: string, outputAbsPath: string) { +export async function generateTypes(inputPath: string, contractName: string, outputPath: string) { await fs.ensureDir(TEMP_ARTIFACTS_PATH); // Getting error if typechain-polkadot takes folder with unnecessary files/folders as inputs. @@ -150,15 +135,16 @@ export async function generateTypes(inputAbsPath: string, contractName: string, // Cannot generate typedContract directly to `outputAbsPath` // because relative path of typechain-polkadot input and output folder does matter for later use. await fs.copyFile( - path.resolve(inputAbsPath, `${contractName}.contract`), + path.resolve(inputPath, `${contractName}.contract`), path.resolve(TEMP_ARTIFACTS_PATH, `${contractName}.contract`), ), await fs.copyFile( - path.resolve(inputAbsPath, `${contractName}.json`), + path.resolve(inputPath, `${contractName}.json`), path.resolve(TEMP_ARTIFACTS_PATH, `${contractName}.json`), ) - await execa.command(`npx typechain-polkadot --in ${TEMP_ARTIFACTS_PATH} --out ${TEMP_TYPED_CONTRACT_PATH}`); + const outputRelativePath = path.relative(path.resolve(), path.resolve(outputPath)); + await execa.command(`npx typechain-polkadot --in ${TEMP_ARTIFACTS_PATH} --out ${outputRelativePath}`); - await fs.move(path.resolve(TEMP_TYPED_CONTRACT_PATH), outputAbsPath) + await fs.remove(TEMP_ARTIFACTS_PATH); } diff --git a/packages/core/src/lib/consts.ts b/packages/core/src/lib/consts.ts index d924deea..0ad51fc2 100644 --- a/packages/core/src/lib/consts.ts +++ b/packages/core/src/lib/consts.ts @@ -4,9 +4,4 @@ export const DEFAULT_SHIDEN_NETWORK_URL = "wss://rpc.shiden.astar.network"; export const DEFAULT_SHIBUYA_NETWORK_URL = "wss://rpc.shibuya.astar.network"; export const STORED_ARTIFACTS_PATH = "./artifacts"; - -// typechain-polkadot's output files are tightly coupled with input folder path. -// ./artifacts folder is used not only for storing historical artifacts, but also as typechain-polkadot's input folder. -// So, name duplication with `STORED_ARTIFACTS_PATH` is expected at least for now. -export const TEMP_ARTIFACTS_PATH = "./artifacts"; -export const TEMP_TYPED_CONTRACT_PATH = "./typedContract"; \ No newline at end of file +export const TEMP_ARTIFACTS_PATH = "./tmp_artifacts"; \ No newline at end of file diff --git a/packages/templates/src/templates/contracts/ask/blank/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ask/blank/test/index.test.ts.hbs index ffc279f9..2b5fb202 100644 --- a/packages/templates/src/templates/contracts/ask/blank/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ask/blank/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "./typedContract/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "./typedContract/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "./typedContracts/{{contract_name}}/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/contracts/ask/erc20token/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ask/erc20token/test/index.test.ts.hbs index 2615a834..31d33af7 100644 --- a/packages/templates/src/templates/contracts/ask/erc20token/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ask/erc20token/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "./typedContract/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "./typedContract/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "./typedContracts/{{contract_name}}/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/contracts/ink/blank/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ink/blank/test/index.test.ts.hbs index ffc279f9..2b5fb202 100644 --- a/packages/templates/src/templates/contracts/ink/blank/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ink/blank/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "./typedContract/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "./typedContract/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "./typedContracts/{{contract_name}}/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/contracts/ink/flipper/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ink/flipper/test/index.test.ts.hbs index 460a711b..783596de 100644 --- a/packages/templates/src/templates/contracts/ink/flipper/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ink/flipper/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "./typedContract/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "./typedContract/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "./typedContracts/{{contract_name}}/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/contracts/ink/psp22/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ink/psp22/test/index.test.ts.hbs index 1723d29a..8938fd3e 100644 --- a/packages/templates/src/templates/contracts/ink/psp22/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ink/psp22/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "./typedContract/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "./typedContract/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "./typedContracts/{{contract_name}}/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; From 3c5ce3b0a0f4beb76b1047ef2bca27cbb19d4958 Mon Sep 17 00:00:00 2001 From: Shunsuke Watanabe Date: Fri, 28 Apr 2023 14:17:22 +0900 Subject: [PATCH 2/5] fix --- packages/cli/src/commands/contract/compile.ts | 2 +- .../src/templates/contracts/ask/blank/test/index.test.ts.hbs | 4 ++-- .../templates/contracts/ask/erc20token/test/index.test.ts.hbs | 4 ++-- .../templates/contracts/ask/flipper/test/index.test.ts.hbs | 4 ++-- .../src/templates/contracts/ink/blank/test/index.test.ts.hbs | 4 ++-- .../templates/contracts/ink/flipper/test/index.test.ts.hbs | 4 ++-- .../src/templates/contracts/ink/psp22/test/index.test.ts.hbs | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/cli/src/commands/contract/compile.ts b/packages/cli/src/commands/contract/compile.ts index 361b1350..4886ed8d 100644 --- a/packages/cli/src/commands/contract/compile.ts +++ b/packages/cli/src/commands/contract/compile.ts @@ -163,7 +163,7 @@ export class CompileContract extends Command { const buildData = (await spinner.runCommand(async () => { return storeArtifacts(artifactsPath, contractInfo.name); - }, "Moving artifacts")) as BuildData; + }, "Storing artifacts")) as BuildData; contractInfo.build = buildData; } diff --git a/packages/templates/src/templates/contracts/ask/blank/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ask/blank/test/index.test.ts.hbs index 2b5fb202..385f5066 100644 --- a/packages/templates/src/templates/contracts/ask/blank/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ask/blank/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "./typedContracts/{{contract_name}}/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "../../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "../../typedContracts/{{contract_name}}/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/contracts/ask/erc20token/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ask/erc20token/test/index.test.ts.hbs index 31d33af7..568b35c0 100644 --- a/packages/templates/src/templates/contracts/ask/erc20token/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ask/erc20token/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "./typedContracts/{{contract_name}}/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "../../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "../../typedContracts/{{contract_name}}/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/contracts/ask/flipper/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ask/flipper/test/index.test.ts.hbs index ff21bf6b..6a0095cd 100644 --- a/packages/templates/src/templates/contracts/ask/flipper/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ask/flipper/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "./typedContract/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "./typedContract/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "../../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "../../typedContracts/{{contract_name}}/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/contracts/ink/blank/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ink/blank/test/index.test.ts.hbs index 2b5fb202..385f5066 100644 --- a/packages/templates/src/templates/contracts/ink/blank/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ink/blank/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "./typedContracts/{{contract_name}}/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "../../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "../../typedContracts/{{contract_name}}/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/contracts/ink/flipper/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ink/flipper/test/index.test.ts.hbs index 783596de..702a1033 100644 --- a/packages/templates/src/templates/contracts/ink/flipper/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ink/flipper/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "./typedContracts/{{contract_name}}/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "../../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "../../typedContracts/{{contract_name}}/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/contracts/ink/psp22/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ink/psp22/test/index.test.ts.hbs index 8938fd3e..5e018a64 100644 --- a/packages/templates/src/templates/contracts/ink/psp22/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ink/psp22/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "./typedContracts/{{contract_name}}/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "../../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "../../typedContracts/{{contract_name}}/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; From 393aafd21f3071dd6f1078b3863d61e548d4034d Mon Sep 17 00:00:00 2001 From: Shunsuke Watanabe Date: Mon, 1 May 2023 19:15:12 +0900 Subject: [PATCH 3/5] up --- packages/cli/src/commands/contract/test.ts | 2 +- packages/cli/src/commands/script/run.ts | 50 ++++++++ packages/core/src/lib/tasks.ts | 9 ++ .../src/templates/scripts/00_deploy.ts | 64 +++++++++++ .../flipper/build-extrinsic/flipper.ts | 43 +++++++ .../flipper/constructors/flipper.ts | 81 +++++++++++++ .../flipper/contract-info/flipper.ts | 2 + .../flipper/contracts/flipper.ts | 107 ++++++++++++++++++ .../typedContracts/flipper/data/flipper.json | 3 + .../flipper/event-data/flipper.json | 3 + .../flipper/event-types/flipper.ts | 3 + .../typedContracts/flipper/events/flipper.ts | 44 +++++++ .../flipper/mixed-methods/flipper.ts | 64 +++++++++++ .../typedContracts/flipper/query/flipper.ts | 54 +++++++++ .../typedContracts/flipper/shared/utils.ts | 38 +++++++ .../flipper/tx-sign-and-send/flipper.ts | 55 +++++++++ .../flipper/types-arguments/flipper.ts | 6 + .../flipper/types-returns/flipper.ts | 7 ++ 18 files changed, 634 insertions(+), 1 deletion(-) create mode 100644 packages/cli/src/commands/script/run.ts create mode 100644 packages/templates/src/templates/scripts/00_deploy.ts create mode 100644 packages/templates/src/templates/typedContracts/flipper/build-extrinsic/flipper.ts create mode 100644 packages/templates/src/templates/typedContracts/flipper/constructors/flipper.ts create mode 100644 packages/templates/src/templates/typedContracts/flipper/contract-info/flipper.ts create mode 100644 packages/templates/src/templates/typedContracts/flipper/contracts/flipper.ts create mode 100644 packages/templates/src/templates/typedContracts/flipper/data/flipper.json create mode 100644 packages/templates/src/templates/typedContracts/flipper/event-data/flipper.json create mode 100644 packages/templates/src/templates/typedContracts/flipper/event-types/flipper.ts create mode 100644 packages/templates/src/templates/typedContracts/flipper/events/flipper.ts create mode 100644 packages/templates/src/templates/typedContracts/flipper/mixed-methods/flipper.ts create mode 100644 packages/templates/src/templates/typedContracts/flipper/query/flipper.ts create mode 100644 packages/templates/src/templates/typedContracts/flipper/shared/utils.ts create mode 100644 packages/templates/src/templates/typedContracts/flipper/tx-sign-and-send/flipper.ts create mode 100644 packages/templates/src/templates/typedContracts/flipper/types-arguments/flipper.ts create mode 100644 packages/templates/src/templates/typedContracts/flipper/types-returns/flipper.ts diff --git a/packages/cli/src/commands/contract/test.ts b/packages/cli/src/commands/contract/test.ts index e3145bb3..5a1e485c 100644 --- a/packages/cli/src/commands/contract/test.ts +++ b/packages/cli/src/commands/contract/test.ts @@ -4,7 +4,7 @@ import path = require("node:path"); import { ensureSwankyProject, getSwankyConfig } from "@astar-network/swanky-core"; import globby from "globby"; import Mocha from "mocha"; -import { ensureDir, readdirSync } from "fs-extra"; +import { ensureDir } from "fs-extra"; import * as shell from "shelljs"; declare global { diff --git a/packages/cli/src/commands/script/run.ts b/packages/cli/src/commands/script/run.ts new file mode 100644 index 00000000..1dc80411 --- /dev/null +++ b/packages/cli/src/commands/script/run.ts @@ -0,0 +1,50 @@ +import { BaseCommand } from "../../lib/baseCommand"; +import { Args } from "@oclif/core"; +import { ensureSwankyProject } from "@astar-network/swanky-core"; +import { existsSync } from "fs-extra"; +import { fork } from "child_process"; +import path = require("node:path"); + +declare global { + var contractTypesPath: string; // eslint-disable-line no-var +} + +export class RunCommand extends BaseCommand { + static description = "Run a user-defined scripts"; + + static args = { + scriptName: Args.string({ + name: "scriptName", + required: true, + description: "Name of the script to run", + }), + }; + + async run(): Promise { + await ensureSwankyProject(); + + const { args } = await this.parse(RunCommand); + + const scriptPath = path.resolve("scripts", args.scriptName); + console.log(scriptPath) + + if (!existsSync(scriptPath)) { + throw new Error(`Script ${args.scriptName} does not exist`) + } + + await new Promise((resolve, reject) => { + const childProcess = fork(scriptPath, [], { + stdio: "inherit", + execArgv: ["--require", "ts-node/register/transpile-only"], + env: { ...process.env }, + }); + + childProcess.once("close", (status) => { + this.log(`Script ${scriptPath} exited with status code ${status ?? "null"}`); + + resolve(status as number); + }); + childProcess.once("error", reject); + }) + } +} diff --git a/packages/core/src/lib/tasks.ts b/packages/core/src/lib/tasks.ts index b511220d..8999c403 100644 --- a/packages/core/src/lib/tasks.ts +++ b/packages/core/src/lib/tasks.ts @@ -43,6 +43,15 @@ export async function copyTemplateFiles( path.resolve(templatesPath, "github"), path.resolve(projectPath, ".github") ); + await ensureDir(path.resolve(projectPath, "typedContracts")); + await copy( + path.resolve(templatesPath, "typedContracts", "flipper"), + path.resolve(projectPath, "typedContracts", "flipper") + ); + await copy( + path.resolve(templatesPath, "scripts"), + path.resolve(projectPath, "scripts") + ) await copyContractTemplateFiles(contractTemplatePath, contractName, projectPath); } diff --git a/packages/templates/src/templates/scripts/00_deploy.ts b/packages/templates/src/templates/scripts/00_deploy.ts new file mode 100644 index 00000000..77764437 --- /dev/null +++ b/packages/templates/src/templates/scripts/00_deploy.ts @@ -0,0 +1,64 @@ +import FlipperFactory from "../typedContracts/flipper/constructors/flipper"; +import Flipper from "../typedContracts/flipper/contracts/flipper"; +import { ApiPromise, WsProvider } from "@polkadot/api"; +import { getSwankyConfig, AccountData, ChainAccount, Encrypted, decrypt, resolveNetworkUrl } from "@astar-network/swanky-core"; +import inquirer from "inquirer"; +import chalk from "chalk"; + +// Change account alias to use +const accountName = "alice"; + +// Change network name to deploy to +const networkName = "local"; + +async function main() { + const config = await getSwankyConfig(); + + // Keyring settings + const accountData = config.accounts.find( + (account: AccountData) => account.alias === accountName + ); + if (!accountData) { + throw new Error("Provided account alias not found in swanky.config.json"); + } + + const mnemonic = accountData.isDev + ? (accountData.mnemonic as string) + : decrypt( + accountData.mnemonic as Encrypted, + ( + await inquirer.prompt([ + { + type: "password", + message: `Enter password for ${chalk.yellowBright(accountData.alias)}: `, + name: "password", + }, + ]) + ).password + ); + + const deployer = new ChainAccount(mnemonic).pair; + + // Network settings + const networkUrl = resolveNetworkUrl(config, networkName ?? ""); + const wsProvider = new WsProvider(networkUrl); + const api = await ApiPromise.create({ provider: wsProvider }); + + const flipperFactory = new FlipperFactory(api, deployer); + const initialState = true; + + const contract = new Flipper( + (await flipperFactory.new(initialState)).address, + deployer, + api + ); + + console.log(`Flipper with initial state \`true\` deployed to ${contract.address}`); + + await api.disconnect(); +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/packages/templates/src/templates/typedContracts/flipper/build-extrinsic/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/build-extrinsic/flipper.ts new file mode 100644 index 00000000..be21f1b3 --- /dev/null +++ b/packages/templates/src/templates/typedContracts/flipper/build-extrinsic/flipper.ts @@ -0,0 +1,43 @@ +/* This file is auto-generated */ + +import type { ContractPromise } from '@polkadot/api-contract'; +import type { GasLimit, GasLimitAndRequiredValue } from '@727-ventures/typechain-types'; +import { buildSubmittableExtrinsic } from '@727-ventures/typechain-types'; +import type * as ArgumentTypes from '../types-arguments/flipper'; +import type BN from 'bn.js'; +import type { ApiPromise } from '@polkadot/api'; + + + +export default class Methods { + private __nativeContract : ContractPromise; + private __apiPromise: ApiPromise; + + constructor( + nativeContract : ContractPromise, + apiPromise: ApiPromise, + ) { + this.__nativeContract = nativeContract; + this.__apiPromise = apiPromise; + } + /** + * flip + * + */ + "flip" ( + __options: GasLimit, + ){ + return buildSubmittableExtrinsic( this.__apiPromise, this.__nativeContract, "flip", [], __options); + } + + /** + * get + * + */ + "get" ( + __options: GasLimit, + ){ + return buildSubmittableExtrinsic( this.__apiPromise, this.__nativeContract, "get", [], __options); + } + +} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/constructors/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/constructors/flipper.ts new file mode 100644 index 00000000..097c0163 --- /dev/null +++ b/packages/templates/src/templates/typedContracts/flipper/constructors/flipper.ts @@ -0,0 +1,81 @@ +import {CodePromise} from "@polkadot/api-contract"; +import type {KeyringPair} from "@polkadot/keyring/types"; +import type {ApiPromise} from "@polkadot/api"; +import {_genValidGasLimitAndValue, _signAndSend, SignAndSendSuccessResponse} from "@727-ventures/typechain-types"; +import type {ConstructorOptions} from "@727-ventures/typechain-types"; +import type {WeightV2} from "@polkadot/types/interfaces"; +import type * as ArgumentTypes from '../types-arguments/flipper'; +import { ContractFile } from '../contract-info/flipper'; +import type BN from 'bn.js'; + +export default class Constructors { + readonly nativeAPI: ApiPromise; + readonly signer: KeyringPair; + + constructor( + nativeAPI: ApiPromise, + signer: KeyringPair, + ) { + this.nativeAPI = nativeAPI; + this.signer = signer; + } + + /** + * new + * + * @param { boolean } initValue, + */ + async "new" ( + initValue: boolean, + __options ? : ConstructorOptions, + ) { + const __contract = JSON.parse(ContractFile); + const code = new CodePromise(this.nativeAPI, __contract, __contract.source.wasm); + const gasLimit = (await _genValidGasLimitAndValue(this.nativeAPI, __options)).gasLimit as WeightV2; + + const storageDepositLimit = __options?.storageDepositLimit; + const tx = code.tx["new"]!({ gasLimit, storageDepositLimit, value: __options?.value }, initValue); + let response; + + try { + response = await _signAndSend(this.nativeAPI.registry, tx, this.signer, (event: any) => event); + } + catch (error) { + console.log(error); + } + + return { + result: response as SignAndSendSuccessResponse, + // @ts-ignore + address: (response as SignAndSendSuccessResponse)!.result!.contract.address.toString(), + }; + } + /** + * default + * + */ + async "default" ( + __options ? : ConstructorOptions, + ) { + const __contract = JSON.parse(ContractFile); + const code = new CodePromise(this.nativeAPI, __contract, __contract.source.wasm); + const gasLimit = (await _genValidGasLimitAndValue(this.nativeAPI, __options)).gasLimit as WeightV2; + + const storageDepositLimit = __options?.storageDepositLimit; + const tx = code.tx["default"]!({ gasLimit, storageDepositLimit, value: __options?.value }, ); + let response; + + try { + response = await _signAndSend(this.nativeAPI.registry, tx, this.signer, (event: any) => event); + } + catch (error) { + console.log(error); + } + + return { + result: response as SignAndSendSuccessResponse, + // @ts-ignore + address: (response as SignAndSendSuccessResponse)!.result!.contract.address.toString(), + }; + } +} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/contract-info/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/contract-info/flipper.ts new file mode 100644 index 00000000..8dd4d67d --- /dev/null +++ b/packages/templates/src/templates/typedContracts/flipper/contract-info/flipper.ts @@ -0,0 +1,2 @@ +export const ContractAbi = `{"source":{"hash":"0x224de7dbc0ee76dfb431fb59c30fe463d07cae59ce4585be27e9d9a4344bebbe","language":"ink! 4.2.0","compiler":"rustc 1.68.0-nightly","build_info":{"build_mode":"Debug","cargo_contract_version":"2.1.0","rust_toolchain":"nightly-aarch64-apple-darwin","wasm_opt_settings":{"keep_debug_symbols":false,"optimization_passes":"Z"}}},"contract":{"name":"flipper","version":"0.1.0","authors":["Shunsuke Watanabe"]},"spec":{"constructors":[{"args":[{"label":"init_value","type":{"displayName":["bool"],"type":0}}],"default":false,"docs":["Constructor that initializes the \`bool\` value to the given \`init_value\`."],"label":"new","payable":false,"returnType":{"displayName":["ink_primitives","ConstructorResult"],"type":1},"selector":"0x9bae9d5e"},{"args":[],"default":false,"docs":["Constructor that initializes the \`bool\` value to \`false\`.","","Constructors can delegate to other constructors."],"label":"default","payable":false,"returnType":{"displayName":["ink_primitives","ConstructorResult"],"type":1},"selector":"0xed4b9d1b"}],"docs":[],"environment":{"accountId":{"displayName":["AccountId"],"type":5},"balance":{"displayName":["Balance"],"type":8},"blockNumber":{"displayName":["BlockNumber"],"type":11},"chainExtension":{"displayName":["ChainExtension"],"type":12},"hash":{"displayName":["Hash"],"type":9},"maxEventTopics":4,"timestamp":{"displayName":["Timestamp"],"type":10}},"events":[],"lang_error":{"displayName":["ink","LangError"],"type":3},"messages":[{"args":[],"default":false,"docs":[" A message that can be called on instantiated contracts."," This one flips the value of the stored \`bool\` from \`true\`"," to \`false\` and vice versa.",""," To avoid typechain-polkadot [issue](https://github.com/727-Ventures/typechain-polkadot/issues/19)"," returning bool intentionally until it is resolved."],"label":"flip","mutates":true,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":4},"selector":"0x633aa551"},{"args":[],"default":false,"docs":[" Simply returns the current value of our \`bool\`."],"label":"get","mutates":false,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":4},"selector":"0x2f865bd9"}]},"storage":{"root":{"layout":{"struct":{"fields":[{"layout":{"leaf":{"key":"0x00000000","ty":0}},"name":"value"}],"name":"Flipper"}},"root_key":"0x00000000"}},"types":[{"id":0,"type":{"def":{"primitive":"bool"}}},{"id":1,"type":{"def":{"variant":{"variants":[{"fields":[{"type":2}],"index":0,"name":"Ok"},{"fields":[{"type":3}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":2},{"name":"E","type":3}],"path":["Result"]}},{"id":2,"type":{"def":{"tuple":[]}}},{"id":3,"type":{"def":{"variant":{"variants":[{"index":1,"name":"CouldNotReadInput"}]}},"path":["ink_primitives","LangError"]}},{"id":4,"type":{"def":{"variant":{"variants":[{"fields":[{"type":0}],"index":0,"name":"Ok"},{"fields":[{"type":3}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":0},{"name":"E","type":3}],"path":["Result"]}},{"id":5,"type":{"def":{"composite":{"fields":[{"type":6,"typeName":"[u8; 32]"}]}},"path":["ink_primitives","types","AccountId"]}},{"id":6,"type":{"def":{"array":{"len":32,"type":7}}}},{"id":7,"type":{"def":{"primitive":"u8"}}},{"id":8,"type":{"def":{"primitive":"u128"}}},{"id":9,"type":{"def":{"composite":{"fields":[{"type":6,"typeName":"[u8; 32]"}]}},"path":["ink_primitives","types","Hash"]}},{"id":10,"type":{"def":{"primitive":"u64"}}},{"id":11,"type":{"def":{"primitive":"u32"}}},{"id":12,"type":{"def":{"variant":{}},"path":["ink_env","types","NoChainExtension"]}}],"version":"4"}`; +export const ContractFile = `{"source":{"hash":"0x224de7dbc0ee76dfb431fb59c30fe463d07cae59ce4585be27e9d9a4344bebbe","language":"ink! 4.2.0","compiler":"rustc 1.68.0-nightly","wasm":"0x0061736d0100000001450c60027f7f017f60037f7f7f017f60027f7f0060037f7f7f0060017f0060000060047f7f7f7f017f60047f7f7f7f0060017f017f60017f017e60057f7f7f7f7f006000017f028a0107057365616c310b6765745f73746f726167650006057365616c301176616c75655f7472616e736665727265640002057365616c3005696e7075740002057365616c300d64656275675f6d6573736167650000057365616c320b7365745f73746f726167650006057365616c300b7365616c5f72657475726e000303656e76066d656d6f7279020102100338370102030b0803040002080102040505040302020505000101030003000702040502000400040900000a0607060000030a0100000000070404050170010f0f0608017f01418080040b0711020463616c6c0019066465706c6f79001a0914010041010b0e0d32273a29333738281d1f21392b0af741372b01017f037f2002200346047f200005200020036a200120036a2d00003a0000200341016a21030c010b0b0b2601017f230041106b22022400200220003a000f20012002410f6a41011008200241106a24000b5c01037f02402000280208220420026a220320044f04402003200028020422054b0d01200028020020046a200320046b20012002418c9a041035200020033602080f0b41b09804411c41ec99041020000b2003200541fc9904100b000b5502027f027e230041206b22002400200041106a22014200370300200042003703082000411036021c200041086a2000411c6a10012001290300210220002903082103200041206a2400410541042002200384501b0b1b002000418180014f044020004180800141e48104100b000b20000b7501017f230041306b220324002003200136020420032000360200200341146a41023602002003411c6a41023602002003412c6a410336020020034198900436021020034100360208200341033602242003200341206a3602182003200341046a36022820032003360220200341086a2002100e000b5201017f230041206b220124002001410c6a4101360200200141146a4101360200200141ac9704360208200141003602002001410136021c200120003602182001200141186a360210200141fc8204100e000b910101017f230041306b22022400200241146a41013602002002411c6a4101360200200241ac97043602102002410036020820024102360224200220002d0000410274220041e89c046a28020036022c2002200041fc9c046a280200360228200141046a28020021002002200241206a3602182002200241286a36022020012802002000200241086a1036200241306a24000b3c01017f230041206b22022400200241013a00182002200136021420022000360210200241c08b0436020c200241ac9804360208200241086a102a000b4001017f230041106b22012400200141003a000f20002001410f6a41011010047f4102054101410220012d000f22004101461b410020001b0b200141106a24000b6001047f230041106b22032400200028020422042002492205450440200341086a4100200220002802002206103b200120022003280208200328020c41d89c0410352003200220042006103b200020032903003702000b200341106a240020050b4701017f230041106b220224002002410036020c024020012002410c6a410410104504402000200228020c360001200041003a00000c010b200041013a00000b200241106a24000b3701017f230041106b22012400200142808001370204200141989d0436020020014100101820002001100741002001280208100a1017000b06004100103c0b06004101103c0bae0102057f017e230041306b2201240020014100360218200142808001370224200141989d043602202001410036021c200141206a22022001411c6a4104100820012001290320370310200141086a200141106a220320012802281016200128020c2104200128020820012903102106200141003602282001200637032020002002100720012001290320370310200120032001280228101620042001280200200128020410041a200141306a24000b4501017f2002200128020422034b044041cc9804412341ac9a041020000b2001200320026b36020420012001280200220120026a36020020002002360204200020013602000b0d00200041989d0420011005000ba10101027f20002802082202200028020422034904402000200241016a360208200028020020026a20013a00000f0b230041306b220024002000200336020420002002360200200041146a41023602002000411c6a41023602002000412c6a4103360200200041948b0436021020004100360208200041033602242000200041206a360218200020003602282000200041046a360220200041086a419c9a04100e000bf90401077f230041406a22002400024002400240024002400240100941ff0171410546044020004180800136022041989d04200041206a100220002802202201418180014f0d0120002001360224200041989d04360220200041106a200041206a101120002d00100d0520002800112201411876210220014110762104200141087621030240200141ff01712201412f470440200141e30047200341ff0171413a4772200441ff017141a50147720d0741012101200241d100460d010c070b200341ff017141860147200441ff017141db0047720d0641002101200241d901470d060b20004100360218200042808001370224200041989d043602202000410036023c200041206a22032000413c6a4104100820002000290320370310200041086a200041106a20002802281016200028020c210520002802082000280210210220002000280214220436022020052002200310002103200420002802202205490d02024002400240410c20032003410c4f1b0e0402000001000b2000412c6a4101360200200041346a4100360200200041908204360228200041ac980436023020004100360220200041206a41988204100e000b2000412c6a4101360200200041346a4100360200200041d483043602280c070b2000200536022420002002360220200041206a100f41ff017122024102460d042001450d032002452200101520001012000b200041043a0020200041206a100c000b20014180800141e88004100b000b2005200441e88004100b000b20024100471012000b2000412c6a4101360200200041346a4100360200200041b483043602280c010b1014000b200041ac980436023020004100360220200041206a41fc8204100e000b870201057f230041106b2200240002400240100941ff01712201410546044020004180800136020041989d042000100220002802002201418180014f0d0120002001360204200041989d04360200200041086a20001011024020002d00080d002000280009220141187621022001411076210320014108762104200141ff01712201419b01470440200141ed0147200441ff017141cb004772200341ff0171419d01472002411b4772720d01410010151013000b200441ff017141ae0147200341ff0171419d014772200241de0047720d002000100f41ff017122004102470d030b1014000b200020013a00002000100c000b20014180800141e88004100b000b200010151013000b5501017f230041206b2202240020022000360204200241186a200141106a290200370300200241106a200141086a29020037030020022001290200370308200241046a41dc8304200241086a101c200241206a24000bee0301057f230041406a22032400200341033a003820034280808080800437033020034100360228200341003602202003200136021c20032000360218027f0240024020022802002201450440200241146a28020022004103742105200041ffffffff017121072002280210210441002101034020012005460d02200228020820016a220041046a28020022060440200328021820002802002006200328021c28020c1101000d040b200141086a2101200428020020042802042106200441086a2104200341186a2006110000450d000b0c020b200228020422074105742100200741ffffff3f71210703402000450d01200228020820046a220541046a28020022060440200328021820052802002006200328021c28020c1101000d030b20032001411c6a2d00003a00382003200141146a290200370330200341106a200228021022052001410c6a103420032003290310370320200341086a2005200141046a103420032003290308370328200441086a2104200041206b210020012802002106200141206a2101200520064103746a2205280200200341186a2005280204110000450d000b0c010b2002410c6a28020020074b04402003280218200228020820074103746a22002802002000280204200328021c28020c1101000d010b41000c010b41010b200341406b24000b0f00200028020020012002101e41000b7701027f230041106b2204240020022000280200200028020822036b4b0440200441086a20002003200210222004280208200428020c1023200028020821030b200028020420036a2001200210061a2003200220036a22014b044041808404411c41908a041020000b20002001360208200441106a24000bdd0201037f230041106b220224000240024002400240200028020022002002410c6a027f0240024020014180014f04402002410036020c2001418010490d012001418080044f0d0220022001413f71418001723a000e20022001410c7641e001723a000c20022001410676413f71418001723a000d41030c030b200028020822032000280200460d030c040b20022001413f71418001723a000d2002200141067641c001723a000c41020c010b20022001413f71418001723a000f20022001410676413f71418001723a000e20022001410c76413f71418001723a000d2002200141127641077141f001723a000c41040b101e0c020b230041106b22042400200441086a20002003410110222004280208200428020c1023200441106a2400200028020821030b200028020420036a20013a0000200341016a2201450d01200020013602080b200241106a240041000f0b41808404411c41808a041020000b5001017f230041206b220324002003410c6a4101360200200341146a4100360200200341ac9804360210200341003602002003200136021c200320003602182003200341186a36020820032002100e000b4a01017f230041206b220224002000280200200241186a200141106a290200370300200241106a200141086a29020037030020022001290200370308200241086a101b200241206a24000bac0401067f230041206b2204240002402000027f4100200220036a22032002490d001a2001280200220220026a22062002490d0141082006200320032006491b2203200341084d1b2203417f73411f7621050240200204402004410136021820042002360214200420012802043602100c010b200441003602180b200441106a2107230041106b220624002004027f0240027f0240200504400240200341004e044020072802080d012006200310262006280204210220062802000c040b0c040b20072802042209450440200641086a20031026200628020c210220062802080c030b20032102410041909d04280200220520036a22082005490d021a2007280200210741949d042802002008490440200341ffff036a220841107640002202417f46200241ffff0371200247720d022002411074220520084180807c716a22022005490d0241949d042002360200200321024100200320056a22082005490d031a0b41909d04200836020041002005450d021a20052007200910060c020b200420033602040c020b2003210241000b2205044020042005360204200441086a200236020041000c020b20042003360204200441086a410136020041010c010b200441086a410036020041010b360200200641106a240020042802004504402004280204210220012003360200200120023602044181808080780c010b20042802042103200441086a2802000b36020420002003360200200441206a24000f0b41a08404412141d085041020000b1f00024020014181808080784704402001450d0120001024000b0f0b1025000b900101017f230041306b220124002001200036020c2001411c6a4102360200200141246a4101360200200141a88704360218200141003602102001410336022c2001200141286a36022020012001410c6a360228230041206b22002400200041003a0018200041b887043602142000200141106a360210200041c08b0436020c200041ac9804360208200041086a102a000b4601017f230041206b22002400200041146a41013602002000411c6a4100360200200041f48504360210200041ac980436021820004100360208200041086a41fc8504100e000ba10101027f027f410041909d04280200220320016a22022003490d001a024041949d042802002002490440200141ffff036a22022001490d012002411076220240002203417f46200341ffff0371200347720d012003411074220320024110746a22022003490d0141949d0420023602004100200120036a22022003490d021a0b41909d04200236020020030c010b41000b210220002001360204200020023602000bd806020b7f027e230041406a2203240020002802002202ad210d0240024002400240024002400240024020024190ce004f044041272100200d210e0240034020004104490d01200341196a20006a220241046b200e200e4290ce0080220d4290ce007e7da7220441ffff037141e4006e220641017441ff8c046a2f00003b0000200241026b2004200641e4006c6b41ffff037141017441ff8c046a2f00003b0000200041046b2100200e42ffc1d72f56200d210e0d000b200da7220241e3004d0d0320004102490d090c020b0c080b41272100200241e3004b0d002002410a490d040c020b200041026b2200200341196a6a200da72202200241ffff037141e4006e220241e4006c6b41ffff037141017441ff8c046a2f00003b00000b2002410a490d01200041024f0d000c050b200041026b2200200341196a6a200241017441ff8c046a2f00003b00000c020b2000450d030b200041016b2200200341196a6a200241306a3a00000b200041274b0d01412820006b412720006b22062001280218220541017122071b2102410021042005410471044041ac98042104200241ac980441ac9804102c20026a22024b0d010b412b418080c40020071b2107200341196a20006a2108024020012802084504404101210020012802002202200141046a280200220120072004102f0d01200220082006200128020c11010021000c010b024020022001410c6a28020022094904402005410871450d01200128021c210b2001413036021c20012d0020210c41012100200141013a002020012802002205200141046a280200220a20072004102f0d02200341106a2001200920026b4101103020032802142202418080c400460d022003280210200520082006200a28020c1101000d0220022005200a10310d022001200c3a00202001200b36021c410021000c020b4101210020012802002202200141046a280200220120072004102f0d01200220082006200128020c11010021000c010b41012100200341086a2001200920026b41011030200328020c2205418080c400460d00200328020820012802002202200141046a280200220120072004102f0d00200220082006200128020c1101000d00200520022001103121000b200341406b240020000f0b41a08a04411c41c48f041020000b41c08a044121419497041020000b0300010b0e0020002802001a03400c000b000bde0301037f230041406a220124002001200036020c2001410436022420012001410c6a3602204100210041042102024002400240024002400240024003402000200241f098046a2802006a22032000490d0120032100200241086a22024114470d000b41012100027f410020034110490d001a41002003200320036a22024b0d001a41002002450d001a20024100480d0220012002102620012802002200450d0320020b21032001410036021820012000360214200120033602102001410136023c20014102360234200141f09804360230200141003602282001200141206a360238200141106a200141286a101b0d0341989d052d000045044041999d052d00004101710d070b410c20012802142001280218100322002000410c4f1b4109470d040c050b41808404411c418497041020000b1025000b20021024000b230041406a220024002000413336020c200041c88704360208200041c484043602142000200141286a360210200041246a41023602002000412c6a41023602002000413c6a4106360200200041f48b0436022020004100360218200041023602342000200041306a3602282000200041106a3602382000200041086a360230200041186a41f48804100e000b41989d0541013a00000b41999d0541013a00000b000b0d0042e5b0b0dab9e2cd9daa7f0ba704010a7f230041106b2203240002400240200020016b22024110490d002002200141036a417c7120016b220049200041044b720d00200220006b22044104490d0020012000102d2206200020016a22082004417c716a2004410371102d6a220220064f0440200441027621050240024003402005450d0520032008200541c0012005200541c0014f1b41a89104102e200328020c21052003280208210820032003280200200328020422002000417c7141b89204102e200328020c210920032802082107024020032802042200450440410021010c010b2003280200220420004102746a210a4100210103402004220641106a2104410021000240034020012001200020066a280200220b417f73410776200b410676724181828408716a22014d0440200041046a22004110470d010c020b0b41a08a04411c41b094041020000b2004200a470d000b0b20022002200141087641ff81fc0771200141ff81fc07716a418180046c4110766a22024b0d012009450d000b200941027421004100210103402001200120072802002204417f734107762004410676724181828408716a22014b0d02200741046a2107200041046b22000d000b20022002200141087641ff81fc0771200141ff81fc07716a418180046c4110766a22024d0d0441a08a04411c41e094041020000b41a08a04411c41c094041020000b41a08a04411c41d094041020000b41a08a04411c41a094041020000b20012002102d21020b200341106a240020020b4601017f200145044041000f0b024003402002200220002c000041bf7f4a6a22024b0d01200041016a2100200141016b22010d000b20020f0b41a08a04411c418497041020000b3e00200220034f044020002003360204200020013602002000410c6a200220036b3602002000200120034102746a3602080f0b41cc9804412320041020000b39000240027f2002418080c40047044041012000200220012802101100000d011a0b20030d0141000b0f0b200020034100200128020c1101000bae0101027f20022104024002400240200320012d0020220320034103461b41ff0171220341016b0e03010001020b200241016a2203044020034101762104200241017621030c020b41a08a04411c41d48f041020000b41002104200221030b200341016a2102200128021c2103200128020421052001280200210102400340200241016b2202450d01200120032005280210110000450d000b418080c40021030b20002003360204200020043602000b3201017f027f0340200020002004460d011a200441016a2104200220012003280210110000450d000b200441016b0b2000490bea04010b7f230041106b2209240020002802042104200028020021030240024002402001280208220b410147200128021022024101477145044020024101470d02200320046a210c200141146a28020041016a210a410021022003210003402000200c460d03027f024020002c0000220641004e0440200041016a2105200641ff017121070c010b20002d0001413f7121052006411f7121072006415f4d044020074106742005722107200041026a21050c010b20002d0002413f7120054106747221082006417049044020082007410c74722107200041036a21050c010b200041046a210520022106418080c4002007411274418080f0007120002d0003413f71200841067472722207418080c400460d011a0b2002200520006b6a22062002490d0320070b2108200a41016b220a044020052100200621022008418080c400470d010c040b0b2008418080c400460d02024002402002450d00200220044f04404100210020022004460d010c020b41002100200220036a2c00004140480d010b200321000b2002200420001b21042000200320001b21030c020b200128020020032004200128020428020c11010021000c020b41a08a04411c41ec95041020000b200b450440200128020020032004200128020428020c11010021000c010b2001410c6a2802002200200320046a2003102c22024b0440200941086a2001200020026b4100103041012100200928020c2202418080c400460d0120092802082001280200220520032004200141046a280200220128020c1101000d01200220052001103121000c010b200128020020032004200128020428020c11010021000b200941106a240020000b140020002802002001200028020428020c1100000b5501027f0240027f02400240200228020041016b0e020103000b200241046a0c010b200120022802044103746a22012802044105470d0120012802000b2802002104410121030b20002004360204200020033602000b8501002001200346044020002002200110061a0f0b230041306b220024002000200336020420002001360200200041146a41033602002000411c6a41023602002000412c6a410336020020004188930436021020004100360208200041033602242000200041206a360218200020003602282000200041046a360220200041086a2004100e000b4901017f230041206b22032400200341186a200241106a290200370300200341106a200241086a2902003703002003200229020037030820002001200341086a101c200341206a24000b5801027f230041206b22022400200128020421032001280200200241186a2000280200220041106a290200370300200241106a200041086a290200370300200220002902003703082003200241086a101c200241206a24000b0b002000280200200110320b1800200128020041a497044105200128020428020c1101000b990301037f230041406a22022400200028020021034101210002402001280200220441d08b04410c200141046a280200220128020c1101000d0002402003280208220004402002200036020c200241346a4102360200410121002002413c6a4101360200200241e08b0436023020024100360228200241073602142002200241106a36023820022002410c6a36021020042001200241286a1036450d010c020b20032802002200200328020428020c11090042c8b5e0cfca86dbd3897f520d002002200036020c200241346a4102360200410121002002413c6a4101360200200241e08b0436023020024100360228200241083602142002200241106a36023820022002410c6a36021020042001200241286a10360d010b200328020c21002002411c6a4103360200200241246a41033602002002413c6a4103360200200241346a4103360200200241a88b043602182002410036021020022000410c6a3602382002200041086a3602302002410236022c200220003602282002200241286a36022020042001200241106a103621000b200241406b240020000b2c00200120024d04402000200220016b3602042000200120036a3602000f0b41d09b04412141bc9b041020000b3701017f230041106b22012400200142808001370204200141989d0436020020012000101820012000101820002001280208100a1017000b0b911d0200418080040bf1032f55736572732f7368756e73756b652f2e636172676f2f72656769737472792f7372632f6769746875622e636f6d2d316563633632393964623965633832332f696e6b5f656e762d342e322e302f7372632f656e67696e652f6f6e5f636861696e2f6578742e72730000010068000000e4000000140000002f55736572732f7368756e73756b652f2e636172676f2f72656769737472792f7372632f6769746875622e636f6d2d316563633632393964623965633832332f696e6b5f656e762d342e322e302f7372632f656e67696e652f6f6e5f636861696e2f696d706c732e72730000780001006a0000002401000023000000656e636f756e746572656420756e6578706563746564206572726f72f40001001c000000780001006a000000ed000000170000002f55736572732f7368756e73756b652f41737461722f7377616e6b792d636c692f7061636b616765732f636c692f73616d706c652f636f6e7472616374732f666c69707065722f7372632f6c69622e727300000028010100510000000600000005000000636f756c64206e6f742070726f7065726c79206465636f64652073746f7261676520656e747279008c0101002700000073746f7261676520656e7472792077617320656d70747900bc010100170000000900000004000000040000000a0000000b0000000c00418084040b8f19617474656d707420746f206164642077697468206f766572666c6f7700000000617474656d707420746f206d756c7469706c792077697468206f766572666c6f770000000900000000000000010000000d0000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f616c6c6f632f7372632f7261775f7665632e7273540201007c0000008a0100001c0000006361706163697479206f766572666c6f77000000e002010011000000540201007c00000006020000050000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f616c6c6f632f7372632f616c6c6f632e72736d656d6f727920616c6c6f636174696f6e206f6620206279746573206661696c656486030100150000009b0301000d0000000c0301007a0000009f0100000d0000006120666f726d617474696e6720747261697420696d706c656d656e746174696f6e2072657475726e656420616e206572726f722f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f616c6c6f632f7372632f666d742e727300fb0301007800000064020000200000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f616c6c6f632f7372632f7665632f6d6f642e7273840401007c000000350700000d000000840401007c000000a307000009000000617474656d707420746f206164642077697468206f766572666c6f7700000000617474656d707420746f2073756274726163742077697468206f766572666c6f7729696e646578206f7574206f6620626f756e64733a20746865206c656e20697320206275742074686520696e64657820697320620501002000000082050100120000003a0000002c0c010000000000a405010001000000a4050100010000000900000000000000010000000e00000070616e69636b65642061742027272c20dc05010001000000dd050100030000003a2000002c0c010000000000f0050100020000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f666d742f6e756d2e727330303031303230333034303530363037303830393130313131323133313431353136313731383139323032313232323332343235323632373238323933303331333233333334333533363337333833393430343134323433343434353436343734383439353035313532353335343535353635373538353936303631363236333634363536363637363836393730373137323733373437353736373737383739383038313832383338343835383638373838383939303931393239333934393539363937393839392f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f666d742f6d6f642e72730000470701007b0000005d0500000d000000470701007b000000ed05000038000000206f7574206f662072616e676520666f7220736c696365206f66206c656e6774682072616e676520656e6420696e6465782000000608010010000000e4070100220000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f736c6963652f697465722e72730000280801007e000000c4050000250000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f736c6963652f6d6f642e7273000000b80801007d000000fe0300002f000000736f7572636520736c696365206c656e67746820282920646f6573206e6f74206d617463682064657374696e6174696f6e20736c696365206c656e677468202848090100150000005d0901002b00000061050100010000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f7374722f636f756e742e7273000000a00901007d0000004700000015000000a00901007d0000005400000011000000a00901007d0000005a00000009000000a00901007d0000006400000011000000a00901007d000000660000000d0000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f7374722f697465722e7273700a01007c00000091000000110000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f697465722f7472616974732f616363756d2e7273000000fc0a0100850000009500000001000000040601007b000000cd010000050000004572726f720000002c0c0100000000007061696420616e20756e70617961626c65206d657373616765636f756c64206e6f74207265616420696e707574756e61626c6520746f206465636f646520696e707574656e636f756e746572656420756e6b6e6f776e2073656c6563746f72756e61626c6520746f206465636f64652073656c6563746f7200000000617474656d707420746f206164642077697468206f766572666c6f77617373657274696f6e206661696c65643a206d6964203c3d2073656c662e6c656e28290a2c0c0100000000006f0c0100010000002f55736572732f7368756e73756b652f2e636172676f2f72656769737472792f7372632f6769746875622e636f6d2d316563633632393964623965633832332f696e6b5f656e762d342e322e302f7372632f656e67696e652f6f6e5f636861696e2f6275666665722e727300800c01006b0000005a0000001c000000800c01006b0000005a00000009000000800c01006b0000005a00000031000000800c01006b0000006500000009000000800c01006b0000008d000000210000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f736c6963652f696e6465782e7273003c0d01007f000000820100004700000000000000617474656d707420746f2073756274726163742077697468206f766572666c6f772f55736572732f7368756e73756b652f2e636172676f2f72656769737472792f7372632f6769746875622e636f6d2d316563633632393964623965633832332f7061726974792d7363616c652d636f6465632d332e342e302f7372632f636f6465632e72730000f10d010065000000780000000e000000190000001c000000160000001400000019000000130c0100f70b0100e10b0100cd0b0100b40b01","build_info":{"build_mode":"Debug","cargo_contract_version":"2.1.0","rust_toolchain":"nightly-aarch64-apple-darwin","wasm_opt_settings":{"keep_debug_symbols":false,"optimization_passes":"Z"}}},"contract":{"name":"flipper","version":"0.1.0","authors":["Shunsuke Watanabe"]},"spec":{"constructors":[{"args":[{"label":"init_value","type":{"displayName":["bool"],"type":0}}],"default":false,"docs":["Constructor that initializes the \`bool\` value to the given \`init_value\`."],"label":"new","payable":false,"returnType":{"displayName":["ink_primitives","ConstructorResult"],"type":1},"selector":"0x9bae9d5e"},{"args":[],"default":false,"docs":["Constructor that initializes the \`bool\` value to \`false\`.","","Constructors can delegate to other constructors."],"label":"default","payable":false,"returnType":{"displayName":["ink_primitives","ConstructorResult"],"type":1},"selector":"0xed4b9d1b"}],"docs":[],"environment":{"accountId":{"displayName":["AccountId"],"type":5},"balance":{"displayName":["Balance"],"type":8},"blockNumber":{"displayName":["BlockNumber"],"type":11},"chainExtension":{"displayName":["ChainExtension"],"type":12},"hash":{"displayName":["Hash"],"type":9},"maxEventTopics":4,"timestamp":{"displayName":["Timestamp"],"type":10}},"events":[],"lang_error":{"displayName":["ink","LangError"],"type":3},"messages":[{"args":[],"default":false,"docs":[" A message that can be called on instantiated contracts."," This one flips the value of the stored \`bool\` from \`true\`"," to \`false\` and vice versa.",""," To avoid typechain-polkadot [issue](https://github.com/727-Ventures/typechain-polkadot/issues/19)"," returning bool intentionally until it is resolved."],"label":"flip","mutates":true,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":4},"selector":"0x633aa551"},{"args":[],"default":false,"docs":[" Simply returns the current value of our \`bool\`."],"label":"get","mutates":false,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":4},"selector":"0x2f865bd9"}]},"storage":{"root":{"layout":{"struct":{"fields":[{"layout":{"leaf":{"key":"0x00000000","ty":0}},"name":"value"}],"name":"Flipper"}},"root_key":"0x00000000"}},"types":[{"id":0,"type":{"def":{"primitive":"bool"}}},{"id":1,"type":{"def":{"variant":{"variants":[{"fields":[{"type":2}],"index":0,"name":"Ok"},{"fields":[{"type":3}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":2},{"name":"E","type":3}],"path":["Result"]}},{"id":2,"type":{"def":{"tuple":[]}}},{"id":3,"type":{"def":{"variant":{"variants":[{"index":1,"name":"CouldNotReadInput"}]}},"path":["ink_primitives","LangError"]}},{"id":4,"type":{"def":{"variant":{"variants":[{"fields":[{"type":0}],"index":0,"name":"Ok"},{"fields":[{"type":3}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":0},{"name":"E","type":3}],"path":["Result"]}},{"id":5,"type":{"def":{"composite":{"fields":[{"type":6,"typeName":"[u8; 32]"}]}},"path":["ink_primitives","types","AccountId"]}},{"id":6,"type":{"def":{"array":{"len":32,"type":7}}}},{"id":7,"type":{"def":{"primitive":"u8"}}},{"id":8,"type":{"def":{"primitive":"u128"}}},{"id":9,"type":{"def":{"composite":{"fields":[{"type":6,"typeName":"[u8; 32]"}]}},"path":["ink_primitives","types","Hash"]}},{"id":10,"type":{"def":{"primitive":"u64"}}},{"id":11,"type":{"def":{"primitive":"u32"}}},{"id":12,"type":{"def":{"variant":{}},"path":["ink_env","types","NoChainExtension"]}}],"version":"4"}`; \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/contracts/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/contracts/flipper.ts new file mode 100644 index 00000000..7fff052e --- /dev/null +++ b/packages/templates/src/templates/typedContracts/flipper/contracts/flipper.ts @@ -0,0 +1,107 @@ +/* This file is auto-generated */ + +import type { ApiPromise } from '@polkadot/api'; +import { Abi } from '@polkadot/api-contract'; +import type { KeyringPair } from '@polkadot/keyring/types'; +import { ContractPromise } from '@polkadot/api-contract'; +import { ContractAbi } from '../contract-info/flipper'; +import QueryMethods from '../query/flipper'; +import BuildExtrinsicMethods from '../build-extrinsic/flipper'; +import TxSignAndSendMethods from '../tx-sign-and-send/flipper'; +import MixedMethods from '../mixed-methods/flipper'; +import EventsClass from '../events/flipper'; + + +export default class Contract { + readonly query : QueryMethods; + readonly buildExtrinsic : BuildExtrinsicMethods; + readonly tx : TxSignAndSendMethods; + readonly methods : MixedMethods; + readonly events: EventsClass; + + readonly address : string; + readonly signer : KeyringPair; + + private nativeContract : ContractPromise; + private nativeAPI : ApiPromise; + private contractAbi: Abi; + + /** + * @constructor + + * @param address - The address of the contract. + * @param signer - The signer to use for signing transactions. + * @param nativeAPI - The API instance to use for queries. + */ + constructor( + address : string, + signer : KeyringPair, + nativeAPI : ApiPromise, + ) { + this.address = address; + this.nativeContract = new ContractPromise(nativeAPI, ContractAbi, address); + this.nativeAPI = nativeAPI; + this.signer = signer; + this.contractAbi = new Abi(ContractAbi); + + this.query = new QueryMethods(this.nativeContract, this.nativeAPI, signer.address); + this.buildExtrinsic = new BuildExtrinsicMethods(this.nativeContract, this.nativeAPI); + this.tx = new TxSignAndSendMethods(nativeAPI, this.nativeContract, signer); + this.methods = new MixedMethods(nativeAPI, this.nativeContract, signer); + this.events = new EventsClass(this.nativeContract, nativeAPI); + } + + /** + * name + * + * @returns The name of the contract. + */ + get name() : string { + return this.nativeContract.abi.info.contract.name.toString(); + } + + /** + * abi + * + * @returns The abi of the contract. + */ + get abi() : Abi { + return this.contractAbi; + } + + /** + * withSigner + * + * @param signer - The signer to use for signing transactions. + * @returns New instance of the contract class with new signer. + * @example + * ```typescript + * const contract = new Contract(address, signerAlice, api); + * await contract.mint(signerBob.address, 100); + * await contract.withSigner(signerBob).transfer(signerAlice.address, 100); + * ``` + */ + withSigner(signer : KeyringPair) : Contract { + return new Contract(this.address, signer, this.nativeAPI); + } + + /** + * withAddress + * + * @param address - The address of the contract. + * @returns New instance of the contract class to interact with new contract. + */ + withAddress(address : string) : Contract { + return new Contract(address, this.signer, this.nativeAPI); + } + + /** + * withAPI + * + * @param api - The API instance to use for queries. + * @returns New instance of the contract class to interact with new API. + */ + withAPI(api : ApiPromise) : Contract { + return new Contract(this.address, this.signer, api); + } +} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/data/flipper.json b/packages/templates/src/templates/typedContracts/flipper/data/flipper.json new file mode 100644 index 00000000..0c0145fe --- /dev/null +++ b/packages/templates/src/templates/typedContracts/flipper/data/flipper.json @@ -0,0 +1,3 @@ +{ +"0": {"name":"boolean","isResult":false,"isPrimitive":true,"isConvertable":false},"2": {"name":"null","isResult":false,"isPrimitive":true,"isConvertable":false},"3": {"name":"LangError","body":{"CouldNotReadInput":null},"isResult":false,"isPrimitive":false,"isConvertable":false},"4": {"name":"Result void, + filter : (eventName: string) => boolean = () => true + ) { + // @ts-ignore + return this.__api.query.system.events((events) => { + events.forEach((record: any) => { + const { event } = record; + + if (event.method == 'ContractEmitted') { + const [address, data] = record.event.data; + + if (address.toString() === this.__nativeContract.address.toString()) { + const {args, event} = this.__nativeContract.abi.decodeEvent(data); + + if (filter(event.identifier.toString())) + callback(args, event); + } + } + }); + }); + } + +} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/mixed-methods/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/mixed-methods/flipper.ts new file mode 100644 index 00000000..9f58fa03 --- /dev/null +++ b/packages/templates/src/templates/typedContracts/flipper/mixed-methods/flipper.ts @@ -0,0 +1,64 @@ +/* This file is auto-generated */ + +import type { ContractPromise } from '@polkadot/api-contract'; +import type { ApiPromise } from '@polkadot/api'; +import type { KeyringPair } from '@polkadot/keyring/types'; +import type { GasLimit, GasLimitAndRequiredValue, Result } from '@727-ventures/typechain-types'; +import type { QueryReturnType } from '@727-ventures/typechain-types'; +import { queryOkJSON, queryJSON, handleReturnType } from '@727-ventures/typechain-types'; +import { txSignAndSend } from '@727-ventures/typechain-types'; +import type * as ArgumentTypes from '../types-arguments/flipper'; +import type * as ReturnTypes from '../types-returns/flipper'; +import type BN from 'bn.js'; +//@ts-ignore +import {ReturnNumber} from '@727-ventures/typechain-types'; +import {getTypeDescription} from './../shared/utils'; +// @ts-ignore +import type {EventRecord} from "@polkadot/api/submittable"; +import {decodeEvents} from "../shared/utils"; +import DATA_TYPE_DESCRIPTIONS from '../data/flipper.json'; +import EVENT_DATA_TYPE_DESCRIPTIONS from '../event-data/flipper.json'; + + +export default class Methods { + private __nativeContract : ContractPromise; + private __keyringPair : KeyringPair; + private __callerAddress : string; + private __apiPromise: ApiPromise; + + constructor( + apiPromise : ApiPromise, + nativeContract : ContractPromise, + keyringPair : KeyringPair, + ) { + this.__apiPromise = apiPromise; + this.__nativeContract = nativeContract; + this.__keyringPair = keyringPair; + this.__callerAddress = keyringPair.address; + } + + /** + * flip + * + * @returns { void } + */ + "flip" ( + __options: GasLimit, + ){ + return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "flip", (events: EventRecord) => { + return decodeEvents(events, this.__nativeContract, EVENT_DATA_TYPE_DESCRIPTIONS); + }, [], __options); + } + + /** + * get + * + * @returns { Result } + */ + "get" ( + __options: GasLimit, + ): Promise< QueryReturnType< Result > >{ + return queryOkJSON( this.__apiPromise, this.__nativeContract, this.__callerAddress, "get", [], __options, (result) => { return handleReturnType(result, getTypeDescription(4, DATA_TYPE_DESCRIPTIONS)); }); + } + +} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/query/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/query/flipper.ts new file mode 100644 index 00000000..f287e008 --- /dev/null +++ b/packages/templates/src/templates/typedContracts/flipper/query/flipper.ts @@ -0,0 +1,54 @@ +/* This file is auto-generated */ + +import type { ContractPromise } from '@polkadot/api-contract'; +import type { ApiPromise } from '@polkadot/api'; +import type { GasLimit, GasLimitAndRequiredValue, Result } from '@727-ventures/typechain-types'; +import type { QueryReturnType } from '@727-ventures/typechain-types'; +import { queryJSON, queryOkJSON, handleReturnType } from '@727-ventures/typechain-types'; +import type * as ArgumentTypes from '../types-arguments/flipper'; +import type * as ReturnTypes from '../types-returns/flipper'; +import type BN from 'bn.js'; +//@ts-ignore +import {ReturnNumber} from '@727-ventures/typechain-types'; +import {getTypeDescription} from './../shared/utils'; +import DATA_TYPE_DESCRIPTIONS from '../data/flipper.json'; + + +export default class Methods { + private __nativeContract : ContractPromise; + private __apiPromise: ApiPromise; + private __callerAddress : string; + + constructor( + nativeContract : ContractPromise, + nativeApi : ApiPromise, + callerAddress : string, + ) { + this.__nativeContract = nativeContract; + this.__callerAddress = callerAddress; + this.__apiPromise = nativeApi; + } + + /** + * flip + * + * @returns { Result } + */ + "flip" ( + __options ? : GasLimit, + ): Promise< QueryReturnType< Result > >{ + return queryOkJSON( this.__apiPromise, this.__nativeContract, this.__callerAddress, "flip", [], __options , (result) => { return handleReturnType(result, getTypeDescription(4, DATA_TYPE_DESCRIPTIONS)); }); + } + + /** + * get + * + * @returns { Result } + */ + "get" ( + __options ? : GasLimit, + ): Promise< QueryReturnType< Result > >{ + return queryOkJSON( this.__apiPromise, this.__nativeContract, this.__callerAddress, "get", [], __options , (result) => { return handleReturnType(result, getTypeDescription(4, DATA_TYPE_DESCRIPTIONS)); }); + } + +} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/shared/utils.ts b/packages/templates/src/templates/typedContracts/flipper/shared/utils.ts new file mode 100644 index 00000000..395aa488 --- /dev/null +++ b/packages/templates/src/templates/typedContracts/flipper/shared/utils.ts @@ -0,0 +1,38 @@ +import fs from "fs"; +import type {ContractPromise} from "@polkadot/api-contract"; +import {handleEventReturn} from "@727-ventures/typechain-types"; + +export function getTypeDescription(id: number | string, types: any): any { + return types[id]; +} + +export function getEventTypeDescription(name: string, types: any): any { + return types[name]; +} + +export function decodeEvents(events: any[], contract: ContractPromise, types: any): any[] { + return events.filter((record: any) => { + const { event } = record; + + const [address, data] = record.event.data; + + return event.method == 'ContractEmitted' && address.toString() === contract.address.toString(); + }).map((record: any) => { + const [address, data] = record.event.data; + + const {args, event} = contract.abi.decodeEvent(data); + + const _event: Record < string, any > = {}; + + for (let i = 0; i < args.length; i++) { + _event[event.args[i]!.name] = args[i]!.toJSON(); + } + + handleEventReturn(_event, getEventTypeDescription(event.identifier.toString(), types)); + + return { + name: event.identifier.toString(), + args: _event, + }; + }); +} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/tx-sign-and-send/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/tx-sign-and-send/flipper.ts new file mode 100644 index 00000000..bbbdf401 --- /dev/null +++ b/packages/templates/src/templates/typedContracts/flipper/tx-sign-and-send/flipper.ts @@ -0,0 +1,55 @@ +/* This file is auto-generated */ + +import type { ContractPromise } from '@polkadot/api-contract'; +import type { KeyringPair } from '@polkadot/keyring/types'; +import type { ApiPromise } from '@polkadot/api'; +import type { GasLimit, GasLimitAndRequiredValue, Result } from '@727-ventures/typechain-types'; +import { txSignAndSend } from '@727-ventures/typechain-types'; +import type * as ArgumentTypes from '../types-arguments/flipper'; +import type BN from 'bn.js'; +// @ts-ignore +import type {EventRecord} from "@polkadot/api/submittable"; +import {decodeEvents} from "../shared/utils"; +import EVENT_DATA_TYPE_DESCRIPTIONS from '../event-data/flipper.json'; + + +export default class Methods { + private __nativeContract : ContractPromise; + private __keyringPair : KeyringPair; + private __apiPromise: ApiPromise; + + constructor( + apiPromise: ApiPromise, + nativeContract : ContractPromise, + keyringPair : KeyringPair, + ) { + this.__apiPromise = apiPromise; + this.__nativeContract = nativeContract; + this.__keyringPair = keyringPair; + } + + /** + * flip + * + */ + "flip" ( + __options ? : GasLimit, + ){ + return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "flip", (events: EventRecord) => { + return decodeEvents(events, this.__nativeContract, EVENT_DATA_TYPE_DESCRIPTIONS); + }, [], __options); + } + + /** + * get + * + */ + "get" ( + __options ? : GasLimit, + ){ + return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "get", (events: EventRecord) => { + return decodeEvents(events, this.__nativeContract, EVENT_DATA_TYPE_DESCRIPTIONS); + }, [], __options); + } + +} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/types-arguments/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/types-arguments/flipper.ts new file mode 100644 index 00000000..87c5918a --- /dev/null +++ b/packages/templates/src/templates/typedContracts/flipper/types-arguments/flipper.ts @@ -0,0 +1,6 @@ +import type BN from 'bn.js'; + +export enum LangError { + couldNotReadInput = 'CouldNotReadInput' +} + diff --git a/packages/templates/src/templates/typedContracts/flipper/types-returns/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/types-returns/flipper.ts new file mode 100644 index 00000000..0791057e --- /dev/null +++ b/packages/templates/src/templates/typedContracts/flipper/types-returns/flipper.ts @@ -0,0 +1,7 @@ +import type BN from 'bn.js'; +import type {ReturnNumber} from '@727-ventures/typechain-types'; + +export enum LangError { + couldNotReadInput = 'CouldNotReadInput' +} + From a09048d4541c5105c029f2f83645392edd2340cc Mon Sep 17 00:00:00 2001 From: Shunsuke Watanabe Date: Mon, 1 May 2023 19:28:23 +0900 Subject: [PATCH 4/5] up --- packages/cli/src/commands/script/run.ts | 11 +++++------ packages/core/src/lib/consts.ts | 2 +- .../src/templates/scripts/00_deploy.ts | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/commands/script/run.ts b/packages/cli/src/commands/script/run.ts index 1dc80411..d7f40499 100644 --- a/packages/cli/src/commands/script/run.ts +++ b/packages/cli/src/commands/script/run.ts @@ -5,10 +5,6 @@ import { existsSync } from "fs-extra"; import { fork } from "child_process"; import path = require("node:path"); -declare global { - var contractTypesPath: string; // eslint-disable-line no-var -} - export class RunCommand extends BaseCommand { static description = "Run a user-defined scripts"; @@ -25,9 +21,12 @@ export class RunCommand extends BaseCommand { const { args } = await this.parse(RunCommand); - const scriptPath = path.resolve("scripts", args.scriptName); - console.log(scriptPath) + let scriptName = args.scriptName; + if (!scriptName.endsWith(".ts")) { + scriptName += ".ts"; + } + const scriptPath = path.resolve("scripts", scriptName); if (!existsSync(scriptPath)) { throw new Error(`Script ${args.scriptName} does not exist`) } diff --git a/packages/core/src/lib/consts.ts b/packages/core/src/lib/consts.ts index 0ad51fc2..6d9d09ea 100644 --- a/packages/core/src/lib/consts.ts +++ b/packages/core/src/lib/consts.ts @@ -4,4 +4,4 @@ export const DEFAULT_SHIDEN_NETWORK_URL = "wss://rpc.shiden.astar.network"; export const DEFAULT_SHIBUYA_NETWORK_URL = "wss://rpc.shibuya.astar.network"; export const STORED_ARTIFACTS_PATH = "./artifacts"; -export const TEMP_ARTIFACTS_PATH = "./tmp_artifacts"; \ No newline at end of file +export const TEMP_ARTIFACTS_PATH = "./tmp_artifacts"; diff --git a/packages/templates/src/templates/scripts/00_deploy.ts b/packages/templates/src/templates/scripts/00_deploy.ts index 77764437..91f9c72e 100644 --- a/packages/templates/src/templates/scripts/00_deploy.ts +++ b/packages/templates/src/templates/scripts/00_deploy.ts @@ -1,7 +1,20 @@ +import { ApiPromise, WsProvider } from "@polkadot/api"; + +// `swanky script run 00_deploy` will run this script. + +// User-defined script to run. +// This is just an deploy contract example, you can change it freely. + +import { + getSwankyConfig, + AccountData, + ChainAccount, + Encrypted, + decrypt, + resolveNetworkUrl +} from "@astar-network/swanky-core"; import FlipperFactory from "../typedContracts/flipper/constructors/flipper"; import Flipper from "../typedContracts/flipper/contracts/flipper"; -import { ApiPromise, WsProvider } from "@polkadot/api"; -import { getSwankyConfig, AccountData, ChainAccount, Encrypted, decrypt, resolveNetworkUrl } from "@astar-network/swanky-core"; import inquirer from "inquirer"; import chalk from "chalk"; @@ -44,6 +57,7 @@ async function main() { const wsProvider = new WsProvider(networkUrl); const api = await ApiPromise.create({ provider: wsProvider }); + // Deploy flipper contract whose initial state is set to `true`. const flipperFactory = new FlipperFactory(api, deployer); const initialState = true; From 734aaca8800ba359df283b7b38ea628b3b67817c Mon Sep 17 00:00:00 2001 From: Shunsuke Watanabe Date: Mon, 8 May 2023 14:19:27 +0900 Subject: [PATCH 5/5] up --- packages/cli/src/commands/contract/compile.ts | 2 +- packages/cli/src/commands/contract/deploy.ts | 2 +- packages/cli/src/commands/contract/test.ts | 3 +- packages/cli/src/commands/init/index.ts | 1 - packages/core/src/lib/tasks.ts | 5 - .../ask/blank/test/index.test.ts.hbs | 4 +- .../ask/erc20token/test/index.test.ts.hbs | 4 +- .../ask/flipper/test/index.test.ts.hbs | 4 +- .../ink/blank/test/index.test.ts.hbs | 4 +- .../ink/flipper/test/index.test.ts.hbs | 4 +- .../ink/psp22/test/index.test.ts.hbs | 4 +- .../flipper/build-extrinsic/flipper.ts | 43 ------- .../flipper/constructors/flipper.ts | 81 ------------- .../flipper/contract-info/flipper.ts | 2 - .../flipper/contracts/flipper.ts | 107 ------------------ .../typedContracts/flipper/data/flipper.json | 3 - .../flipper/event-data/flipper.json | 3 - .../flipper/event-types/flipper.ts | 3 - .../typedContracts/flipper/events/flipper.ts | 44 ------- .../flipper/mixed-methods/flipper.ts | 64 ----------- .../typedContracts/flipper/query/flipper.ts | 54 --------- .../typedContracts/flipper/shared/utils.ts | 38 ------- .../flipper/tx-sign-and-send/flipper.ts | 55 --------- .../flipper/types-arguments/flipper.ts | 6 - .../flipper/types-returns/flipper.ts | 7 -- 25 files changed, 15 insertions(+), 532 deletions(-) delete mode 100644 packages/templates/src/templates/typedContracts/flipper/build-extrinsic/flipper.ts delete mode 100644 packages/templates/src/templates/typedContracts/flipper/constructors/flipper.ts delete mode 100644 packages/templates/src/templates/typedContracts/flipper/contract-info/flipper.ts delete mode 100644 packages/templates/src/templates/typedContracts/flipper/contracts/flipper.ts delete mode 100644 packages/templates/src/templates/typedContracts/flipper/data/flipper.json delete mode 100644 packages/templates/src/templates/typedContracts/flipper/event-data/flipper.json delete mode 100644 packages/templates/src/templates/typedContracts/flipper/event-types/flipper.ts delete mode 100644 packages/templates/src/templates/typedContracts/flipper/events/flipper.ts delete mode 100644 packages/templates/src/templates/typedContracts/flipper/mixed-methods/flipper.ts delete mode 100644 packages/templates/src/templates/typedContracts/flipper/query/flipper.ts delete mode 100644 packages/templates/src/templates/typedContracts/flipper/shared/utils.ts delete mode 100644 packages/templates/src/templates/typedContracts/flipper/tx-sign-and-send/flipper.ts delete mode 100644 packages/templates/src/templates/typedContracts/flipper/types-arguments/flipper.ts delete mode 100644 packages/templates/src/templates/typedContracts/flipper/types-returns/flipper.ts diff --git a/packages/cli/src/commands/contract/compile.ts b/packages/cli/src/commands/contract/compile.ts index 4886ed8d..66ac65e3 100644 --- a/packages/cli/src/commands/contract/compile.ts +++ b/packages/cli/src/commands/contract/compile.ts @@ -154,7 +154,7 @@ export class CompileContract extends Command { await fs.remove(path.resolve(artifactsPath, `${contractName}.wasm`)); } - const typedContractDestPath = path.resolve("typedContracts", contractName); + const typedContractDestPath = path.resolve("test", contractName, "typedContract"); await spinner.runCommand( async () => await generateTypes(artifactsPath, contractName, typedContractDestPath), `Generating ${contractName} contract ts types`, diff --git a/packages/cli/src/commands/contract/deploy.ts b/packages/cli/src/commands/contract/deploy.ts index b93b9bf1..9152931c 100644 --- a/packages/cli/src/commands/contract/deploy.ts +++ b/packages/cli/src/commands/contract/deploy.ts @@ -1,6 +1,6 @@ import { Args, Command, Flags } from "@oclif/core"; import path = require("node:path"); -import { readJSON, readFile, writeJSON } from "fs-extra"; +import { readJSON, writeJSON } from "fs-extra"; import { cryptoWaitReady } from "@polkadot/util-crypto"; import { ensureSwankyProject, diff --git a/packages/cli/src/commands/contract/test.ts b/packages/cli/src/commands/contract/test.ts index 5a1e485c..8ed0ee2f 100644 --- a/packages/cli/src/commands/contract/test.ts +++ b/packages/cli/src/commands/contract/test.ts @@ -52,7 +52,6 @@ export class TestContract extends Command { const projectDir = path.resolve(); const testDir = path.resolve("test"); - const typedContractsDir = path.resolve("typedCotracts") for (const contractName of contractNames) { const contractInfo = config.contracts[contractName]; if (!contractInfo.build) { @@ -87,7 +86,7 @@ export class TestContract extends Command { mocha.addFile(test); }); - global.contractTypesPath = path.resolve(typedContractsDir, contractName); + global.contractTypesPath = path.resolve(testDir, contractName, "typedContract"); shell.cd(`${testDir}/${contractName}`); try { diff --git a/packages/cli/src/commands/init/index.ts b/packages/cli/src/commands/init/index.ts index 56734f37..5e9b9336 100644 --- a/packages/cli/src/commands/init/index.ts +++ b/packages/cli/src/commands/init/index.ts @@ -116,7 +116,6 @@ export class Init extends Command { } await ensureDir(path.resolve(projectPath, "artifacts", answers.contractName)); - await ensureDir(path.resolve(projectPath, "typedContracts", answers.contractName)); await ensureDir(path.resolve(projectPath, "test", answers.contractName)); await spinner.runCommand( diff --git a/packages/core/src/lib/tasks.ts b/packages/core/src/lib/tasks.ts index 8999c403..4c34a1b0 100644 --- a/packages/core/src/lib/tasks.ts +++ b/packages/core/src/lib/tasks.ts @@ -43,11 +43,6 @@ export async function copyTemplateFiles( path.resolve(templatesPath, "github"), path.resolve(projectPath, ".github") ); - await ensureDir(path.resolve(projectPath, "typedContracts")); - await copy( - path.resolve(templatesPath, "typedContracts", "flipper"), - path.resolve(projectPath, "typedContracts", "flipper") - ); await copy( path.resolve(templatesPath, "scripts"), path.resolve(projectPath, "scripts") diff --git a/packages/templates/src/templates/contracts/ask/blank/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ask/blank/test/index.test.ts.hbs index 385f5066..ffc279f9 100644 --- a/packages/templates/src/templates/contracts/ask/blank/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ask/blank/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "../../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "../../typedContracts/{{contract_name}}/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "./typedContract/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "./typedContract/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/contracts/ask/erc20token/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ask/erc20token/test/index.test.ts.hbs index 568b35c0..2615a834 100644 --- a/packages/templates/src/templates/contracts/ask/erc20token/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ask/erc20token/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "../../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "../../typedContracts/{{contract_name}}/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "./typedContract/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "./typedContract/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/contracts/ask/flipper/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ask/flipper/test/index.test.ts.hbs index 6a0095cd..8309a83b 100644 --- a/packages/templates/src/templates/contracts/ask/flipper/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ask/flipper/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "../../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "../../typedContracts/{{contract_name}}/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "./typedContracts/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "./typedContracts/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/contracts/ink/blank/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ink/blank/test/index.test.ts.hbs index 385f5066..ffc279f9 100644 --- a/packages/templates/src/templates/contracts/ink/blank/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ink/blank/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "../../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "../../typedContracts/{{contract_name}}/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "./typedContract/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "./typedContract/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/contracts/ink/flipper/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ink/flipper/test/index.test.ts.hbs index 702a1033..460a711b 100644 --- a/packages/templates/src/templates/contracts/ink/flipper/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ink/flipper/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "../../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "../../typedContracts/{{contract_name}}/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "./typedContract/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "./typedContract/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/contracts/ink/psp22/test/index.test.ts.hbs b/packages/templates/src/templates/contracts/ink/psp22/test/index.test.ts.hbs index 5e018a64..1723d29a 100644 --- a/packages/templates/src/templates/contracts/ink/psp22/test/index.test.ts.hbs +++ b/packages/templates/src/templates/contracts/ink/psp22/test/index.test.ts.hbs @@ -1,7 +1,7 @@ import { expect, use } from "chai"; import chaiAsPromised from "chai-as-promised"; -import {{contract_name_pascal}}Factory from "../../typedContracts/{{contract_name}}/constructors/{{contract_name}}"; -import {{contract_name_pascal}} from "../../typedContracts/{{contract_name}}/contracts/{{contract_name}}"; +import {{contract_name_pascal}}Factory from "./typedContract/constructors/{{contract_name}}"; +import {{contract_name_pascal}} from "./typedContract/contracts/{{contract_name}}"; import { ApiPromise, WsProvider, Keyring } from "@polkadot/api"; import { KeyringPair } from "@polkadot/keyring/types"; diff --git a/packages/templates/src/templates/typedContracts/flipper/build-extrinsic/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/build-extrinsic/flipper.ts deleted file mode 100644 index be21f1b3..00000000 --- a/packages/templates/src/templates/typedContracts/flipper/build-extrinsic/flipper.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* This file is auto-generated */ - -import type { ContractPromise } from '@polkadot/api-contract'; -import type { GasLimit, GasLimitAndRequiredValue } from '@727-ventures/typechain-types'; -import { buildSubmittableExtrinsic } from '@727-ventures/typechain-types'; -import type * as ArgumentTypes from '../types-arguments/flipper'; -import type BN from 'bn.js'; -import type { ApiPromise } from '@polkadot/api'; - - - -export default class Methods { - private __nativeContract : ContractPromise; - private __apiPromise: ApiPromise; - - constructor( - nativeContract : ContractPromise, - apiPromise: ApiPromise, - ) { - this.__nativeContract = nativeContract; - this.__apiPromise = apiPromise; - } - /** - * flip - * - */ - "flip" ( - __options: GasLimit, - ){ - return buildSubmittableExtrinsic( this.__apiPromise, this.__nativeContract, "flip", [], __options); - } - - /** - * get - * - */ - "get" ( - __options: GasLimit, - ){ - return buildSubmittableExtrinsic( this.__apiPromise, this.__nativeContract, "get", [], __options); - } - -} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/constructors/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/constructors/flipper.ts deleted file mode 100644 index 097c0163..00000000 --- a/packages/templates/src/templates/typedContracts/flipper/constructors/flipper.ts +++ /dev/null @@ -1,81 +0,0 @@ -import {CodePromise} from "@polkadot/api-contract"; -import type {KeyringPair} from "@polkadot/keyring/types"; -import type {ApiPromise} from "@polkadot/api"; -import {_genValidGasLimitAndValue, _signAndSend, SignAndSendSuccessResponse} from "@727-ventures/typechain-types"; -import type {ConstructorOptions} from "@727-ventures/typechain-types"; -import type {WeightV2} from "@polkadot/types/interfaces"; -import type * as ArgumentTypes from '../types-arguments/flipper'; -import { ContractFile } from '../contract-info/flipper'; -import type BN from 'bn.js'; - -export default class Constructors { - readonly nativeAPI: ApiPromise; - readonly signer: KeyringPair; - - constructor( - nativeAPI: ApiPromise, - signer: KeyringPair, - ) { - this.nativeAPI = nativeAPI; - this.signer = signer; - } - - /** - * new - * - * @param { boolean } initValue, - */ - async "new" ( - initValue: boolean, - __options ? : ConstructorOptions, - ) { - const __contract = JSON.parse(ContractFile); - const code = new CodePromise(this.nativeAPI, __contract, __contract.source.wasm); - const gasLimit = (await _genValidGasLimitAndValue(this.nativeAPI, __options)).gasLimit as WeightV2; - - const storageDepositLimit = __options?.storageDepositLimit; - const tx = code.tx["new"]!({ gasLimit, storageDepositLimit, value: __options?.value }, initValue); - let response; - - try { - response = await _signAndSend(this.nativeAPI.registry, tx, this.signer, (event: any) => event); - } - catch (error) { - console.log(error); - } - - return { - result: response as SignAndSendSuccessResponse, - // @ts-ignore - address: (response as SignAndSendSuccessResponse)!.result!.contract.address.toString(), - }; - } - /** - * default - * - */ - async "default" ( - __options ? : ConstructorOptions, - ) { - const __contract = JSON.parse(ContractFile); - const code = new CodePromise(this.nativeAPI, __contract, __contract.source.wasm); - const gasLimit = (await _genValidGasLimitAndValue(this.nativeAPI, __options)).gasLimit as WeightV2; - - const storageDepositLimit = __options?.storageDepositLimit; - const tx = code.tx["default"]!({ gasLimit, storageDepositLimit, value: __options?.value }, ); - let response; - - try { - response = await _signAndSend(this.nativeAPI.registry, tx, this.signer, (event: any) => event); - } - catch (error) { - console.log(error); - } - - return { - result: response as SignAndSendSuccessResponse, - // @ts-ignore - address: (response as SignAndSendSuccessResponse)!.result!.contract.address.toString(), - }; - } -} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/contract-info/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/contract-info/flipper.ts deleted file mode 100644 index 8dd4d67d..00000000 --- a/packages/templates/src/templates/typedContracts/flipper/contract-info/flipper.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const ContractAbi = `{"source":{"hash":"0x224de7dbc0ee76dfb431fb59c30fe463d07cae59ce4585be27e9d9a4344bebbe","language":"ink! 4.2.0","compiler":"rustc 1.68.0-nightly","build_info":{"build_mode":"Debug","cargo_contract_version":"2.1.0","rust_toolchain":"nightly-aarch64-apple-darwin","wasm_opt_settings":{"keep_debug_symbols":false,"optimization_passes":"Z"}}},"contract":{"name":"flipper","version":"0.1.0","authors":["Shunsuke Watanabe"]},"spec":{"constructors":[{"args":[{"label":"init_value","type":{"displayName":["bool"],"type":0}}],"default":false,"docs":["Constructor that initializes the \`bool\` value to the given \`init_value\`."],"label":"new","payable":false,"returnType":{"displayName":["ink_primitives","ConstructorResult"],"type":1},"selector":"0x9bae9d5e"},{"args":[],"default":false,"docs":["Constructor that initializes the \`bool\` value to \`false\`.","","Constructors can delegate to other constructors."],"label":"default","payable":false,"returnType":{"displayName":["ink_primitives","ConstructorResult"],"type":1},"selector":"0xed4b9d1b"}],"docs":[],"environment":{"accountId":{"displayName":["AccountId"],"type":5},"balance":{"displayName":["Balance"],"type":8},"blockNumber":{"displayName":["BlockNumber"],"type":11},"chainExtension":{"displayName":["ChainExtension"],"type":12},"hash":{"displayName":["Hash"],"type":9},"maxEventTopics":4,"timestamp":{"displayName":["Timestamp"],"type":10}},"events":[],"lang_error":{"displayName":["ink","LangError"],"type":3},"messages":[{"args":[],"default":false,"docs":[" A message that can be called on instantiated contracts."," This one flips the value of the stored \`bool\` from \`true\`"," to \`false\` and vice versa.",""," To avoid typechain-polkadot [issue](https://github.com/727-Ventures/typechain-polkadot/issues/19)"," returning bool intentionally until it is resolved."],"label":"flip","mutates":true,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":4},"selector":"0x633aa551"},{"args":[],"default":false,"docs":[" Simply returns the current value of our \`bool\`."],"label":"get","mutates":false,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":4},"selector":"0x2f865bd9"}]},"storage":{"root":{"layout":{"struct":{"fields":[{"layout":{"leaf":{"key":"0x00000000","ty":0}},"name":"value"}],"name":"Flipper"}},"root_key":"0x00000000"}},"types":[{"id":0,"type":{"def":{"primitive":"bool"}}},{"id":1,"type":{"def":{"variant":{"variants":[{"fields":[{"type":2}],"index":0,"name":"Ok"},{"fields":[{"type":3}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":2},{"name":"E","type":3}],"path":["Result"]}},{"id":2,"type":{"def":{"tuple":[]}}},{"id":3,"type":{"def":{"variant":{"variants":[{"index":1,"name":"CouldNotReadInput"}]}},"path":["ink_primitives","LangError"]}},{"id":4,"type":{"def":{"variant":{"variants":[{"fields":[{"type":0}],"index":0,"name":"Ok"},{"fields":[{"type":3}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":0},{"name":"E","type":3}],"path":["Result"]}},{"id":5,"type":{"def":{"composite":{"fields":[{"type":6,"typeName":"[u8; 32]"}]}},"path":["ink_primitives","types","AccountId"]}},{"id":6,"type":{"def":{"array":{"len":32,"type":7}}}},{"id":7,"type":{"def":{"primitive":"u8"}}},{"id":8,"type":{"def":{"primitive":"u128"}}},{"id":9,"type":{"def":{"composite":{"fields":[{"type":6,"typeName":"[u8; 32]"}]}},"path":["ink_primitives","types","Hash"]}},{"id":10,"type":{"def":{"primitive":"u64"}}},{"id":11,"type":{"def":{"primitive":"u32"}}},{"id":12,"type":{"def":{"variant":{}},"path":["ink_env","types","NoChainExtension"]}}],"version":"4"}`; -export const ContractFile = `{"source":{"hash":"0x224de7dbc0ee76dfb431fb59c30fe463d07cae59ce4585be27e9d9a4344bebbe","language":"ink! 4.2.0","compiler":"rustc 1.68.0-nightly","wasm":"0x0061736d0100000001450c60027f7f017f60037f7f7f017f60027f7f0060037f7f7f0060017f0060000060047f7f7f7f017f60047f7f7f7f0060017f017f60017f017e60057f7f7f7f7f006000017f028a0107057365616c310b6765745f73746f726167650006057365616c301176616c75655f7472616e736665727265640002057365616c3005696e7075740002057365616c300d64656275675f6d6573736167650000057365616c320b7365745f73746f726167650006057365616c300b7365616c5f72657475726e000303656e76066d656d6f7279020102100338370102030b0803040002080102040505040302020505000101030003000702040502000400040900000a0607060000030a0100000000070404050170010f0f0608017f01418080040b0711020463616c6c0019066465706c6f79001a0914010041010b0e0d32273a29333738281d1f21392b0af741372b01017f037f2002200346047f200005200020036a200120036a2d00003a0000200341016a21030c010b0b0b2601017f230041106b22022400200220003a000f20012002410f6a41011008200241106a24000b5c01037f02402000280208220420026a220320044f04402003200028020422054b0d01200028020020046a200320046b20012002418c9a041035200020033602080f0b41b09804411c41ec99041020000b2003200541fc9904100b000b5502027f027e230041206b22002400200041106a22014200370300200042003703082000411036021c200041086a2000411c6a10012001290300210220002903082103200041206a2400410541042002200384501b0b1b002000418180014f044020004180800141e48104100b000b20000b7501017f230041306b220324002003200136020420032000360200200341146a41023602002003411c6a41023602002003412c6a410336020020034198900436021020034100360208200341033602242003200341206a3602182003200341046a36022820032003360220200341086a2002100e000b5201017f230041206b220124002001410c6a4101360200200141146a4101360200200141ac9704360208200141003602002001410136021c200120003602182001200141186a360210200141fc8204100e000b910101017f230041306b22022400200241146a41013602002002411c6a4101360200200241ac97043602102002410036020820024102360224200220002d0000410274220041e89c046a28020036022c2002200041fc9c046a280200360228200141046a28020021002002200241206a3602182002200241286a36022020012802002000200241086a1036200241306a24000b3c01017f230041206b22022400200241013a00182002200136021420022000360210200241c08b0436020c200241ac9804360208200241086a102a000b4001017f230041106b22012400200141003a000f20002001410f6a41011010047f4102054101410220012d000f22004101461b410020001b0b200141106a24000b6001047f230041106b22032400200028020422042002492205450440200341086a4100200220002802002206103b200120022003280208200328020c41d89c0410352003200220042006103b200020032903003702000b200341106a240020050b4701017f230041106b220224002002410036020c024020012002410c6a410410104504402000200228020c360001200041003a00000c010b200041013a00000b200241106a24000b3701017f230041106b22012400200142808001370204200141989d0436020020014100101820002001100741002001280208100a1017000b06004100103c0b06004101103c0bae0102057f017e230041306b2201240020014100360218200142808001370224200141989d043602202001410036021c200141206a22022001411c6a4104100820012001290320370310200141086a200141106a220320012802281016200128020c2104200128020820012903102106200141003602282001200637032020002002100720012001290320370310200120032001280228101620042001280200200128020410041a200141306a24000b4501017f2002200128020422034b044041cc9804412341ac9a041020000b2001200320026b36020420012001280200220120026a36020020002002360204200020013602000b0d00200041989d0420011005000ba10101027f20002802082202200028020422034904402000200241016a360208200028020020026a20013a00000f0b230041306b220024002000200336020420002002360200200041146a41023602002000411c6a41023602002000412c6a4103360200200041948b0436021020004100360208200041033602242000200041206a360218200020003602282000200041046a360220200041086a419c9a04100e000bf90401077f230041406a22002400024002400240024002400240100941ff0171410546044020004180800136022041989d04200041206a100220002802202201418180014f0d0120002001360224200041989d04360220200041106a200041206a101120002d00100d0520002800112201411876210220014110762104200141087621030240200141ff01712201412f470440200141e30047200341ff0171413a4772200441ff017141a50147720d0741012101200241d100460d010c070b200341ff017141860147200441ff017141db0047720d0641002101200241d901470d060b20004100360218200042808001370224200041989d043602202000410036023c200041206a22032000413c6a4104100820002000290320370310200041086a200041106a20002802281016200028020c210520002802082000280210210220002000280214220436022020052002200310002103200420002802202205490d02024002400240410c20032003410c4f1b0e0402000001000b2000412c6a4101360200200041346a4100360200200041908204360228200041ac980436023020004100360220200041206a41988204100e000b2000412c6a4101360200200041346a4100360200200041d483043602280c070b2000200536022420002002360220200041206a100f41ff017122024102460d042001450d032002452200101520001012000b200041043a0020200041206a100c000b20014180800141e88004100b000b2005200441e88004100b000b20024100471012000b2000412c6a4101360200200041346a4100360200200041b483043602280c010b1014000b200041ac980436023020004100360220200041206a41fc8204100e000b870201057f230041106b2200240002400240100941ff01712201410546044020004180800136020041989d042000100220002802002201418180014f0d0120002001360204200041989d04360200200041086a20001011024020002d00080d002000280009220141187621022001411076210320014108762104200141ff01712201419b01470440200141ed0147200441ff017141cb004772200341ff0171419d01472002411b4772720d01410010151013000b200441ff017141ae0147200341ff0171419d014772200241de0047720d002000100f41ff017122004102470d030b1014000b200020013a00002000100c000b20014180800141e88004100b000b200010151013000b5501017f230041206b2202240020022000360204200241186a200141106a290200370300200241106a200141086a29020037030020022001290200370308200241046a41dc8304200241086a101c200241206a24000bee0301057f230041406a22032400200341033a003820034280808080800437033020034100360228200341003602202003200136021c20032000360218027f0240024020022802002201450440200241146a28020022004103742105200041ffffffff017121072002280210210441002101034020012005460d02200228020820016a220041046a28020022060440200328021820002802002006200328021c28020c1101000d040b200141086a2101200428020020042802042106200441086a2104200341186a2006110000450d000b0c020b200228020422074105742100200741ffffff3f71210703402000450d01200228020820046a220541046a28020022060440200328021820052802002006200328021c28020c1101000d030b20032001411c6a2d00003a00382003200141146a290200370330200341106a200228021022052001410c6a103420032003290310370320200341086a2005200141046a103420032003290308370328200441086a2104200041206b210020012802002106200141206a2101200520064103746a2205280200200341186a2005280204110000450d000b0c010b2002410c6a28020020074b04402003280218200228020820074103746a22002802002000280204200328021c28020c1101000d010b41000c010b41010b200341406b24000b0f00200028020020012002101e41000b7701027f230041106b2204240020022000280200200028020822036b4b0440200441086a20002003200210222004280208200428020c1023200028020821030b200028020420036a2001200210061a2003200220036a22014b044041808404411c41908a041020000b20002001360208200441106a24000bdd0201037f230041106b220224000240024002400240200028020022002002410c6a027f0240024020014180014f04402002410036020c2001418010490d012001418080044f0d0220022001413f71418001723a000e20022001410c7641e001723a000c20022001410676413f71418001723a000d41030c030b200028020822032000280200460d030c040b20022001413f71418001723a000d2002200141067641c001723a000c41020c010b20022001413f71418001723a000f20022001410676413f71418001723a000e20022001410c76413f71418001723a000d2002200141127641077141f001723a000c41040b101e0c020b230041106b22042400200441086a20002003410110222004280208200428020c1023200441106a2400200028020821030b200028020420036a20013a0000200341016a2201450d01200020013602080b200241106a240041000f0b41808404411c41808a041020000b5001017f230041206b220324002003410c6a4101360200200341146a4100360200200341ac9804360210200341003602002003200136021c200320003602182003200341186a36020820032002100e000b4a01017f230041206b220224002000280200200241186a200141106a290200370300200241106a200141086a29020037030020022001290200370308200241086a101b200241206a24000bac0401067f230041206b2204240002402000027f4100200220036a22032002490d001a2001280200220220026a22062002490d0141082006200320032006491b2203200341084d1b2203417f73411f7621050240200204402004410136021820042002360214200420012802043602100c010b200441003602180b200441106a2107230041106b220624002004027f0240027f0240200504400240200341004e044020072802080d012006200310262006280204210220062802000c040b0c040b20072802042209450440200641086a20031026200628020c210220062802080c030b20032102410041909d04280200220520036a22082005490d021a2007280200210741949d042802002008490440200341ffff036a220841107640002202417f46200241ffff0371200247720d022002411074220520084180807c716a22022005490d0241949d042002360200200321024100200320056a22082005490d031a0b41909d04200836020041002005450d021a20052007200910060c020b200420033602040c020b2003210241000b2205044020042005360204200441086a200236020041000c020b20042003360204200441086a410136020041010c010b200441086a410036020041010b360200200641106a240020042802004504402004280204210220012003360200200120023602044181808080780c010b20042802042103200441086a2802000b36020420002003360200200441206a24000f0b41a08404412141d085041020000b1f00024020014181808080784704402001450d0120001024000b0f0b1025000b900101017f230041306b220124002001200036020c2001411c6a4102360200200141246a4101360200200141a88704360218200141003602102001410336022c2001200141286a36022020012001410c6a360228230041206b22002400200041003a0018200041b887043602142000200141106a360210200041c08b0436020c200041ac9804360208200041086a102a000b4601017f230041206b22002400200041146a41013602002000411c6a4100360200200041f48504360210200041ac980436021820004100360208200041086a41fc8504100e000ba10101027f027f410041909d04280200220320016a22022003490d001a024041949d042802002002490440200141ffff036a22022001490d012002411076220240002203417f46200341ffff0371200347720d012003411074220320024110746a22022003490d0141949d0420023602004100200120036a22022003490d021a0b41909d04200236020020030c010b41000b210220002001360204200020023602000bd806020b7f027e230041406a2203240020002802002202ad210d0240024002400240024002400240024020024190ce004f044041272100200d210e0240034020004104490d01200341196a20006a220241046b200e200e4290ce0080220d4290ce007e7da7220441ffff037141e4006e220641017441ff8c046a2f00003b0000200241026b2004200641e4006c6b41ffff037141017441ff8c046a2f00003b0000200041046b2100200e42ffc1d72f56200d210e0d000b200da7220241e3004d0d0320004102490d090c020b0c080b41272100200241e3004b0d002002410a490d040c020b200041026b2200200341196a6a200da72202200241ffff037141e4006e220241e4006c6b41ffff037141017441ff8c046a2f00003b00000b2002410a490d01200041024f0d000c050b200041026b2200200341196a6a200241017441ff8c046a2f00003b00000c020b2000450d030b200041016b2200200341196a6a200241306a3a00000b200041274b0d01412820006b412720006b22062001280218220541017122071b2102410021042005410471044041ac98042104200241ac980441ac9804102c20026a22024b0d010b412b418080c40020071b2107200341196a20006a2108024020012802084504404101210020012802002202200141046a280200220120072004102f0d01200220082006200128020c11010021000c010b024020022001410c6a28020022094904402005410871450d01200128021c210b2001413036021c20012d0020210c41012100200141013a002020012802002205200141046a280200220a20072004102f0d02200341106a2001200920026b4101103020032802142202418080c400460d022003280210200520082006200a28020c1101000d0220022005200a10310d022001200c3a00202001200b36021c410021000c020b4101210020012802002202200141046a280200220120072004102f0d01200220082006200128020c11010021000c010b41012100200341086a2001200920026b41011030200328020c2205418080c400460d00200328020820012802002202200141046a280200220120072004102f0d00200220082006200128020c1101000d00200520022001103121000b200341406b240020000f0b41a08a04411c41c48f041020000b41c08a044121419497041020000b0300010b0e0020002802001a03400c000b000bde0301037f230041406a220124002001200036020c2001410436022420012001410c6a3602204100210041042102024002400240024002400240024003402000200241f098046a2802006a22032000490d0120032100200241086a22024114470d000b41012100027f410020034110490d001a41002003200320036a22024b0d001a41002002450d001a20024100480d0220012002102620012802002200450d0320020b21032001410036021820012000360214200120033602102001410136023c20014102360234200141f09804360230200141003602282001200141206a360238200141106a200141286a101b0d0341989d052d000045044041999d052d00004101710d070b410c20012802142001280218100322002000410c4f1b4109470d040c050b41808404411c418497041020000b1025000b20021024000b230041406a220024002000413336020c200041c88704360208200041c484043602142000200141286a360210200041246a41023602002000412c6a41023602002000413c6a4106360200200041f48b0436022020004100360218200041023602342000200041306a3602282000200041106a3602382000200041086a360230200041186a41f48804100e000b41989d0541013a00000b41999d0541013a00000b000b0d0042e5b0b0dab9e2cd9daa7f0ba704010a7f230041106b2203240002400240200020016b22024110490d002002200141036a417c7120016b220049200041044b720d00200220006b22044104490d0020012000102d2206200020016a22082004417c716a2004410371102d6a220220064f0440200441027621050240024003402005450d0520032008200541c0012005200541c0014f1b41a89104102e200328020c21052003280208210820032003280200200328020422002000417c7141b89204102e200328020c210920032802082107024020032802042200450440410021010c010b2003280200220420004102746a210a4100210103402004220641106a2104410021000240034020012001200020066a280200220b417f73410776200b410676724181828408716a22014d0440200041046a22004110470d010c020b0b41a08a04411c41b094041020000b2004200a470d000b0b20022002200141087641ff81fc0771200141ff81fc07716a418180046c4110766a22024b0d012009450d000b200941027421004100210103402001200120072802002204417f734107762004410676724181828408716a22014b0d02200741046a2107200041046b22000d000b20022002200141087641ff81fc0771200141ff81fc07716a418180046c4110766a22024d0d0441a08a04411c41e094041020000b41a08a04411c41c094041020000b41a08a04411c41d094041020000b41a08a04411c41a094041020000b20012002102d21020b200341106a240020020b4601017f200145044041000f0b024003402002200220002c000041bf7f4a6a22024b0d01200041016a2100200141016b22010d000b20020f0b41a08a04411c418497041020000b3e00200220034f044020002003360204200020013602002000410c6a200220036b3602002000200120034102746a3602080f0b41cc9804412320041020000b39000240027f2002418080c40047044041012000200220012802101100000d011a0b20030d0141000b0f0b200020034100200128020c1101000bae0101027f20022104024002400240200320012d0020220320034103461b41ff0171220341016b0e03010001020b200241016a2203044020034101762104200241017621030c020b41a08a04411c41d48f041020000b41002104200221030b200341016a2102200128021c2103200128020421052001280200210102400340200241016b2202450d01200120032005280210110000450d000b418080c40021030b20002003360204200020043602000b3201017f027f0340200020002004460d011a200441016a2104200220012003280210110000450d000b200441016b0b2000490bea04010b7f230041106b2209240020002802042104200028020021030240024002402001280208220b410147200128021022024101477145044020024101470d02200320046a210c200141146a28020041016a210a410021022003210003402000200c460d03027f024020002c0000220641004e0440200041016a2105200641ff017121070c010b20002d0001413f7121052006411f7121072006415f4d044020074106742005722107200041026a21050c010b20002d0002413f7120054106747221082006417049044020082007410c74722107200041036a21050c010b200041046a210520022106418080c4002007411274418080f0007120002d0003413f71200841067472722207418080c400460d011a0b2002200520006b6a22062002490d0320070b2108200a41016b220a044020052100200621022008418080c400470d010c040b0b2008418080c400460d02024002402002450d00200220044f04404100210020022004460d010c020b41002100200220036a2c00004140480d010b200321000b2002200420001b21042000200320001b21030c020b200128020020032004200128020428020c11010021000c020b41a08a04411c41ec95041020000b200b450440200128020020032004200128020428020c11010021000c010b2001410c6a2802002200200320046a2003102c22024b0440200941086a2001200020026b4100103041012100200928020c2202418080c400460d0120092802082001280200220520032004200141046a280200220128020c1101000d01200220052001103121000c010b200128020020032004200128020428020c11010021000b200941106a240020000b140020002802002001200028020428020c1100000b5501027f0240027f02400240200228020041016b0e020103000b200241046a0c010b200120022802044103746a22012802044105470d0120012802000b2802002104410121030b20002004360204200020033602000b8501002001200346044020002002200110061a0f0b230041306b220024002000200336020420002001360200200041146a41033602002000411c6a41023602002000412c6a410336020020004188930436021020004100360208200041033602242000200041206a360218200020003602282000200041046a360220200041086a2004100e000b4901017f230041206b22032400200341186a200241106a290200370300200341106a200241086a2902003703002003200229020037030820002001200341086a101c200341206a24000b5801027f230041206b22022400200128020421032001280200200241186a2000280200220041106a290200370300200241106a200041086a290200370300200220002902003703082003200241086a101c200241206a24000b0b002000280200200110320b1800200128020041a497044105200128020428020c1101000b990301037f230041406a22022400200028020021034101210002402001280200220441d08b04410c200141046a280200220128020c1101000d0002402003280208220004402002200036020c200241346a4102360200410121002002413c6a4101360200200241e08b0436023020024100360228200241073602142002200241106a36023820022002410c6a36021020042001200241286a1036450d010c020b20032802002200200328020428020c11090042c8b5e0cfca86dbd3897f520d002002200036020c200241346a4102360200410121002002413c6a4101360200200241e08b0436023020024100360228200241083602142002200241106a36023820022002410c6a36021020042001200241286a10360d010b200328020c21002002411c6a4103360200200241246a41033602002002413c6a4103360200200241346a4103360200200241a88b043602182002410036021020022000410c6a3602382002200041086a3602302002410236022c200220003602282002200241286a36022020042001200241106a103621000b200241406b240020000b2c00200120024d04402000200220016b3602042000200120036a3602000f0b41d09b04412141bc9b041020000b3701017f230041106b22012400200142808001370204200141989d0436020020012000101820012000101820002001280208100a1017000b0b911d0200418080040bf1032f55736572732f7368756e73756b652f2e636172676f2f72656769737472792f7372632f6769746875622e636f6d2d316563633632393964623965633832332f696e6b5f656e762d342e322e302f7372632f656e67696e652f6f6e5f636861696e2f6578742e72730000010068000000e4000000140000002f55736572732f7368756e73756b652f2e636172676f2f72656769737472792f7372632f6769746875622e636f6d2d316563633632393964623965633832332f696e6b5f656e762d342e322e302f7372632f656e67696e652f6f6e5f636861696e2f696d706c732e72730000780001006a0000002401000023000000656e636f756e746572656420756e6578706563746564206572726f72f40001001c000000780001006a000000ed000000170000002f55736572732f7368756e73756b652f41737461722f7377616e6b792d636c692f7061636b616765732f636c692f73616d706c652f636f6e7472616374732f666c69707065722f7372632f6c69622e727300000028010100510000000600000005000000636f756c64206e6f742070726f7065726c79206465636f64652073746f7261676520656e747279008c0101002700000073746f7261676520656e7472792077617320656d70747900bc010100170000000900000004000000040000000a0000000b0000000c00418084040b8f19617474656d707420746f206164642077697468206f766572666c6f7700000000617474656d707420746f206d756c7469706c792077697468206f766572666c6f770000000900000000000000010000000d0000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f616c6c6f632f7372632f7261775f7665632e7273540201007c0000008a0100001c0000006361706163697479206f766572666c6f77000000e002010011000000540201007c00000006020000050000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f616c6c6f632f7372632f616c6c6f632e72736d656d6f727920616c6c6f636174696f6e206f6620206279746573206661696c656486030100150000009b0301000d0000000c0301007a0000009f0100000d0000006120666f726d617474696e6720747261697420696d706c656d656e746174696f6e2072657475726e656420616e206572726f722f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f616c6c6f632f7372632f666d742e727300fb0301007800000064020000200000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f616c6c6f632f7372632f7665632f6d6f642e7273840401007c000000350700000d000000840401007c000000a307000009000000617474656d707420746f206164642077697468206f766572666c6f7700000000617474656d707420746f2073756274726163742077697468206f766572666c6f7729696e646578206f7574206f6620626f756e64733a20746865206c656e20697320206275742074686520696e64657820697320620501002000000082050100120000003a0000002c0c010000000000a405010001000000a4050100010000000900000000000000010000000e00000070616e69636b65642061742027272c20dc05010001000000dd050100030000003a2000002c0c010000000000f0050100020000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f666d742f6e756d2e727330303031303230333034303530363037303830393130313131323133313431353136313731383139323032313232323332343235323632373238323933303331333233333334333533363337333833393430343134323433343434353436343734383439353035313532353335343535353635373538353936303631363236333634363536363637363836393730373137323733373437353736373737383739383038313832383338343835383638373838383939303931393239333934393539363937393839392f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f666d742f6d6f642e72730000470701007b0000005d0500000d000000470701007b000000ed05000038000000206f7574206f662072616e676520666f7220736c696365206f66206c656e6774682072616e676520656e6420696e6465782000000608010010000000e4070100220000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f736c6963652f697465722e72730000280801007e000000c4050000250000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f736c6963652f6d6f642e7273000000b80801007d000000fe0300002f000000736f7572636520736c696365206c656e67746820282920646f6573206e6f74206d617463682064657374696e6174696f6e20736c696365206c656e677468202848090100150000005d0901002b00000061050100010000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f7374722f636f756e742e7273000000a00901007d0000004700000015000000a00901007d0000005400000011000000a00901007d0000005a00000009000000a00901007d0000006400000011000000a00901007d000000660000000d0000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f7374722f697465722e7273700a01007c00000091000000110000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f697465722f7472616974732f616363756d2e7273000000fc0a0100850000009500000001000000040601007b000000cd010000050000004572726f720000002c0c0100000000007061696420616e20756e70617961626c65206d657373616765636f756c64206e6f74207265616420696e707574756e61626c6520746f206465636f646520696e707574656e636f756e746572656420756e6b6e6f776e2073656c6563746f72756e61626c6520746f206465636f64652073656c6563746f7200000000617474656d707420746f206164642077697468206f766572666c6f77617373657274696f6e206661696c65643a206d6964203c3d2073656c662e6c656e28290a2c0c0100000000006f0c0100010000002f55736572732f7368756e73756b652f2e636172676f2f72656769737472792f7372632f6769746875622e636f6d2d316563633632393964623965633832332f696e6b5f656e762d342e322e302f7372632f656e67696e652f6f6e5f636861696e2f6275666665722e727300800c01006b0000005a0000001c000000800c01006b0000005a00000009000000800c01006b0000005a00000031000000800c01006b0000006500000009000000800c01006b0000008d000000210000002f55736572732f7368756e73756b652f2e7275737475702f746f6f6c636861696e732f6e696768746c792d323032332d30312d31302d616172636836342d6170706c652d64617277696e2f6c69622f727573746c69622f7372632f727573742f6c6962726172792f636f72652f7372632f736c6963652f696e6465782e7273003c0d01007f000000820100004700000000000000617474656d707420746f2073756274726163742077697468206f766572666c6f772f55736572732f7368756e73756b652f2e636172676f2f72656769737472792f7372632f6769746875622e636f6d2d316563633632393964623965633832332f7061726974792d7363616c652d636f6465632d332e342e302f7372632f636f6465632e72730000f10d010065000000780000000e000000190000001c000000160000001400000019000000130c0100f70b0100e10b0100cd0b0100b40b01","build_info":{"build_mode":"Debug","cargo_contract_version":"2.1.0","rust_toolchain":"nightly-aarch64-apple-darwin","wasm_opt_settings":{"keep_debug_symbols":false,"optimization_passes":"Z"}}},"contract":{"name":"flipper","version":"0.1.0","authors":["Shunsuke Watanabe"]},"spec":{"constructors":[{"args":[{"label":"init_value","type":{"displayName":["bool"],"type":0}}],"default":false,"docs":["Constructor that initializes the \`bool\` value to the given \`init_value\`."],"label":"new","payable":false,"returnType":{"displayName":["ink_primitives","ConstructorResult"],"type":1},"selector":"0x9bae9d5e"},{"args":[],"default":false,"docs":["Constructor that initializes the \`bool\` value to \`false\`.","","Constructors can delegate to other constructors."],"label":"default","payable":false,"returnType":{"displayName":["ink_primitives","ConstructorResult"],"type":1},"selector":"0xed4b9d1b"}],"docs":[],"environment":{"accountId":{"displayName":["AccountId"],"type":5},"balance":{"displayName":["Balance"],"type":8},"blockNumber":{"displayName":["BlockNumber"],"type":11},"chainExtension":{"displayName":["ChainExtension"],"type":12},"hash":{"displayName":["Hash"],"type":9},"maxEventTopics":4,"timestamp":{"displayName":["Timestamp"],"type":10}},"events":[],"lang_error":{"displayName":["ink","LangError"],"type":3},"messages":[{"args":[],"default":false,"docs":[" A message that can be called on instantiated contracts."," This one flips the value of the stored \`bool\` from \`true\`"," to \`false\` and vice versa.",""," To avoid typechain-polkadot [issue](https://github.com/727-Ventures/typechain-polkadot/issues/19)"," returning bool intentionally until it is resolved."],"label":"flip","mutates":true,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":4},"selector":"0x633aa551"},{"args":[],"default":false,"docs":[" Simply returns the current value of our \`bool\`."],"label":"get","mutates":false,"payable":false,"returnType":{"displayName":["ink","MessageResult"],"type":4},"selector":"0x2f865bd9"}]},"storage":{"root":{"layout":{"struct":{"fields":[{"layout":{"leaf":{"key":"0x00000000","ty":0}},"name":"value"}],"name":"Flipper"}},"root_key":"0x00000000"}},"types":[{"id":0,"type":{"def":{"primitive":"bool"}}},{"id":1,"type":{"def":{"variant":{"variants":[{"fields":[{"type":2}],"index":0,"name":"Ok"},{"fields":[{"type":3}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":2},{"name":"E","type":3}],"path":["Result"]}},{"id":2,"type":{"def":{"tuple":[]}}},{"id":3,"type":{"def":{"variant":{"variants":[{"index":1,"name":"CouldNotReadInput"}]}},"path":["ink_primitives","LangError"]}},{"id":4,"type":{"def":{"variant":{"variants":[{"fields":[{"type":0}],"index":0,"name":"Ok"},{"fields":[{"type":3}],"index":1,"name":"Err"}]}},"params":[{"name":"T","type":0},{"name":"E","type":3}],"path":["Result"]}},{"id":5,"type":{"def":{"composite":{"fields":[{"type":6,"typeName":"[u8; 32]"}]}},"path":["ink_primitives","types","AccountId"]}},{"id":6,"type":{"def":{"array":{"len":32,"type":7}}}},{"id":7,"type":{"def":{"primitive":"u8"}}},{"id":8,"type":{"def":{"primitive":"u128"}}},{"id":9,"type":{"def":{"composite":{"fields":[{"type":6,"typeName":"[u8; 32]"}]}},"path":["ink_primitives","types","Hash"]}},{"id":10,"type":{"def":{"primitive":"u64"}}},{"id":11,"type":{"def":{"primitive":"u32"}}},{"id":12,"type":{"def":{"variant":{}},"path":["ink_env","types","NoChainExtension"]}}],"version":"4"}`; \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/contracts/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/contracts/flipper.ts deleted file mode 100644 index 7fff052e..00000000 --- a/packages/templates/src/templates/typedContracts/flipper/contracts/flipper.ts +++ /dev/null @@ -1,107 +0,0 @@ -/* This file is auto-generated */ - -import type { ApiPromise } from '@polkadot/api'; -import { Abi } from '@polkadot/api-contract'; -import type { KeyringPair } from '@polkadot/keyring/types'; -import { ContractPromise } from '@polkadot/api-contract'; -import { ContractAbi } from '../contract-info/flipper'; -import QueryMethods from '../query/flipper'; -import BuildExtrinsicMethods from '../build-extrinsic/flipper'; -import TxSignAndSendMethods from '../tx-sign-and-send/flipper'; -import MixedMethods from '../mixed-methods/flipper'; -import EventsClass from '../events/flipper'; - - -export default class Contract { - readonly query : QueryMethods; - readonly buildExtrinsic : BuildExtrinsicMethods; - readonly tx : TxSignAndSendMethods; - readonly methods : MixedMethods; - readonly events: EventsClass; - - readonly address : string; - readonly signer : KeyringPair; - - private nativeContract : ContractPromise; - private nativeAPI : ApiPromise; - private contractAbi: Abi; - - /** - * @constructor - - * @param address - The address of the contract. - * @param signer - The signer to use for signing transactions. - * @param nativeAPI - The API instance to use for queries. - */ - constructor( - address : string, - signer : KeyringPair, - nativeAPI : ApiPromise, - ) { - this.address = address; - this.nativeContract = new ContractPromise(nativeAPI, ContractAbi, address); - this.nativeAPI = nativeAPI; - this.signer = signer; - this.contractAbi = new Abi(ContractAbi); - - this.query = new QueryMethods(this.nativeContract, this.nativeAPI, signer.address); - this.buildExtrinsic = new BuildExtrinsicMethods(this.nativeContract, this.nativeAPI); - this.tx = new TxSignAndSendMethods(nativeAPI, this.nativeContract, signer); - this.methods = new MixedMethods(nativeAPI, this.nativeContract, signer); - this.events = new EventsClass(this.nativeContract, nativeAPI); - } - - /** - * name - * - * @returns The name of the contract. - */ - get name() : string { - return this.nativeContract.abi.info.contract.name.toString(); - } - - /** - * abi - * - * @returns The abi of the contract. - */ - get abi() : Abi { - return this.contractAbi; - } - - /** - * withSigner - * - * @param signer - The signer to use for signing transactions. - * @returns New instance of the contract class with new signer. - * @example - * ```typescript - * const contract = new Contract(address, signerAlice, api); - * await contract.mint(signerBob.address, 100); - * await contract.withSigner(signerBob).transfer(signerAlice.address, 100); - * ``` - */ - withSigner(signer : KeyringPair) : Contract { - return new Contract(this.address, signer, this.nativeAPI); - } - - /** - * withAddress - * - * @param address - The address of the contract. - * @returns New instance of the contract class to interact with new contract. - */ - withAddress(address : string) : Contract { - return new Contract(address, this.signer, this.nativeAPI); - } - - /** - * withAPI - * - * @param api - The API instance to use for queries. - * @returns New instance of the contract class to interact with new API. - */ - withAPI(api : ApiPromise) : Contract { - return new Contract(this.address, this.signer, api); - } -} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/data/flipper.json b/packages/templates/src/templates/typedContracts/flipper/data/flipper.json deleted file mode 100644 index 0c0145fe..00000000 --- a/packages/templates/src/templates/typedContracts/flipper/data/flipper.json +++ /dev/null @@ -1,3 +0,0 @@ -{ -"0": {"name":"boolean","isResult":false,"isPrimitive":true,"isConvertable":false},"2": {"name":"null","isResult":false,"isPrimitive":true,"isConvertable":false},"3": {"name":"LangError","body":{"CouldNotReadInput":null},"isResult":false,"isPrimitive":false,"isConvertable":false},"4": {"name":"Result void, - filter : (eventName: string) => boolean = () => true - ) { - // @ts-ignore - return this.__api.query.system.events((events) => { - events.forEach((record: any) => { - const { event } = record; - - if (event.method == 'ContractEmitted') { - const [address, data] = record.event.data; - - if (address.toString() === this.__nativeContract.address.toString()) { - const {args, event} = this.__nativeContract.abi.decodeEvent(data); - - if (filter(event.identifier.toString())) - callback(args, event); - } - } - }); - }); - } - -} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/mixed-methods/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/mixed-methods/flipper.ts deleted file mode 100644 index 9f58fa03..00000000 --- a/packages/templates/src/templates/typedContracts/flipper/mixed-methods/flipper.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* This file is auto-generated */ - -import type { ContractPromise } from '@polkadot/api-contract'; -import type { ApiPromise } from '@polkadot/api'; -import type { KeyringPair } from '@polkadot/keyring/types'; -import type { GasLimit, GasLimitAndRequiredValue, Result } from '@727-ventures/typechain-types'; -import type { QueryReturnType } from '@727-ventures/typechain-types'; -import { queryOkJSON, queryJSON, handleReturnType } from '@727-ventures/typechain-types'; -import { txSignAndSend } from '@727-ventures/typechain-types'; -import type * as ArgumentTypes from '../types-arguments/flipper'; -import type * as ReturnTypes from '../types-returns/flipper'; -import type BN from 'bn.js'; -//@ts-ignore -import {ReturnNumber} from '@727-ventures/typechain-types'; -import {getTypeDescription} from './../shared/utils'; -// @ts-ignore -import type {EventRecord} from "@polkadot/api/submittable"; -import {decodeEvents} from "../shared/utils"; -import DATA_TYPE_DESCRIPTIONS from '../data/flipper.json'; -import EVENT_DATA_TYPE_DESCRIPTIONS from '../event-data/flipper.json'; - - -export default class Methods { - private __nativeContract : ContractPromise; - private __keyringPair : KeyringPair; - private __callerAddress : string; - private __apiPromise: ApiPromise; - - constructor( - apiPromise : ApiPromise, - nativeContract : ContractPromise, - keyringPair : KeyringPair, - ) { - this.__apiPromise = apiPromise; - this.__nativeContract = nativeContract; - this.__keyringPair = keyringPair; - this.__callerAddress = keyringPair.address; - } - - /** - * flip - * - * @returns { void } - */ - "flip" ( - __options: GasLimit, - ){ - return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "flip", (events: EventRecord) => { - return decodeEvents(events, this.__nativeContract, EVENT_DATA_TYPE_DESCRIPTIONS); - }, [], __options); - } - - /** - * get - * - * @returns { Result } - */ - "get" ( - __options: GasLimit, - ): Promise< QueryReturnType< Result > >{ - return queryOkJSON( this.__apiPromise, this.__nativeContract, this.__callerAddress, "get", [], __options, (result) => { return handleReturnType(result, getTypeDescription(4, DATA_TYPE_DESCRIPTIONS)); }); - } - -} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/query/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/query/flipper.ts deleted file mode 100644 index f287e008..00000000 --- a/packages/templates/src/templates/typedContracts/flipper/query/flipper.ts +++ /dev/null @@ -1,54 +0,0 @@ -/* This file is auto-generated */ - -import type { ContractPromise } from '@polkadot/api-contract'; -import type { ApiPromise } from '@polkadot/api'; -import type { GasLimit, GasLimitAndRequiredValue, Result } from '@727-ventures/typechain-types'; -import type { QueryReturnType } from '@727-ventures/typechain-types'; -import { queryJSON, queryOkJSON, handleReturnType } from '@727-ventures/typechain-types'; -import type * as ArgumentTypes from '../types-arguments/flipper'; -import type * as ReturnTypes from '../types-returns/flipper'; -import type BN from 'bn.js'; -//@ts-ignore -import {ReturnNumber} from '@727-ventures/typechain-types'; -import {getTypeDescription} from './../shared/utils'; -import DATA_TYPE_DESCRIPTIONS from '../data/flipper.json'; - - -export default class Methods { - private __nativeContract : ContractPromise; - private __apiPromise: ApiPromise; - private __callerAddress : string; - - constructor( - nativeContract : ContractPromise, - nativeApi : ApiPromise, - callerAddress : string, - ) { - this.__nativeContract = nativeContract; - this.__callerAddress = callerAddress; - this.__apiPromise = nativeApi; - } - - /** - * flip - * - * @returns { Result } - */ - "flip" ( - __options ? : GasLimit, - ): Promise< QueryReturnType< Result > >{ - return queryOkJSON( this.__apiPromise, this.__nativeContract, this.__callerAddress, "flip", [], __options , (result) => { return handleReturnType(result, getTypeDescription(4, DATA_TYPE_DESCRIPTIONS)); }); - } - - /** - * get - * - * @returns { Result } - */ - "get" ( - __options ? : GasLimit, - ): Promise< QueryReturnType< Result > >{ - return queryOkJSON( this.__apiPromise, this.__nativeContract, this.__callerAddress, "get", [], __options , (result) => { return handleReturnType(result, getTypeDescription(4, DATA_TYPE_DESCRIPTIONS)); }); - } - -} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/shared/utils.ts b/packages/templates/src/templates/typedContracts/flipper/shared/utils.ts deleted file mode 100644 index 395aa488..00000000 --- a/packages/templates/src/templates/typedContracts/flipper/shared/utils.ts +++ /dev/null @@ -1,38 +0,0 @@ -import fs from "fs"; -import type {ContractPromise} from "@polkadot/api-contract"; -import {handleEventReturn} from "@727-ventures/typechain-types"; - -export function getTypeDescription(id: number | string, types: any): any { - return types[id]; -} - -export function getEventTypeDescription(name: string, types: any): any { - return types[name]; -} - -export function decodeEvents(events: any[], contract: ContractPromise, types: any): any[] { - return events.filter((record: any) => { - const { event } = record; - - const [address, data] = record.event.data; - - return event.method == 'ContractEmitted' && address.toString() === contract.address.toString(); - }).map((record: any) => { - const [address, data] = record.event.data; - - const {args, event} = contract.abi.decodeEvent(data); - - const _event: Record < string, any > = {}; - - for (let i = 0; i < args.length; i++) { - _event[event.args[i]!.name] = args[i]!.toJSON(); - } - - handleEventReturn(_event, getEventTypeDescription(event.identifier.toString(), types)); - - return { - name: event.identifier.toString(), - args: _event, - }; - }); -} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/tx-sign-and-send/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/tx-sign-and-send/flipper.ts deleted file mode 100644 index bbbdf401..00000000 --- a/packages/templates/src/templates/typedContracts/flipper/tx-sign-and-send/flipper.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* This file is auto-generated */ - -import type { ContractPromise } from '@polkadot/api-contract'; -import type { KeyringPair } from '@polkadot/keyring/types'; -import type { ApiPromise } from '@polkadot/api'; -import type { GasLimit, GasLimitAndRequiredValue, Result } from '@727-ventures/typechain-types'; -import { txSignAndSend } from '@727-ventures/typechain-types'; -import type * as ArgumentTypes from '../types-arguments/flipper'; -import type BN from 'bn.js'; -// @ts-ignore -import type {EventRecord} from "@polkadot/api/submittable"; -import {decodeEvents} from "../shared/utils"; -import EVENT_DATA_TYPE_DESCRIPTIONS from '../event-data/flipper.json'; - - -export default class Methods { - private __nativeContract : ContractPromise; - private __keyringPair : KeyringPair; - private __apiPromise: ApiPromise; - - constructor( - apiPromise: ApiPromise, - nativeContract : ContractPromise, - keyringPair : KeyringPair, - ) { - this.__apiPromise = apiPromise; - this.__nativeContract = nativeContract; - this.__keyringPair = keyringPair; - } - - /** - * flip - * - */ - "flip" ( - __options ? : GasLimit, - ){ - return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "flip", (events: EventRecord) => { - return decodeEvents(events, this.__nativeContract, EVENT_DATA_TYPE_DESCRIPTIONS); - }, [], __options); - } - - /** - * get - * - */ - "get" ( - __options ? : GasLimit, - ){ - return txSignAndSend( this.__apiPromise, this.__nativeContract, this.__keyringPair, "get", (events: EventRecord) => { - return decodeEvents(events, this.__nativeContract, EVENT_DATA_TYPE_DESCRIPTIONS); - }, [], __options); - } - -} \ No newline at end of file diff --git a/packages/templates/src/templates/typedContracts/flipper/types-arguments/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/types-arguments/flipper.ts deleted file mode 100644 index 87c5918a..00000000 --- a/packages/templates/src/templates/typedContracts/flipper/types-arguments/flipper.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type BN from 'bn.js'; - -export enum LangError { - couldNotReadInput = 'CouldNotReadInput' -} - diff --git a/packages/templates/src/templates/typedContracts/flipper/types-returns/flipper.ts b/packages/templates/src/templates/typedContracts/flipper/types-returns/flipper.ts deleted file mode 100644 index 0791057e..00000000 --- a/packages/templates/src/templates/typedContracts/flipper/types-returns/flipper.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type BN from 'bn.js'; -import type {ReturnNumber} from '@727-ventures/typechain-types'; - -export enum LangError { - couldNotReadInput = 'CouldNotReadInput' -} -