whisky_provider/blockfrost/
submitter.rs

1use async_trait::async_trait;
2use whisky_common::{Submitter, WError};
3
4use super::BlockfrostProvider;
5
6#[async_trait]
7impl Submitter for BlockfrostProvider {
8    async fn submit_tx(&self, tx_hex: &str) -> Result<String, WError> {
9        let url = "/tx/submit";
10        let blockfrost_client = &self.blockfrost_client;
11
12        let tx_binary = hex::decode(tx_hex).map_err(WError::from_err("Invalid hex data"))?;
13        let req = blockfrost_client
14            .http_client
15            .post(format!("{}{}", &blockfrost_client.base_url, url))
16            .header("Content-Type", "application/cbor")
17            .body(tx_binary);
18
19        let mut response_body = String::new();
20        self.blockfrost_client
21            .send_request(req, &mut response_body)
22            .await
23            .map_err(WError::from_err("Blockfrost - submit_tx"))?;
24
25        let tx_hash = response_body.trim_matches('"').to_string();
26
27        Ok(tx_hash)
28    }
29}