multiversx_sdk/gateway/
gateway_chain_simulator_send_funds.rs

1use std::collections::HashMap;
2
3use anyhow::anyhow;
4use multiversx_chain_core::std::Bech32Address;
5
6use super::{
7    gateway_chain_simulator_blocks::GenerateBlocksResponse, GatewayRequest, GatewayRequestType,
8    SEND_USER_FUNDS_ENDPOINT,
9};
10
11/// Generates blocks using the chain simulator API.
12pub struct ChainSimulatorSendFundsRequest {
13    payload: HashMap<&'static str, String>,
14}
15
16impl ChainSimulatorSendFundsRequest {
17    pub fn to_address(receiver: &Bech32Address) -> Self {
18        let mut payload = HashMap::new();
19        payload.insert("receiver", receiver.bech32.clone());
20        Self { payload }
21    }
22}
23
24impl GatewayRequest for ChainSimulatorSendFundsRequest {
25    type Payload = HashMap<&'static str, String>;
26    type DecodedJson = GenerateBlocksResponse;
27    type Result = String;
28
29    fn request_type(&self) -> GatewayRequestType {
30        GatewayRequestType::Post
31    }
32
33    fn get_endpoint(&self) -> String {
34        SEND_USER_FUNDS_ENDPOINT.to_owned()
35    }
36
37    fn get_payload(&self) -> Option<&Self::Payload> {
38        Some(&self.payload)
39    }
40
41    fn process_json(&self, decoded: Self::DecodedJson) -> anyhow::Result<Self::Result> {
42        match decoded.code.as_str() {
43            "successful" => Ok(decoded.code),
44            _ => Err(anyhow!("{}", decoded.error)),
45        }
46    }
47}