From f5411dc8f0e26ef087080e3e599d2794bf7bd1b6 Mon Sep 17 00:00:00 2001 From: DaPorkchop_ Date: Thu, 18 Jul 2024 12:37:38 +0200 Subject: [PATCH] Completely disable all P2SH code P2SH doesn't work yet, I don't want it to exist at all for the time being --- src/primitives/transaction.rs | 24 ------------------------ src/utils/script_utils.rs | 8 +++++--- src/utils/transaction_utils.rs | 33 +++++++++++++++++++++------------ 3 files changed, 26 insertions(+), 39 deletions(-) diff --git a/src/primitives/transaction.rs b/src/primitives/transaction.rs index 08435fd..ba2a2b9 100644 --- a/src/primitives/transaction.rs +++ b/src/primitives/transaction.rs @@ -164,16 +164,6 @@ impl TxOut { _ => panic!("Cannot create TxOut for asset of type {:?}", asset), } } - - /// Returns whether current tx_out is a P2SH - pub fn is_p2sh_tx_out(&self) -> bool { - if let Some(pk) = &self.script_public_key { - let pk_bytes = pk.as_bytes(); - return pk_bytes[0] == P2SH_PREPEND; - } - - false - } } /// The basic transaction that is broadcasted on the network and contained in @@ -236,18 +226,4 @@ impl Transaction { .map(|a| !a.is_token()) .unwrap_or_default() } - - /// Returns whether current transaction is a P2SH tx - pub fn is_p2sh_tx(&self) -> bool { - if self.outputs.len() != 1 { - return false; - } - - if let Some(pk) = &self.outputs[0].script_public_key { - let pk_bytes = pk.as_bytes(); - return pk_bytes[0] == P2SH_PREPEND; - } - - false - } } diff --git a/src/utils/script_utils.rs b/src/utils/script_utils.rs index a2cd085..f286b28 100644 --- a/src/utils/script_utils.rs +++ b/src/utils/script_utils.rs @@ -95,7 +95,7 @@ pub fn tx_is_valid<'a>( if let Some(pk) = tx_out_pk { // Check will need to include other signature types here if !tx_has_valid_p2pkh_sig(&tx_in.script_signature, &full_tx_hash, pk) - && !tx_has_valid_p2sh_script(&tx_in.script_signature, pk) + // TODO: jrabil: P2SH && !tx_has_valid_p2sh_script(&tx_in.script_signature, pk) { error!("INVALID SIGNATURE OR SCRIPT TYPE"); return false; @@ -258,8 +258,9 @@ fn tx_has_valid_p2pkh_sig(script: &Script, outpoint_hash: &str, tx_out_pub_key: /// /// * `script` - Script to validate /// * `address` - Address of the P2SH transaction +#[allow(unused_variables)] pub fn tx_has_valid_p2sh_script(script: &Script, address: &str) -> bool { - let p2sh_address = construct_p2sh_address(script); + /*let p2sh_address = construct_p2sh_address(script); if p2sh_address == address { return script.interpret(); @@ -271,7 +272,8 @@ pub fn tx_has_valid_p2sh_script(script: &Script, address: &str) -> bool { address ); - false + false*/ + todo!("P2SH not yet supported!") } /// Checks that a item's metadata conforms to the network size constraint diff --git a/src/utils/transaction_utils.rs b/src/utils/transaction_utils.rs index 8e9fd99..c03047b 100644 --- a/src/utils/transaction_utils.rs +++ b/src/utils/transaction_utils.rs @@ -20,15 +20,17 @@ pub struct ReceiverInfo { /// ### Arguments /// /// * `script` - Script to build address for +#[allow(unused_variables)] pub fn construct_p2sh_address(script: &Script) -> String { - let bytes = match serialize(script) { + /*let bytes = match serialize(script) { Ok(bytes) => bytes, Err(_) => vec![], }; let mut addr = hex::encode(sha3_256::digest(&bytes)); addr.insert(ZERO, P2SH_PREPEND as char); addr.truncate(STANDARD_ADDRESS_LENGTH); - addr + addr*/ + todo!("P2SH not yet supported!") } /// Builds an address from a public key and a specified network version @@ -448,6 +450,7 @@ pub fn construct_payment_tx( /// * `drs_block_hash` - Hash of the block containing the original DRS. Only for data trades /// * `asset` - Asset to send /// * `locktime` - Block height below which the payment is restricted. "0" means no locktime +#[allow(unused_variables)] pub fn construct_p2sh_tx( tx_ins: Vec, fee: Option, @@ -456,7 +459,7 @@ pub fn construct_p2sh_tx( locktime: u64, key_material: &BTreeMap ) -> Transaction { - let script_hash = construct_p2sh_address(script); + /*let script_hash = construct_p2sh_address(script); let tx_out = TxOut { value: asset, @@ -466,7 +469,8 @@ pub fn construct_p2sh_tx( let tx_outs = vec![tx_out]; let final_tx_ins = update_input_signatures(&tx_ins, &tx_outs, key_material); - construct_tx_core(final_tx_ins, tx_outs, fee) + construct_tx_core(final_tx_ins, tx_outs, fee)*/ + todo!("P2SH not yet supported!") } /// Constructs a P2SH transaction to burn tokens @@ -693,8 +697,9 @@ pub fn construct_payment_tx_ins(tx_values: Vec) -> Vec { /// /// * `tx_values` - Series of values required for TxIn construction /// * `script` - Script to be used in the scriptSig +#[allow(unused_variables)] pub fn construct_p2sh_redeem_tx_ins(tx_values: TxConstructor, script: Script) -> Vec { - let mut tx_ins = Vec::new(); + /*let mut tx_ins = Vec::new(); let previous_out = Some(tx_values.previous_out); tx_ins.push(TxIn { @@ -702,7 +707,8 @@ pub fn construct_p2sh_redeem_tx_ins(tx_values: TxConstructor, script: Script) -> script_signature: script, }); - tx_ins + tx_ins*/ + todo!("P2SH not yet supported!") } /// Constructs a dual double entry tx @@ -737,8 +743,7 @@ mod tests { use super::*; use crate::crypto::sign_ed25519::{self as sign, Signature}; use crate::primitives::asset::{AssetValues, ItemAsset, TokenAmount}; - use crate::script::OpCodes; - use crate::utils::script_utils::{tx_has_valid_p2sh_script, tx_outs_are_valid}; + use crate::utils::script_utils::tx_outs_are_valid; #[test] // Creates a valid payment transaction @@ -782,8 +787,9 @@ mod tests { } #[test] + #[should_panic] fn test_construct_a_valid_p2sh_tx() { - let token_amount = TokenAmount(400000); + /*let token_amount = TokenAmount(400000); let (tx_ins, _drs_block_hash, key_material) = test_construct_valid_inputs(Some(NETWORK_VERSION_V0)); let mut script = Script::new_for_coinbase(10); script.stack.push(StackEntry::Op(OpCodes::OP_DROP)); @@ -818,14 +824,16 @@ mod tests { assert!(tx_has_valid_p2sh_script( &redeeming_tx.inputs[0].script_signature, p2sh_tx.outputs[0].script_public_key.as_ref().unwrap() - )); + ));*/ + todo!("P2SH not yet supported!") // TODO: Add assertion for full tx validity } #[test] + #[should_panic] fn test_construct_a_valid_burn_tx() { - let token_amount = TokenAmount(400000); + /*let token_amount = TokenAmount(400000); let (tx_ins, _drs_block_hash, key_material) = test_construct_valid_inputs(Some(NETWORK_VERSION_V0)); let burn_tx = construct_burn_tx(tx_ins, None, &key_material); @@ -862,7 +870,8 @@ mod tests { assert!(!tx_has_valid_p2sh_script( &redeeming_tx.inputs[0].script_signature, burn_tx.outputs[0].script_public_key.as_ref().unwrap() - )); + ));*/ + todo!("P2SH not yet supported") // TODO: Add assertion for full tx validity }