feat(txbuilder): expose independent output builder (#522)

This commit is contained in:
Santiago Carmuega 2024-10-17 13:36:33 -03:00 committed by GitHub
parent 19b0ac3072
commit 33b076ad23

View file

@ -49,7 +49,7 @@ impl BuildBabbage for StagingTransaction {
.outputs
.unwrap_or_default()
.iter()
.map(babbage_output)
.map(Output::build_babbage_raw)
.collect::<Result<Vec<_>, _>>()?;
let mint: Option<KeyValuePairs<Hash<28>, KeyValuePairs<_, _>>> = self.mint.map(|massets| {
@ -100,7 +100,7 @@ impl BuildBabbage for StagingTransaction {
let collateral_return = self
.collateral_output
.as_ref()
.map(babbage_output)
.map(Output::build_babbage_raw)
.transpose()?;
let reference_inputs = self
@ -261,10 +261,11 @@ impl BuildBabbage for StagingTransaction {
// }
}
fn babbage_output(
output: &Output,
impl Output {
pub fn build_babbage_raw(
&self,
) -> Result<PseudoTransactionOutput<PostAlonzoTransactionOutput>, TxBuilderError> {
let value = if let Some(ref assets) = output.assets {
let value = if let Some(ref assets) = self.assets {
let txb_assets = assets
.deref()
.iter()
@ -281,12 +282,12 @@ fn babbage_output(
.collect::<Vec<_>>()
.into();
Value::Multiasset(output.lovelace, txb_assets)
Value::Multiasset(self.lovelace, txb_assets)
} else {
Value::Coin(output.lovelace)
Value::Coin(self.lovelace)
};
let datum_option = if let Some(ref d) = output.datum {
let datum_option = if let Some(ref d) = self.datum {
match d.kind {
DatumKind::Hash => {
let dh: [u8; 32] = d
@ -306,7 +307,7 @@ fn babbage_output(
None
};
let script_ref = if let Some(ref s) = output.script {
let script_ref = if let Some(ref s) = self.script {
let script = match s.kind {
ScriptKind::Native => PallasScript::NativeScript(
NativeScript::decode_fragment(s.bytes.as_ref())
@ -327,10 +328,11 @@ fn babbage_output(
Ok(PseudoTransactionOutput::PostAlonzo(
PostAlonzoTransactionOutput {
address: output.address.to_vec().into(),
address: self.address.to_vec().into(),
value,
datum_option,
script_ref,
},
))
}
}