Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Command Line Interface (CLI) #177

Merged
merged 152 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
5c7f56e
Added better gas estimation for low gas txs
Kayanski Jul 11, 2023
ad23682
formatting
Kayanski Jul 11, 2023
806252f
prototype
Buckram123 Aug 7, 2023
78c5e42
small improvements
Buckram123 Aug 8, 2023
3492e3b
instantiate msg
Buckram123 Aug 8, 2023
f88cec8
Merge remote-tracking branch 'origin/update/gas-estimation' into feat…
Buckram123 Aug 8, 2023
c462420
migrate
Buckram123 Aug 8, 2023
1598180
small refactor
Buckram123 Aug 8, 2023
0b54614
Parse fields
Buckram123 Aug 10, 2023
fd9ca60
small refactor
Buckram123 Aug 11, 2023
ac9fd99
lints
Buckram123 Aug 11, 2023
81e96c1
Set admin and add coins
Buckram123 Aug 14, 2023
16c2552
fix generics as variants
Buckram123 Aug 14, 2023
d07426f
add state_interface to cw_parse
Buckram123 Aug 15, 2023
6093b1b
StateInterface is enough
Buckram123 Aug 15, 2023
682ecfe
parse into Empty
Buckram123 Aug 15, 2023
10d5681
sloppy addons implementation
Buckram123 Aug 15, 2023
272615c
fmt
Buckram123 Aug 15, 2023
202d023
addons
Buckram123 Aug 16, 2023
10a5b57
from_cli for daemon
Buckram123 Aug 16, 2023
f21770b
clean unused dependencies
Buckram123 Aug 16, 2023
e2d25df
move to trait and create custom error
Buckram123 Aug 16, 2023
2ea6567
main cli
Buckram123 Aug 22, 2023
952da12
addonscontext autoimpl for clone
Buckram123 Aug 22, 2023
363c218
Merge branch 'main' into feat/orch-cli
Buckram123 Aug 22, 2023
8a53b5d
add key to keyring
Buckram123 Sep 4, 2023
4234d5f
refactor
Buckram123 Sep 7, 2023
024227c
clean ups
Buckram123 Sep 7, 2023
f480f40
edit comment
Buckram123 Sep 7, 2023
b071d89
no need to confirm
Buckram123 Sep 7, 2023
a409558
messages fix
Buckram123 Sep 7, 2023
0e4e41f
format toml
Buckram123 Sep 7, 2023
a4dac3f
cosmwasm execute
Buckram123 Sep 7, 2023
1a6e378
execute wasm
Buckram123 Sep 8, 2023
1c447b7
finished execute wasm
Buckram123 Sep 8, 2023
6474a19
query method
Buckram123 Sep 8, 2023
8646bb1
fix comment
Buckram123 Sep 8, 2023
0134cf6
instantiate and upload
Buckram123 Sep 15, 2023
a55856b
small renames
Buckram123 Nov 10, 2023
a48f9f8
rename actions as actions
Buckram123 Nov 10, 2023
05d1051
Merge remote-tracking branch 'origin/main' into feat/orch-cli
Buckram123 Nov 10, 2023
63f0f88
taplo fmt
Buckram123 Nov 10, 2023
bf2747e
add chain selector
Buckram123 Nov 17, 2023
6c036ce
transfers
Buckram123 Nov 17, 2023
489e672
get and transfer ownership cw-ownable
Buckram123 Dec 1, 2023
e80fdbf
auto-claim if given receiver
Buckram123 Dec 1, 2023
b690379
accept and renounce ownerships
Buckram123 Dec 1, 2023
fe3f0cc
fix show address
Buckram123 Dec 1, 2023
265101b
disable warning
Buckram123 Dec 1, 2023
ca76028
Change parse_network return type + exposed supported networks
Kayanski Dec 4, 2023
6ea8464
Added env variable for disabling all logs
Kayanski Dec 4, 2023
b1f4416
Modified docs
Kayanski Dec 4, 2023
f5dfd6a
Added granter flag
Kayanski Dec 4, 2023
0fd7029
Stabilized snapshots
Kayanski Dec 7, 2023
e358fc5
Using bTreeMap and better syntax
Kayanski Dec 7, 2023
e9ae2b8
Merge branch 'update/small-updates' into feat/orch-cli
Buckram123 Dec 8, 2023
f76d61c
disable logs message
Buckram123 Dec 8, 2023
72fd346
add comment on disabling log messages
Buckram123 Dec 8, 2023
afe47b6
fix macos keyring
Buckram123 Dec 8, 2023
0a19212
fix coin parse
Buckram123 Dec 8, 2023
9b79c40
rename cw-ownable action
Buckram123 Dec 8, 2023
bdd429e
move cw-ownable
Buckram123 Dec 8, 2023
eedad7c
messages update
Buckram123 Dec 8, 2023
4666f45
raw query
Buckram123 Dec 8, 2023
749856e
Save chain instead of chain-id after locking
Buckram123 Dec 18, 2023
2d41da6
add latest command to the history
Buckram123 Dec 21, 2023
c450f66
Merge remote-tracking branch 'origin/main' into feat/orch-cli
Buckram123 Dec 21, 2023
713771e
fix cosmrs update
Buckram123 Dec 22, 2023
a4f065c
ux improvement and balance queries
Buckram123 Dec 22, 2023
1a295d8
initial readme
Buckram123 Dec 22, 2023
6e58e01
cut out contract cli
Buckram123 Dec 22, 2023
9203aff
move cw-orch-cli upper
Buckram123 Dec 22, 2023
569bbf9
update authors
Buckram123 Dec 22, 2023
c254301
small description
Buckram123 Dec 22, 2023
3d443c0
Fix link
Buckram123 Dec 22, 2023
1454e17
structure Cargo.toml
Buckram123 Dec 29, 2023
3cd7630
remove tonic
Buckram123 Dec 29, 2023
ce90ec2
keys docs
Buckram123 Dec 29, 2023
bac1087
update readme and some prompts
CyberHoward Jan 3, 2024
86eea24
add spaces for emojis
Buckram123 Jan 12, 2024
77799dc
Validate and re-prompt json/base64 if needed
Buckram123 Jan 12, 2024
5254f94
format
Buckram123 Jan 12, 2024
e475548
Merge remote-tracking branch 'origin/main' into feat/orch-cli
Buckram123 Jan 12, 2024
d047e64
Address book in commands
Buckram123 Jan 15, 2024
250315a
Address book sub-commands
Buckram123 Jan 15, 2024
b224f07
format
Buckram123 Jan 15, 2024
2931f32
fix cw-plus deps
Buckram123 Jan 26, 2024
09671bf
Merge remote-tracking branch 'origin/main' into feat/orch-cli
Buckram123 Jan 26, 2024
e9edf73
Merge branch 'buckram/add-abstract-prefix' into feat/orch-cli
Buckram123 Jan 26, 2024
2e7292d
merge fixes
Buckram123 Jan 26, 2024
31a5ffb
cover null query responses
Buckram123 Jan 26, 2024
3779a44
disable back on the first menu
Buckram123 Jan 26, 2024
9932dc6
restrict empty aliases
Buckram123 Jan 26, 2024
b5e33f1
Fix of help messages
Buckram123 Jan 29, 2024
3a670a4
WIP: fetch cw_orch
Buckram123 Feb 9, 2024
ea70a54
Merge remote-tracking branch 'origin' into feat/orch-cli
Buckram123 Feb 9, 2024
87c59e1
cw_orch state fetcher
Buckram123 Feb 9, 2024
51adc2e
formatting of messages
Buckram123 Feb 9, 2024
3d78924
Disable skip of expiration
Buckram123 Feb 9, 2024
74e395d
small optimization
Buckram123 Feb 9, 2024
afcc68c
few fixes
Buckram123 Feb 12, 2024
8f40b90
multiline json
Buckram123 Feb 19, 2024
c49827b
enable logs with verbose flag
Buckram123 Feb 19, 2024
2709233
Save signer and signer selector
Buckram123 Feb 21, 2024
7d76ab0
empty-out file before writing
Buckram123 Feb 21, 2024
e40fa3f
std fs fixes
Buckram123 Feb 22, 2024
1a50604
file management quickfix
Buckram123 Feb 23, 2024
c413359
merge cw orch state option
Buckram123 Mar 4, 2024
f63a038
update readme script
Buckram123 Mar 11, 2024
1d49508
flag to merge cw-orch state
Buckram123 Mar 15, 2024
58f99bb
fix clippy
Buckram123 Mar 15, 2024
b1005fb
Merge remote-tracking branch 'origin/main' into feat/orch-cli
Buckram123 Mar 15, 2024
ae71ced
add file message input
Buckram123 Mar 15, 2024
47d9060
few fixes
Buckram123 Mar 15, 2024
7058a87
readme update
Buckram123 Mar 15, 2024
21aea2c
move contract cli
Buckram123 Mar 15, 2024
17a7a2f
fix readme
Buckram123 Mar 15, 2024
1dd817b
include cw-orch-cli as workspace member
Buckram123 Mar 15, 2024
4ac2ff5
force disable cw-orch state merging for address_book::remove_address
Buckram123 Mar 15, 2024
ada5ecc
Remove msg postfix for a file message type
Buckram123 Mar 15, 2024
bc7971e
clippy
Buckram123 Mar 15, 2024
9bd5df7
bump msrv
Buckram123 Mar 15, 2024
c83ecae
merge-cw-orch-state > source-state-file
Buckram123 Mar 15, 2024
17dc4ea
newline on errors
Buckram123 Mar 15, 2024
4e25af8
Merge remote-tracking branch 'origin/main' into feat/orch-cli
Buckram123 Apr 2, 2024
f1f05f3
Log url of tx
Buckram123 Apr 12, 2024
8d5cc63
add explorer to any address
Buckram123 Apr 12, 2024
5797c26
base64 raw queries
Buckram123 Apr 12, 2024
5079fc2
quick readme fix
Buckram123 Apr 12, 2024
46dc1d4
fix of explorers
Buckram123 Apr 12, 2024
e78168e
Merge remote-tracking branch 'origin/main' into feat/orch-cli
Buckram123 Apr 12, 2024
e37b863
versionbump
Buckram123 Apr 12, 2024
5bb8f7a
Merge remote-tracking branch 'origin' into feat/orch-cli
Buckram123 Jun 20, 2024
4fbe6b7
update to newest cw-orch
Buckram123 Jun 20, 2024
9bf0175
clippy
Buckram123 Jun 20, 2024
7dc6b11
use daemon bank querier for querying balance
Buckram123 Jun 20, 2024
f9b29fa
unused cosmrs
Buckram123 Jun 20, 2024
328a82b
Use Daemon for sending coins
Buckram123 Jun 20, 2024
41782c2
Merge remote-tracking branch 'origin/main' into feat/orch-cli
Buckram123 Jul 19, 2024
2072aa7
post-merge fixes
Buckram123 Jul 19, 2024
9eb20de
new contract queries
Buckram123 Jul 19, 2024
cf7836d
toml format
Buckram123 Jul 22, 2024
4737fc9
Merge remote-tracking branch 'origin/main' into feat/orch-cli
Buckram123 Jul 26, 2024
1379823
Merge remote-tracking branch 'origin/main' into feat/orch-cli
Buckram123 Sep 4, 2024
42c490d
upgrade cw-orch-cli to 0.25 cw-orch
Buckram123 Sep 4, 2024
69c4d80
small formatting
Buckram123 Sep 4, 2024
8689d72
cli doc formatting
Buckram123 Sep 9, 2024
a7730c7
update cosmos action docs
Buckram123 Sep 26, 2024
930b65a
bump interactive clap
Buckram123 Sep 27, 2024
991293f
Merge remote-tracking branch 'origin/main' into feat/orch-cli
Buckram123 Oct 8, 2024
ecca95d
wasm upload fixed
Buckram123 Oct 8, 2024
f7549cd
remove rejected todos
Buckram123 Oct 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ignore:
- "tests"
- "**/examples"
- "**/schema.rs"
- "cw-orch-cli"

# Make comments less noisy
comment:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
## 0.21.2

- Allow cw-orch wasm compilation without features
- Bumped MSRV to 1.74 because of dependency `[email protected]`
- Transaction Response now inspects logs and events to find matching events.

## 0.21.1
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"cw-orch",
"cw-orch-cli",
"cw-orch-daemon",
"cw-orch-interchain",
"packages/cw-orch-core",
Expand Down
45 changes: 45 additions & 0 deletions cw-orch-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[package]
name = "cw-orch-cli"
version = "0.2.4"
authors = ["Buckram <[email protected]>"]
edition.workspace = true
license.workspace = true
repository.workspace = true
description = "Command-line tool for managing Cosmos-based interaction."

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cw-orch = { workspace = true, features = ["daemon"] }

# Logs
pretty_env_logger = { version = "0.5.0" }
async-trait = { version = "0.1" }

# Cosmos
cosmwasm-std = { workspace = true }
cw-utils = "2.0.0"
cw20 = { version = "2.0" }
cw-ownable = { version = "2.0.0" }
cosmrs = { workspace = true, features = ["cosmwasm", "grpc"] }
ibc-chain-registry = { workspace = true }

# Serde
serde_json = { workspace = true }
serde = { workspace = true }
base64 = { version = "0.22.1" }

# Interactive clap
interactive-clap = "0.3.0"
interactive-clap-derive = "0.3.0"
clap = { version = "4.0.18", features = ["derive"] }
color-eyre = { version = "0.6" }
strum = { version = "0.24", features = ["derive"] }
derive_more = "0.99"
shell-words = "1.0.0"
inquire = { version = "0.6", features = ["editor"] }

# Key management
keyring = "2.0.5"
bip32 = { version = "0.5", features = ["mnemonic"] }
rand_core = { version = "0.6", features = ["std"] }
69 changes: 69 additions & 0 deletions cw-orch-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# CosmWasm Orch Command Line Interface (CLI)

The CosmWasm Orch CLI is a tool designed to facilitate the development, deployment, and interaction with CosmWasm smart contracts on Cosmos blockchains. It enables developers to create, test, and manage contracts using the interactive CLI and easily deploy them onto supported Cosmos networks.

## Installation

### Prerequisites

- Rust
- OpenSSL
- Access to keyring

### Cargo

```bash
cargo install cw-orch-cli
```

### Add last command to the shell history (Optional)

If Cw Orch CLI ran in interactive mode it's executed command will **not** be appended to your shell history. This means you will not be able to `arrow up` to get the last command and tweak it to your liking.

To solve this you can add the function below to your `~/.bashrc` or similar.
This function wraps the CLI and appends its executed action to your current shell history, enabling you to retrieve it from the history.

```bash
cw-orch-cli() {
command=$(command cw-orch-cli "$@" | tee /dev/tty | grep 'Your console command' | cut -f2- -d':')
if [ "$command" != "cw-orch-cli" ]
then
history -s cw-orch-cli "$@" # if you still want to be able `arrow up` to the original command
fi
history -s $command
}
```

## Usage

The CLI supports two modes of execution: interactive and non-interactive.

### Interactive mode

In interactive mode the CLI will guide you through complex tasks by reducing the initial command's complexity, and ensuring a more intuitive user experience.

The interactive mode will prompt you for new information when needed as you go through the process of creating, testing, and deploying a contract.

Example:

```bash
cw-orch-cli --verbose
```

### Non-interactive mode

You can utilize the non-interactive mode for scripting, automated operations, and tweaking of the interactive mode's commands. Often you'll find yourself using the interactive mode to get the command you need, and then debug it with the non-interactive mode.

Example:

```bash
cw-orch-cli action uni-6 cw query raw juno1czkm9gq96zwwncxusgzruvpuex4wjf4ak7lms6q698938k529q3shmfl90 raw contract_info
```

### Global optional arguments

- `-v` or `--verbose` - enable verbose mode, this will log actions from cw-orch daemon executions that corresponds to your `RUST_LOG` level
- `-s` or `--source-state-file` - source cw-orch state file(`STATE_FILE` [cw-orch env variable]) to use together with address-book entries (address book have higher priority)
- --deployment-id <DEPLOYMENT_ID> - cw-orch state deployment-id, defaults to "default"

[cw-orch env variable]: ../docs/src/contracts/env-variable.md
35 changes: 35 additions & 0 deletions cw-orch-cli/src/commands/action/asset/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use super::CosmosContext;

use strum::{EnumDiscriminants, EnumIter, EnumMessage};

mod query_cw20;
mod query_native;
mod send_cw20;
mod send_native;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(context = CosmosContext)]
pub struct AssetCommands {
#[interactive_clap(subcommand)]
action: AssetAction,
}

#[derive(Debug, EnumDiscriminants, Clone, interactive_clap::InteractiveClap)]
#[strum_discriminants(derive(EnumMessage, EnumIter))]
#[interactive_clap(context = CosmosContext)]
/// Select asset action
pub enum AssetAction {
/// Native or factory coin send
#[strum_discriminants(strum(message = "Send native coins"))]
SendNative(send_native::SendNativeCommands),
/// Cw20 coin transfer
#[strum_discriminants(strum(message = "Send cw20 coin"))]
SendCw20(send_cw20::Cw20TransferCommands),
/// Native or factory coins query
#[strum_discriminants(strum(message = "Query native coins"))]
QueryNative(query_native::QueryNativeCommands),
/// Cw20 coin query
#[strum_discriminants(strum(message = "Query cw20 coins"))]
QueryCw20(query_cw20::QueryCw20Commands),
// TODO: cw720?
}
50 changes: 50 additions & 0 deletions cw-orch-cli/src/commands/action/asset/query_cw20/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use crate::types::CliAddress;

use super::CosmosContext;

use cw20::BalanceResponse;
use cw_orch::prelude::*;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = CosmosContext)]
#[interactive_clap(output_context = QueryCw20Output)]
pub struct QueryCw20Commands {
/// Cw20 Address or alias from address-book
cw20_address: CliAddress,
/// Address or alias from address-book
address: CliAddress,
}

pub struct QueryCw20Output;

impl QueryCw20Output {
fn from_previous_context(
previous_context: CosmosContext,
scope: &<QueryCw20Commands as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let chain = previous_context.chain;

let cw20_account_id = scope
.cw20_address
.clone()
.account_id(chain.chain_info(), &previous_context.global_config)?;
let cw20_addr = Addr::unchecked(cw20_account_id);

let account_id = scope
.address
.clone()
.account_id(chain.chain_info(), &previous_context.global_config)?;

let daemon = chain.daemon_querier()?;

let balance: BalanceResponse = daemon.query(
&(cw20::Cw20QueryMsg::Balance {
address: account_id.to_string(),
}),
&cw20_addr,
)?;
println!("{}", serde_json::to_string_pretty(&balance)?);

Ok(QueryCw20Output)
}
}
47 changes: 47 additions & 0 deletions cw-orch-cli/src/commands/action/asset/query_native/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use crate::types::{CliAddress, CliSkippable};

use super::CosmosContext;

use cw_orch::prelude::*;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = CosmosContext)]
#[interactive_clap(output_context = QueryNativeOutput)]
pub struct QueryNativeCommands {
/// Input denom or leave empty to query all balances
denom: CliSkippable<String>,
/// Address or alias from address-book
address: CliAddress,
}

pub struct QueryNativeOutput;

impl QueryNativeOutput {
fn from_previous_context(
previous_context: CosmosContext,
scope: &<QueryNativeCommands as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let chain = previous_context.chain;
let denom = scope.denom.0.clone();

let account_id = scope
.address
.clone()
.account_id(chain.chain_info(), &previous_context.global_config)?;
let addr = Addr::unchecked(account_id);

let daemon = chain.daemon_querier()?;

if let Some(denom) = denom {
let balance = daemon.balance(&addr, Some(denom))?.swap_remove(0);
println!("balance: {balance}")
} else {
let balances = daemon.balance(&addr, None)?;
// `cosmwasm_std::Coins` have nice display
let coins = cosmwasm_std::Coins::try_from(balances).unwrap();
println!("balances: {coins}")
}

Ok(QueryNativeOutput)
}
}
66 changes: 66 additions & 0 deletions cw-orch-cli/src/commands/action/asset/send_cw20/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use crate::{
log::LogOutput,
types::{keys::seed_phrase_for_id, CliAddress},
};

use super::CosmosContext;

use cosmwasm_std::Uint128;
use cw_orch::prelude::*;

#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
#[interactive_clap(input_context = CosmosContext)]
#[interactive_clap(output_context = SendCw20Output)]
pub struct Cw20TransferCommands {
/// Cw20 Address or alias from address-book
cw20_address: CliAddress,
/// Cw20 Amount
amount: u128,
/// Recipient address or alias from address-book
to_address: CliAddress,
#[interactive_clap(skip_default_input_arg)]
signer: String,
}

impl Cw20TransferCommands {
fn input_signer(_context: &CosmosContext) -> color_eyre::eyre::Result<Option<String>> {
crate::common::select_signer()
}
}

pub struct SendCw20Output;

impl SendCw20Output {
fn from_previous_context(
previous_context: CosmosContext,
scope: &<Cw20TransferCommands as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let chain = previous_context.chain;

let to_address_account_id = scope
.to_address
.clone()
.account_id(chain.chain_info(), &previous_context.global_config)?;

let cw20_account_id = scope
.cw20_address
.clone()
.account_id(chain.chain_info(), &previous_context.global_config)?;
let cw20_addr = Addr::unchecked(cw20_account_id);

let seed = seed_phrase_for_id(&scope.signer)?;
let daemon = chain.daemon(seed)?;

let resp = daemon.execute(
&cw20::Cw20ExecuteMsg::Transfer {
recipient: to_address_account_id.to_string(),
amount: Uint128::new(scope.amount),
},
&[],
&cw20_addr,
)?;
resp.log(chain.chain_info());

Ok(SendCw20Output)
}
}
Loading
Loading