-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #558 from tonlabs/cli-as-module
cli as module
- Loading branch information
Showing
5 changed files
with
164 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#!/usr/bin/env node | ||
|
||
import { program } from "commander" | ||
import { TonClient } from "@eversdk/core" | ||
import { libNode } from "@eversdk/lib-node" | ||
import { toString as qrcode } from "qrcode" | ||
import { promisify } from "util" | ||
import dotenv from "dotenv" | ||
|
||
import { myParseInt, getEnv } from "./utils" | ||
import { graphql } from "./graphql" | ||
import { kamikadze } from "./kamikadze" | ||
import { | ||
touch, | ||
DEFAULT_TOUCH_MAX_BALANCE, | ||
DEFAULT_TOUCH_TRY_COUNT, | ||
DEFAULT_TOUCH_TRY_SLEEP, | ||
} from "./touch" | ||
import { compile } from "./compile" | ||
import { DEFAULT_TOPUP_BALANCE, deploy } from "./giver" | ||
|
||
dotenv.config() | ||
|
||
TonClient.useBinaryLibrary(libNode) | ||
|
||
program | ||
.name("evercloud") | ||
.description("Evercloud CLI") | ||
.version(getEnv("npm_package_version") as string) | ||
|
||
program.option("-d, --debug", "Output debug information (time)") | ||
|
||
program | ||
.command("compile") | ||
.alias("c") | ||
.argument("<string>", "Path to Contract source file (.sol)") | ||
.description( | ||
"Compile contract, wrap it into js, generate d.ts (depends on `npx` tool, should be in PATH)", | ||
) | ||
.action(compile) | ||
|
||
program.command("deploy").alias("d").description("Deploy giver").action(deploy) | ||
|
||
program | ||
.command("graphql") | ||
.alias("q") | ||
.argument("<string>", "query text (also can be subscription or mutation)") | ||
.description("Sending a query to a GraphQL endpoint.") | ||
.option( | ||
"-c, --count <number>", | ||
"Specify the number of events to wait.", | ||
myParseInt, | ||
0, | ||
) | ||
.action(graphql) | ||
|
||
program | ||
.command("kamikadze") | ||
.alias("k") | ||
.description( | ||
"Run the Kamikaze contract, which triggers the self-destruct process by calling the `sendAllMoney` function.", | ||
) | ||
.option( | ||
"-v, --value <number>", | ||
"Top up the Kamikaze contract before deploying it in nanotokens.", | ||
myParseInt, | ||
DEFAULT_TOPUP_BALANCE, | ||
) | ||
.action(kamikadze) | ||
|
||
program | ||
.command("qrcode") | ||
.alias("qr") | ||
.argument("<string>") | ||
.description( | ||
"Generate a QR code using the provided text argument and output it to the console.", | ||
) | ||
.action(async req => { | ||
console.log(await promisify(qrcode)(req)) | ||
}) | ||
|
||
program | ||
.command("touch") | ||
.alias("t") | ||
.description( | ||
"Run the Touch contract, which increases local state variable timestamp.", | ||
) | ||
.option( | ||
"-v, --value <number>", | ||
"Top up the Touch contract before deploying it in nanotokens.", | ||
myParseInt, | ||
DEFAULT_TOUCH_MAX_BALANCE, | ||
) | ||
.option( | ||
"-c, --try-count <number>", | ||
"If the GraphQL response does not contain a valid value, retry the request a maximum of `tryCount` times.", | ||
myParseInt, | ||
DEFAULT_TOUCH_TRY_COUNT, | ||
) | ||
.option( | ||
"-s, --try-sleep <number>", | ||
"If the GraphQL response does not contain a valid value, sleep for `trySleep` milisecodes before next try.", | ||
myParseInt, | ||
DEFAULT_TOUCH_TRY_SLEEP, | ||
) | ||
.action(touch) | ||
|
||
program.addHelpText( | ||
"after", | ||
` | ||
Examples: | ||
$ evercloud c ./contracts/Kamikadze.sol | ||
$ evercloud q "query{blockchain{blocks(last:1 workchain:-1){edges{node{seq_no hash}}}}}" | ||
$ evercloud q "subscription{blocks(filter:{workchain_id:{eq:-1}}){seq_no id}}" | ||
$ EVERCLOUD_GIVER_TYPE=v2 TON_NETWORK_ADDRESS=https://devnet.evercloud.dev/<ProjectId> TON_GIVER_ADDRESS=<address> TON_GIVER_SECRET=<privateKey> evercloud k | ||
$ evercloud qr 0:66cb703cd63dd0b9eafbce702a9f838211ba1ea5ccce101dc81b98114d824b8a | ||
$ evercloud t -d | ||
`, | ||
) | ||
|
||
program | ||
.parseAsync(process.argv) | ||
.then(cmd => { | ||
if (cmd.opts().debug) { | ||
console.log(`finished in ${process.uptime().toFixed(2)}s`) | ||
} | ||
process.exit(0) | ||
}) | ||
.catch(error => { | ||
console.dir(error, { showHidden: false, depth: null }) | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,138 +1,6 @@ | ||
#!/usr/bin/env node | ||
|
||
import { program } from "commander" | ||
import { TonClient } from "@eversdk/core" | ||
import { libNode } from "@eversdk/lib-node" | ||
import { toString as qrcode } from "qrcode" | ||
import { promisify } from "util" | ||
import dotenv from "dotenv" | ||
|
||
import { myParseInt, getEnv } from "./utils" | ||
import { graphql } from "./graphql" | ||
import { kamikadze } from "./kamikadze" | ||
import { | ||
touch, | ||
DEFAULT_TOUCH_MAX_BALANCE, | ||
DEFAULT_TOUCH_TRY_COUNT, | ||
DEFAULT_TOUCH_TRY_SLEEP, | ||
} from "./touch" | ||
import { compile } from "./compile" | ||
import { DEFAULT_TOPUP_BALANCE, deploy } from "./giver" | ||
|
||
dotenv.config() | ||
|
||
TonClient.useBinaryLibrary(libNode) | ||
|
||
program | ||
.name("evercloud") | ||
.description("Evercloud CLI") | ||
.version(getEnv("npm_package_version") as string) | ||
|
||
program.option("-d, --debug", "Output debug information (time)") | ||
|
||
program | ||
.command("compile") | ||
.alias("c") | ||
.argument("<string>", "Path to Contract source file (.sol)") | ||
.description( | ||
"Compile contract, wrap it into js, generate d.ts (depends on `npx` tool, should be in PATH)", | ||
) | ||
.action(compile) | ||
|
||
program.command("deploy").alias("d").description("Deploy giver").action(deploy) | ||
|
||
program | ||
.command("graphql") | ||
.alias("q") | ||
.argument("<string>", "query text (also can be subscription or mutation)") | ||
.description("Sending a query to a GraphQL endpoint.") | ||
.option( | ||
"-c, --count <number>", | ||
"Specify the number of events to wait.", | ||
myParseInt, | ||
0, | ||
) | ||
.action(graphql) | ||
|
||
program | ||
.command("kamikadze") | ||
.alias("k") | ||
.description( | ||
"Run the Kamikaze contract, which triggers the self-destruct process by calling the `sendAllMoney` function.", | ||
) | ||
.option( | ||
"-v, --value <number>", | ||
"Top up the Kamikaze contract before deploying it in nanotokens.", | ||
myParseInt, | ||
DEFAULT_TOPUP_BALANCE, | ||
) | ||
.action(kamikadze) | ||
|
||
program | ||
.command("qrcode") | ||
.alias("qr") | ||
.argument("<string>") | ||
.description( | ||
"Generate a QR code using the provided text argument and output it to the console.", | ||
) | ||
.action(async req => { | ||
console.log(await promisify(qrcode)(req)) | ||
}) | ||
|
||
program | ||
.command("touch") | ||
.alias("t") | ||
.description( | ||
"Run the Touch contract, which increases local state variable timestamp.", | ||
) | ||
.option( | ||
"-v, --value <number>", | ||
"Top up the Touch contract before deploying it in nanotokens.", | ||
myParseInt, | ||
DEFAULT_TOUCH_MAX_BALANCE, | ||
) | ||
.option( | ||
"-c, --try-count <number>", | ||
"If the GraphQL response does not contain a valid value, retry the request a maximum of `tryCount` times.", | ||
myParseInt, | ||
DEFAULT_TOUCH_TRY_COUNT, | ||
) | ||
.option( | ||
"-s, --try-sleep <number>", | ||
"If the GraphQL response does not contain a valid value, sleep for `trySleep` milisecodes before next try.", | ||
myParseInt, | ||
DEFAULT_TOUCH_TRY_SLEEP, | ||
) | ||
.action(touch) | ||
|
||
program.addHelpText( | ||
"after", | ||
` | ||
Examples: | ||
$ evercloud c ./contracts/Kamikadze.sol | ||
$ evercloud q "query{blockchain{blocks(last:1 workchain:-1){edges{node{seq_no hash}}}}}" | ||
$ evercloud q "subscription{blocks(filter:{workchain_id:{eq:-1}}){seq_no id}}" | ||
$ EVERCLOUD_GIVER_TYPE=v2 TON_NETWORK_ADDRESS=https://devnet.evercloud.dev/<ProjectId> TON_GIVER_ADDRESS=<address> TON_GIVER_SECRET=<privateKey> evercloud k | ||
$ evercloud qr 0:66cb703cd63dd0b9eafbce702a9f838211ba1ea5ccce101dc81b98114d824b8a | ||
$ evercloud t -d | ||
`, | ||
) | ||
|
||
program | ||
.parseAsync(process.argv) | ||
.then(cmd => { | ||
if (cmd.opts().debug) { | ||
console.log(`finished in ${process.uptime().toFixed(2)}s`) | ||
} | ||
process.exit(0) | ||
}) | ||
.catch(error => { | ||
console.dir(error, { showHidden: false, depth: null }) | ||
process.exit(1) | ||
}) | ||
export * from "./compile" | ||
export * from "./giver" | ||
export * from "./graphql" | ||
export * from "./kamikadze" | ||
export * from "./touch" | ||
export * from "./utils" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters