diff --git a/src/primitives/transaction.rs b/src/primitives/transaction.rs index fe697e0..7ab0363 100644 --- a/src/primitives/transaction.rs +++ b/src/primitives/transaction.rs @@ -169,16 +169,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 @@ -241,20 +231,6 @@ 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 - } } #[cfg(test)] diff --git a/src/utils/script_utils.rs b/src/utils/script_utils.rs index 786ac0b..403b4d9 100644 --- a/src/utils/script_utils.rs +++ b/src/utils/script_utils.rs @@ -109,7 +109,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, "Invalid signature or script structure".to_string()); @@ -282,8 +282,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(); @@ -295,7 +296,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 eee4332..24a5298 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 @@ -707,8 +711,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 { @@ -716,7 +721,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 @@ -751,8 +757,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 @@ -802,8 +807,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); @@ -846,14 +852,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)); @@ -891,7 +899,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 }