From e561588c3b7025f1703666ad6fc022a6fe04c441 Mon Sep 17 00:00:00 2001 From: Pedro Camboim Date: Wed, 17 Apr 2024 14:28:33 -0300 Subject: [PATCH] feat: serialize btc raw tx --- packages/kos-sdk/src/chains/bitcoin/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/kos-sdk/src/chains/bitcoin/mod.rs b/packages/kos-sdk/src/chains/bitcoin/mod.rs index 0320b02..23e1810 100644 --- a/packages/kos-sdk/src/chains/bitcoin/mod.rs +++ b/packages/kos-sdk/src/chains/bitcoin/mod.rs @@ -296,6 +296,16 @@ impl BTC { } } + #[wasm_bindgen(js_name = "serializeTx")] + pub fn serialize_tx(tx: Transaction) -> Result { + match tx.data { + Some(TransactionRaw::Bitcoin(btc_tx)) => Ok(btc_tx.btc_serialize_hex()), + _ => Err(Error::InvalidTransaction( + "not a bitcoin transaction".to_string(), + )), + } + } + fn decode_magic(hex_magic: String) -> Result { let magic_bytes = hex::decode(hex_magic)?; if magic_bytes.len() != 4 {