Skip to content

Commit d5c1066

Browse files
authored
[Feat aptos-labs#1813] Make cli work with v3 apis (#217)
* new function for * api version argument * rpc_url argument * remove cached package new function
1 parent 1cf2263 commit d5c1066

File tree

6 files changed

+38
-15
lines changed

6 files changed

+38
-15
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/aptos/src/account/key_rotation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl CliCommand<RotateSummary> for RotateKey {
230230
..self.txn_options.profile_options.profile()?
231231
};
232232

233-
if let Some(url) = self.txn_options.rest_options.url {
233+
if let Some(url) = self.txn_options.rest_options.rpc_url {
234234
profile_config.rest_url = Some(url.into());
235235
}
236236

crates/aptos/src/common/types.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ use std::{
6969
};
7070
use thiserror::Error;
7171
use aptos_crypto::hash::HashValueParseError;
72+
use supra_aptos::ApiVersion;
7273

7374
pub const USER_AGENT: &str = concat!("aptos-cli/", env!("CARGO_PKG_VERSION"));
7475
const US_IN_SECS: u64 = 1_000_000;
@@ -977,7 +978,7 @@ pub struct RestOptions {
977978
///
978979
/// Defaults to the URL in the `default` profile
979980
#[clap(long)]
980-
pub(crate) url: Option<reqwest::Url>,
981+
pub(crate) rpc_url: Option<reqwest::Url>,
981982

982983
/// Connection timeout in seconds, used for the REST endpoint of the fullnode
983984
#[clap(long, default_value_t = DEFAULT_EXPIRATION_SECS, alias = "connection-timeout-s")]
@@ -988,20 +989,23 @@ pub struct RestOptions {
988989
/// environment variable.
989990
#[clap(long, env)]
990991
pub node_api_key: Option<String>,
992+
#[clap(long, default_value_t = ApiVersion::V3)]
993+
pub(crate) api_version: ApiVersion,
991994
}
992995

993996
impl RestOptions {
994997
pub fn new(url: Option<reqwest::Url>, connection_timeout_secs: Option<u64>) -> Self {
995998
RestOptions {
996-
url,
999+
rpc_url: url,
9971000
connection_timeout_secs: connection_timeout_secs.unwrap_or(DEFAULT_EXPIRATION_SECS),
9981001
node_api_key: None,
1002+
api_version: ApiVersion::default(),
9991003
}
10001004
}
10011005

10021006
/// Retrieve the URL from the profile or the command line
10031007
pub fn url(&self, profile: &ProfileOptions) -> CliTypedResult<reqwest::Url> {
1004-
if let Some(ref url) = self.url {
1008+
if let Some(ref url) = self.rpc_url {
10051009
Ok(url.clone())
10061010
} else if let Some(Some(url)) = CliConfig::load_profile(
10071011
profile.profile_name(),

crates/aptos/src/supra_specific.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Copyright (c) Aptos Foundation
2-
// SPDX-License-Identifier: Apache-2.0
1+
// Copyright © Entropy Foundation
32

43
use crate::common::types::{GasOptions, ProfileOptions, RestOptions};
54

@@ -12,9 +11,10 @@ impl From<ProfileOptions> for supra_aptos::ProfileOptions {
1211
impl From<RestOptions> for supra_aptos::RestOptions {
1312
fn from(value: RestOptions) -> Self {
1413
Self {
15-
url: value.url,
14+
rpc_url: value.rpc_url,
1615
connection_timeout_secs: value.connection_timeout_secs,
1716
node_api_key: value.node_api_key,
17+
api_version: value.api_version,
1818
}
1919
}
2020
}

crates/supra/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ rust-version.workspace = true
1313
aptos-types = { workspace = true }
1414
reqwest = { workspace = true }
1515
anyhow = { workspace = true }
16-
async-trait= { workspace = true }
16+
async-trait = { workspace = true }
17+
clap = { workspace = true }

crates/supra/src/lib.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
1-
// Copyright (c) Aptos Foundation
2-
// SPDX-License-Identifier: Apache-2.0
3-
41
// Copyright © Entropy Foundation
52

63
use anyhow::Result;
7-
use async_trait::async_trait;
84
use aptos_types::account_address::AccountAddress;
95
use aptos_types::transaction::TransactionPayload;
6+
use async_trait::async_trait;
7+
use clap::ValueEnum;
8+
use std::fmt::{Display, Formatter};
9+
10+
/// RPC api versions maintained by this module.
11+
#[derive(PartialEq, Eq, Debug, Clone, Copy, Default, ValueEnum)]
12+
pub enum ApiVersion {
13+
V1,
14+
V2,
15+
#[default]
16+
V3,
17+
}
18+
19+
impl Display for ApiVersion {
20+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
21+
match self {
22+
ApiVersion::V1 => write!(f, "v1"),
23+
ApiVersion::V2 => write!(f, "v2"),
24+
ApiVersion::V3 => write!(f, "v3"),
25+
}
26+
}
27+
}
1028

1129
pub struct ProfileOptions {
1230
/// Profile to use from the CLI config
@@ -22,7 +40,7 @@ pub struct RestOptions {
2240
/// URL to a fullnode on the network
2341
///
2442
/// Defaults to the URL in the `default` profile
25-
pub url: Option<reqwest::Url>,
43+
pub rpc_url: Option<reqwest::Url>,
2644

2745
/// Connection timeout in seconds, used for the REST endpoint of the fullnode
2846
pub connection_timeout_secs: u64,
@@ -31,6 +49,7 @@ pub struct RestOptions {
3149
/// as `Authorization: Bearer <key>`. You may also set this with the NODE_API_KEY
3250
/// environment variable.
3351
pub node_api_key: Option<String>,
52+
pub api_version: ApiVersion,
3453
}
3554

3655
pub struct GasOptions {
@@ -74,13 +93,11 @@ pub struct SupraCommandArguments {
7493
pub profile_options: ProfileOptions,
7594
pub rest_options: RestOptions,
7695
pub gas_options: GasOptions,
77-
7896
}
7997

8098
/// Trait required by supra cli for its operation.
8199
#[async_trait]
82100
pub trait SupraCommand {
83-
84101
/// consume self and returns [SupraCommandArguments]
85102
async fn supra_command_arguments(self) -> Result<SupraCommandArguments>;
86103
}

0 commit comments

Comments
 (0)