pub struct GatewayHttpProxy { /* private fields */ }
Expand description
Allows communication with the MultiversX gateway API.
Implementations§
Source§impl GatewayHttpProxy
impl GatewayHttpProxy
Sourcepub async fn get_account(&self, address: &Address) -> Result<Account>
pub async fn get_account(&self, address: &Address) -> Result<Account>
pub async fn get_account_esdt_roles( &self, address: &Address, ) -> Result<HashMap<String, Vec<String>>>
Sourcepub async fn get_account_esdt_tokens(
&self,
address: &Address,
) -> Result<HashMap<String, EsdtBalance>>
pub async fn get_account_esdt_tokens( &self, address: &Address, ) -> Result<HashMap<String, EsdtBalance>>
Source§impl GatewayHttpProxy
impl GatewayHttpProxy
Sourcepub async fn get_hyper_block_by_hash(&self, hash: &str) -> Result<HyperBlock>
pub async fn get_hyper_block_by_hash(&self, hash: &str) -> Result<HyperBlock>
Sourcepub async fn get_hyper_block_by_nonce(&self, nonce: u64) -> Result<HyperBlock>
pub async fn get_hyper_block_by_nonce(&self, nonce: u64) -> Result<HyperBlock>
Sourcepub async fn get_latest_hyper_block_nonce(&self) -> Result<u64>
pub async fn get_latest_hyper_block_nonce(&self) -> Result<u64>
Source§impl GatewayHttpProxy
impl GatewayHttpProxy
pub async fn send_user_funds(&self, receiver: &Address) -> Result<String, Error>
pub async fn generate_blocks(&self, num_blocks: u64) -> Result<String, Error>
pub async fn generate_blocks_until_epoch( &self, epoch_number: u64, ) -> Result<String, Error>
pub async fn generate_blocks_until_tx_processed( &self, tx_hash: &str, ) -> Result<String, Error>
Source§impl GatewayHttpProxy
impl GatewayHttpProxy
Sourcepub async fn get_network_config(&self) -> Result<NetworkConfig>
pub async fn get_network_config(&self) -> Result<NetworkConfig>
Examples found in repository?
More examples
examples/tx_default_args.rs (line 7)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
async fn main() {
let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string());
let network_config = blockchain.get_network_config().await.unwrap();
let addr = SdkAddress::from_bech32_string(
"erd1qqqqqqqqqqqqqpgqfzydqmdw7m2vazsp6u5p95yxz76t2p9rd8ss0zp9ts",
)
.unwrap();
let arg = blockchain
.get_default_transaction_arguments(&addr.0, &network_config)
.await
.unwrap();
println!("default tx arg: {arg:#?}");
}
examples/sign_tx.rs (line 15)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
async fn main() {
let wl = Wallet::from_private_key(
"1648ad209d6b157a289884933e3bb30f161ec7113221ec16f87c3578b05830b0",
)
.unwrap();
let addr = wl.to_address();
let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string());
let network_config = blockchain.get_network_config().await.unwrap();
let arg = blockchain
.get_default_transaction_arguments(&addr, &network_config)
.await
.unwrap();
let mut unsign_tx = Transaction {
nonce: arg.nonce,
value: "0".to_string(),
receiver: SdkAddress(addr.clone()),
sender: SdkAddress(addr.clone()),
gas_price: arg.gas_price,
gas_limit: arg.gas_limit,
data: arg.data,
signature: None,
chain_id: arg.chain_id,
version: arg.version,
options: arg.options,
};
let signature = wl.sign_tx(&unsign_tx);
unsign_tx.signature = Some(hex::encode(signature));
let tx_hash = blockchain.send_transaction(&unsign_tx).await.unwrap();
println!("tx_hash {tx_hash}");
}
examples/sign_txs.rs (line 15)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
async fn main() {
let wl = Wallet::from_private_key(
"1648ad209d6b157a289884933e3bb30f161ec7113221ec16f87c3578b05830b0",
)
.unwrap();
let addr = wl.to_address();
let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string());
let network_config = blockchain.get_network_config().await.unwrap();
let arg = blockchain
.get_default_transaction_arguments(&addr, &network_config)
.await
.unwrap();
let mut unsign_tx = Transaction {
nonce: arg.nonce,
value: "1000000000000000000".to_string(),
receiver: SdkAddress(addr.clone()),
sender: SdkAddress(addr.clone()),
gas_price: arg.gas_price,
gas_limit: arg.gas_limit,
data: arg.data,
signature: None,
chain_id: arg.chain_id,
version: arg.version,
options: arg.options,
};
let mut txs: Vec<Transaction> = vec![];
let signature = wl.sign_tx(&unsign_tx);
unsign_tx.signature = Some(hex::encode(signature));
txs.push(unsign_tx.clone());
unsign_tx.version = 2;
unsign_tx.options = 1;
unsign_tx.nonce += 1;
let signature = wl.sign_tx(&unsign_tx);
unsign_tx.signature = Some(hex::encode(signature));
txs.push(unsign_tx.clone());
let tx_hash = blockchain.send_transactions(&txs).await.unwrap();
println!("tx_hashes {tx_hash:?}");
}
Sourcepub async fn get_network_economics(&self) -> Result<NetworkEconomics>
pub async fn get_network_economics(&self) -> Result<NetworkEconomics>
Source§impl GatewayHttpProxy
impl GatewayHttpProxy
Sourcepub async fn request_transaction_cost(
&self,
tx: &Transaction,
) -> Result<TxCostResponseData>
pub async fn request_transaction_cost( &self, tx: &Transaction, ) -> Result<TxCostResponseData>
Examples found in repository?
examples/tx_cost.rs (line 30)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
async fn main() {
let tx = Transaction {
nonce: 1,
value: "50".to_string(),
receiver: SdkAddress::from_bech32_string(
"erd1rh5ws22jxm9pe7dtvhfy6j3uttuupkepferdwtmslms5fydtrh5sx3xr8r",
)
.unwrap(),
sender: SdkAddress::from_bech32_string(
"erd1rh5ws22jxm9pe7dtvhfy6j3uttuupkepferdwtmslms5fydtrh5sx3xr8r",
)
.unwrap(),
data: Some(base64_encode("hello")),
chain_id: "1".to_string(),
version: 1,
options: 0,
gas_limit: 0,
gas_price: 0,
signature: None,
};
let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string());
let cost = blockchain.request_transaction_cost(&tx).await.unwrap();
println!("tx cost: {cost:#?}");
assert_eq!(
cost.tx_gas_units, 57500,
"receive cost {}",
cost.tx_gas_units
);
}
Sourcepub async fn get_transaction_info(
&self,
hash: &str,
) -> Result<TransactionOnNetwork>
pub async fn get_transaction_info( &self, hash: &str, ) -> Result<TransactionOnNetwork>
Examples found in repository?
examples/tx_info.rs (line 11)
4 5 6 7 8 9 10 11 12 13 14 15 16
async fn main() {
let tx_hash = "fd21782ddb9e2217a3239e849e39d1d2c8fa74142a73f2dda3adb3028c0514e9";
let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string());
let status = blockchain.get_transaction_status(tx_hash).await;
println!("tx status: {status:?}");
let tx = blockchain.get_transaction_info(tx_hash).await;
println!("tx: {tx:#?}");
let tx = blockchain.get_transaction_info_with_results(tx_hash).await;
println!("tx with results: {tx:#?}");
}
Sourcepub async fn get_transaction_info_with_results(
&self,
hash: &str,
) -> Result<TransactionOnNetwork>
pub async fn get_transaction_info_with_results( &self, hash: &str, ) -> Result<TransactionOnNetwork>
Examples found in repository?
examples/tx_info.rs (line 14)
4 5 6 7 8 9 10 11 12 13 14 15 16
async fn main() {
let tx_hash = "fd21782ddb9e2217a3239e849e39d1d2c8fa74142a73f2dda3adb3028c0514e9";
let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string());
let status = blockchain.get_transaction_status(tx_hash).await;
println!("tx status: {status:?}");
let tx = blockchain.get_transaction_info(tx_hash).await;
println!("tx: {tx:#?}");
let tx = blockchain.get_transaction_info_with_results(tx_hash).await;
println!("tx with results: {tx:#?}");
}
Sourcepub async fn get_transaction_status(&self, hash: &str) -> Result<String>
pub async fn get_transaction_status(&self, hash: &str) -> Result<String>
Examples found in repository?
examples/tx_info.rs (line 8)
4 5 6 7 8 9 10 11 12 13 14 15 16
async fn main() {
let tx_hash = "fd21782ddb9e2217a3239e849e39d1d2c8fa74142a73f2dda3adb3028c0514e9";
let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string());
let status = blockchain.get_transaction_status(tx_hash).await;
println!("tx status: {status:?}");
let tx = blockchain.get_transaction_info(tx_hash).await;
println!("tx: {tx:#?}");
let tx = blockchain.get_transaction_info_with_results(tx_hash).await;
println!("tx with results: {tx:#?}");
}
pub async fn get_transaction_process_status( &self, hash: &str, ) -> Result<(String, String)>
Sourcepub async fn get_default_transaction_arguments(
&self,
address: &Address,
network_configs: &NetworkConfig,
) -> Result<ArgCreateTransaction>
pub async fn get_default_transaction_arguments( &self, address: &Address, network_configs: &NetworkConfig, ) -> Result<ArgCreateTransaction>
Examples found in repository?
examples/tx_default_args.rs (line 14)
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
async fn main() {
let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string());
let network_config = blockchain.get_network_config().await.unwrap();
let addr = SdkAddress::from_bech32_string(
"erd1qqqqqqqqqqqqqpgqfzydqmdw7m2vazsp6u5p95yxz76t2p9rd8ss0zp9ts",
)
.unwrap();
let arg = blockchain
.get_default_transaction_arguments(&addr.0, &network_config)
.await
.unwrap();
println!("default tx arg: {arg:#?}");
}
More examples
examples/sign_tx.rs (line 18)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
async fn main() {
let wl = Wallet::from_private_key(
"1648ad209d6b157a289884933e3bb30f161ec7113221ec16f87c3578b05830b0",
)
.unwrap();
let addr = wl.to_address();
let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string());
let network_config = blockchain.get_network_config().await.unwrap();
let arg = blockchain
.get_default_transaction_arguments(&addr, &network_config)
.await
.unwrap();
let mut unsign_tx = Transaction {
nonce: arg.nonce,
value: "0".to_string(),
receiver: SdkAddress(addr.clone()),
sender: SdkAddress(addr.clone()),
gas_price: arg.gas_price,
gas_limit: arg.gas_limit,
data: arg.data,
signature: None,
chain_id: arg.chain_id,
version: arg.version,
options: arg.options,
};
let signature = wl.sign_tx(&unsign_tx);
unsign_tx.signature = Some(hex::encode(signature));
let tx_hash = blockchain.send_transaction(&unsign_tx).await.unwrap();
println!("tx_hash {tx_hash}");
}
examples/sign_txs.rs (line 18)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
async fn main() {
let wl = Wallet::from_private_key(
"1648ad209d6b157a289884933e3bb30f161ec7113221ec16f87c3578b05830b0",
)
.unwrap();
let addr = wl.to_address();
let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string());
let network_config = blockchain.get_network_config().await.unwrap();
let arg = blockchain
.get_default_transaction_arguments(&addr, &network_config)
.await
.unwrap();
let mut unsign_tx = Transaction {
nonce: arg.nonce,
value: "1000000000000000000".to_string(),
receiver: SdkAddress(addr.clone()),
sender: SdkAddress(addr.clone()),
gas_price: arg.gas_price,
gas_limit: arg.gas_limit,
data: arg.data,
signature: None,
chain_id: arg.chain_id,
version: arg.version,
options: arg.options,
};
let mut txs: Vec<Transaction> = vec![];
let signature = wl.sign_tx(&unsign_tx);
unsign_tx.signature = Some(hex::encode(signature));
txs.push(unsign_tx.clone());
unsign_tx.version = 2;
unsign_tx.options = 1;
unsign_tx.nonce += 1;
let signature = wl.sign_tx(&unsign_tx);
unsign_tx.signature = Some(hex::encode(signature));
txs.push(unsign_tx.clone());
let tx_hash = blockchain.send_transactions(&txs).await.unwrap();
println!("tx_hashes {tx_hash:?}");
}
Sourcepub async fn send_transaction(&self, tx: &Transaction) -> Result<String>
pub async fn send_transaction(&self, tx: &Transaction) -> Result<String>
Examples found in repository?
examples/sign_tx.rs (line 38)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
async fn main() {
let wl = Wallet::from_private_key(
"1648ad209d6b157a289884933e3bb30f161ec7113221ec16f87c3578b05830b0",
)
.unwrap();
let addr = wl.to_address();
let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string());
let network_config = blockchain.get_network_config().await.unwrap();
let arg = blockchain
.get_default_transaction_arguments(&addr, &network_config)
.await
.unwrap();
let mut unsign_tx = Transaction {
nonce: arg.nonce,
value: "0".to_string(),
receiver: SdkAddress(addr.clone()),
sender: SdkAddress(addr.clone()),
gas_price: arg.gas_price,
gas_limit: arg.gas_limit,
data: arg.data,
signature: None,
chain_id: arg.chain_id,
version: arg.version,
options: arg.options,
};
let signature = wl.sign_tx(&unsign_tx);
unsign_tx.signature = Some(hex::encode(signature));
let tx_hash = blockchain.send_transaction(&unsign_tx).await.unwrap();
println!("tx_hash {tx_hash}");
}
Sourcepub async fn send_transactions(
&self,
txs: &Vec<Transaction>,
) -> Result<Vec<String>>
pub async fn send_transactions( &self, txs: &Vec<Transaction>, ) -> Result<Vec<String>>
Examples found in repository?
examples/sign_txs.rs (line 50)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
async fn main() {
let wl = Wallet::from_private_key(
"1648ad209d6b157a289884933e3bb30f161ec7113221ec16f87c3578b05830b0",
)
.unwrap();
let addr = wl.to_address();
let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string());
let network_config = blockchain.get_network_config().await.unwrap();
let arg = blockchain
.get_default_transaction_arguments(&addr, &network_config)
.await
.unwrap();
let mut unsign_tx = Transaction {
nonce: arg.nonce,
value: "1000000000000000000".to_string(),
receiver: SdkAddress(addr.clone()),
sender: SdkAddress(addr.clone()),
gas_price: arg.gas_price,
gas_limit: arg.gas_limit,
data: arg.data,
signature: None,
chain_id: arg.chain_id,
version: arg.version,
options: arg.options,
};
let mut txs: Vec<Transaction> = vec![];
let signature = wl.sign_tx(&unsign_tx);
unsign_tx.signature = Some(hex::encode(signature));
txs.push(unsign_tx.clone());
unsign_tx.version = 2;
unsign_tx.options = 1;
unsign_tx.nonce += 1;
let signature = wl.sign_tx(&unsign_tx);
unsign_tx.signature = Some(hex::encode(signature));
txs.push(unsign_tx.clone());
let tx_hash = blockchain.send_transactions(&txs).await.unwrap();
println!("tx_hashes {tx_hash:?}");
}
Sourcepub async fn execute_vmquery(
&self,
vm_request: &VMQueryInput,
) -> Result<VmValuesResponseData>
pub async fn execute_vmquery( &self, vm_request: &VMQueryInput, ) -> Result<VmValuesResponseData>
Examples found in repository?
examples/vm_query.rs (line 16)
5 6 7 8 9 10 11 12 13 14 15 16 17 18
async fn main() {
let blockchain = GatewayHttpProxy::new(DEVNET_GATEWAY.to_string());
let sc_address = SdkAddress::from_bech32_string(
"erd1qqqqqqqqqqqqqpgq5dvvkmka7sujfsx7cfmygnx0n7luv8k0d8sskpqcec",
)
.unwrap();
let req = VMQueryInput {
sc_address: sc_address.clone(),
func_name: "empty".to_string(),
args: vec![],
};
let result = blockchain.execute_vmquery(&req).await;
println!("{result:#?}");
}
Source§impl GatewayHttpProxy
impl GatewayHttpProxy
Sourcepub async fn http_request<G>(&self, request: G) -> Result<G::Result>where
G: GatewayRequest,
pub async fn http_request<G>(&self, request: G) -> Result<G::Result>where
G: GatewayRequest,
Performs a request to the gateway. Can be either GET or POST, depending on the argument.
Trait Implementations§
Source§impl Clone for GatewayHttpProxy
impl Clone for GatewayHttpProxy
Source§fn clone(&self) -> GatewayHttpProxy
fn clone(&self) -> GatewayHttpProxy
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for GatewayHttpProxy
impl Debug for GatewayHttpProxy
Source§impl GatewayAsyncService for GatewayHttpProxy
impl GatewayAsyncService for GatewayHttpProxy
fn from_uri(uri: &str) -> Self
fn request<G>(&self, request: G) -> impl Future<Output = Result<G::Result>>where
G: GatewayRequest,
fn sleep(&self, millis: u64) -> impl Future<Output = ()>
fn now(&self) -> Self::Instant
fn elapsed_seconds(&self, instant: &Self::Instant) -> f32
Auto Trait Implementations§
impl Freeze for GatewayHttpProxy
impl !RefUnwindSafe for GatewayHttpProxy
impl Send for GatewayHttpProxy
impl Sync for GatewayHttpProxy
impl Unpin for GatewayHttpProxy
impl !UnwindSafe for GatewayHttpProxy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more