Skip to content

Commit 2dba2ee

Browse files
committed
add LiquidClient::get_tx
1 parent dd5b0f6 commit 2dba2ee

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/network/electrum.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ impl LiquidClient for ElectrumLiquidClient {
252252
))
253253
}
254254

255+
async fn get_tx(&self, txid: elements::Txid) -> Result<elements::Transaction, Error> {
256+
let bitcoin_txid = bitcoin::Txid::from_raw_hash(txid.to_raw_hash().into());
257+
let raw_tx = self.inner.transaction_get_raw(&bitcoin_txid)?;
258+
Ok(elements::encode::deserialize(&raw_tx)?)
259+
}
260+
255261
async fn broadcast_tx(&self, signed_tx: &elements::Transaction) -> Result<String, Error> {
256262
let serialized = serialize(signed_tx);
257263
Ok(self

src/network/esplora.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@ impl LiquidClient for EsploraLiquidClient {
264264
Ok(elements::BlockHash::from_str(&text)?)
265265
}
266266

267+
async fn get_tx(&self, txid: elements::Txid) -> Result<elements::Transaction, Error> {
268+
let url = format!("{}/tx/{txid}/raw", self.base_url);
269+
let response = get_with_retry(&self.client, &url, self.timeout).await?;
270+
let raw_tx = response.bytes().await?;
271+
272+
Ok(elements::encode::deserialize(&raw_tx)?)
273+
}
274+
267275
async fn broadcast_tx(&self, signed_tx: &elements::Transaction) -> Result<String, Error> {
268276
let url = format!("{}/tx", self.base_url);
269277
let tx_hex = signed_tx.serialize().to_hex();

src/network/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ pub trait LiquidClient: Send + Sync {
156156

157157
async fn get_genesis_hash(&self) -> Result<elements::BlockHash, Error>;
158158

159+
async fn get_tx(&self, txid: elements::Txid) -> Result<elements::Transaction, Error>;
160+
159161
async fn broadcast_tx(&self, signed_tx: &elements::Transaction) -> Result<String, Error>;
160162

161163
fn network(&self) -> LiquidChain;

0 commit comments

Comments
 (0)