diff --git a/Cargo.lock b/Cargo.lock index e1b410aedf..0834b88f90 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -2425,7 +2425,7 @@ dependencies = [ "log", "multiversx-chain-scenario-format", "multiversx-sc-scenario", - "multiversx-sdk-reqwest", + "multiversx-sdk-http", "serde_json", "tokio", ] @@ -2484,7 +2484,7 @@ dependencies = [ ] [[package]] -name = "multiversx-sdk-reqwest" +name = "multiversx-sdk-http" version = "0.6.1" dependencies = [ "anyhow", diff --git a/Cargo.toml b/Cargo.toml index b4412fb681..f052471768 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ members = [ "framework/wasm-adapter", "sdk/core", - "sdk/reqwest", + "sdk/http", "sdk/wbg", "sdk/scenario-format", diff --git a/framework/snippets/Cargo.toml b/framework/snippets/Cargo.toml index 92237a074e..a3a3011d45 100644 --- a/framework/snippets/Cargo.toml +++ b/framework/snippets/Cargo.toml @@ -29,9 +29,9 @@ path = "../scenario" version = "0.23.0" path = "../../sdk/scenario-format" -[dependencies.multiversx-sdk-reqwest] +[dependencies.multiversx-sdk-http] version = "=0.6.1" -path = "../../sdk/reqwest" +path = "../../sdk/http" [dev-dependencies] serde_json = "1.0" diff --git a/framework/snippets/src/account_tool.rs b/framework/snippets/src/account_tool.rs index 7121d3d613..df51497df8 100644 --- a/framework/snippets/src/account_tool.rs +++ b/framework/snippets/src/account_tool.rs @@ -4,7 +4,7 @@ use multiversx_sc_scenario::{ imports::Bech32Address, scenario_model::{Account, BytesKey, BytesValue, Scenario, SetStateStep, Step}, }; -use multiversx_sdk_reqwest::gateway::GatewayProxy; +use multiversx_sdk_http::GatewayHttpProxy; use std::collections::{BTreeMap, HashMap}; /// Called directly from CLI, from `sc-meta`. @@ -16,7 +16,7 @@ pub async fn print_account_as_scenario_set_state( use_chain_simulator: bool, address_bech32_string: String, ) { - let api = GatewayProxy::new(api_string, use_chain_simulator); + let api = GatewayHttpProxy::new(api_string, use_chain_simulator); let address = Bech32Address::from_bech32_string(address_bech32_string); let set_state = retrieve_account_as_scenario_set_state(&api, &address).await; let scenario = build_scenario(set_state); @@ -33,7 +33,7 @@ fn build_scenario(set_state: SetStateStep) -> Scenario { } pub async fn retrieve_account_as_scenario_set_state( - api: &GatewayProxy, + api: &GatewayHttpProxy, address: &Bech32Address, ) -> SetStateStep { let sdk_address = Address::from_bech32_string(address.to_bech32_str()).unwrap(); diff --git a/framework/snippets/src/interactor.rs b/framework/snippets/src/interactor.rs index 45825284db..bf1b517743 100644 --- a/framework/snippets/src/interactor.rs +++ b/framework/snippets/src/interactor.rs @@ -4,8 +4,7 @@ use multiversx_sc_scenario::{ mandos_system::{run_list::ScenarioRunnerList, run_trace::ScenarioTraceFile}, multiversx_sc::types::Address, }; -// use multiversx_sdk_reqwest::core::{data::network_config::NetworkConfig, wallet::Wallet}; -use multiversx_sdk_reqwest::gateway::GatewayProxy; +use multiversx_sdk_http::GatewayHttpProxy; use std::{ collections::HashMap, path::{Path, PathBuf}, @@ -17,7 +16,7 @@ use crate::{account_tool::retrieve_account_as_scenario_set_state, Sender}; pub const INTERACTOR_SCENARIO_TRACE_PATH: &str = "interactor_trace.scen.json"; pub struct Interactor { - pub proxy: GatewayProxy, + pub proxy: GatewayHttpProxy, pub network_config: NetworkConfig, pub sender_map: HashMap, @@ -30,7 +29,7 @@ pub struct Interactor { impl Interactor { pub async fn new(gateway_uri: &str, use_chain_simulator: bool) -> Self { - let proxy = GatewayProxy::new(gateway_uri.to_string(), use_chain_simulator); + let proxy = GatewayHttpProxy::new(gateway_uri.to_string(), use_chain_simulator); let network_config = proxy.get_network_config().await.unwrap(); Self { proxy, diff --git a/framework/snippets/src/interactor_scenario/interactor_sc_call.rs b/framework/snippets/src/interactor_scenario/interactor_sc_call.rs index 5677fb3ac6..112e5aba0e 100644 --- a/framework/snippets/src/interactor_scenario/interactor_sc_call.rs +++ b/framework/snippets/src/interactor_scenario/interactor_sc_call.rs @@ -5,7 +5,7 @@ use multiversx_sc_scenario::{ scenario::ScenarioRunner, scenario_model::{ScCallStep, SetStateStep, TxCall}, }; -use multiversx_sdk_reqwest::core::{data::transaction::Transaction, utils::base64_encode}; +use multiversx_sdk_http::core::{data::transaction::Transaction, utils::base64_encode}; impl Interactor { pub async fn sc_call(&mut self, mut sc_call_step: S) diff --git a/framework/snippets/src/interactor_scenario/interactor_sc_deploy.rs b/framework/snippets/src/interactor_scenario/interactor_sc_deploy.rs index 68f3427266..331af64752 100644 --- a/framework/snippets/src/interactor_scenario/interactor_sc_deploy.rs +++ b/framework/snippets/src/interactor_scenario/interactor_sc_deploy.rs @@ -5,7 +5,7 @@ use multiversx_sc_scenario::{ mandos_system::ScenarioRunner, scenario_model::{ScDeployStep, SetStateStep}, }; -use multiversx_sdk_reqwest::core::{data::transaction::Transaction, utils::base64_encode}; +use multiversx_sdk_http::core::{data::transaction::Transaction, utils::base64_encode}; impl Interactor { pub(crate) fn sc_deploy_to_blockchain_tx(&self, sc_deploy_step: &ScDeployStep) -> Transaction { diff --git a/framework/snippets/src/interactor_scenario/interactor_vm_query.rs b/framework/snippets/src/interactor_scenario/interactor_vm_query.rs index 81298894b1..e11d753fbb 100644 --- a/framework/snippets/src/interactor_scenario/interactor_vm_query.rs +++ b/framework/snippets/src/interactor_scenario/interactor_vm_query.rs @@ -8,7 +8,7 @@ use multiversx_sc_scenario::{ multiversx_sc::{abi::TypeAbiFrom, codec::TopDecodeMulti, types::ContractCall}, scenario_model::{ScQueryStep, TxResponse}, }; -use multiversx_sdk_reqwest::core::{data::vm::VMQueryInput, utils::base64_decode}; +use multiversx_sdk_http::core::{data::vm::VMQueryInput, utils::base64_decode}; impl Interactor { pub async fn sc_query(&mut self, mut step: S) -> &mut Self diff --git a/framework/snippets/src/lib.rs b/framework/snippets/src/lib.rs index 2c1f37c5e3..d3e51792f2 100644 --- a/framework/snippets/src/lib.rs +++ b/framework/snippets/src/lib.rs @@ -6,7 +6,6 @@ mod interactor_sender; mod interactor_tx; mod multi; pub mod network_response; -// pub mod test_wallets; pub use env_logger; pub use hex; @@ -17,8 +16,8 @@ pub use interactor_tx::*; pub use log; pub use multi::*; pub use multiversx_sc_scenario::{self, multiversx_sc}; -pub use multiversx_sdk_reqwest::core as sdk_core; -pub use multiversx_sdk_reqwest::core as sdk; +pub use multiversx_sdk_http::core as sdk_core; +pub use multiversx_sdk_http::core as sdk; pub use tokio; /// Imports normally needed in interactors, grouped together. diff --git a/sdk/core/src/gateway.rs b/sdk/core/src/gateway.rs index 7b40532231..3730381055 100644 --- a/sdk/core/src/gateway.rs +++ b/sdk/core/src/gateway.rs @@ -57,12 +57,12 @@ pub enum GatewayRequestType { } /// Models requests to the gateway. -pub trait GatewayRequest { +pub trait GatewayRequest: Send { type Payload: serde::ser::Serialize + ?Sized; type DecodedJson: serde::de::DeserializeOwned; - type Result; + type Result: Send; fn request_type(&self) -> GatewayRequestType; @@ -74,3 +74,12 @@ pub trait GatewayRequest { fn process_json(&self, decoded: Self::DecodedJson) -> anyhow::Result; } + +pub trait GatewayAsyncService: Send { + fn request( + &self, + request: G, + ) -> impl std::future::Future> + Send + where + G: GatewayRequest; +} diff --git a/sdk/reqwest/Cargo.toml b/sdk/http/Cargo.toml similarity index 96% rename from sdk/reqwest/Cargo.toml rename to sdk/http/Cargo.toml index 9f9287c173..cb304039a3 100644 --- a/sdk/reqwest/Cargo.toml +++ b/sdk/http/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "multiversx-sdk-reqwest" +name = "multiversx-sdk-http" version = "0.6.1" edition = "2021" diff --git a/sdk/reqwest/README.md b/sdk/http/README.md similarity index 100% rename from sdk/reqwest/README.md rename to sdk/http/README.md diff --git a/sdk/reqwest/examples/account.rs b/sdk/http/examples/account.rs similarity index 62% rename from sdk/reqwest/examples/account.rs rename to sdk/http/examples/account.rs index 99de9b0bd0..c7348cd156 100644 --- a/sdk/reqwest/examples/account.rs +++ b/sdk/http/examples/account.rs @@ -1,5 +1,5 @@ use multiversx_sdk::data::address::Address; -use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; +use multiversx_sdk_http::{GatewayHttpProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; #[tokio::main] async fn main() { @@ -8,7 +8,7 @@ async fn main() { ) .unwrap(); - let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); + let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); let account = blockchain.get_account(&addr).await.unwrap(); println!("account: {account:#?}"); diff --git a/sdk/reqwest/examples/account_storage.rs b/sdk/http/examples/account_storage.rs similarity index 64% rename from sdk/reqwest/examples/account_storage.rs rename to sdk/http/examples/account_storage.rs index 52c69c7e03..e957f59926 100644 --- a/sdk/reqwest/examples/account_storage.rs +++ b/sdk/http/examples/account_storage.rs @@ -1,5 +1,5 @@ use multiversx_sdk::data::address::Address; -use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; +use multiversx_sdk_http::{GatewayHttpProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; #[tokio::main] async fn main() { @@ -8,7 +8,7 @@ async fn main() { ) .unwrap(); - let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); + let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); let account_storage = blockchain.get_account_storage_keys(&addr).await.unwrap(); println!("Account Storage: {account_storage:#?}"); diff --git a/sdk/reqwest/examples/generate_mnemonic.rs b/sdk/http/examples/generate_mnemonic.rs similarity index 100% rename from sdk/reqwest/examples/generate_mnemonic.rs rename to sdk/http/examples/generate_mnemonic.rs diff --git a/sdk/reqwest/examples/get_esdt_tokens.rs b/sdk/http/examples/get_esdt_tokens.rs similarity index 62% rename from sdk/reqwest/examples/get_esdt_tokens.rs rename to sdk/http/examples/get_esdt_tokens.rs index 93fd96a700..97f51132dd 100644 --- a/sdk/reqwest/examples/get_esdt_tokens.rs +++ b/sdk/http/examples/get_esdt_tokens.rs @@ -1,5 +1,5 @@ use multiversx_sdk::data::address::Address; -use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; +use multiversx_sdk_http::{GatewayHttpProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; #[tokio::main] async fn main() { @@ -8,7 +8,7 @@ async fn main() { ) .unwrap(); - let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); + let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); let balances = blockchain.get_account_esdt_tokens(&addr).await.unwrap(); println!("{balances:#?}"); diff --git a/sdk/reqwest/examples/get_hyper_block_by_hash.rs b/sdk/http/examples/get_hyper_block_by_hash.rs similarity index 54% rename from sdk/reqwest/examples/get_hyper_block_by_hash.rs rename to sdk/http/examples/get_hyper_block_by_hash.rs index f4bf399eb3..f4687880d8 100644 --- a/sdk/reqwest/examples/get_hyper_block_by_hash.rs +++ b/sdk/http/examples/get_hyper_block_by_hash.rs @@ -1,8 +1,8 @@ -use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; +use multiversx_sdk_http::{GatewayHttpProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; #[tokio::main] async fn main() { - let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); + let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); let result = blockchain .get_hyper_block_by_hash("d59e0dc7d407b1175655357cb8056ec3bb77961192753cddda2fb700c6ce71c6") .await; diff --git a/sdk/http/examples/get_hyper_block_by_nonce.rs b/sdk/http/examples/get_hyper_block_by_nonce.rs new file mode 100644 index 0000000000..88e08f10bd --- /dev/null +++ b/sdk/http/examples/get_hyper_block_by_nonce.rs @@ -0,0 +1,9 @@ +use multiversx_sdk_http::{GatewayHttpProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; + +#[tokio::main] +async fn main() { + let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); + let result = blockchain.get_hyper_block_by_nonce(7468).await; + + println!("block by nonce result: {result:#?}") +} diff --git a/sdk/http/examples/get_hyper_block_latest.rs b/sdk/http/examples/get_hyper_block_latest.rs new file mode 100644 index 0000000000..c38e528c64 --- /dev/null +++ b/sdk/http/examples/get_hyper_block_latest.rs @@ -0,0 +1,9 @@ +use multiversx_sdk_http::{GatewayHttpProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; + +#[tokio::main] +async fn main() { + let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); + let result = blockchain.get_latest_hyper_block_nonce().await; + + println!("latest block result: {result:?}") +} diff --git a/sdk/http/examples/get_network_config.rs b/sdk/http/examples/get_network_config.rs new file mode 100644 index 0000000000..3e34deb6aa --- /dev/null +++ b/sdk/http/examples/get_network_config.rs @@ -0,0 +1,9 @@ +use multiversx_sdk_http::{GatewayHttpProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; + +#[tokio::main] +async fn main() { + let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); + let network_config = blockchain.get_network_config().await.unwrap(); + + println!("network_config: {network_config:#?}") +} diff --git a/sdk/http/examples/get_network_economics.rs b/sdk/http/examples/get_network_economics.rs new file mode 100644 index 0000000000..a73a2c5b0a --- /dev/null +++ b/sdk/http/examples/get_network_economics.rs @@ -0,0 +1,9 @@ +use multiversx_sdk_http::{GatewayHttpProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; + +#[tokio::main] +async fn main() { + let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); + let network_economics = blockchain.get_network_economics().await.unwrap(); + + println!("network_economics: {network_economics:#?}") +} diff --git a/sdk/reqwest/examples/sign_tx.rs b/sdk/http/examples/sign_tx.rs similarity index 84% rename from sdk/reqwest/examples/sign_tx.rs rename to sdk/http/examples/sign_tx.rs index ec83f5796d..713db7fe3c 100644 --- a/sdk/reqwest/examples/sign_tx.rs +++ b/sdk/http/examples/sign_tx.rs @@ -1,5 +1,5 @@ use multiversx_sdk::{data::transaction::Transaction, wallet::Wallet}; -use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; +use multiversx_sdk_http::{GatewayHttpProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; #[tokio::main] async fn main() { @@ -8,7 +8,7 @@ async fn main() { ) .unwrap(); let addr = wl.address(); - let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); + let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); let network_config = blockchain.get_network_config().await.unwrap(); let arg = blockchain diff --git a/sdk/reqwest/examples/sign_txs.rs b/sdk/http/examples/sign_txs.rs similarity index 87% rename from sdk/reqwest/examples/sign_txs.rs rename to sdk/http/examples/sign_txs.rs index 1c52e2d6aa..4b35e2d032 100644 --- a/sdk/reqwest/examples/sign_txs.rs +++ b/sdk/http/examples/sign_txs.rs @@ -1,5 +1,5 @@ use multiversx_sdk::{data::transaction::Transaction, wallet::Wallet}; -use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; +use multiversx_sdk_http::{GatewayHttpProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; #[tokio::main] async fn main() { @@ -8,7 +8,7 @@ async fn main() { ) .unwrap(); let addr = wl.address(); - let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); + let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); let network_config = blockchain.get_network_config().await.unwrap(); let arg = blockchain diff --git a/sdk/reqwest/examples/tx_cost.rs b/sdk/http/examples/tx_cost.rs similarity index 82% rename from sdk/reqwest/examples/tx_cost.rs rename to sdk/http/examples/tx_cost.rs index 3e2601cf95..ff08a7be35 100644 --- a/sdk/reqwest/examples/tx_cost.rs +++ b/sdk/http/examples/tx_cost.rs @@ -2,7 +2,7 @@ use multiversx_sdk::{ data::{address::Address, transaction::Transaction}, utils::base64_encode, }; -use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; +use multiversx_sdk_http::{GatewayHttpProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; #[tokio::main] async fn main() { @@ -26,7 +26,7 @@ async fn main() { signature: None, }; - let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); + let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); let cost = blockchain.request_transaction_cost(&tx).await.unwrap(); println!("tx cost: {cost:#?}"); diff --git a/sdk/reqwest/examples/tx_default_args.rs b/sdk/http/examples/tx_default_args.rs similarity index 70% rename from sdk/reqwest/examples/tx_default_args.rs rename to sdk/http/examples/tx_default_args.rs index aaec0d81a9..13235cc0a6 100644 --- a/sdk/reqwest/examples/tx_default_args.rs +++ b/sdk/http/examples/tx_default_args.rs @@ -1,9 +1,9 @@ use multiversx_sdk::data::address::Address; -use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; +use multiversx_sdk_http::{GatewayHttpProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; #[tokio::main] async fn main() { - let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); + let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); let network_config = blockchain.get_network_config().await.unwrap(); let addr = Address::from_bech32_string( "erd1qqqqqqqqqqqqqpgqfzydqmdw7m2vazsp6u5p95yxz76t2p9rd8ss0zp9ts", diff --git a/sdk/reqwest/examples/tx_info.rs b/sdk/http/examples/tx_info.rs similarity index 69% rename from sdk/reqwest/examples/tx_info.rs rename to sdk/http/examples/tx_info.rs index ef1f27979d..753828bb84 100644 --- a/sdk/reqwest/examples/tx_info.rs +++ b/sdk/http/examples/tx_info.rs @@ -1,9 +1,9 @@ -use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; +use multiversx_sdk_http::{GatewayHttpProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; #[tokio::main] async fn main() { let tx_hash = "fd21782ddb9e2217a3239e849e39d1d2c8fa74142a73f2dda3adb3028c0514e9"; - let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); + let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); let status = blockchain.get_transaction_status(tx_hash).await; println!("tx status: {status:?}"); diff --git a/sdk/reqwest/examples/vm_query.rs b/sdk/http/examples/vm_query.rs similarity index 70% rename from sdk/reqwest/examples/vm_query.rs rename to sdk/http/examples/vm_query.rs index b1c78c537e..76441840ac 100644 --- a/sdk/reqwest/examples/vm_query.rs +++ b/sdk/http/examples/vm_query.rs @@ -1,9 +1,9 @@ use multiversx_sdk::data::{address::Address, vm::VMQueryInput}; -use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; +use multiversx_sdk_http::{GatewayHttpProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; #[tokio::main] async fn main() { - let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); + let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); let sc_address = Address::from_bech32_string( "erd1qqqqqqqqqqqqqpgq5dvvkmka7sujfsx7cfmygnx0n7luv8k0d8sskpqcec", ) diff --git a/sdk/reqwest/src/gateway/gateway_proxy.rs b/sdk/http/src/gateway_http_proxy.rs similarity index 65% rename from sdk/reqwest/src/gateway/gateway_proxy.rs rename to sdk/http/src/gateway_http_proxy.rs index d097581a8e..cb86e126ef 100644 --- a/sdk/reqwest/src/gateway/gateway_proxy.rs +++ b/sdk/http/src/gateway_http_proxy.rs @@ -1,19 +1,25 @@ -use multiversx_sdk::gateway::GatewayRequest; -use reqwest::Client; +mod http_account; +mod http_block; +mod http_chain_simulator; +mod http_network; +mod http_tx; +mod http_tx_retrieve; + +use multiversx_sdk::gateway::{GatewayAsyncService, GatewayRequest}; /// Allows communication with the MultiversX gateway API. #[derive(Clone, Debug)] -pub struct GatewayProxy { +pub struct GatewayHttpProxy { pub(crate) proxy_uri: String, - pub(crate) client: Client, + pub(crate) client: reqwest::Client, pub chain_simulator: bool, } -impl GatewayProxy { +impl GatewayHttpProxy { pub fn new(proxy_uri: String, chain_simulator: bool) -> Self { Self { proxy_uri, - client: Client::new(), + client: reqwest::Client::new(), chain_simulator, } } @@ -24,9 +30,7 @@ impl GatewayProxy { /// Performs a request to the gateway. /// Can be either GET or POST, depending on the argument. - /// - /// - pub async fn request(&self, request: G) -> anyhow::Result + pub async fn http_request(&self, request: G) -> anyhow::Result where G: GatewayRequest, { @@ -54,3 +58,15 @@ impl GatewayProxy { request.process_json(decoded) } } + +impl GatewayAsyncService for GatewayHttpProxy { + fn request( + &self, + request: G, + ) -> impl std::future::Future> + Send + where + G: multiversx_sdk::gateway::GatewayRequest, + { + self.http_request(request) + } +} diff --git a/sdk/reqwest/src/gateway/gateway_account.rs b/sdk/http/src/gateway_http_proxy/http_account.rs similarity index 76% rename from sdk/reqwest/src/gateway/gateway_account.rs rename to sdk/http/src/gateway_http_proxy/http_account.rs index 55a066dfd1..1ec2f489cf 100644 --- a/sdk/reqwest/src/gateway/gateway_account.rs +++ b/sdk/http/src/gateway_http_proxy/http_account.rs @@ -8,12 +8,12 @@ use multiversx_sdk::{ }; use std::collections::HashMap; -use super::GatewayProxy; +use super::GatewayHttpProxy; -impl GatewayProxy { +impl GatewayHttpProxy { // get_account retrieves an account info from the network (nonce, balance) pub async fn get_account(&self, address: &Address) -> Result { - self.request(GetAccountRequest::new(address)).await + self.http_request(GetAccountRequest::new(address)).await } // get_account_esdt_roles retrieves an all esdt roles of an account from the network @@ -21,7 +21,8 @@ impl GatewayProxy { &self, address: &Address, ) -> Result>> { - self.request(GetAccountEsdtRolesRequest::new(address)).await + self.http_request(GetAccountEsdtRolesRequest::new(address)) + .await } // get_account_esdt_tokens retrieves an all esdt token of an account from the network @@ -29,7 +30,7 @@ impl GatewayProxy { &self, address: &Address, ) -> Result> { - self.request(GetAccountEsdtTokensRequest::new(address)) + self.http_request(GetAccountEsdtTokensRequest::new(address)) .await } @@ -38,6 +39,7 @@ impl GatewayProxy { &self, address: &Address, ) -> Result> { - self.request(GetAccountStorageRequest::new(address)).await + self.http_request(GetAccountStorageRequest::new(address)) + .await } } diff --git a/sdk/reqwest/src/gateway/gateway_block.rs b/sdk/http/src/gateway_http_proxy/http_block.rs similarity index 70% rename from sdk/reqwest/src/gateway/gateway_block.rs rename to sdk/http/src/gateway_http_proxy/http_block.rs index a45e9ed458..4acaf04a67 100644 --- a/sdk/reqwest/src/gateway/gateway_block.rs +++ b/sdk/http/src/gateway_http_proxy/http_block.rs @@ -4,22 +4,23 @@ use multiversx_sdk::{ gateway::{GetHyperBlockRequest, NetworkStatusRequest}, }; -use super::GatewayProxy; +use super::GatewayHttpProxy; -impl GatewayProxy { +impl GatewayHttpProxy { // get_hyper_block_by_hash retrieves a hyper block's info by hash from the network pub async fn get_hyper_block_by_hash(&self, hash: &str) -> Result { - self.request(GetHyperBlockRequest::by_hash(hash)).await + self.http_request(GetHyperBlockRequest::by_hash(hash)).await } // get_hyper_block_by_nonce retrieves a hyper block's info by nonce from the network pub async fn get_hyper_block_by_nonce(&self, nonce: u64) -> Result { - self.request(GetHyperBlockRequest::by_nonce(nonce)).await + self.http_request(GetHyperBlockRequest::by_nonce(nonce)) + .await } // get_latest_hyper_block_nonce retrieves the latest hyper block (metachain) nonce from the network pub async fn get_latest_hyper_block_nonce(&self) -> Result { - let network_status = self.request(NetworkStatusRequest::default()).await?; + let network_status = self.http_request(NetworkStatusRequest::default()).await?; Ok(network_status.nonce) } } diff --git a/sdk/reqwest/src/gateway/gateway_chain_simulator.rs b/sdk/http/src/gateway_http_proxy/http_chain_simulator.rs similarity index 98% rename from sdk/reqwest/src/gateway/gateway_chain_simulator.rs rename to sdk/http/src/gateway_http_proxy/http_chain_simulator.rs index c6670f9703..ec262dca28 100644 --- a/sdk/reqwest/src/gateway/gateway_chain_simulator.rs +++ b/sdk/http/src/gateway_http_proxy/http_chain_simulator.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use super::GatewayProxy; +use super::GatewayHttpProxy; use anyhow::{anyhow, Error}; use serde::{Deserialize, Serialize}; @@ -18,7 +18,7 @@ pub struct GenerateBlocksResponse { pub code: String, } -impl GatewayProxy { +impl GatewayHttpProxy { pub async fn send_user_funds(&self, receiver: &String) -> Result { if !self.chain_simulator { return Ok(String::from("no-simulator")); diff --git a/sdk/reqwest/src/gateway/gateway_network.rs b/sdk/http/src/gateway_http_proxy/http_network.rs similarity index 75% rename from sdk/reqwest/src/gateway/gateway_network.rs rename to sdk/http/src/gateway_http_proxy/http_network.rs index aa40f240eb..d6808689c9 100644 --- a/sdk/reqwest/src/gateway/gateway_network.rs +++ b/sdk/http/src/gateway_http_proxy/http_network.rs @@ -4,16 +4,16 @@ use multiversx_sdk::{ gateway::{NetworkConfigRequest, NetworkEconimicsRequest}, }; -use super::GatewayProxy; +use super::GatewayHttpProxy; -impl GatewayProxy { +impl GatewayHttpProxy { // get_network_config retrieves the network configuration from the proxy pub async fn get_network_config(&self) -> Result { - self.request(NetworkConfigRequest).await + self.http_request(NetworkConfigRequest).await } // get_network_economics retrieves the network economics from the proxy pub async fn get_network_economics(&self) -> Result { - self.request(NetworkEconimicsRequest).await + self.http_request(NetworkEconimicsRequest).await } } diff --git a/sdk/reqwest/src/gateway/gateway_tx.rs b/sdk/http/src/gateway_http_proxy/http_tx.rs similarity index 84% rename from sdk/reqwest/src/gateway/gateway_tx.rs rename to sdk/http/src/gateway_http_proxy/http_tx.rs index 100cfc6567..7ae18bc77d 100644 --- a/sdk/reqwest/src/gateway/gateway_tx.rs +++ b/sdk/http/src/gateway_http_proxy/http_tx.rs @@ -14,17 +14,17 @@ use multiversx_sdk::{ }, }; -use super::GatewayProxy; +use super::GatewayHttpProxy; -impl GatewayProxy { +impl GatewayHttpProxy { // request_transaction_cost retrieves how many gas a transaction will consume pub async fn request_transaction_cost(&self, tx: &Transaction) -> Result { - self.request(GetTxCost(tx)).await + self.http_request(GetTxCost(tx)).await } // get_transaction_info retrieves a transaction's details from the network pub async fn get_transaction_info(&self, hash: &str) -> Result { - self.request(GetTxInfo::new(hash)).await + self.http_request(GetTxInfo::new(hash)).await } // get_transaction_info_with_results retrieves a transaction's details from the network with events @@ -32,17 +32,17 @@ impl GatewayProxy { &self, hash: &str, ) -> Result { - self.request(GetTxInfo::new(hash).with_results()).await + self.http_request(GetTxInfo::new(hash).with_results()).await } // get_transaction_status retrieves a transaction's status from the network pub async fn get_transaction_status(&self, hash: &str) -> Result { - self.request(GetTxStatus::new(hash)).await + self.http_request(GetTxStatus::new(hash)).await } // get_transaction_process_status retrieves a transaction's status from the network using process-status API pub async fn get_transaction_process_status(&self, hash: &str) -> Result<(String, String)> { - self.request(GetTxProcessStatus::new(hash)).await + self.http_request(GetTxProcessStatus::new(hash)).await } // get_default_transaction_arguments will prepare the transaction creation argument by querying the account's info @@ -70,16 +70,16 @@ impl GatewayProxy { } pub async fn send_transaction(&self, tx: &Transaction) -> Result { - self.request(SendTxRequest(tx)).await + self.http_request(SendTxRequest(tx)).await } #[allow(clippy::ptr_arg)] pub async fn send_transactions(&self, txs: &Vec) -> Result> { - self.request(SendMultiTxRequest(txs)).await + self.http_request(SendMultiTxRequest(txs)).await } // execute_vmquery retrieves data from existing SC trie through the use of a VM pub async fn execute_vmquery(&self, vm_request: &VMQueryInput) -> Result { - self.request(VMQueryRequest(vm_request)).await + self.http_request(VMQueryRequest(vm_request)).await } } diff --git a/sdk/reqwest/src/gateway/gateway_tx_retrieve.rs b/sdk/http/src/gateway_http_proxy/http_tx_retrieve.rs similarity index 98% rename from sdk/reqwest/src/gateway/gateway_tx_retrieve.rs rename to sdk/http/src/gateway_http_proxy/http_tx_retrieve.rs index 14256c7527..e39b87621b 100644 --- a/sdk/reqwest/src/gateway/gateway_tx_retrieve.rs +++ b/sdk/http/src/gateway_http_proxy/http_tx_retrieve.rs @@ -2,13 +2,13 @@ use log::info; use multiversx_sdk::data::transaction::TransactionOnNetwork; use std::time::{Duration, Instant}; -use super::GatewayProxy; +use super::GatewayHttpProxy; const INITIAL_BACKOFF_DELAY: f32 = 1.4; const MAX_RETRIES: usize = 8; const MAX_BACKOFF_DELAY: Duration = Duration::from_secs(6); -impl GatewayProxy { +impl GatewayHttpProxy { /// Retrieves a transaction from the network. pub async fn retrieve_tx_on_network(&self, tx_hash: String) -> TransactionOnNetwork { let mut retries = 0; diff --git a/sdk/reqwest/src/gateway.rs b/sdk/http/src/lib.rs similarity index 67% rename from sdk/reqwest/src/gateway.rs rename to sdk/http/src/lib.rs index 72278183d8..45c69ee2b4 100644 --- a/sdk/reqwest/src/gateway.rs +++ b/sdk/http/src/lib.rs @@ -1,12 +1,8 @@ -mod gateway_account; -mod gateway_block; -mod gateway_chain_simulator; -mod gateway_network; -mod gateway_proxy; -mod gateway_tx; -mod gateway_tx_retrieve; +mod gateway_http_proxy; -pub use gateway_proxy::GatewayProxy; +pub use gateway_http_proxy::GatewayHttpProxy; + +pub use multiversx_sdk as core; pub const MAINNET_GATEWAY: &str = "https://gateway.multiversx.com"; pub const TESTNET_GATEWAY: &str = "https://testnet-gateway.multiversx.com"; diff --git a/sdk/reqwest/examples/get_hyper_block_by_nonce.rs b/sdk/reqwest/examples/get_hyper_block_by_nonce.rs deleted file mode 100644 index 776a7deb3f..0000000000 --- a/sdk/reqwest/examples/get_hyper_block_by_nonce.rs +++ /dev/null @@ -1,9 +0,0 @@ -use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; - -#[tokio::main] -async fn main() { - let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); - let result = blockchain.get_hyper_block_by_nonce(7468).await; - - println!("block by nonce result: {result:#?}") -} diff --git a/sdk/reqwest/examples/get_hyper_block_latest.rs b/sdk/reqwest/examples/get_hyper_block_latest.rs deleted file mode 100644 index a6051bf71d..0000000000 --- a/sdk/reqwest/examples/get_hyper_block_latest.rs +++ /dev/null @@ -1,9 +0,0 @@ -use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; - -#[tokio::main] -async fn main() { - let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); - let result = blockchain.get_latest_hyper_block_nonce().await; - - println!("latest block result: {result:?}") -} diff --git a/sdk/reqwest/examples/get_network_config.rs b/sdk/reqwest/examples/get_network_config.rs deleted file mode 100644 index edb8b4c604..0000000000 --- a/sdk/reqwest/examples/get_network_config.rs +++ /dev/null @@ -1,9 +0,0 @@ -use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; - -#[tokio::main] -async fn main() { - let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); - let network_config = blockchain.get_network_config().await.unwrap(); - - println!("network_config: {network_config:#?}") -} diff --git a/sdk/reqwest/examples/get_network_economics.rs b/sdk/reqwest/examples/get_network_economics.rs deleted file mode 100644 index 5511ce9e16..0000000000 --- a/sdk/reqwest/examples/get_network_economics.rs +++ /dev/null @@ -1,9 +0,0 @@ -use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEFAULT_USE_CHAIN_SIMULATOR, DEVNET_GATEWAY}; - -#[tokio::main] -async fn main() { - let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string(), DEFAULT_USE_CHAIN_SIMULATOR); - let network_economics = blockchain.get_network_economics().await.unwrap(); - - println!("network_economics: {network_economics:#?}") -} diff --git a/sdk/reqwest/src/lib.rs b/sdk/reqwest/src/lib.rs deleted file mode 100644 index 7ec54f216c..0000000000 --- a/sdk/reqwest/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod gateway; - -pub use multiversx_sdk as core;