@cartesi/cli 2.0.0-alpha.3 → 2.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/base.d.ts +14 -0
  2. package/dist/base.d.ts.map +1 -0
  3. package/dist/base.js +77 -0
  4. package/dist/commands/address-book.d.ts +2 -8
  5. package/dist/commands/address-book.d.ts.map +1 -1
  6. package/dist/commands/address-book.js +15 -14
  7. package/dist/commands/build.d.ts +2 -11
  8. package/dist/commands/build.d.ts.map +1 -1
  9. package/dist/commands/build.js +16 -28
  10. package/dist/commands/clean.d.ts +2 -7
  11. package/dist/commands/clean.d.ts.map +1 -1
  12. package/dist/commands/clean.js +9 -10
  13. package/dist/commands/create.d.ts +2 -14
  14. package/dist/commands/create.d.ts.map +1 -1
  15. package/dist/commands/create.js +37 -51
  16. package/dist/commands/deploy/build.d.ts +2 -14
  17. package/dist/commands/deploy/build.d.ts.map +1 -1
  18. package/dist/commands/deploy/build.js +41 -47
  19. package/dist/commands/deploy.d.ts +3 -0
  20. package/dist/commands/deploy.d.ts.map +1 -0
  21. package/dist/commands/{deploy/index.js → deploy.js} +26 -28
  22. package/dist/commands/doctor.d.ts +2 -12
  23. package/dist/commands/doctor.d.ts.map +1 -1
  24. package/dist/commands/doctor.js +83 -90
  25. package/dist/commands/hash.d.ts +2 -9
  26. package/dist/commands/hash.d.ts.map +1 -1
  27. package/dist/commands/hash.js +14 -14
  28. package/dist/commands/run.d.ts +2 -20
  29. package/dist/commands/run.d.ts.map +1 -1
  30. package/dist/commands/run.js +49 -82
  31. package/dist/commands/send/erc20.d.ts +2 -13
  32. package/dist/commands/send/erc20.d.ts.map +1 -1
  33. package/dist/commands/send/erc20.js +55 -52
  34. package/dist/commands/send/erc721.d.ts +2 -13
  35. package/dist/commands/send/erc721.d.ts.map +1 -1
  36. package/dist/commands/send/erc721.js +49 -46
  37. package/dist/commands/send/ether.d.ts +2 -12
  38. package/dist/commands/send/ether.d.ts.map +1 -1
  39. package/dist/commands/send/ether.js +23 -21
  40. package/dist/commands/send/generic.d.ts +2 -14
  41. package/dist/commands/send/generic.d.ts.map +1 -1
  42. package/dist/commands/send/generic.js +91 -97
  43. package/dist/commands/send.d.ts +21 -0
  44. package/dist/commands/send.d.ts.map +1 -0
  45. package/dist/commands/send.js +67 -0
  46. package/dist/commands/shell.d.ts +2 -14
  47. package/dist/commands/shell.d.ts.map +1 -1
  48. package/dist/commands/shell.js +21 -43
  49. package/dist/config.d.ts +1 -1
  50. package/dist/config.js +1 -1
  51. package/dist/index.d.ts +2 -1
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +51 -1
  54. package/dist/node/docker-compose-anvil.yaml +2 -2
  55. package/dist/node/docker-compose-bundler.yaml +1 -1
  56. package/dist/node/docker-compose-database.yaml +1 -1
  57. package/dist/node/docker-compose-espresso.yaml +127 -0
  58. package/dist/node/docker-compose-explorer.yaml +1 -1
  59. package/dist/node/docker-compose-paymaster.yaml +1 -1
  60. package/package.json +8 -27
  61. package/bin/dev.cmd +0 -3
  62. package/bin/dev.js +0 -25
  63. package/bin/run.cmd +0 -3
  64. package/bin/run.js +0 -8
  65. package/dist/baseCommand.d.ts +0 -22
  66. package/dist/baseCommand.d.ts.map +0 -1
  67. package/dist/baseCommand.js +0 -92
  68. package/dist/commands/deploy/index.d.ts +0 -12
  69. package/dist/commands/deploy/index.d.ts.map +0 -1
  70. package/dist/commands/send/index.d.ts +0 -28
  71. package/dist/commands/send/index.d.ts.map +0 -1
  72. package/dist/commands/send/index.js +0 -102
  73. package/dist/flags.d.ts +0 -17
  74. package/dist/flags.d.ts.map +0 -1
  75. package/dist/flags.js +0 -28
  76. package/oclif.manifest.json +0 -876
@@ -1,50 +1,58 @@
1
1
  import input from "@inquirer/input";
2
- import { erc20Abi, isAddress, parseEther, } from "viem";
2
+ import ora from "ora";
3
+ import { erc20Abi, getAddress, isAddress, parseEther, } from "viem";
3
4
  import { erc20PortalAbi, erc20PortalAddress } from "../../contracts.js";
4
- import * as CustomFlags from "../../flags.js";
5
- import { SendBaseCommand } from "./index.js";
6
- class SendERC20 extends SendBaseCommand {
7
- async readToken(publicClient, address) {
8
- const args = { abi: erc20Abi, address };
9
- const symbol = await publicClient.readContract({
10
- ...args,
11
- functionName: "symbol",
12
- });
13
- const name = await publicClient.readContract({
14
- ...args,
15
- functionName: "name",
16
- });
17
- const decimals = await publicClient.readContract({
18
- ...args,
19
- functionName: "decimals",
20
- });
21
- return {
22
- name,
23
- symbol,
24
- decimals,
25
- };
5
+ import { addCommonOptions, connect, getInputApplicationAddress, } from "../send.js";
6
+ const readToken = async (publicClient, address) => {
7
+ const args = { abi: erc20Abi, address };
8
+ const symbol = await publicClient.readContract({
9
+ ...args,
10
+ functionName: "symbol",
11
+ });
12
+ const name = await publicClient.readContract({
13
+ ...args,
14
+ functionName: "name",
15
+ });
16
+ const decimals = await publicClient.readContract({
17
+ ...args,
18
+ functionName: "decimals",
19
+ });
20
+ return {
21
+ name,
22
+ symbol,
23
+ decimals,
24
+ };
25
+ };
26
+ const ercValidator = (publicClient) => async (value) => {
27
+ if (!isAddress(value)) {
28
+ return "Invalid address";
26
29
  }
27
- async send(publicClient, walletClient) {
30
+ try {
31
+ await readToken(publicClient, value);
32
+ }
33
+ catch (e) {
34
+ return "Invalid token";
35
+ }
36
+ return true;
37
+ };
38
+ export const registerErc20Command = (program) => {
39
+ addCommonOptions(program
40
+ .command("erc20")
41
+ .description("Sends ERC-20 deposits to the application, optionally in interactive mode."))
42
+ .option("--token <address>", "token address")
43
+ .option("--amount <number>", "amount to send")
44
+ .action(async (options) => {
45
+ // connect to RPC provider
46
+ const { publicClient, walletClient } = await connect(options);
28
47
  // get dapp address from local node, or ask
29
- const applicationAddress = await super.getApplicationAddress();
30
- const ercValidator = async (value) => {
31
- if (!isAddress(value)) {
32
- return "Invalid address";
33
- }
34
- try {
35
- await this.readToken(publicClient, value);
36
- }
37
- catch (e) {
38
- return "Invalid token";
39
- }
40
- return true;
41
- };
42
- const tokenAddress = this.flags.token ||
43
- (await input({
48
+ const applicationAddress = await getInputApplicationAddress();
49
+ const tokenAddress = options.token && isAddress(options.token)
50
+ ? getAddress(options.token)
51
+ : (await input({
44
52
  message: "Token address",
45
- validate: ercValidator,
53
+ validate: ercValidator(publicClient),
46
54
  }));
47
- const amount = this.flags.amount || (await input({ message: "Amount" }));
55
+ const amount = options.amount || (await input({ message: "Amount" }));
48
56
  const { request } = await publicClient.simulateContract({
49
57
  address: erc20PortalAddress,
50
58
  abi: erc20PortalAbi,
@@ -52,19 +60,14 @@ class SendERC20 extends SendBaseCommand {
52
60
  args: [
53
61
  tokenAddress,
54
62
  applicationAddress,
55
- parseEther(amount),
63
+ parseEther(amount), // XXX: we need to use the token decimals here!
56
64
  "0x",
57
65
  ],
58
66
  account: walletClient.account,
59
67
  });
60
- return walletClient.writeContract(request);
61
- }
62
- }
63
- SendERC20.summary = "Send ERC-20 deposit to the application.";
64
- SendERC20.description = "Sends ERC-20 deposits to the application, optionally in interactive mode.";
65
- SendERC20.flags = {
66
- token: CustomFlags.address({ description: "token address" }),
67
- amount: CustomFlags.number({ description: "amount" }),
68
+ const hash = await walletClient.writeContract(request);
69
+ const progress = ora("Sending input...").start();
70
+ await publicClient.waitForTransactionReceipt({ hash });
71
+ progress.succeed(`Input sent: ${hash}`);
72
+ });
68
73
  };
69
- SendERC20.examples = ["<%= config.bin %> <%= command.id %>"];
70
- export default SendERC20;
@@ -1,14 +1,3 @@
1
- import { Address, PublicClient, WalletClient } from "viem";
2
- import { SendBaseCommand } from "./index.js";
3
- export default class SendERC721 extends SendBaseCommand<typeof SendERC721> {
4
- static summary: string;
5
- static description: string;
6
- static flags: {
7
- token: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<`0x${string}` | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
- tokenId: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<bigint | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
- };
10
- static examples: string[];
11
- private readToken;
12
- send(publicClient: PublicClient, walletClient: WalletClient): Promise<Address>;
13
- }
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const registerErc721Command: (program: Command) => void;
14
3
  //# sourceMappingURL=erc721.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"erc721.d.ts","sourceRoot":"","sources":["../../../src/commands/send/erc721.ts"],"names":[],"mappings":"AACA,OAAO,EACH,OAAO,EAGP,YAAY,EACZ,YAAY,EACf,MAAM,MAAM,CAAC;AAId,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAO7C,MAAM,CAAC,OAAO,OAAO,UAAW,SAAQ,eAAe,CAAC,OAAO,UAAU,CAAC;IACtE,MAAM,CAAC,OAAO,SAA8C;IAE5D,MAAM,CAAC,WAAW,SAC+D;IAEjF,MAAM,CAAC,KAAK;;;MAGV;IAEF,MAAM,CAAC,QAAQ,WAA2C;YAE5C,SAAS;IAmBV,IAAI,CACb,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY,GAC3B,OAAO,CAAC,OAAO,CAAC;CAkDtB"}
1
+ {"version":3,"file":"erc721.d.ts","sourceRoot":"","sources":["../../../src/commands/send/erc721.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAiDtD,eAAO,MAAM,qBAAqB,YAAa,OAAO,SAqDrD,CAAC"}
@@ -1,45 +1,53 @@
1
1
  import input from "@inquirer/input";
2
- import { erc721Abi, isAddress, } from "viem";
2
+ import ora from "ora";
3
+ import { erc721Abi, getAddress, isAddress } from "viem";
3
4
  import { erc721PortalAbi, erc721PortalAddress } from "../../contracts.js";
4
- import * as CustomFlags from "../../flags.js";
5
- import { SendBaseCommand } from "./index.js";
6
- class SendERC721 extends SendBaseCommand {
7
- async readToken(publicClient, address) {
8
- const args = { abi: erc721Abi, address };
9
- const symbol = await publicClient.readContract({
10
- ...args,
11
- functionName: "symbol",
12
- });
13
- const name = await publicClient.readContract({
14
- ...args,
15
- functionName: "name",
16
- });
17
- return {
18
- name,
19
- symbol,
20
- };
5
+ import { addCommonOptions, connect, getInputApplicationAddress, } from "../send.js";
6
+ const readToken = async (publicClient, address) => {
7
+ const args = { abi: erc721Abi, address };
8
+ const symbol = await publicClient.readContract({
9
+ ...args,
10
+ functionName: "symbol",
11
+ });
12
+ const name = await publicClient.readContract({
13
+ ...args,
14
+ functionName: "name",
15
+ });
16
+ return {
17
+ name,
18
+ symbol,
19
+ };
20
+ };
21
+ const ercValidator = (publicClient) => async (value) => {
22
+ if (!isAddress(value)) {
23
+ return "Invalid address";
24
+ }
25
+ try {
26
+ await readToken(publicClient, value);
21
27
  }
22
- async send(publicClient, walletClient) {
28
+ catch (e) {
29
+ return "Invalid token";
30
+ }
31
+ return true;
32
+ };
33
+ export const registerErc721Command = (program) => {
34
+ addCommonOptions(program
35
+ .command("erc721")
36
+ .description("Sends ERC-721 deposits to the application, optionally in interactive mode."))
37
+ .option("--token <address>", "token address")
38
+ .option("--token-id <number>", "token ID")
39
+ .action(async (options) => {
40
+ // connect to RPC provider
41
+ const { publicClient, walletClient } = await connect(options);
23
42
  // get dapp address from local node, or ask
24
- const applicationAddress = await super.getApplicationAddress();
25
- const ercValidator = async (value) => {
26
- if (!isAddress(value)) {
27
- return "Invalid address";
28
- }
29
- try {
30
- await this.readToken(publicClient, value);
31
- }
32
- catch (e) {
33
- return "Invalid token";
34
- }
35
- return true;
36
- };
37
- const token = this.flags.token ||
38
- (await input({
43
+ const applicationAddress = await getInputApplicationAddress();
44
+ const token = options.token && isAddress(options.token)
45
+ ? getAddress(options.token)
46
+ : (await input({
39
47
  message: "Token address",
40
- validate: ercValidator,
48
+ validate: ercValidator(publicClient),
41
49
  }));
42
- const tokenId = this.flags.tokenId ||
50
+ const tokenId = options.tokenId ||
43
51
  (await input({
44
52
  message: "Token ID",
45
53
  validate: (value) => {
@@ -60,14 +68,9 @@ class SendERC721 extends SendBaseCommand {
60
68
  account: walletClient.account,
61
69
  });
62
70
  // XXX: add support for baseLayerData and execLayerData
63
- return walletClient.writeContract(request);
64
- }
65
- }
66
- SendERC721.summary = "Send ERC-721 deposit to the application.";
67
- SendERC721.description = "Sends ERC-721 deposits to the application, optionally in interactive mode.";
68
- SendERC721.flags = {
69
- token: CustomFlags.address({ description: "token address" }),
70
- tokenId: CustomFlags.bigint({ description: "token ID" }),
71
+ const hash = await walletClient.writeContract(request);
72
+ const progress = ora("Sending input...").start();
73
+ await publicClient.waitForTransactionReceipt({ hash });
74
+ progress.succeed(`Input sent: ${hash}`);
75
+ });
71
76
  };
72
- SendERC721.examples = ["<%= config.bin %> <%= command.id %>"];
73
- export default SendERC721;
@@ -1,13 +1,3 @@
1
- import { Address, PublicClient, WalletClient } from "viem";
2
- import { SendBaseCommand } from "./index.js";
3
- export default class SendEther extends SendBaseCommand<typeof SendEther> {
4
- static summary: string;
5
- static description: string;
6
- static flags: {
7
- amount: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<`${number}` | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
- execLayerData: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<`0x${string}`, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
- };
10
- static examples: string[];
11
- send(publicClient: PublicClient, walletClient: WalletClient): Promise<Address>;
12
- }
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const registerEtherCommand: (program: Command) => void;
13
3
  //# sourceMappingURL=ether.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ether.d.ts","sourceRoot":"","sources":["../../../src/commands/send/ether.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAc,YAAY,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAIvE,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,eAAe,CAAC,OAAO,SAAS,CAAC;IACpE,MAAM,CAAC,OAAO,SAA4C;IAE1D,MAAM,CAAC,WAAW,SAC6D;IAE/E,MAAM,CAAC,KAAK;;;MAMV;IAEF,MAAM,CAAC,QAAQ,WAA2C;IAE7C,IAAI,CACb,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY,GAC3B,OAAO,CAAC,OAAO,CAAC;CAkBtB"}
1
+ {"version":3,"file":"ether.d.ts","sourceRoot":"","sources":["../../../src/commands/send/ether.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAWtD,eAAO,MAAM,oBAAoB,YAAa,OAAO,SAqCpD,CAAC"}
@@ -1,32 +1,34 @@
1
1
  import input from "@inquirer/input";
2
- import { parseEther } from "viem";
2
+ import ora from "ora";
3
+ import { isHex, parseEther } from "viem";
3
4
  import { etherPortalAbi, etherPortalAddress } from "../../contracts.js";
4
- import * as CustomFlags from "../../flags.js";
5
- import { SendBaseCommand } from "./index.js";
6
- class SendEther extends SendBaseCommand {
7
- async send(publicClient, walletClient) {
5
+ import { addCommonOptions, connect, getInputApplicationAddress, } from "../send.js";
6
+ export const registerEtherCommand = (program) => {
7
+ addCommonOptions(program
8
+ .command("ether")
9
+ .description("Sends ether deposits to the application, optionally in interactive mode."))
10
+ .option("--amount <number>", "amount, in ETH units")
11
+ .option("--exec-layer-data <hex>", "exec layer data", "0x")
12
+ .action(async (options) => {
13
+ // connect to RPC provider
14
+ const { publicClient, walletClient } = await connect(options);
8
15
  // get dapp address from local node, or ask
9
- const applicationAddress = await super.getApplicationAddress();
10
- const amount = this.flags.amount || (await input({ message: "Amount" }));
16
+ const applicationAddress = await getInputApplicationAddress();
17
+ const amount = options.amount || (await input({ message: "Amount" }));
11
18
  const { request } = await publicClient.simulateContract({
12
19
  address: etherPortalAddress,
13
20
  abi: etherPortalAbi,
14
21
  functionName: "depositEther",
15
- args: [applicationAddress, this.flags.execLayerData],
22
+ args: [
23
+ applicationAddress,
24
+ isHex(options.execLayerData) ? options.execLayerData : "0x", // XXX: validate before this
25
+ ],
16
26
  value: parseEther(amount),
17
27
  account: walletClient.account,
18
28
  });
19
- return walletClient.writeContract(request);
20
- }
21
- }
22
- SendEther.summary = "Send ether deposit to the application.";
23
- SendEther.description = "Sends ether deposits to the application, optionally in interactive mode.";
24
- SendEther.flags = {
25
- amount: CustomFlags.number({ description: "amount, in ETH units" }),
26
- execLayerData: CustomFlags.hex({
27
- description: "exec layer data",
28
- default: "0x",
29
- }),
29
+ const hash = await walletClient.writeContract(request);
30
+ const progress = ora("Sending input...").start();
31
+ await publicClient.waitForTransactionReceipt({ hash });
32
+ progress.succeed(`Input sent: ${hash}`);
33
+ });
30
34
  };
31
- SendEther.examples = ["<%= config.bin %> <%= command.id %>"];
32
- export default SendEther;
@@ -1,15 +1,3 @@
1
- import { Address, PublicClient, WalletClient } from "viem";
2
- import { SendBaseCommand } from "./index.js";
3
- export default class SendGeneric extends SendBaseCommand<typeof SendGeneric> {
4
- static summary: string;
5
- static description: string;
6
- static examples: string[];
7
- static flags: {
8
- input: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
9
- "input-encoding": import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
10
- "input-abi-params": import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
11
- };
12
- protected getInput(): Promise<`0x${string}` | undefined>;
13
- send(publicClient: PublicClient, walletClient: WalletClient): Promise<Address>;
14
- }
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const registerGenericCommand: (program: Command) => void;
15
3
  //# sourceMappingURL=generic.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../../src/commands/send/generic.ts"],"names":[],"mappings":"AACA,OAAO,EACH,OAAO,EACP,YAAY,EACZ,YAAY,EAOf,MAAM,MAAM,CAAC;AAId,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,eAAe,CAAC,OAAO,WAAW,CAAC;IACxE,MAAM,CAAC,OAAO,SAA4C;IAE1D,MAAM,CAAC,WAAW,SAC8D;IAEhF,MAAM,CAAC,QAAQ,WAA2C;IAE1D,MAAM,CAAC,KAAK;;;;MAgBV;cAEc,QAAQ,IAAI,OAAO,CAAC,KAAK,MAAM,EAAE,GAAG,SAAS,CAAC;IA8EjD,IAAI,CACb,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY,GAC3B,OAAO,CAAC,OAAO,CAAC;CAgBtB"}
1
+ {"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../../src/commands/send/generic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,6BAA6B,CAAC;AAoG9D,eAAO,MAAM,sBAAsB,YAAa,OAAO,SAuCtD,CAAC"}
@@ -1,93 +1,103 @@
1
- import { Flags } from "@oclif/core";
1
+ import { Option } from "@commander-js/extra-typings";
2
+ import ora from "ora";
2
3
  import { encodeAbiParameters, getAddress, isAddress, isHex, parseAbiParameters, stringToHex, } from "viem";
3
4
  import { inputBoxAbi, inputBoxAddress } from "../../contracts.js";
4
5
  import { bytesInput } from "../../prompts.js";
5
- import { SendBaseCommand } from "./index.js";
6
- class SendGeneric extends SendBaseCommand {
7
- async getInput() {
8
- const input = this.flags.input;
9
- const encoding = this.flags["input-encoding"];
10
- if (input) {
11
- if (encoding === "hex") {
12
- // validate if is a hex value
13
- if (!isHex(input)) {
14
- throw new Error("input encoded as hex must start with 0x");
15
- }
16
- return input;
6
+ import { addCommonOptions, connect, getInputApplicationAddress, } from "../send.js";
7
+ const getInput = async (options) => {
8
+ const input = options.input;
9
+ const encoding = options.inputEncoding;
10
+ if (input) {
11
+ if (encoding === "hex") {
12
+ // validate if is a hex value
13
+ if (!isHex(input)) {
14
+ throw new Error("input encoded as hex must start with 0x");
17
15
  }
18
- else if (encoding === "string") {
19
- // encode UTF-8 string as hex
20
- return stringToHex(input);
16
+ return input;
17
+ }
18
+ else if (encoding === "string") {
19
+ // encode UTF-8 string as hex
20
+ return stringToHex(input);
21
+ }
22
+ else if (encoding === "abi") {
23
+ const abiParams = options.inputAbiParams;
24
+ if (!abiParams) {
25
+ throw new Error("Undefined input-abi-params");
21
26
  }
22
- else if (encoding === "abi") {
23
- const abiParams = this.flags["input-abi-params"];
24
- if (!abiParams) {
25
- throw new Error("Undefined input-abi-params");
27
+ const abiParameters = parseAbiParameters(abiParams);
28
+ // TODO: decode values
29
+ const values = input.split(",").map((v, index) => {
30
+ if (index >= abiParameters.length) {
31
+ throw new Error(`Too many values, expected ${abiParameters.length} values based on --input-abi-params '${abiParams}', parsing value at index ${index} from input '${input}'`);
26
32
  }
27
- const abiParameters = parseAbiParameters(abiParams);
28
- // TODO: decode values
29
- const values = input.split(",").map((v, index) => {
30
- if (index >= abiParameters.length) {
31
- throw new Error(`Too many values, expected ${abiParameters.length} values based on --input-abi-params '${abiParams}', parsing value at index ${index} from input '${input}'`);
32
- }
33
- const param = abiParameters[index];
34
- switch (param.type) {
35
- case "string":
33
+ const param = abiParameters[index];
34
+ switch (param.type) {
35
+ case "string":
36
+ return v;
37
+ case "bool":
38
+ if (v === "true")
39
+ return true;
40
+ if (v === "false")
41
+ return false;
42
+ throw new Error(`Invalid boolean value: ${v}`);
43
+ case "uint":
44
+ case "uint8":
45
+ case "uint16":
46
+ case "uint32":
47
+ case "uint64":
48
+ case "uint128":
49
+ case "uint256":
50
+ try {
51
+ return BigInt(v);
52
+ }
53
+ catch (e) {
54
+ throw new Error(`Invalid uint value: ${v}`);
55
+ }
56
+ case "bytes":
57
+ if (isHex(v)) {
36
58
  return v;
37
- case "bool":
38
- if (v === "true")
39
- return true;
40
- if (v === "false")
41
- return false;
42
- throw new Error(`Invalid boolean value: ${v}`);
43
- case "uint":
44
- case "uint8":
45
- case "uint16":
46
- case "uint32":
47
- case "uint64":
48
- case "uint128":
49
- case "uint256":
50
- try {
51
- return BigInt(v);
52
- }
53
- catch (e) {
54
- throw new Error(`Invalid uint value: ${v}`);
55
- }
56
- case "bytes":
57
- if (isHex(v)) {
58
- return v;
59
- }
60
- throw new Error(`Invalid bytes value: ${v}`);
61
- case "address":
62
- if (isAddress(v)) {
63
- return getAddress(v);
64
- }
65
- throw new Error(`Invalid address value: ${v}`);
66
- default:
67
- throw new Error(`Unsupported type ${param.type}`);
68
- }
69
- });
70
- if (values.length !== abiParameters.length) {
71
- throw new Error(`Not enough values, expected ${abiParameters.length} values based on --input-abi-params '${abiParams}', parsed ${values.length} values from input '${input}'`);
59
+ }
60
+ throw new Error(`Invalid bytes value: ${v}`);
61
+ case "address":
62
+ if (isAddress(v)) {
63
+ return getAddress(v);
64
+ }
65
+ throw new Error(`Invalid address value: ${v}`);
66
+ default:
67
+ throw new Error(`Unsupported type ${param.type}`);
72
68
  }
73
- return encodeAbiParameters(abiParameters, values);
69
+ });
70
+ if (values.length !== abiParameters.length) {
71
+ throw new Error(`Not enough values, expected ${abiParameters.length} values based on --input-abi-params '${abiParams}', parsed ${values.length} values from input '${input}'`);
72
+ }
73
+ return encodeAbiParameters(abiParameters, values);
74
+ }
75
+ else {
76
+ if (isHex(input)) {
77
+ return input;
74
78
  }
75
79
  else {
76
- if (isHex(input)) {
77
- return input;
78
- }
79
- else {
80
- // encode UTF-8 string as hex
81
- return stringToHex(input);
82
- }
80
+ // encode UTF-8 string as hex
81
+ return stringToHex(input);
83
82
  }
84
83
  }
85
- return undefined;
86
84
  }
87
- async send(publicClient, walletClient) {
85
+ return undefined;
86
+ };
87
+ export const registerGenericCommand = (program) => {
88
+ addCommonOptions(program
89
+ .command("generic")
90
+ .description("Sends generics inputs to the application, optionally in interactive mode."))
91
+ .option("--input <input>", "input payload")
92
+ .addOption(new Option("--input-encoding <input-encoding>", "input encoding").choices(["hex", "string", "abi"]))
93
+ .option("--input-abi-params <input-abi-params>", "input abi params")
94
+ .action(async (options) => {
95
+ // connect to RPC provider
96
+ const { publicClient, walletClient } = await connect(options);
88
97
  // get dapp address from local node, or ask
89
- const applicationAddress = await super.getApplicationAddress();
90
- const payload = (await this.getInput()) || (await bytesInput({ message: "Input" }));
98
+ const applicationAddress = await getInputApplicationAddress();
99
+ const payload = (await getInput(options)) ||
100
+ (await bytesInput({ message: "Input" }));
91
101
  const { request } = await publicClient.simulateContract({
92
102
  address: inputBoxAddress,
93
103
  abi: inputBoxAbi,
@@ -95,25 +105,9 @@ class SendGeneric extends SendBaseCommand {
95
105
  args: [applicationAddress, payload],
96
106
  account: walletClient.account,
97
107
  });
98
- return walletClient.writeContract(request);
99
- }
100
- }
101
- SendGeneric.summary = "Send generic input to the application.";
102
- SendGeneric.description = "Sends generics inputs to the application, optionally in interactive mode.";
103
- SendGeneric.examples = ["<%= config.bin %> <%= command.id %>"];
104
- SendGeneric.flags = {
105
- input: Flags.string({
106
- description: "input payload",
107
- summary: "see input-encoding for definition on how input is parsed",
108
- }),
109
- "input-encoding": Flags.string({
110
- description: "input encoding",
111
- summary: "if input-encoding is undefined, the input is parsed as a hex-string if it starts with 0x or else is parsed as a UTF-8 encoding",
112
- options: ["hex", "string", "abi"],
113
- }),
114
- "input-abi-params": Flags.string({
115
- description: "input abi params",
116
- summary: "ABI params definition for input, following human-readable format specified at https://abitype.dev/api/human.html#parseabiparameters",
117
- }),
108
+ const hash = await walletClient.writeContract(request);
109
+ const progress = ora("Sending input...").start();
110
+ await publicClient.waitForTransactionReceipt({ hash });
111
+ progress.succeed(`Input sent: ${hash}`);
112
+ });
118
113
  };
119
- export default SendGeneric;
@@ -0,0 +1,21 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ import { Address, PublicClient, WalletClient } from "viem";
3
+ export declare const connect: (options: {
4
+ chainId?: number;
5
+ rpcUrl?: string;
6
+ mnemonic?: string;
7
+ mnemonicIndex: number;
8
+ }) => Promise<{
9
+ publicClient: PublicClient;
10
+ walletClient: WalletClient;
11
+ }>;
12
+ export declare const getInputApplicationAddress: (dapp?: string) => Promise<Address>;
13
+ export declare const addCommonOptions: (command: Command) => Command<[], {
14
+ dapp?: string | undefined;
15
+ chainId?: number | undefined;
16
+ rpcUrl?: string | undefined;
17
+ mnemonic?: string | undefined;
18
+ mnemonicIndex: number;
19
+ }, {}>;
20
+ export declare const registerSendCommand: (program: Command) => void;
21
+ //# sourceMappingURL=send.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/commands/send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAGtD,OAAO,EAAE,OAAO,EAAa,YAAY,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAQtE,eAAO,MAAM,OAAO,YAAa;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACzB,KAAG,OAAO,CAAC;IACR,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;CAC9B,CAYA,CAAC;AAEF,eAAO,MAAM,0BAA0B,UAC5B,MAAM,KACd,OAAO,CAAC,OAAO,CAiBjB,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAAa,OAAO;;;;;;MAYhD,CAAC;AAEF,eAAO,MAAM,mBAAmB,YAAa,OAAO,SA+BnD,CAAC"}