From 9b77f3a75a783b25c84f7f65ae1eb3d3dbbb1061 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 28 Feb 2024 12:00:19 -0500 Subject: [PATCH] fix: use async_trait --- Cargo.lock | 1 + Cargo.toml | 1 + cmd/soroban-cli/Cargo.toml | 14 +++++++------- .../src/commands/contract/deploy/asset.rs | 2 ++ .../src/commands/contract/deploy/wasm.rs | 1 + cmd/soroban-cli/src/commands/contract/extend.rs | 4 +++- cmd/soroban-cli/src/commands/contract/fetch.rs | 1 + cmd/soroban-cli/src/commands/contract/install.rs | 1 + cmd/soroban-cli/src/commands/contract/invoke.rs | 1 + cmd/soroban-cli/src/commands/contract/read.rs | 1 + cmd/soroban-cli/src/commands/contract/restore.rs | 1 + cmd/soroban-cli/src/commands/events.rs | 2 ++ cmd/soroban-cli/src/commands/mod.rs | 6 ++++-- 13 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 167b00c632..b0c5b4b403 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3518,6 +3518,7 @@ version = "20.3.1" dependencies = [ "assert_cmd", "assert_fs", + "async-trait", "base64 0.21.7", "cargo_metadata", "chrono", diff --git a/Cargo.toml b/Cargo.toml index c2f0f3e6d2..aad28acebe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,6 +85,7 @@ sha2 = "0.10.7" ethnum = "1.3.2" hex = "0.4.3" itertools = "0.10.0" +async-trait = "0.1.76" serde-aux = "4.1.2" serde_json = "1.0.82" diff --git a/cmd/soroban-cli/Cargo.toml b/cmd/soroban-cli/Cargo.toml index e20a6458f6..846b4a36aa 100644 --- a/cmd/soroban-cli/Cargo.toml +++ b/cmd/soroban-cli/Cargo.toml @@ -48,13 +48,13 @@ soroban-sdk = { workspace = true } soroban-rpc = { workspace = true } clap = { workspace = true, features = [ - "derive", - "env", - "deprecated", - "string", + "derive", + "env", + "deprecated", + "string", ] } -clap_complete = {workspace = true} - +clap_complete = { workspace = true } +async-trait = { workspace = true } base64 = { workspace = true } thiserror = { workspace = true } serde = { workspace = true, features = ["derive"] } @@ -101,7 +101,7 @@ gix = { version = "0.58.0", default-features = false, features = [ "blocking-http-transport-reqwest-rust-tls", "worktree-mutation", ] } -ureq = {version = "2.9.1", features = ["json"]} +ureq = { version = "2.9.1", features = ["json"] } tempfile = "3.8.1" toml_edit = "0.21.0" diff --git a/cmd/soroban-cli/src/commands/contract/deploy/asset.rs b/cmd/soroban-cli/src/commands/contract/deploy/asset.rs index 8f27ad2820..dbca1940c7 100644 --- a/cmd/soroban-cli/src/commands/contract/deploy/asset.rs +++ b/cmd/soroban-cli/src/commands/contract/deploy/asset.rs @@ -63,6 +63,8 @@ impl Cmd { Ok(()) } } + +#[async_trait::async_trait] impl NetworkRunnable for Cmd { type Error = Error; type Result = String; diff --git a/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs b/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs index 3d0740fcea..bac7fe2f0e 100644 --- a/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs +++ b/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs @@ -101,6 +101,7 @@ impl Cmd { } } +#[async_trait::async_trait] impl NetworkRunnable for Cmd { type Error = Error; type Result = String; diff --git a/cmd/soroban-cli/src/commands/contract/extend.rs b/cmd/soroban-cli/src/commands/contract/extend.rs index 3f5d68f505..bcf8a90d5b 100644 --- a/cmd/soroban-cli/src/commands/contract/extend.rs +++ b/cmd/soroban-cli/src/commands/contract/extend.rs @@ -100,6 +100,8 @@ impl Cmd { res } } + +#[async_trait::async_trait] impl NetworkRunnable for Cmd { type Error = Error; type Result = u32; @@ -108,7 +110,7 @@ impl NetworkRunnable for Cmd { &self, _args: Option<&global::Args>, config: Option<&config::Args>, - ) -> Result { + ) -> Result { let config = config.unwrap_or(&self.config); let network = config.get_network()?; tracing::trace!(?network); diff --git a/cmd/soroban-cli/src/commands/contract/fetch.rs b/cmd/soroban-cli/src/commands/contract/fetch.rs index 9d4a876c1b..eefb1b4b89 100644 --- a/cmd/soroban-cli/src/commands/contract/fetch.rs +++ b/cmd/soroban-cli/src/commands/contract/fetch.rs @@ -129,6 +129,7 @@ impl Cmd { } } +#[async_trait::async_trait] impl NetworkRunnable for Cmd { type Error = Error; type Result = Vec; diff --git a/cmd/soroban-cli/src/commands/contract/install.rs b/cmd/soroban-cli/src/commands/contract/install.rs index f1741d35e4..47a47e1d2f 100644 --- a/cmd/soroban-cli/src/commands/contract/install.rs +++ b/cmd/soroban-cli/src/commands/contract/install.rs @@ -72,6 +72,7 @@ impl Cmd { } } +#[async_trait::async_trait] impl NetworkRunnable for Cmd { type Error = Error; type Result = Hash; diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index b1797fdba7..29637dcbd3 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -283,6 +283,7 @@ impl Cmd { } } +#[async_trait::async_trait] impl NetworkRunnable for Cmd { type Error = Error; type Result = String; diff --git a/cmd/soroban-cli/src/commands/contract/read.rs b/cmd/soroban-cli/src/commands/contract/read.rs index 72195fee38..a7b1d07a8b 100644 --- a/cmd/soroban-cli/src/commands/contract/read.rs +++ b/cmd/soroban-cli/src/commands/contract/read.rs @@ -170,6 +170,7 @@ impl Cmd { } } +#[async_trait::async_trait] impl NetworkRunnable for Cmd { type Error = Error; type Result = FullLedgerEntries; diff --git a/cmd/soroban-cli/src/commands/contract/restore.rs b/cmd/soroban-cli/src/commands/contract/restore.rs index fa51cfe6fa..869d260154 100644 --- a/cmd/soroban-cli/src/commands/contract/restore.rs +++ b/cmd/soroban-cli/src/commands/contract/restore.rs @@ -108,6 +108,7 @@ impl Cmd { } } +#[async_trait::async_trait] impl NetworkRunnable for Cmd { type Error = Error; type Result = u32; diff --git a/cmd/soroban-cli/src/commands/events.rs b/cmd/soroban-cli/src/commands/events.rs index 12ac050101..42145f5bfd 100644 --- a/cmd/soroban-cli/src/commands/events.rs +++ b/cmd/soroban-cli/src/commands/events.rs @@ -204,6 +204,8 @@ impl Cmd { Ok(start) } } + +#[async_trait::async_trait] impl NetworkRunnable for Cmd { type Error = Error; type Result = rpc::GetEventsResponse; diff --git a/cmd/soroban-cli/src/commands/mod.rs b/cmd/soroban-cli/src/commands/mod.rs index bb84dbf3b5..ae3ac3ecb5 100644 --- a/cmd/soroban-cli/src/commands/mod.rs +++ b/cmd/soroban-cli/src/commands/mod.rs @@ -1,5 +1,6 @@ use std::str::FromStr; +use async_trait::async_trait; use clap::{command, error::ErrorKind, CommandFactory, FromArgMatches, Parser}; pub mod completion; @@ -159,13 +160,14 @@ pub enum Error { Network(#[from] network::Error), } +#[async_trait] pub trait NetworkRunnable { type Error; type Result; - fn run_against_rpc_server( + async fn run_against_rpc_server( &self, global_args: Option<&global::Args>, config: Option<&config::Args>, - ) -> impl std::future::Future> + Send; + ) -> Result; }