Skip to content

Commit

Permalink
Serialize the asset's issuance_prevout as an object
Browse files Browse the repository at this point in the history
As was the case prior to rust-bitcoin/rust-bitcoin#271
  • Loading branch information
shesek committed Oct 1, 2021
1 parent ef2434f commit 0db507d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/elements/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 49,7 @@ pub struct NativeAsset {
pub struct IssuedAsset {
pub asset_id: AssetId,
pub issuance_txin: TxInput,
#[serde(serialize_with = "crate::util::serialize_outpoint")]
pub issuance_prevout: OutPoint,
pub reissuance_token: AssetId,

Expand Down
3 changes: 2 additions & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 9,8 @@ pub use self::block::{BlockHeaderMeta, BlockId, BlockMeta, BlockStatus, HeaderEn
pub use self::fees::get_tx_fee;
pub use self::script::{get_innerscripts, ScriptToAddr, ScriptToAsm};
pub use self::transaction::{
extract_tx_prevouts, has_prevout, is_coinbase, is_spendable, TransactionStatus, TxInput,
extract_tx_prevouts, has_prevout, is_coinbase, is_spendable, serialize_outpoint,
TransactionStatus, TxInput,
};

use std::collections::HashMap;
Expand Down
11 changes: 11 additions & 0 deletions src/util/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 94,14 @@ pub fn extract_tx_prevouts<'a>(
})
.collect()
}

pub fn serialize_outpoint<S>(outpoint: &OutPoint, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
use serde::ser::SerializeStruct;
let mut s = serializer.serialize_struct("OutPoint", 2)?;
s.serialize_field("txid", &outpoint.txid)?;
s.serialize_field("vout", &outpoint.vout)?;
s.end()
}

0 comments on commit 0db507d

Please sign in to comment.