Skip to content

Commit

Permalink
make FixedTxWitnessesSet public
Browse files Browse the repository at this point in the history
  • Loading branch information
lisicky committed Sep 9, 2024
1 parent 4ac086c commit f6cb29a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions rust/src/protocol_types/witnesses/fixed_tx_witnesses_set.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
use crate::*;
#[allow(dead_code)]


/// A set of witnesses for a transaction.
/// Keeps original bytes to allow for safe roundtrip serialization.
/// That helps to avoid incorrect script data hash after adding a vkey or bootstrap witness.
/// You can add a vkey witness or a bootstrap witness to the set.
/// Or get TransactionWitnessSet to read fields.
#[wasm_bindgen]
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct FixedTxWitnessesSet {
pub(crate) raw_parts: TransactionWitnessSetRaw,
pub(crate) tx_witnesses_set: TransactionWitnessSet,
}

#[wasm_bindgen]
impl FixedTxWitnessesSet {
pub(crate) fn tx_witnesses_set(&self) -> TransactionWitnessSet {
pub fn tx_witnesses_set(&self) -> TransactionWitnessSet {
self.tx_witnesses_set.clone()
}

pub(crate) fn add_vkey_witness(&mut self, vkey_witness: Vkeywitness) {
pub fn add_vkey_witness(&mut self, vkey_witness: Vkeywitness) {
if self.tx_witnesses_set.vkeys.is_none() {
self.tx_witnesses_set.vkeys = Some(Vkeywitnesses::new());
}
Expand All @@ -22,7 +30,7 @@ impl FixedTxWitnessesSet {
self.raw_parts.vkeys = None;
}

pub(crate) fn add_bootstrap_witness(&mut self, bootstrap_witness: BootstrapWitness) {
pub fn add_bootstrap_witness(&mut self, bootstrap_witness: BootstrapWitness) {
if self.tx_witnesses_set.bootstraps.is_none() {
self.tx_witnesses_set.bootstraps = Some(BootstrapWitnesses::new());
}
Expand All @@ -32,20 +40,20 @@ impl FixedTxWitnessesSet {
self.raw_parts.bootstraps = None;
}

pub(crate) fn to_bytes(&self) -> Vec<u8> {
pub fn to_bytes(&self) -> Vec<u8> {
let mut buf = Serializer::new_vec();
self.serialize(&mut buf).unwrap();
buf.finalize()
}

#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
pub(crate) fn from_bytes(data: Vec<u8>) -> Result<FixedTxWitnessesSet, DeserializeError> {
pub fn from_bytes(data: Vec<u8>) -> Result<FixedTxWitnessesSet, DeserializeError> {
let mut raw = Deserializer::from(std::io::Cursor::new(data));
Self::deserialize(&mut raw)
}

#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
pub(crate) fn from_bytes(data: Vec<u8>) -> Result<FixedTxWitnessesSet, JsError> {
pub fn from_bytes(data: Vec<u8>) -> Result<FixedTxWitnessesSet, JsError> {
let mut raw = Deserializer::from(std::io::Cursor::new(data));
Ok(Self::deserialize(&mut raw)?)
}
Expand Down
2 changes: 1 addition & 1 deletion rust/src/protocol_types/witnesses/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ mod transaction_witnesses_sets;
pub use transaction_witnesses_sets::*;

mod fixed_tx_witnesses_set;
pub(crate) use fixed_tx_witnesses_set::*;
pub use fixed_tx_witnesses_set::*;

0 comments on commit f6cb29a

Please sign in to comment.