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

Add flag to enable interactive prompt in create channel CLI #2014

Merged
merged 29 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
02c35b6
Document CreateChannelCommand
seanchen1991 Mar 24, 2022
6193d1d
Add `new-client-connection` flag to `create channel` command
seanchen1991 Mar 24, 2022
5a9be15
Add new `run` logic for `CreateChannelCommand`
seanchen1991 Mar 24, 2022
7904011
Add dialoguer dependency in order to enable interactive CLI prompts
seanchen1991 Mar 24, 2022
9ac2bb1
Add interactive prompt functionality
seanchen1991 Mar 24, 2022
1b4428a
Remove unnecessary Term::stdout parameter
seanchen1991 Mar 24, 2022
b96c735
Add style to prompts
seanchen1991 Mar 25, 2022
4668dc7
Clean up CreateChannelCommand documentation
seanchen1991 Mar 25, 2022
3a19b77
Fix documentation formatting
seanchen1991 Mar 25, 2022
0ebb59f
Add changelog entry
seanchen1991 Mar 25, 2022
27d9369
Document CreateChannelCommand
seanchen1991 Mar 24, 2022
2642dd8
Add `new-client-connection` flag to `create channel` command
seanchen1991 Mar 25, 2022
514d512
Add new `run` logic for `CreateChannelCommand`
seanchen1991 Mar 24, 2022
cc30c4d
Add dialoguer dependency in order to enable interactive CLI prompts
seanchen1991 Mar 24, 2022
b8faca0
Add interactive prompt functionality
seanchen1991 Mar 24, 2022
d2d20cf
Remove unnecessary Term::stdout parameter
seanchen1991 Mar 24, 2022
6ffb41c
Add style to prompts
seanchen1991 Mar 25, 2022
b3e3259
Clean up CreateChannelCommand documentation
seanchen1991 Mar 25, 2022
419d5e5
Fix documentation formatting
seanchen1991 Mar 25, 2022
b2747e5
Add changelog entry
seanchen1991 Mar 25, 2022
3e0e6d6
Merge branch 'create-channel-cli' of github.com:seanchen1991/ibc-rs i…
seanchen1991 Mar 25, 2022
e095270
Incorporate PR feedback
seanchen1991 Mar 29, 2022
771ad3d
Remove unnecessary attribute cruft and make help messages consistent
seanchen1991 Mar 31, 2022
473b121
Update Hermes guide with the new `create channel` flow
seanchen1991 Mar 31, 2022
610baa5
Remove `_id` suffixes from create channel options
seanchen1991 Apr 4, 2022
01a1f31
Fix inconsistent naming in code and guide
seanchen1991 Apr 5, 2022
381e17c
Remove `-id`s in output messages
seanchen1991 Apr 5, 2022
dd35d59
Make error message a bit clearer
seanchen1991 Apr 6, 2022
536feec
Revert guide changes
seanchen1991 Apr 7, 2022
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
4 changes: 2 additions & 2 deletions guide/src/commands/path-setup/channels.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ POSITIONAL ARGUMENTS:
<CONNECTION_A> Identifier of the connection on chain `a` to use in creating the new channel

FLAGS:
-c, --chain-b-id <CHAIN_B_ID> Identifier of the side `b` chain for the new channel
-c, --chain-b <CHAIN_B_ID> Identifier of the side `b` chain for the new channel
-h, --help Print help information
--new-client-connection Indicates that a new client and connection will be created
underlying the new channel
Expand Down Expand Up @@ -213,7 +213,7 @@ pops up notifying you that a new client and a new connection will be initialized
as part of the process:

```shell
hermes create channel ibc-0 --chain-b-id ibc-1 --port-a transfer --port-b transfer -o unordered --new-client-connection
hermes create channel ibc-0 --chain-b ibc-1 --port-a transfer --port-b transfer -o unordered --new-client-connection
```

```json
Expand Down
26 changes: 12 additions & 14 deletions relayer-cli/src/commands/create/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Runnable for CreateChannelCommand {
fn run(&self) {
match &self.connection_a {
Some(conn) => self.run_reusing_connection(conn),
None => match &self.chain_b_id {
None => match &self.chain_b {
Some(chain_b) => {
if self.new_client_connection {
match Confirm::new()
Expand Down Expand Up @@ -129,26 +129,24 @@ impl Runnable for CreateChannelCommand {
}
} else {
Output::error(
"The `--new-client-connection` flag is required if invoking with `<chain-b-id>`".to_string()
"The `--new-client-connection` flag is required if invoking with `<chain-b>`".to_string()
seanchen1991 marked this conversation as resolved.
Show resolved Hide resolved
)
.exit();
}
}
None => {
Output::error("Missing one of `<chain-b-id>` or `<connection-a>`".to_string())
.exit()
}
None => Output::error("Missing one of `<chain-b>` or `<connection-a>`".to_string())
.exit(),
},
}
}
}

impl CreateChannelCommand {
/// Creates a new channel, as well as a new underlying connection and clients.
fn run_using_new_connection(&self, chain_b_id: &ChainId) {
fn run_using_new_connection(&self, chain_b: &ChainId) {
let config = app_config();

let chains = ChainHandlePair::spawn(&config, &self.chain_a_id, chain_b_id)
let chains = ChainHandlePair::spawn(&config, &self.chain_a, chain_b)
.unwrap_or_else(exit_with_unrecoverable_error);

info!(
Expand Down Expand Up @@ -179,36 +177,36 @@ impl CreateChannelCommand {
}

/// Creates a new channel, reusing an already existing connection and its clients.
fn run_reusing_connection(&self, connection_a_id: &ConnectionId) {
fn run_reusing_connection(&self, connection_a: &ConnectionId) {
let config = app_config();

// Validate & spawn runtime for side a.
let chain_a = spawn_chain_runtime(&config, &self.chain_a_id)
let chain_a = spawn_chain_runtime(&config, &self.chain_a)
.unwrap_or_else(exit_with_unrecoverable_error);

// Query the connection end.
let height = Height::new(chain_a.id().version(), 0);
let conn_end = chain_a
.query_connection(connection_a_id, height)
.query_connection(connection_a, height)
.unwrap_or_else(exit_with_unrecoverable_error);

// Query the client state, obtain the identifier of chain b.
let chain_b_id = chain_a
let chain_b = chain_a
.query_client_state(conn_end.client_id(), height)
.map(|cs| cs.chain_id())
.unwrap_or_else(exit_with_unrecoverable_error);

// Spawn the runtime for side b.
let chain_b =
spawn_chain_runtime(&config, &chain_b_id).unwrap_or_else(exit_with_unrecoverable_error);
spawn_chain_runtime(&config, &chain_b).unwrap_or_else(exit_with_unrecoverable_error);

// Create the foreign client handles.
let client_a = ForeignClient::find(chain_b.clone(), chain_a.clone(), conn_end.client_id())
.unwrap_or_else(exit_with_unrecoverable_error);
let client_b = ForeignClient::find(chain_a, chain_b, conn_end.counterparty().client_id())
.unwrap_or_else(exit_with_unrecoverable_error);

let identified_end = IdentifiedConnectionEnd::new(connection_a_id.clone(), conn_end);
let identified_end = IdentifiedConnectionEnd::new(connection_a.clone(), conn_end);

let connection = Connection::find(client_a, client_b, &identified_end)
.unwrap_or_else(exit_with_unrecoverable_error);
Expand Down