Skip to content

Commit

Permalink
gateway proxy rename
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed May 30, 2024
1 parent 89524db commit ca237ea
Show file tree
Hide file tree
Showing 23 changed files with 48 additions and 47 deletions.
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::{
scenario_model::{Account, BytesKey, BytesValue, Scenario, SetStateStep, Step},
};
use multiversx_sdk::{
blockchain::CommunicationProxy,
blockchain::GatewayProxy,
data::{address::Address, esdt::EsdtBalance},
};
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,7 +5,7 @@ use multiversx_sc_scenario::{
scenario_model::AddressValue,
};
use multiversx_sdk::{
blockchain::CommunicationProxy,
blockchain::GatewayProxy,
data::{address::Address as ErdrsAddress, network_config::NetworkConfig},
wallet::Wallet,
};
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
4 changes: 2 additions & 2 deletions sdk/core/examples/account.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
blockchain::{GatewayProxy, DEVNET_GATEWAY},
data::address::Address,
};

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,5 +1,5 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
blockchain::{GatewayProxy, DEVNET_GATEWAY},
data::address::Address,
};

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,5 +1,5 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
blockchain::{GatewayProxy, DEVNET_GATEWAY},
data::address::Address,
};

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::blockchain::{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::blockchain::{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::blockchain::{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::blockchain::{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::blockchain::{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,5 +1,5 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
blockchain::{GatewayProxy, DEVNET_GATEWAY},
data::transaction::Transaction,
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,5 +1,5 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
blockchain::{GatewayProxy, DEVNET_GATEWAY},
data::transaction::Transaction,
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,5 +1,5 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
blockchain::{GatewayProxy, DEVNET_GATEWAY},
data::{address::Address, transaction::Transaction},
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},
blockchain::{GatewayProxy, DEVNET_GATEWAY},
data::address::Address,
};

#[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::blockchain::{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,5 +1,5 @@
use multiversx_sdk::{
blockchain::{CommunicationProxy, DEVNET_GATEWAY},
blockchain::{GatewayProxy, DEVNET_GATEWAY},
data::{address::Address, vm::VmValueRequest},
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
2 changes: 1 addition & 1 deletion sdk/core/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod gateway_proxy;
mod gateway_tx;
mod gateway_tx_retrieve;

pub use gateway_proxy::CommunicationProxy;
pub use gateway_proxy::GatewayProxy;

pub const MAINNET_GATEWAY: &str = "https://gateway.multiversx.com";
pub const TESTNET_GATEWAY: &str = "https://testnet-gateway.multiversx.com";
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/src/blockchain/gateway_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use crate::data::{
use anyhow::{anyhow, Result};
use std::collections::HashMap;

use super::CommunicationProxy;
use super::GatewayProxy;

const ACCOUNT_ENDPOINT: &str = "address/";
const KEYS_ENDPOINT: &str = "/keys/";

impl CommunicationProxy {
impl GatewayProxy {
// get_account retrieves an account info from the network (nonce, balance)
pub async fn get_account(&self, address: &Address) -> Result<Account> {
if !address.is_valid() {
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/src/blockchain/gateway_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use crate::data::{
};
use anyhow::{anyhow, Result};

use super::CommunicationProxy;
use super::GatewayProxy;
use super::METACHAIN_SHARD_ID;

const GET_HYPER_BLOCK_BY_NONCE_ENDPOINT: &str = "hyperblock/by-nonce/";
const GET_HYPER_BLOCK_BY_HASH_ENDPOINT: &str = "hyperblock/by-hash/";
const GET_NETWORK_STATUS_ENDPOINT: &str = "network/status";

impl CommunicationProxy {
impl GatewayProxy {
async fn get_hyper_block(&self, endpoint: &str) -> Result<HyperBlock> {
let endpoint = self.get_endpoint(endpoint);
let resp = self
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/src/blockchain/gateway_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use crate::data::{
};
use anyhow::{anyhow, Result};

use super::CommunicationProxy;
use super::GatewayProxy;

const NETWORK_CONFIG_ENDPOINT: &str = "network/config";
const NETWORK_ECONOMICS_ENDPOINT: &str = "network/economics";

impl CommunicationProxy {
impl GatewayProxy {
// get_network_config retrieves the network configuration from the proxy
pub async fn get_network_config(&self) -> Result<NetworkConfig> {
let endpoint = self.get_endpoint(NETWORK_CONFIG_ENDPOINT);
Expand Down
5 changes: 3 additions & 2 deletions sdk/core/src/blockchain/gateway_proxy.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use reqwest::Client;

/// Allows communication with the MultiversX gateway API.
#[derive(Clone, Debug)]
pub struct CommunicationProxy {
pub struct GatewayProxy {
pub(crate) proxy_url: String,
pub(crate) client: Client,
}

impl CommunicationProxy {
impl GatewayProxy {
pub fn new(proxy_url: String) -> Self {
Self {
proxy_url,
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/src/blockchain/gateway_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::data::{
use anyhow::{anyhow, Result};
use itertools::Itertools;

use super::CommunicationProxy;
use super::GatewayProxy;

const COST_TRANSACTION_ENDPOINT: &str = "transaction/cost";
const SEND_TRANSACTION_ENDPOINT: &str = "transaction/send";
Expand All @@ -19,7 +19,7 @@ const GET_TRANSACTION_INFO_ENDPOINT: &str = "transaction/";
const WITH_RESULTS_QUERY_PARAM: &str = "?withResults=true";
const VM_VALUES_ENDPOINT: &str = "vm-values/query";

impl CommunicationProxy {
impl GatewayProxy {
// request_transaction_cost retrieves how many gas a transaction will consume
pub async fn request_transaction_cost(&self, tx: &Transaction) -> Result<TxCostResponseData> {
let endpoint = self.get_endpoint(COST_TRANSACTION_ENDPOINT);
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/src/blockchain/gateway_tx_retrieve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use crate::data::transaction::TransactionOnNetwork;
use log::info;
use std::time::{Duration, Instant};

use super::CommunicationProxy;
use super::GatewayProxy;

const INITIAL_BACKOFF_DELAY: f32 = 1.4;
const MAX_RETRIES: usize = 8;
const MAX_BACKOFF_DELAY: Duration = Duration::from_secs(6);

impl CommunicationProxy {
impl GatewayProxy {
/// Retrieves a transaction from the network.
pub async fn retrieve_tx_on_network(&self, tx_hash: String) -> TransactionOnNetwork {
let mut retries = 0;
Expand Down

0 comments on commit ca237ea

Please sign in to comment.