Skip to content

Commit

Permalink
Get rid of tx_total_outputs_value()
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapsk committed Nov 28, 2023
1 parent 09eea1b commit ca972cd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
9 changes: 0 additions & 9 deletions src/jmbitcoin/secp256k1_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,6 @@ def tx_vsize(tx):
non_witness_size = raw_tx_size - witness_size
return ceil(non_witness_size + .25 * witness_size)

def tx_total_outputs_value(tx: CTransaction) -> int:
"""
Returns sum of all transaction outputs value in satoshis.
"""
tx_out_sum = 0
for txout in tx.vout:
tx_out_sum = tx_out_sum + txout.nValue
return tx_out_sum

def pubkey_to_p2pkh_script(pub, require_compressed=False):
"""
Given a pubkey in bytes, return a CScript
Expand Down
9 changes: 4 additions & 5 deletions src/jmclient/maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def on_tx_received(self, nick, tx, offerinfo):
sigs.append(base64.b64encode(sigmsg).decode('ascii'))
return (True, sigs)

def verify_unsigned_tx(self, tx, offerinfo):
def verify_unsigned_tx(self, tx: btc.CTransaction, offerinfo):
"""This code is security-critical.
Before signing the transaction the Maker must ensure
that all details are as expected, and most importantly
Expand All @@ -191,10 +191,9 @@ def verify_unsigned_tx(self, tx, offerinfo):

if self.minimum_tx_fee_rate > 1000:
tx_inp_data = jm_single().bc_interface.query_utxo_set(tx_utxo_set)
total_input_value_sum = 0
for utxo in tx_inp_data:
total_input_value_sum = total_input_value_sum + utxo["value"]
tx_fee = total_input_value_sum - btc.tx_total_outputs_value(tx)
total_input_value_sum = sum([x["value"] for x in tx_inp_data])
total_output_value_sum = sum([x.nValue for x in tx.vout])
tx_fee = total_input_value_sum - total_output_value_sum
tx_fee_rate = tx_fee / btc.tx_vsize(tx) * 1000
if tx_fee_rate < self.minimum_tx_fee_rate:
return (False, "tx feerate below configured minimum tx feerate")
Expand Down
1 change: 0 additions & 1 deletion test/jmbitcoin/test_tx_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def test_sign_standard_txs(addrtype):
txin = btc.CTxIn(btc.COutPoint(txid[::-1], vout))
txout = btc.CTxOut(amount_less_fee, target_scriptPubKey)
tx = btc.CMutableTransaction([txin], [txout])
assert btc.tx_total_outputs_value(tx) == amount_less_fee

# Calculate the signature hash for the transaction. This is then signed by the
# private key that controls the UTXO being spent here at this txin_index.
Expand Down

0 comments on commit ca972cd

Please sign in to comment.