Skip to content

Commit

Permalink
Merge pull request #1660 from multiversx/sdk-proxy-refactor
Browse files Browse the repository at this point in the history
Gateway proxy refactor
  • Loading branch information
andrei-marinica authored May 30, 2024
2 parents aadc163 + a31a3b2 commit 6f30d15
Show file tree
Hide file tree
Showing 32 changed files with 491 additions and 451 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

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,8 +4,8 @@ use multiversx_sc_scenario::{
scenario_model::{Account, BytesKey, BytesValue, Scenario, SetStateStep, Step},
};
use multiversx_sdk::{
blockchain::CommunicationProxy,
data::{address::Address, esdt::EsdtBalance},
gateway::GatewayProxy,
};
use std::collections::{BTreeMap, HashMap};

Expand All @@ -17,7 +17,7 @@ pub async fn print_account_as_scenario_set_state(
api_string: String,
address_bech32_string: String,
) {
let api = CommunicationProxy::new(api_string);
let api = GatewayProxy::new(api_string);
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 @@ -34,7 +34,7 @@ fn build_scenario(set_state: SetStateStep) -> Scenario {
}

pub async fn retrieve_account_as_scenario_set_state(
api: &CommunicationProxy,
api: &GatewayProxy,
address: &Bech32Address,
) -> SetStateStep {
let sdk_address = Address::from_bech32_string(address.to_bech32_str()).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions framework/snippets/src/interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use multiversx_sc_scenario::{
scenario_model::AddressValue,
};
use multiversx_sdk::{
blockchain::CommunicationProxy,
data::{address::Address as ErdrsAddress, network_config::NetworkConfig},
gateway::GatewayProxy,
wallet::Wallet,
};
use std::{
Expand All @@ -20,7 +20,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: CommunicationProxy,
pub proxy: GatewayProxy,
pub network_config: NetworkConfig,
pub sender_map: HashMap<Address, Sender>,

Expand All @@ -33,7 +33,7 @@ pub struct Interactor {

impl Interactor {
pub async fn new(gateway_url: &str) -> Self {
let proxy = CommunicationProxy::new(gateway_url.to_string());
let proxy = GatewayProxy::new(gateway_url.to_string());
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 @@ -14,7 +14,7 @@ impl Interactor {
{
let sc_call_step = sc_call_step.as_mut();
let tx_hash = self.launch_sc_call(sc_call_step).await;
let tx = self.retrieve_tx_on_network(tx_hash.clone()).await;
let tx = self.proxy.retrieve_tx_on_network(tx_hash.clone()).await;

sc_call_step.save_response(network_response::parse_tx_response(tx));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Interactor {
{
let sc_deploy_step = sc_deploy_step.as_mut();
let tx_hash = self.launch_sc_deploy(sc_deploy_step).await;
let tx = self.retrieve_tx_on_network(tx_hash.clone()).await;
let tx = self.proxy.retrieve_tx_on_network(tx_hash.clone()).await;

let addr = sc_deploy_step.tx.from.clone();
let nonce = tx.nonce;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Interactor {
println!("transfer tx hash: {tx_hash}");
info!("transfer tx hash: {}", tx_hash);

self.retrieve_tx_on_network(tx_hash.clone()).await;
self.proxy.retrieve_tx_on_network(tx_hash.clone()).await;

self.post_runners.run_transfer_step(&transfer_step);

Expand Down
1 change: 0 additions & 1 deletion framework/snippets/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod account_tool;
mod interactor;
mod interactor_dns;
mod interactor_retrieve;
mod interactor_scenario;
mod interactor_sender;
mod interactor_tx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Interactor {
.expect("failed to send transaction");

println!("process tx hash: {tx_hash} with nonce: {}", tx.nonce);
futures.push(self.retrieve_tx_on_network(tx_hash.clone()));
futures.push(self.proxy.retrieve_tx_on_network(tx_hash.clone()));
}

join_all(futures).await
Expand Down
1 change: 1 addition & 0 deletions sdk/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ zeroize = "1.4.2"
bech32 = "0.9"
itertools = "0.12.0"
pem = "3.0.2"
log = "0.4.17"
4 changes: 2 additions & 2 deletions sdk/core/examples/account.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
data::address::Address,
gateway::{GatewayProxy, DEVNET_GATEWAY},
};

#[tokio::main]
Expand All @@ -10,7 +10,7 @@ async fn main() {
)
.unwrap();

let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string());
let account = blockchain.get_account(&addr).await.unwrap();

println!("account: {account:#?}");
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/examples/account_storage.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
data::address::Address,
gateway::{GatewayProxy, DEVNET_GATEWAY},
};

#[tokio::main]
Expand All @@ -10,7 +10,7 @@ async fn main() {
)
.unwrap();

let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string());
let account_storage = blockchain.get_account_storage_keys(&addr).await.unwrap();

println!("Account Storage: {account_storage:#?}");
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/examples/get_esdt_tokens.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
data::address::Address,
gateway::{GatewayProxy, DEVNET_GATEWAY},
};

#[tokio::main]
Expand All @@ -10,7 +10,7 @@ async fn main() {
)
.unwrap();

let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string());
let balances = blockchain.get_account_esdt_tokens(&addr).await.unwrap();

println!("{balances:#?}");
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/examples/get_hyper_block_by_hash.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use multiversx_sdk::blockchain::{CommunicationProxy, DEVNET_GATEWAY};
use multiversx_sdk::gateway::{GatewayProxy, DEVNET_GATEWAY};

#[tokio::main]
async fn main() {
let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string());
let result = blockchain
.get_hyper_block_by_hash("20b14ba0e68c465810c5ded091f220e51dad41629d7ccd87dab572206185e419")
.await;
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/examples/get_hyper_block_by_nonce.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use multiversx_sdk::blockchain::{CommunicationProxy, DEVNET_GATEWAY};
use multiversx_sdk::gateway::{GatewayProxy, DEVNET_GATEWAY};

#[tokio::main]
async fn main() {
let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string());
let result = blockchain.get_hyper_block_by_nonce(7468).await;

println!("block by nonce result: {result:?}")
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/examples/get_hyper_block_latest.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use multiversx_sdk::blockchain::{CommunicationProxy, DEVNET_GATEWAY};
use multiversx_sdk::gateway::{GatewayProxy, DEVNET_GATEWAY};

#[tokio::main]
async fn main() {
let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string());
let result = blockchain.get_latest_hyper_block_nonce(false).await;

println!("latest block result: {result:?}")
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/examples/get_network_config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use multiversx_sdk::blockchain::{CommunicationProxy, DEVNET_GATEWAY};
use multiversx_sdk::gateway::{GatewayProxy, DEVNET_GATEWAY};

#[tokio::main]
async fn main() {
let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string());
let network_config = blockchain.get_network_config().await.unwrap();

println!("network_config: {network_config:#?}")
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/examples/get_network_economics.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use multiversx_sdk::blockchain::{CommunicationProxy, DEVNET_GATEWAY};
use multiversx_sdk::gateway::{GatewayProxy, DEVNET_GATEWAY};

#[tokio::main]
async fn main() {
let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string());
let network_economics = blockchain.get_network_economics().await.unwrap();

println!("network_economics: {network_economics:#?}")
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/examples/sign_tx.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
data::transaction::Transaction,
gateway::{GatewayProxy, DEVNET_GATEWAY},
wallet::Wallet,
};

Expand All @@ -11,7 +11,7 @@ async fn main() {
)
.unwrap();
let addr = wl.address();
let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string());
let network_config = blockchain.get_network_config().await.unwrap();

let arg = blockchain
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/examples/sign_txs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
data::transaction::Transaction,
gateway::{GatewayProxy, DEVNET_GATEWAY},
wallet::Wallet,
};

Expand All @@ -11,7 +11,7 @@ async fn main() {
)
.unwrap();
let addr = wl.address();
let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string());
let network_config = blockchain.get_network_config().await.unwrap();

let arg = blockchain
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/examples/tx_cost.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
data::{address::Address, transaction::Transaction},
gateway::{GatewayProxy, DEVNET_GATEWAY},
utils::base64_encode,
};

Expand All @@ -26,7 +26,7 @@ async fn main() {
signature: None,
};

let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string());
let cost = blockchain.request_transaction_cost(&tx).await.unwrap();

println!("tx cost: {cost:#?}");
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/examples/tx_default_args.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
data::address::Address,
gateway::{GatewayProxy, DEVNET_GATEWAY},
};

#[tokio::main]
async fn main() {
let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string());
let network_config = blockchain.get_network_config().await.unwrap();
let addr = Address::from_bech32_string(
"erd1qqqqqqqqqqqqqpgqfzydqmdw7m2vazsp6u5p95yxz76t2p9rd8ss0zp9ts",
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/examples/tx_info.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use multiversx_sdk::blockchain::{CommunicationProxy, DEVNET_GATEWAY};
use multiversx_sdk::gateway::{GatewayProxy, DEVNET_GATEWAY};

#[tokio::main]
async fn main() {
let tx_hash = "49edb289892a655a0e988b360c19326c21107f9696c6197b435667c6e8c6e1a3";
let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string());

let status = blockchain.get_transaction_status(tx_hash).await;
println!("tx status: {status:?}");
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/examples/vm_query.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
data::{address::Address, vm::VmValueRequest},
gateway::{GatewayProxy, DEVNET_GATEWAY},
wallet::Wallet,
};

Expand All @@ -11,7 +11,7 @@ async fn main() {
)
.unwrap();
let addr = wl.address();
let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let blockchain = GatewayProxy::new(DEVNET_GATEWAY.to_string());
let req = VmValueRequest {
sc_address: Address::from_bech32_string(
"erd1qqqqqqqqqqqqqpgqhn3ae8dpc957t7jadn7kywtg503dy7pnj9ts3umqxx",
Expand Down
Loading

0 comments on commit 6f30d15

Please sign in to comment.