Skip to content

Commit

Permalink
Merge 6cd4bbe into 3a9c7f7
Browse files Browse the repository at this point in the history
  • Loading branch information
FroVolod authored Jun 26, 2021
2 parents 3a9c7f7 + 6cd4bbe commit ddc7172
Show file tree
Hide file tree
Showing 10 changed files with 319 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Get the release version from the tag
# if: env.NEAR_CLI_VERSION == ''
run: |
echo "NEAR_CLI_VERSION=0.1.5" >> $GITHUB_ENV
echo "NEAR_CLI_VERSION=0.1.6" >> $GITHUB_ENV
echo "version is: ${{ env.NEAR_CLI_VERSION }}"
- name: Create GitHub release
Expand Down
23 changes: 22 additions & 1 deletion docs/GUIDE.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Before proceeding to the description of specific commands, it is necessary to co

* _recent block hash_

Information for this parameter should be found [here](https://explorer.testnet.near.org/blocks).
Information for this parameter should be found [here](https://explorer.testnet.near.org/blocks) or will need to be obtained using [View recent block hash](#view-recent-block-hash).

<details><summary><i>recent block hash</i></summary>
<img src="media/blocks.png" width="836"/>
Expand Down Expand Up @@ -368,6 +368,27 @@ current nonce: 168 for a public key: ed25519:7FmDRADa1v4BcLiiR9MPPdmWQp3Um1iPdA
</a>
</details>

#### View recent block hash

To view the _recent block hash_ for network, type the following in the terminal command line:
```txt
./near-cli view recent-block-hash \
network testnet
```

<details><summary><i>The result of this command will be as follows:</i></summary>

```txt
recent block hash: `CDgRvkv2qv2c8e5m2WDKFUFqAtXrq2fiUteM6XHpy58t`
```
</details>

<details><summary><i>Demonstration of the command in interactive mode</i></summary>
<a href="https://asciinema.org/a/vF2X1zKIMg2rdByGCKHDIYDKa?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/vF2X1zKIMg2rdByGCKHDIYDKa.png" width="836"/>
</a>
</details>


### Transfer tokens

Expand Down
23 changes: 22 additions & 1 deletion docs/GUIDE.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

* _recent block hash_

Информацию для этого параметра нужно искать [здесь](https://explorer.testnet.near.org/blocks).
Информацию для этого параметра нужно искать [здесь](https://explorer.testnet.near.org/blocks) либо получить при помощи [View recent block hash](#view-recent-block-hash)

<details><summary><i>recent block hash</i></summary>
<img src="media/blocks.png" width="836"/>
Expand Down Expand Up @@ -367,6 +367,27 @@ current nonce: 168 for a public key: ed25519:7FmDRADa1v4BcLiiR9MPPdmWQp3Um1iPdA
</a>
</details>

#### View recent block hash

Для просмотра _recent block hash_ выбранной сети необходимо ввести в командной строке терминала:
```txt
./near-cli view recent-block-hash \
network testnet
```

<details><summary><i>Результат выполнения команды</i></summary>

```txt
recent block hash: `CDgRvkv2qv2c8e5m2WDKFUFqAtXrq2fiUteM6XHpy58t`
```
</details>

<details><summary><i>Демонстрация работы команды в интерактивном режиме</i></summary>
<a href="https://asciinema.org/a/vF2X1zKIMg2rdByGCKHDIYDKa?autoplay=1&t=1&speed=2">
<img src="https://asciinema.org/a/vF2X1zKIMg2rdByGCKHDIYDKa.png" width="836"/>
</a>
</details>


### Transfer tokens

Expand Down
4 changes: 2 additions & 2 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub enum CliTopLevelCommand {
Transfer(self::transfer_command::CliCurrency),
/// Helpers
Utils(self::utils_command::CliUtils),
/// View account, contract code, contract state, transaction
/// View account, contract code, contract state, transaction, nonce, recent block hash
View(self::view_command::CliViewQueryRequest),
}

Expand All @@ -39,7 +39,7 @@ pub enum TopLevelCommand {
#[strum_discriminants(strum(message = "Login with wallet authorization"))]
Login(self::login::operation_mode::OperationMode),
#[strum_discriminants(strum(
message = "View account, contract code, contract state, transaction, nonce"
message = "View account, contract code, contract state, transaction, nonce, recent block hash"
))]
View(self::view_command::ViewQueryRequest),
#[strum_discriminants(strum(message = "Transfer tokens"))]
Expand Down
10 changes: 10 additions & 0 deletions src/commands/view_command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod view_account;
mod view_contract_code;
mod view_contract_state;
mod view_nonce;
mod view_recent_block_hash;
mod view_transaction_status;

/// инструмент выбора to view
Expand Down Expand Up @@ -52,6 +53,8 @@ pub enum CliQueryRequest {
Transaction(self::view_transaction_status::operation_mode::CliOperationMode),
/// View a nonce for a public key
Nonce(self::view_nonce::operation_mode::CliOperationMode),
/// View recent block hash for this network
RecentBlockHash(self::view_recent_block_hash::operation_mode::CliOperationMode)
}

#[derive(Debug, EnumDiscriminants)]
Expand All @@ -67,6 +70,8 @@ pub enum QueryRequest {
Transaction(self::view_transaction_status::operation_mode::OperationMode),
#[strum_discriminants(strum(message = "View a nonce for a public key"))]
Nonce(self::view_nonce::operation_mode::OperationMode),
#[strum_discriminants(strum(message = "View recent block hash for this network"))]
RecentBlockHash(self::view_recent_block_hash::operation_mode::OperationMode),
}

impl From<CliQueryRequest> for QueryRequest {
Expand All @@ -87,6 +92,9 @@ impl From<CliQueryRequest> for QueryRequest {
CliQueryRequest::Nonce(cli_operation_mode) => {
QueryRequest::Nonce(cli_operation_mode.into())
}
CliQueryRequest::RecentBlockHash(cli_operation_mode) => {
QueryRequest::RecentBlockHash(cli_operation_mode.into())
}
}
}
}
Expand Down Expand Up @@ -119,6 +127,7 @@ impl QueryRequest {
CliQueryRequest::Transaction(Default::default())
}
QueryRequestDiscriminants::Nonce => CliQueryRequest::Nonce(Default::default()),
QueryRequestDiscriminants::RecentBlockHash => CliQueryRequest::RecentBlockHash(Default::default()),
};
Self::from(cli_request)
}
Expand All @@ -130,6 +139,7 @@ impl QueryRequest {
QueryRequest::ContractState(operation_mode) => operation_mode.process().await,
QueryRequest::Transaction(operation_mode) => operation_mode.process().await,
QueryRequest::Nonce(operation_mode) => operation_mode.process().await,
QueryRequest::RecentBlockHash(operation_mode) => operation_mode.process().await,
}
}
}
1 change: 1 addition & 0 deletions src/commands/view_command/view_recent_block_hash/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod operation_mode;
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use strum::{EnumDiscriminants, EnumIter, EnumMessage};

pub mod online_mode;

/// инструмент выбора режима online/offline
#[derive(Debug, Default, clap::Clap)]
#[clap(
setting(clap::AppSettings::ColoredHelp),
setting(clap::AppSettings::DisableHelpSubcommand),
setting(clap::AppSettings::VersionlessSubcommands)
)]
pub struct CliOperationMode {
#[clap(subcommand)]
mode: Option<CliMode>,
}

#[derive(Debug)]
pub struct OperationMode {
pub mode: Mode,
}

impl From<CliOperationMode> for OperationMode {
fn from(item: CliOperationMode) -> Self {
let mode = match item.mode {
Some(cli_mode) => Mode::from(cli_mode),
None => Mode::choose_mode(),
};
Self { mode }
}
}

impl OperationMode {
pub async fn process(self) -> crate::CliResult {
self.mode.process().await
}
}

#[derive(Debug, clap::Clap)]
pub enum CliMode {
/// Execute a change method with online mode
Network(self::online_mode::CliNetworkArgs),
}

#[derive(Debug, EnumDiscriminants)]
#[strum_discriminants(derive(EnumMessage, EnumIter))]
pub enum Mode {
#[strum_discriminants(strum(message = "Yes, I keep it simple"))]
Network(self::online_mode::NetworkArgs),
}

impl From<CliMode> for Mode {
fn from(item: CliMode) -> Self {
match item {
CliMode::Network(cli_network_args) => Self::Network(cli_network_args.into()),
}
}
}

impl Mode {
pub fn choose_mode() -> Self {
Self::from(CliMode::Network(Default::default()))
}

pub async fn process(self) -> crate::CliResult {
match self {
Self::Network(network_args) => network_args.process().await,
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
pub mod select_server;

/// аргументы, необходимые для создания транзакции в online mode
#[derive(Debug, Default, clap::Clap)]
#[clap(
setting(clap::AppSettings::ColoredHelp),
setting(clap::AppSettings::DisableHelpSubcommand),
setting(clap::AppSettings::VersionlessSubcommands)
)]
pub struct CliNetworkArgs {
#[clap(subcommand)]
selected_server: Option<self::select_server::CliSelectServer>,
}

#[derive(Debug)]
pub struct NetworkArgs {
selected_server: self::select_server::SelectServer,
}

impl From<CliNetworkArgs> for NetworkArgs {
fn from(item: CliNetworkArgs) -> Self {
let selected_server = match item.selected_server {
Some(cli_selected_server) => {
self::select_server::SelectServer::from(cli_selected_server)
}
None => self::select_server::SelectServer::choose_server(),
};
Self { selected_server }
}
}

impl NetworkArgs {
pub async fn process(self) -> crate::CliResult {
self.selected_server.process().await
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use dialoguer::{theme::ColorfulTheme, Select};
use strum::{EnumDiscriminants, EnumIter, EnumMessage, IntoEnumIterator};

pub mod server;

#[derive(Debug, clap::Clap)]
pub enum CliSelectServer {
/// предоставление данных для сервера https://rpc.testnet.near.org
Testnet(self::server::CliServer),
/// предоставление данных для сервера https://rpc.mainnet.near.org
Mainnet(self::server::CliServer),
/// предоставление данных для сервера https://rpc.betanet.near.org
Betanet(self::server::CliServer),
/// предоставление данных для сервера, указанного вручную
Custom(self::server::CliCustomServer),
}

#[derive(Debug, EnumDiscriminants)]
#[strum_discriminants(derive(EnumMessage, EnumIter))]
pub enum SelectServer {
#[strum_discriminants(strum(message = "Testnet"))]
Testnet(self::server::Server),
#[strum_discriminants(strum(message = "Mainnet"))]
Mainnet(self::server::Server),
#[strum_discriminants(strum(message = "Betanet"))]
Betanet(self::server::Server),
#[strum_discriminants(strum(message = "Custom"))]
Custom(self::server::Server),
}

impl From<CliSelectServer> for SelectServer {
fn from(item: CliSelectServer) -> Self {
match item {
CliSelectServer::Testnet(cli_server) => {
Self::Testnet(cli_server.into_server(crate::common::ConnectionConfig::Testnet))
}
CliSelectServer::Mainnet(cli_server) => {
Self::Mainnet(cli_server.into_server(crate::common::ConnectionConfig::Mainnet))
}
CliSelectServer::Betanet(cli_server) => {
Self::Betanet(cli_server.into_server(crate::common::ConnectionConfig::Betanet))
}
CliSelectServer::Custom(cli_custom_server) => {
Self::Custom(cli_custom_server.into_server())
}
}
}
}

impl SelectServer {
pub fn choose_server() -> Self {
println!();
let variants = SelectServerDiscriminants::iter().collect::<Vec<_>>();
let servers = variants
.iter()
.map(|p| p.get_message().unwrap().to_owned())
.collect::<Vec<_>>();
let selected_server = Select::with_theme(&ColorfulTheme::default())
.with_prompt("Select NEAR protocol RPC server:")
.items(&servers)
.default(0)
.interact()
.unwrap();
let cli_select_server = match variants[selected_server] {
SelectServerDiscriminants::Testnet => CliSelectServer::Testnet(Default::default()),
SelectServerDiscriminants::Mainnet => CliSelectServer::Mainnet(Default::default()),
SelectServerDiscriminants::Betanet => CliSelectServer::Betanet(Default::default()),
SelectServerDiscriminants::Custom => CliSelectServer::Custom(Default::default()),
};
Self::from(cli_select_server)
}

pub async fn process(self) -> crate::CliResult {
Ok(match self {
SelectServer::Testnet(server) => {
server.process().await?;
}
SelectServer::Mainnet(server) => {
server.process().await?;
}
SelectServer::Betanet(server) => {
server.process().await?;
}
SelectServer::Custom(server) => {
server.process().await?;
}
})
}
}
Loading

0 comments on commit ddc7172

Please sign in to comment.