multiversx_sdk/gateway/
gateway_tx_send_multi.rs1use crate::data::transaction::{SendTransactionsResponse, Transaction};
2use anyhow::anyhow;
3use itertools::Itertools;
4
5use super::{GatewayRequest, GatewayRequestType, SEND_MULTIPLE_TRANSACTIONS_ENDPOINT};
6
7pub struct SendMultiTxRequest<'a>(pub &'a [Transaction]);
9
10impl GatewayRequest for SendMultiTxRequest<'_> {
11 type Payload = [Transaction];
12 type DecodedJson = SendTransactionsResponse;
13 type Result = Vec<String>;
14
15 fn request_type(&self) -> GatewayRequestType {
16 GatewayRequestType::Post
17 }
18
19 fn get_payload(&self) -> Option<&Self::Payload> {
20 Some(self.0)
21 }
22
23 fn get_endpoint(&self) -> String {
24 SEND_MULTIPLE_TRANSACTIONS_ENDPOINT.to_owned()
25 }
26
27 fn process_json(&self, decoded: Self::DecodedJson) -> anyhow::Result<Self::Result> {
28 match decoded.data {
29 None => Err(anyhow!("{}", decoded.error)),
30 Some(b) => {
31 let mut tx_hashes: Vec<String> = vec![];
32 for key in b.txs_hashes.keys().sorted() {
33 tx_hashes.push(b.txs_hashes[key].clone());
34 }
35
36 Ok(tx_hashes)
37 }
38 }
39 }
40}