From 3de9927ef78c078b545c48893686f1ac9eebe956 Mon Sep 17 00:00:00 2001 From: Cryp Toon Date: Tue, 16 Apr 2024 22:59:21 +0200 Subject: [PATCH] Cleanup Input method --- bitcoinlib/transactions.py | 31 ++++++++++++------------------- bitcoinlib/wallets.py | 10 ---------- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/bitcoinlib/transactions.py b/bitcoinlib/transactions.py index c7d17f9a..0702cc29 100644 --- a/bitcoinlib/transactions.py +++ b/bitcoinlib/transactions.py @@ -146,7 +146,7 @@ class Input(object): """ def __init__(self, prev_txid, output_n, keys=None, signatures=None, public_hash=b'', unlocking_script=b'', - locking_script=None, script=None, script_type=None, address='', + locking_script=None, script_type=None, address='', sequence=0xffffffff, compressed=None, sigs_required=None, sort=False, index_n=0, value=0, double_spend=False, locktime_cltv=None, locktime_csv=None, key_path='', witness_type=None, witnesses=None, encoding=None, strict=True, network=DEFAULT_NETWORK): @@ -272,26 +272,24 @@ def __init__(self, prev_txid, output_n, keys=None, signatures=None, public_hash= elif witnesses: self.witnesses = [bytes.fromhex(w) if isinstance(w, str) else w for w in witnesses] self.script_code = b'' - self.script = script # If unlocking script is specified extract keys, signatures, type from script - if self.unlocking_script and self.script_type != 'coinbase' and not (signatures and keys) and not script: - self.script = Script.parse_bytes(self.unlocking_script, strict=strict) - self.keys = self.script.keys - self.signatures = self.script.signatures + if self.unlocking_script and self.script_type != 'coinbase' and not (signatures and keys): + script = Script.parse_bytes(self.unlocking_script, strict=strict) + self.keys = script.keys + self.signatures = script.signatures if len(self.signatures): self.hash_type = self.signatures[0].hash_type - sigs_required = self.script.sigs_required - self.redeemscript = self.script.redeemscript if self.script.redeemscript else self.redeemscript - if len(self.script.script_types) == 1 and not self.script_type: - self.script_type = self.script.script_types[0] - elif self.script.script_types == ['signature_multisig', 'multisig']: + sigs_required = script.sigs_required + if len(script.script_types) == 1 and not self.script_type: + self.script_type = script.script_types[0] + elif script.script_types == ['signature_multisig', 'multisig']: self.script_type = 'p2sh_multisig' # TODO: Check if this if is necessary - if 'p2wpkh' in self.script.script_types: + if 'p2wpkh' in script.script_types: self.script_type = 'p2sh_p2wpkh' self.witness_type = 'p2sh-segwit' - elif 'p2wsh' in self.script.script_types: + elif 'p2wsh' in script.script_types: self.script_type = 'p2sh_p2wsh' self.witness_type = 'p2sh-segwit' if self.locking_script and not self.signatures: @@ -323,9 +321,6 @@ def __init__(self, prev_txid, output_n, keys=None, signatures=None, public_hash= else: kobj = key if kobj not in self.keys: - # if self.compressed is not None and kobj.compressed != self.compressed: - # _logger.warning("Key compressed is %s but Input class compressed argument is %s " % - # (kobj.compressed, self.compressed)) self.compressed = kobj.compressed self.keys.append(kobj) if self.compressed is None: @@ -439,7 +434,6 @@ def update_scripts(self, hash_type=SIGHASH_ALL): else: self.public_hash = hash160(self.redeemscript) addr_data = self.public_hash - # self.locking_script = self.redeemscript if self.redeemscript and self.keys: n_tag = self.redeemscript[0:1] @@ -491,8 +485,7 @@ def update_scripts(self, hash_type=SIGHASH_ALL): script_type=self.script_type, witness_type=self.witness_type).address if self.locktime_cltv: - self.locking_script = script_add_locktime_cltv(self.locktime_cltv, - self.locking_script) + self.locking_script = script_add_locktime_cltv(self.locktime_cltv, self.locking_script) # if self.unlocking_script: # self.unlocking_script = script_add_locktime_cltv(self.locktime_cltv, self.unlocking_script) # if self.witness_type == 'segwit': diff --git a/bitcoinlib/wallets.py b/bitcoinlib/wallets.py index 0c1e757d..55f20f56 100644 --- a/bitcoinlib/wallets.py +++ b/bitcoinlib/wallets.py @@ -3811,16 +3811,6 @@ def transaction_create(self, output_arr, input_arr=None, input_key_id=None, acco locktime_cltv = inp.locktime_cltv locktime_csv = inp.locktime_csv witness_type = inp.witness_type - # elif isinstance(inp, DbTransactionOutput): - # prev_txid = inp.transaction.txid - # output_n = inp.output_n - # key_id = inp.key_id - # value = inp.value - # signatures = None - # # FIXME: This is probably not an unlocking_script - # unlocking_script = inp.script - # unlocking_script_type = get_unlocking_script_type(inp.script_type) - # address = inp.key.address else: prev_txid = inp[0] output_n = inp[1]