Skip to content

Commit

Permalink
pset: implement (de)serialize for AssetBlindingFactor
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoComandini committed Apr 23, 2024
1 parent d80aa1b commit 04ab514
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/pset/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use std::convert::TryFrom;
use std::io;

use crate::confidential;
use crate::confidential::{self, AssetBlindingFactor};
use crate::encode::{self, deserialize, deserialize_partial, serialize, Decodable, Encodable};
use crate::hashes::{hash160, ripemd160, sha256, sha256d, Hash};
use crate::{AssetId, BlockHash, Script, Transaction, TxOut, Txid};
Expand Down Expand Up @@ -96,6 +96,19 @@ impl Deserialize for Tweak {
}
}

impl Serialize for AssetBlindingFactor {
fn serialize(&self) -> Vec<u8> {
encode::serialize(self.into_inner().as_ref())
}
}

impl Deserialize for AssetBlindingFactor {
fn deserialize(bytes: &[u8]) -> Result<Self, encode::Error> {
let x = deserialize::<[u8; 32]>(bytes)?;
AssetBlindingFactor::from_slice(&x).map_err(|_| encode::Error::ParseFailed("invalid AssetBlindingFactor"))
}
}

impl Serialize for Script {
fn serialize(&self) -> Vec<u8> {
self.to_bytes()
Expand Down

0 comments on commit 04ab514

Please sign in to comment.