Skip to content

Commit

Permalink
remove hash_transaction function
Browse files Browse the repository at this point in the history
  • Loading branch information
lisicky committed Oct 9, 2024
1 parent 942a4eb commit 4a5df88
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
15 changes: 15 additions & 0 deletions rust/src/protocol_types/fixed_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ impl FixedTransaction {
})
}

pub fn new_from_body_bytes(raw_body: &[u8]) -> Result<FixedTransaction, JsError> {
let body = TransactionBody::from_bytes(raw_body.to_vec())?;
let tx_hash = TransactionHash::from(blake2b256(raw_body));

Ok(FixedTransaction {
body,
body_bytes: raw_body.to_vec(),
tx_hash,
witness_set: FixedTxWitnessesSet::new_empty(),
is_valid: true,
auxiliary_data: None,
auxiliary_bytes: None,
})
}

pub(crate) fn new_with_original_bytes(
tx_body: TransactionBody,
raw_body: Vec<u8>,
Expand Down
7 changes: 7 additions & 0 deletions rust/src/protocol_types/witnesses/fixed_tx_witnesses_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ impl FixedTxWitnessesSet {
}
}

pub(crate) fn new_empty() -> Self {
Self {
tx_witnesses_set: TransactionWitnessSet::new(),
raw_parts: TransactionWitnessSetRaw::new(),
}
}

pub fn tx_witnesses_set(&self) -> TransactionWitnessSet {
self.tx_witnesses_set.clone()
}
Expand Down
3 changes: 2 additions & 1 deletion rust/src/tests/builders/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2785,8 +2785,9 @@ fn build_tx_multisig_1on1_signed() {

let mut witness_set = TransactionWitnessSet::new();
let mut vkw = Vkeywitnesses::new();
let fixed_tx = FixedTransaction::new_from_body_bytes(&body.to_bytes()).unwrap();
vkw.add(&make_vkey_witness(
&hash_transaction(&body),
&fixed_tx.transaction_hash(),
&PrivateKey::from_normal_bytes(
&hex::decode("c660e50315d76a53d80732efda7630cae8885dfb85c46378684b3c6103e1284a")
.unwrap(),
Expand Down
23 changes: 14 additions & 9 deletions rust/src/tests/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ fn tx_simple_utxo() {

let mut w = TransactionWitnessSet::new();
let mut vkw = Vkeywitnesses::new();
let fixed_tx = FixedTransaction::new_from_body_bytes(&body.to_bytes()).unwrap();
vkw.add(&make_vkey_witness(
&hash_transaction(&body),
&fixed_tx.transaction_hash(),
&PrivateKey::from_normal_bytes(
&hex::decode("c660e50315d76a53d80732efda7630cae8885dfb85c46378684b3c6103e1284a")
.unwrap(),
Expand Down Expand Up @@ -95,8 +96,9 @@ fn tx_simple_byron_utxo() {

let mut w = TransactionWitnessSet::new();
let mut bootstrap_wits = BootstrapWitnesses::new();
let fixed_tx = FixedTransaction::new_from_body_bytes(&body.to_bytes()).unwrap();
bootstrap_wits.add(&make_icarus_bootstrap_witness(
&hash_transaction(&body),
&fixed_tx.transaction_hash(),
&ByronAddress::from_base58("Ae2tdPwUPEZ6r6zbg4ibhFrNnyKHg7SYuPSfDpjKxgvwFX9LquRep7gj7FQ").unwrap(),
&Bip32PrivateKey::from_bytes(
&hex::decode("d84c65426109a36edda5375ea67f1b738e1dacf8629f2bb5a2b0b20f3cd5075873bf5cdfa7e533482677219ac7d639e30a38e2e645ea9140855f44ff09e60c52c8b95d0d35fe75a70f9f5633a3e2439b2994b9e2bc851c49e9f91d1a5dcbb1a3").unwrap()
Expand Down Expand Up @@ -173,16 +175,17 @@ fn tx_multi_utxo() {

let mut w = TransactionWitnessSet::new();
let mut vkw = Vkeywitnesses::new();
let fixed_tx = FixedTransaction::new_from_body_bytes(&body.to_bytes()).unwrap();
vkw.add(&make_vkey_witness(
&hash_transaction(&body),
&fixed_tx.transaction_hash(),
&PrivateKey::from_normal_bytes(
&hex::decode("c660e50315d76a53d80732efda7630cae8885dfb85c46378684b3c6103e1284a")
.unwrap(),
)
.unwrap(),
));
vkw.add(&make_vkey_witness(
&hash_transaction(&body),
&fixed_tx.transaction_hash(),
&PrivateKey::from_normal_bytes(
&hex::decode("13fe79205e16c09536acb6f0524d04069f380329d13949698c5f22c65c989eb4")
.unwrap(),
Expand Down Expand Up @@ -283,9 +286,10 @@ fn tx_register_stake() {

let mut w = TransactionWitnessSet::new();
let mut vkw = Vkeywitnesses::new();
let fixed_tx = FixedTransaction::new_from_body_bytes(&body.to_bytes()).unwrap();
// input key witness
vkw.add(&make_vkey_witness(
&hash_transaction(&body),
&fixed_tx.transaction_hash(),
&PrivateKey::from_normal_bytes(
&hex::decode("c660e50315d76a53d80732efda7630cae8885dfb85c46378684b3c6103e1284a")
.unwrap(),
Expand All @@ -294,7 +298,7 @@ fn tx_register_stake() {
));
// operator key witness
vkw.add(&make_vkey_witness(
&hash_transaction(&body),
&fixed_tx.transaction_hash(),
&PrivateKey::from_normal_bytes(
&hex::decode("2363f3660b9f3b41685665bf10632272e2d03c258e8a5323436f0f3406293505")
.unwrap(),
Expand All @@ -303,7 +307,7 @@ fn tx_register_stake() {
));
// owner key witness
vkw.add(&make_vkey_witness(
&hash_transaction(&body),
&fixed_tx.transaction_hash(),
&PrivateKey::from_normal_bytes(
&hex::decode("5ada7f4d92bce1ee1707c0a0e211eb7941287356e6ed0e76843806e307b07c8d")
.unwrap(),
Expand Down Expand Up @@ -504,9 +508,10 @@ fn tx_withdrawal() {

let mut w = TransactionWitnessSet::new();
let mut vkw = Vkeywitnesses::new();
let fixed_tx = FixedTransaction::new_from_body_bytes(&body.to_bytes()).unwrap();
// input key witness
vkw.add(&make_vkey_witness(
&hash_transaction(&body),
&fixed_tx.transaction_hash(),
&PrivateKey::from_normal_bytes(
&hex::decode("c660e50315d76a53d80732efda7630cae8885dfb85c46378684b3c6103e1284a")
.unwrap(),
Expand All @@ -515,7 +520,7 @@ fn tx_withdrawal() {
));
// withdrawal key witness
vkw.add(&make_vkey_witness(
&hash_transaction(&body),
&fixed_tx.transaction_hash(),
&PrivateKey::from_normal_bytes(
&hex::decode("5ada7f4d92bce1ee1707c0a0e211eb7941287356e6ed0e76843806e307b07c8d")
.unwrap(),
Expand Down
5 changes: 0 additions & 5 deletions rust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,6 @@ pub fn hash_auxiliary_data(auxiliary_data: &AuxiliaryData) -> AuxiliaryDataHash
AuxiliaryDataHash::from(blake2b256(&auxiliary_data.to_bytes()))
}

#[wasm_bindgen]
pub fn hash_transaction(tx_body: &TransactionBody) -> TransactionHash {
TransactionHash::from(crypto::blake2b256(tx_body.to_bytes().as_ref()))
}

#[wasm_bindgen]
pub fn hash_plutus_data(plutus_data: &PlutusData) -> DataHash {
DataHash::from(blake2b256(&plutus_data.to_bytes()))
Expand Down

0 comments on commit 4a5df88

Please sign in to comment.