Skip to content

Commit

Permalink
fix(txbuilder): support adding signatures to Conway transactions (#553)
Browse files Browse the repository at this point in the history
Co-authored-by: logicalmechanism <[email protected]>
Co-authored-by: logicalmechanism <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2024
1 parent 296b43f commit e9b7ec2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<a name="unreleased"></a>
## [Unreleased]


<a name="v0.30.1"></a>
## [v0.30.1] - 2024-08-25
### Fix
Expand Down
1 change: 0 additions & 1 deletion pallas-txbuilder/src/conway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ impl BuildConway for StagingTransaction {
language_view,
};

dbg!(&dta);
dta.hash()
});

Expand Down
26 changes: 17 additions & 9 deletions pallas-txbuilder/src/transaction/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use pallas_crypto::{
hash::{Hash, Hasher},
key::ed25519,
};
use pallas_primitives::{babbage, conway, Fragment, NonEmptySet};
use pallas_primitives::{conway, Fragment, NonEmptySet};
use pallas_wallet::PrivateKey;

use std::{collections::HashMap, ops::Deref};
Expand Down Expand Up @@ -644,7 +644,7 @@ impl BuiltTransaction {
.map(|x| x.to_vec())
.unwrap_or_default();

vkey_witnesses.push(babbage::VKeyWitness {
vkey_witnesses.push(conway::VKeyWitness {
vkey: Vec::from(pubkey.as_ref()).into(),
signature: Vec::from(signature.as_ref()).into(),
});
Expand Down Expand Up @@ -682,17 +682,21 @@ impl BuiltTransaction {
self.signatures = Some(new_sigs);

// TODO: chance for serialisation round trip issues?
let mut tx = babbage::Tx::decode_fragment(&self.tx_bytes.0)
let mut tx = conway::Tx::decode_fragment(&self.tx_bytes.0)
.map_err(|_| TxBuilderError::CorruptedTxBytes)?;

let mut vkey_witnesses = tx.transaction_witness_set.vkeywitness.unwrap_or_default();
let mut vkey_witnesses = tx
.transaction_witness_set
.vkeywitness
.map(|x| x.to_vec())
.unwrap_or_default();

vkey_witnesses.push(babbage::VKeyWitness {
vkey_witnesses.push(conway::VKeyWitness {
vkey: Vec::from(pub_key.as_ref()).into(),
signature: Vec::from(signature.as_ref()).into(),
});

tx.transaction_witness_set.vkeywitness = Some(vkey_witnesses);
tx.transaction_witness_set.vkeywitness = Some(NonEmptySet::from_vec(vkey_witnesses).unwrap());

self.tx_bytes = tx.encode_fragment().unwrap().into();
}
Expand All @@ -719,14 +723,18 @@ impl BuiltTransaction {
self.signatures = Some(new_sigs);

// TODO: chance for serialisation round trip issues?
let mut tx = babbage::Tx::decode_fragment(&self.tx_bytes.0)
let mut tx = conway::Tx::decode_fragment(&self.tx_bytes.0)
.map_err(|_| TxBuilderError::CorruptedTxBytes)?;

let mut vkey_witnesses = tx.transaction_witness_set.vkeywitness.unwrap_or_default();
let mut vkey_witnesses = tx
.transaction_witness_set
.vkeywitness
.map(|x| x.to_vec())
.unwrap_or_default();

vkey_witnesses.retain(|x| *x.vkey != pk.0.to_vec());

tx.transaction_witness_set.vkeywitness = Some(vkey_witnesses);
tx.transaction_witness_set.vkeywitness = Some(NonEmptySet::from_vec(vkey_witnesses).unwrap());

self.tx_bytes = tx.encode_fragment().unwrap().into();
}
Expand Down

0 comments on commit e9b7ec2

Please sign in to comment.