Skip to content

Commit

Permalink
Update no-history-sync code
Browse files Browse the repository at this point in the history
This updates the new functionality in jmclient.wallet_utils
in the no-history-sync PR #444 to be compatible
with the python-bitcointx refactoring.
  • Loading branch information
AdamISZ committed Apr 29, 2020
1 parent 30350f0 commit e6d7dd6
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions jmclient/jmclient/wallet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
add_base_options, check_regtest)
from jmclient.wallet_service import WalletService
from jmbase.support import (get_password, jmprint, EXIT_FAILURE,
EXIT_ARGERROR, utxo_to_utxostr)
EXIT_ARGERROR, utxo_to_utxostr, hextobin)

from .cryptoengine import TYPE_P2PKH, TYPE_P2SH_P2WPKH, TYPE_P2WPKH
from .output import fmt_utxo
Expand Down Expand Up @@ -308,9 +308,8 @@ def get_tx_info(txid):
"""
rpctx = jm_single().bc_interface.get_transaction(txid)
txhex = str(rpctx['hex'])
txd = btc.deserialize(txhex)
output_script_values = {binascii.unhexlify(sv['script']): sv['value']
for sv in txd['outs']}
tx = btc.CMutableTransaction.deserialize(hextobin(txhex))
output_script_values = {x.scriptPubKey: x.nValue for x in tx.vout}
value_freq_list = sorted(
Counter(output_script_values.values()).most_common(),
key=lambda x: -x[1])
Expand All @@ -322,7 +321,7 @@ def get_tx_info(txid):
cj_amount = value_freq_list[0][0]
cj_n = value_freq_list[0][1]
return is_coinjoin, cj_amount, cj_n, output_script_values,\
rpctx.get('blocktime', 0), txd
rpctx.get('blocktime', 0), tx


def get_imported_privkey_branch(wallet_service, m, showprivkey):
Expand Down Expand Up @@ -399,7 +398,7 @@ def get_addr_status(addr_path, utxos, is_new, is_internal):
# to bci
if jm_single().bc_interface.__class__ == BitcoinCoreInterface:
is_coinjoin, cj_amount, cj_n = \
get_tx_info(binascii.hexlify(utxo[0]).decode('ascii'))[:3]
get_tx_info(utxo[0])[:3]
if is_coinjoin and utxodata['value'] == cj_amount:
status.append('cj-out')
elif is_coinjoin:
Expand Down Expand Up @@ -671,7 +670,7 @@ def print_row(index, time, tx_type, amount, delta, balance, cj_n,
tx_number = 0
for tx in txes:
is_coinjoin, cj_amount, cj_n, output_script_values, blocktime, txd =\
get_tx_info(tx['txid'])
get_tx_info(hextobin(tx['txid']))

# unconfirmed transactions don't have blocktime, get_tx_info() returns
# 0 in that case
Expand All @@ -681,21 +680,21 @@ def print_row(index, time, tx_type, amount, delta, balance, cj_n,
output_script_values.keys())

rpc_inputs = []
for ins in txd['ins']:
for ins in txd.vin:
wallet_tx = jm_single().bc_interface.get_transaction(
ins['outpoint']['hash'])
ins.prevout.hash[::-1])
if wallet_tx is None:
continue
input_dict = btc.deserialize(str(wallet_tx['hex']))['outs'][ins[
'outpoint']['index']]
inp = btc.CMutableTransaction.deserialize(hextobin(
wallet_tx['hex'])).vout[ins.prevout.n]
input_dict = {"script": inp.scriptPubKey, "value": inp.nValue}
rpc_inputs.append(input_dict)

rpc_input_scripts = set(binascii.unhexlify(ind['script'])
for ind in rpc_inputs)
rpc_input_scripts = set(ind['script'] for ind in rpc_inputs)
our_input_scripts = wallet_script_set.intersection(rpc_input_scripts)
our_input_values = [
ind['value'] for ind in rpc_inputs
if binascii.unhexlify(ind['script']) in our_input_scripts]
if ind['script'] in our_input_scripts]
our_input_value = sum(our_input_values)
utxos_consumed = len(our_input_values)

Expand Down

0 comments on commit e6d7dd6

Please sign in to comment.