Skip to content

Commit c14c584

Browse files
committed
feat: enhance storage command functionality and update dependencies
- Added `async_trait` support to multiple storage command implementations (`cat`, `cp`, `ls`, `mv`, `rm`, `stat`, `sync`) to enable asynchronous handling. - Updated `reqwest` dependency in `Cargo.toml` to include `multipart` feature for improved HTTP request capabilities. - Introduced `mime_guess` dependency in `Cargo.lock` for better MIME type handling. - Refactored client binding logic in storage commands to utilize `SignedMessageFactory`, improving message signing consistency.
1 parent 940d869 commit c14c584

12 files changed

Lines changed: 65 additions & 39 deletions

File tree

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.

ipc/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ num-derive = "0.3.3"
4444
num-bigint = { workspace = true }
4545
num-traits = { workspace = true }
4646
openssl = { workspace = true }
47-
reqwest = { workspace = true }
47+
reqwest = { workspace = true, features = ["multipart"] }
4848
serde = { workspace = true }
4949
serde_bytes = "0.11.9"
5050
serde_json = { workspace = true }

ipc/cli/src/commands/storage/bucket.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use fendermint_rpc::{message::GasParams, tx::{BoundClient, TxClient, TxCommit},
1515
use fendermint_vm_message::query::FvmQueryHeight;
1616
use fvm_ipld_encoding::RawBytes;
1717
use fvm_shared::{address::Address, econ::TokenAmount};
18+
use num_traits::Zero;
1819
use std::collections::HashMap;
1920

2021
/// Default gas parameters for bucket transactions

ipc/cli/src/commands/storage/cat.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! Cat command for displaying file contents from storage
55
66
use anyhow::{anyhow, Context, Result};
7+
use async_trait::async_trait;
78
use clap::Args;
89
use std::io::{self, Write};
910
use std::path::PathBuf;
@@ -28,6 +29,7 @@ pub struct CatArgs {
2829

2930
pub struct CatStorage;
3031

32+
#[async_trait]
3133
impl CommandLineHandler for CatStorage {
3234
type Arguments = CatArgs;
3335

ipc/cli/src/commands/storage/cp.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
//! - ipc:// -> ipc:// : Copy between buckets
1010
1111
use anyhow::{anyhow, Context, Result};
12+
use async_trait::async_trait;
1213
use clap::Args;
1314
use fs_err as fs;
1415
use std::collections::HashMap;
1516
use std::path::{Path, PathBuf};
1617

1718
use fendermint_actor_blobs_shared::bytes::B256;
1819
use fendermint_rpc::client::FendermintClient;
19-
use iroh_blobs::Hash;
20+
use fvm_shared::chainid::ChainID;
2021

2122
use crate::commands::storage::{bucket, client::GatewayClient, config::StorageConfig, path};
2223
use crate::{CommandLineHandler, GlobalArguments};
@@ -50,6 +51,7 @@ pub struct CopyArgs {
5051

5152
pub struct CopyStorage;
5253

54+
#[async_trait]
5355
impl CommandLineHandler for CopyStorage {
5456
type Arguments = CopyArgs;
5557

@@ -180,14 +182,9 @@ async fn upload_file(
180182
&config.secret_key_file
181183
)?;
182184

183-
let chain_id = fvm_shared::chainid::ChainID::from(0); // TODO: Get from chain
184-
let bound_client = fendermint_rpc::tx::BoundClientBuilder::new(fm_client)
185-
.secret_key(secret_key)
186-
.chain_id(chain_id)
187-
.build()
188-
.await?;
189-
190-
let mut bound_client = bound_client;
185+
let message_factory =
186+
fendermint_rpc::message::SignedMessageFactory::new_secp256k1(secret_key, 0, ChainID::from(0));
187+
let mut bound_client = fm_client.bind(message_factory);
191188

192189
// Add object to bucket
193190
bucket::add_object(
@@ -323,8 +320,8 @@ async fn download_file(
323320
/// Download a directory recursively (list objects with prefix)
324321
async fn download_directory(
325322
storage_base: &path::StoragePath,
326-
local_dir: &Path,
327-
args: &CopyArgs,
323+
_local_dir: &Path,
324+
_args: &CopyArgs,
328325
) -> Result<()> {
329326
println!("Downloading directory {} recursively...", storage_base.to_uri());
330327

ipc/cli/src/commands/storage/init.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ impl CommandLineHandler for InitStorage {
9191
objects_listen_addr: "127.0.0.1:8080".to_string(),
9292
iroh_gateway_path: storage_dir.join("iroh-gateway"),
9393
iroh_gateway_v4_addr: Some("0.0.0.0:11205".to_string()),
94+
gateway_url: None,
9495
};
9596

9697
storage_cfg

ipc/cli/src/commands/storage/ls.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! List command for storage operations
55
66
use anyhow::{anyhow, Context, Result};
7+
use async_trait::async_trait;
78
use clap::Args;
89
use std::path::PathBuf;
910

@@ -42,6 +43,7 @@ pub struct ListArgs {
4243

4344
pub struct ListStorage;
4445

46+
#[async_trait]
4547
impl CommandLineHandler for ListStorage {
4648
type Arguments = ListArgs;
4749

@@ -133,7 +135,7 @@ fn print_json(
133135

134136
fn print_table(
135137
result: &fendermint_actor_bucket::ListObjectsReturn,
136-
prefix: &Option<String>,
138+
_prefix: &Option<String>,
137139
long: bool,
138140
) -> Result<()> {
139141
if result.objects.is_empty() && result.common_prefixes.is_empty() {

ipc/cli/src/commands/storage/mv.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
//! Move/rename command for storage objects
55
66
use anyhow::{anyhow, Context, Result};
7+
use async_trait::async_trait;
78
use clap::Args;
89
use std::path::PathBuf;
910

1011
use fendermint_actor_blobs_shared::bytes::B256;
1112
use fendermint_rpc::client::FendermintClient;
13+
use fvm_shared::chainid::ChainID;
1214

1315
use crate::commands::storage::{bucket, config::StorageConfig, path};
1416
use crate::{CommandLineHandler, GlobalArguments};
@@ -30,6 +32,7 @@ pub struct MoveArgs {
3032

3133
pub struct MoveStorage;
3234

35+
#[async_trait]
3336
impl CommandLineHandler for MoveStorage {
3437
type Arguments = MoveArgs;
3538

@@ -83,14 +86,12 @@ impl CommandLineHandler for MoveStorage {
8386
&config.secret_key_file
8487
)?;
8588

86-
let chain_id = fvm_shared::chainid::ChainID::from(0); // TODO: Get from chain
87-
let bound_client = fendermint_rpc::tx::BoundClientBuilder::new(fm_client)
88-
.secret_key(secret_key)
89-
.chain_id(chain_id)
90-
.build()
91-
.await?;
92-
93-
let mut bound_client = bound_client;
89+
let message_factory = fendermint_rpc::message::SignedMessageFactory::new_secp256k1(
90+
secret_key,
91+
0,
92+
ChainID::from(0),
93+
);
94+
let mut bound_client = fm_client.bind(message_factory);
9495

9596
// If moving within the same bucket, we can reuse the blob hash
9697
if source_path.bucket_address == dest_path.bucket_address {

ipc/cli/src/commands/storage/rm.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
//! Remove command for deleting objects from storage
55
66
use anyhow::{anyhow, Context, Result};
7+
use async_trait::async_trait;
78
use clap::Args;
89
use std::io::{self, Write};
910
use std::path::PathBuf;
1011

1112
use fendermint_rpc::client::FendermintClient;
13+
use fvm_shared::chainid::ChainID;
1214

1315
use crate::commands::storage::{bucket, config::StorageConfig, path};
1416
use crate::{CommandLineHandler, GlobalArguments};
@@ -34,6 +36,7 @@ pub struct RemoveArgs {
3436

3537
pub struct RemoveStorage;
3638

39+
#[async_trait]
3740
impl CommandLineHandler for RemoveStorage {
3841
type Arguments = RemoveArgs;
3942

@@ -96,14 +99,9 @@ async fn delete_file(storage_path: &path::StoragePath, args: &RemoveArgs) -> Res
9699
&config.secret_key_file
97100
)?;
98101

99-
let chain_id = fvm_shared::chainid::ChainID::from(0); // TODO: Get from chain
100-
let bound_client = fendermint_rpc::tx::BoundClientBuilder::new(fm_client)
101-
.secret_key(secret_key)
102-
.chain_id(chain_id)
103-
.build()
104-
.await?;
105-
106-
let mut bound_client = bound_client;
102+
let message_factory =
103+
fendermint_rpc::message::SignedMessageFactory::new_secp256k1(secret_key, 0, ChainID::from(0));
104+
let mut bound_client = fm_client.bind(message_factory);
107105

108106
// Delete object
109107
println!("Deleting {}...", storage_path.key);
@@ -185,14 +183,9 @@ async fn delete_recursive(storage_path: &path::StoragePath, args: &RemoveArgs) -
185183
&config.secret_key_file
186184
)?;
187185

188-
let chain_id = fvm_shared::chainid::ChainID::from(0);
189-
let bound_client = fendermint_rpc::tx::BoundClientBuilder::new(fm_client.clone())
190-
.secret_key(secret_key)
191-
.chain_id(chain_id)
192-
.build()
193-
.await?;
194-
195-
let mut bound_client = bound_client;
186+
let message_factory =
187+
fendermint_rpc::message::SignedMessageFactory::new_secp256k1(secret_key, 0, ChainID::from(0));
188+
let mut bound_client = fm_client.clone().bind(message_factory);
196189

197190
for (key, _) in &list_result.objects {
198191
let key_str = String::from_utf8_lossy(key).to_string();

ipc/cli/src/commands/storage/stat.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! Stat command for displaying object metadata from storage
55
66
use anyhow::{anyhow, Context, Result};
7+
use async_trait::async_trait;
78
use clap::Args;
89
use std::path::PathBuf;
910

@@ -30,6 +31,7 @@ pub struct StatArgs {
3031

3132
pub struct StatStorage;
3233

34+
#[async_trait]
3335
impl CommandLineHandler for StatStorage {
3436
type Arguments = StatArgs;
3537

0 commit comments

Comments
 (0)