Skip to content

Commit

Permalink
Merge pull request #1795 from multiversx/gateway-refactor-4
Browse files Browse the repository at this point in the history
SDK crate & proxy rename
  • Loading branch information
andrei-marinica authored Oct 2, 2024
2 parents 0611f7c + db46f48 commit 2ce7499
Show file tree
Hide file tree
Showing 40 changed files with 145 additions and 126 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ members = [
"framework/wasm-adapter",

"sdk/core",
"sdk/reqwest",
"sdk/http",
"sdk/wbg",
"sdk/scenario-format",

Expand Down
4 changes: 2 additions & 2 deletions framework/snippets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions framework/snippets/src/account_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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);
Expand All @@ -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();
Expand Down
7 changes: 3 additions & 4 deletions framework/snippets/src/interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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<Address, Sender>,

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<S>(&mut self, mut sc_call_step: S)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<S>(&mut self, mut step: S) -> &mut Self
Expand Down
5 changes: 2 additions & 3 deletions framework/snippets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down
13 changes: 11 additions & 2 deletions sdk/core/src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -74,3 +74,12 @@ pub trait GatewayRequest {

fn process_json(&self, decoded: Self::DecodedJson) -> anyhow::Result<Self::Result>;
}

pub trait GatewayAsyncService: Send {
fn request<G>(
&self,
request: G,
) -> impl std::future::Future<Output = anyhow::Result<G::Result>> + Send
where
G: GatewayRequest;
}
2 changes: 1 addition & 1 deletion sdk/reqwest/Cargo.toml → sdk/http/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "multiversx-sdk-reqwest"
name = "multiversx-sdk-http"
version = "0.6.1"
edition = "2021"

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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:#?}");
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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:#?}");
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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:#?}");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
9 changes: 9 additions & 0 deletions sdk/http/examples/get_hyper_block_by_nonce.rs
Original file line number Diff line number Diff line change
@@ -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:#?}")
}
9 changes: 9 additions & 0 deletions sdk/http/examples/get_hyper_block_latest.rs
Original file line number Diff line number Diff line change
@@ -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:?}")
}
9 changes: 9 additions & 0 deletions sdk/http/examples/get_network_config.rs
Original file line number Diff line number Diff line change
@@ -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:#?}")
}
9 changes: 9 additions & 0 deletions sdk/http/examples/get_network_economics.rs
Original file line number Diff line number Diff line change
@@ -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:#?}")
}
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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:#?}");
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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:?}");
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
)
Expand Down
Loading

0 comments on commit 2ce7499

Please sign in to comment.