fix(txbuilder): support adding signatures to Conway transactions (#553)

Co-authored-by: logicalmechanism <logicalmechanism@protonmail.com>
Co-authored-by: logicalmechanism <logicalmechanism@proton.mail>
This commit is contained in:
Logical Mechanism 2024-12-11 16:54:09 -08:00 committed by GitHub
parent 296b43f33a
commit e9b7ec23ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 11 deletions

View file

@ -1,7 +1,6 @@
<a name="unreleased"></a>
## [Unreleased]
<a name="v0.30.1"></a>
## [v0.30.1] - 2024-08-25
### Fix

View file

@ -230,7 +230,6 @@ impl BuildConway for StagingTransaction {
language_view,
};
dbg!(&dta);
dta.hash()
});

View file

@ -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};
@ -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(),
});
@ -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();
}
@ -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();
}