use bincode;
use reqwest::Client;
use solana_sdk::{signature::Signature, transaction::Transaction};
use std::str::FromStr;
fn build_binary_body(transactions: &[Transaction]) -> Vec<u8> {
let mut body = Vec::new();
for tx in transactions {
let tx_bytes = bincode::serialize(tx).expect("failed to serialize transaction");
let len = tx_bytes.len() as u16;
body.extend_from_slice(&len.to_be_bytes());
body.extend_from_slice(&tx_bytes);
}
body
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let url = "https://lim.gateway.astralane.io/irisb?api-key=APIKEY&method=sendBatch";
// Build your Vec<Transaction> however you like
let transactions: Vec<Transaction> = vec![/* tx1, tx2, ... */];
let binary_body = build_binary_body(&transactions);
let client = Client::new();
let response = client
.post(url)
.header("content-type", "application/octet-stream")
.body(binary_body)
.send()
.await?;
let status = response.status();
let body_text = response.text().await?;
if !status.is_success() {
anyhow::bail!("request failed ({}): {}", status, body_text);
}
// Parse signatures from the response
let parsed: serde_json::Value = serde_json::from_str(&body_text)?;
let sig_array = parsed["result"]
.as_array()
.or_else(|| parsed.as_array())
.expect("unexpected response format");
let signatures: Vec<Signature> = sig_array
.iter()
.map(|v| {
let s = v.as_str().expect("signature must be a string");
Signature::from_str(s).expect("invalid signature")
})
.collect();
for (i, sig) in signatures.iter().enumerate() {
println!("tx[{}] signature: {}", i, sig);
}
Ok(())
}