Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/pset/elip101.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl Output {
#[cfg(test)]
mod test {
use super::*;
use crate::AssetId;
use crate::encode::{serialize_hex, Encodable};
use crate::hex::{FromHex, ToHex};

Expand Down Expand Up @@ -110,4 +111,30 @@ mod test {
assert!(output_hex.contains(ELIP0101_IDENTIFIER));
assert!(output_hex.contains(abf_hex));
}

#[test]
fn abf_roundtrip() {
use crate::pset::PartiallySignedTransaction;

// Set abf on an input and on an output
let abf = AssetBlindingFactor::from_slice(&[3; 32]).unwrap();
let mut pset = PartiallySignedTransaction::new_v2();
let mut input = Input::default();
input.set_abf(abf);
pset.add_input(input);
let mut output = Output {
amount: Some(1),
asset: Some(AssetId::from_slice(&[9; 32]).unwrap()),
..Default::default()
};
output.set_abf(abf);
pset.add_output(output);

// Serialize and deserialize
let bytes = encode::serialize(&pset);
let pset_back = encode::deserialize::<PartiallySignedTransaction>(&bytes).unwrap();
// Check the abf
assert_eq!(pset_back.inputs()[0].get_abf().unwrap().unwrap(), abf);
assert_eq!(pset_back.outputs()[0].get_abf().unwrap().unwrap(), abf);
}
}
10 changes: 10 additions & 0 deletions src/pset/map/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,18 @@ impl Map for Input {
Entry::Occupied(_) => return Err(Error::DuplicateKey(raw_key).into()),
},
}
} else {
match self.proprietary.entry(prop_key) {
Entry::Vacant(empty_key) => {
empty_key.insert(raw_value);
}
Entry::Occupied(_) => {
return Err(Error::DuplicateKey(raw_key).into())
}
}
}
}

_ => match self.unknown.entry(raw_key) {
Entry::Vacant(empty_key) => {
empty_key.insert(raw_value);
Expand Down