Skip to content

Refactor - Completely disable all P2SH code #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions src/primitives/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down
8 changes: 5 additions & 3 deletions src/utils/script_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
33 changes: 21 additions & 12 deletions src/utils/transaction_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<TxIn>,
fee: Option<ReceiverInfo>,
Expand All @@ -456,7 +459,7 @@ pub fn construct_p2sh_tx(
locktime: u64,
key_material: &BTreeMap<OutPoint, (PublicKey, SecretKey)>,
) -> Transaction {
let script_hash = construct_p2sh_address(script);
/*let script_hash = construct_p2sh_address(script);

let tx_out = TxOut {
value: asset,
Expand All @@ -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
Expand Down Expand Up @@ -707,16 +711,18 @@ pub fn construct_payment_tx_ins(tx_values: Vec<TxConstructor>) -> Vec<TxIn> {
///
/// * `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<TxIn> {
let mut tx_ins = Vec::new();
/*let mut tx_ins = Vec::new();
let previous_out = Some(tx_values.previous_out);

tx_ins.push(TxIn {
previous_out,
script_signature: script,
});

tx_ins
tx_ins*/
todo!("P2SH not yet supported!")
}

/// Constructs a dual double entry tx
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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
}
Expand Down