multiversx_sdk_http/gateway_http_proxy/
http_account.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
use anyhow::Result;
use multiversx_sdk::{
    chain_core::types::Address,
    data::{account::Account, esdt::EsdtBalance},
    gateway::{
        GetAccountEsdtRolesRequest, GetAccountEsdtTokensRequest, GetAccountRequest,
        GetAccountStorageRequest,
    },
};
use std::collections::HashMap;

use super::GatewayHttpProxy;

impl GatewayHttpProxy {
    // get_account retrieves an account info from the network (nonce, balance)
    pub async fn get_account(&self, address: &Address) -> Result<Account> {
        self.http_request(GetAccountRequest::new(address)).await
    }

    // get_account_esdt_roles retrieves an all esdt roles of an account from the network
    pub async fn get_account_esdt_roles(
        &self,
        address: &Address,
    ) -> Result<HashMap<String, Vec<String>>> {
        self.http_request(GetAccountEsdtRolesRequest::new(address))
            .await
    }

    // get_account_esdt_tokens retrieves an all esdt token of an account from the network
    pub async fn get_account_esdt_tokens(
        &self,
        address: &Address,
    ) -> Result<HashMap<String, EsdtBalance>> {
        self.http_request(GetAccountEsdtTokensRequest::new(address))
            .await
    }

    // get_account_esdt_tokens retrieves an all esdt token of an account from the network
    pub async fn get_account_storage_keys(
        &self,
        address: &Address,
    ) -> Result<HashMap<String, String>> {
        self.http_request(GetAccountStorageRequest::new(address))
            .await
    }
}