multiversx_sdk/gateway/
gateway_tx_send.rs

1use crate::data::transaction::{SendTransactionResponse, Transaction};
2use anyhow::anyhow;
3
4use super::{GatewayRequest, GatewayRequestType, SEND_TRANSACTION_ENDPOINT};
5
6/// Sends a single transaction.
7pub struct SendTxRequest<'a>(pub &'a Transaction);
8
9impl GatewayRequest for SendTxRequest<'_> {
10    type Payload = Transaction;
11    type DecodedJson = SendTransactionResponse;
12    type Result = String;
13
14    fn request_type(&self) -> GatewayRequestType {
15        GatewayRequestType::Post
16    }
17
18    fn get_payload(&self) -> Option<&Self::Payload> {
19        Some(self.0)
20    }
21
22    fn get_endpoint(&self) -> String {
23        SEND_TRANSACTION_ENDPOINT.to_owned()
24    }
25
26    fn process_json(&self, decoded: Self::DecodedJson) -> anyhow::Result<Self::Result> {
27        match decoded.data {
28            None => Err(anyhow!("{}", decoded.error)),
29            Some(b) => Ok(b.tx_hash),
30        }
31    }
32}