multiversx_sdk_http/gateway_http_proxy/
http_tx.rs

1
2
3
4
5
6
7
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use anyhow::Result;
use multiversx_sdk::{
    chain_core::types::Address,
    data::{
        network_config::NetworkConfig,
        sdk_address::SdkAddress,
        transaction::{
            ArgCreateTransaction, Transaction, TransactionOnNetwork, TxCostResponseData,
        },
        vm::{VMQueryInput, VmValuesResponseData},
    },
    gateway::{
        GetTxCost, GetTxInfo, GetTxProcessStatus, GetTxStatus, SendMultiTxRequest, SendTxRequest,
        VMQueryRequest,
    },
};

use super::GatewayHttpProxy;

impl GatewayHttpProxy {
    // request_transaction_cost retrieves how many gas a transaction will consume
    pub async fn request_transaction_cost(&self, tx: &Transaction) -> Result<TxCostResponseData> {
        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<TransactionOnNetwork> {
        self.http_request(GetTxInfo::new(hash)).await
    }

    // get_transaction_info_with_results retrieves a transaction's details from the network with events
    pub async fn get_transaction_info_with_results(
        &self,
        hash: &str,
    ) -> Result<TransactionOnNetwork> {
        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<String> {
        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.http_request(GetTxProcessStatus::new(hash)).await
    }

    // get_default_transaction_arguments will prepare the transaction creation argument by querying the account's info
    pub async fn get_default_transaction_arguments(
        &self,
        address: &Address,
        network_configs: &NetworkConfig,
    ) -> Result<ArgCreateTransaction> {
        let account = self.get_account(address).await?;

        Ok(ArgCreateTransaction {
            nonce: account.nonce,
            value: "".to_string(),
            rcv_addr: SdkAddress(address.clone()),
            snd_addr: SdkAddress(address.clone()),
            gas_price: network_configs.min_gas_price,
            gas_limit: network_configs.min_gas_limit,
            data: None,
            signature: "".to_string(),
            chain_id: network_configs.chain_id.clone(),
            version: network_configs.min_transaction_version,
            options: 0,
            available_balance: account.balance,
        })
    }

    pub async fn send_transaction(&self, tx: &Transaction) -> Result<String> {
        self.http_request(SendTxRequest(tx)).await
    }

    #[allow(clippy::ptr_arg)]
    pub async fn send_transactions(&self, txs: &Vec<Transaction>) -> Result<Vec<String>> {
        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<VmValuesResponseData> {
        self.http_request(VMQueryRequest(vm_request)).await
    }
}