multiversx_sdk/gateway/
gateway_account_esdt_roles.rs

1use crate::data::esdt::EsdtRolesResponse;
2use anyhow::anyhow;
3use multiversx_chain_core::std::Bech32Address;
4use std::collections::HashMap;
5
6use super::{GatewayRequest, GatewayRequestType, ACCOUNT_ENDPOINT};
7
8/// Retrieves an all esdt roles of an account from the network.
9pub struct GetAccountEsdtRolesRequest<'a> {
10    pub address: &'a Bech32Address,
11}
12
13impl<'a> GetAccountEsdtRolesRequest<'a> {
14    pub fn new(address: &'a Bech32Address) -> Self {
15        Self { address }
16    }
17}
18
19impl GatewayRequest for GetAccountEsdtRolesRequest<'_> {
20    type Payload = ();
21    type DecodedJson = EsdtRolesResponse;
22    type Result = HashMap<String, Vec<String>>;
23
24    fn request_type(&self) -> GatewayRequestType {
25        GatewayRequestType::Get
26    }
27
28    fn get_endpoint(&self) -> String {
29        format!("{ACCOUNT_ENDPOINT}/{}/esdts/roles", 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.roles),
36        }
37    }
38}