multiversx_sdk/gateway/
gateway_account_storage.rs1use crate::data::account_storage::AccountStorageResponse;
2use anyhow::anyhow;
3use multiversx_chain_core::std::Bech32Address;
4use std::collections::HashMap;
5
6use super::{GatewayRequest, GatewayRequestType, ACCOUNT_ENDPOINT, KEYS_ENDPOINT};
7
8pub struct GetAccountStorageRequest<'a> {
10 pub address: &'a Bech32Address,
11}
12
13impl<'a> GetAccountStorageRequest<'a> {
14 pub fn new(address: &'a Bech32Address) -> Self {
15 Self { address }
16 }
17}
18
19impl GatewayRequest for GetAccountStorageRequest<'_> {
20 type Payload = ();
21 type DecodedJson = AccountStorageResponse;
22 type Result = HashMap<String, String>;
23
24 fn request_type(&self) -> GatewayRequestType {
25 GatewayRequestType::Get
26 }
27
28 fn get_endpoint(&self) -> String {
29 format!("{ACCOUNT_ENDPOINT}/{}/{KEYS_ENDPOINT}", self.address.bech32)
30 }
31
32 fn process_json(&self, decoded: Self::DecodedJson) -> anyhow::Result<Self::Result> {
33 match decoded.data {
34 None => Err(anyhow!("{}", decoded.error)),
35 Some(b) => Ok(b.pairs),
36 }
37 }
38}