use serde::Deserialize;
use crate::client::http::transport::calls::{ApiError, Call, Transport, read};
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
pub struct Sent {
pub tx_hash: String,
#[serde(default)]
pub predicted_execution_time_ms: Option<u64>,
#[serde(default)]
pub volume_quota_remaining: Option<u64>,
}
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
pub struct SentBatch {
#[serde(rename = "tx_hash")]
pub tx_hashes: Vec<String>,
#[serde(default)]
pub predicted_execution_time_ms: Option<u64>,
#[serde(default)]
pub volume_quota_remaining: Option<u64>,
}
pub const MOST_IN_BATCH: usize = 50;
#[must_use]
pub fn send_tx_call(tx_type: u8, tx_info: String) -> Call {
Call::post("sendTx").field("tx_type", tx_type).field("tx_info", tx_info)
}
#[must_use]
pub fn send_tx_batch_call(txs: &[(u8, String)]) -> Call {
let types: Vec<u8> = txs.iter().map(|(tx_type, _)| *tx_type).collect();
let infos: Vec<&str> = txs.iter().map(|(_, info)| info.as_str()).collect();
Call::post("sendTxBatch")
.field("tx_types", serde_json::to_string(&types).unwrap_or_default())
.field("tx_infos", serde_json::to_string(&infos).unwrap_or_default())
}
pub async fn send_tx(transport: &impl Transport, tx_type: u8, tx_info: String) -> Result<Sent, ApiError> {
read(transport, send_tx_call(tx_type, tx_info)).await
}
pub async fn send_tx_batch(transport: &impl Transport, txs: &[(u8, String)]) -> Result<SentBatch, ApiError> {
read(transport, send_tx_batch_call(txs)).await
}
#[cfg(test)]
#[path = "tests/answer.rs"]
mod tests;