@ -1,4 +1,3 @@
from future . utils import iteritems
import json
import os
import sys
@ -17,7 +16,7 @@ from jmclient import (get_network, WALLET_IMPLEMENTATIONS, Storage, podle,
is_native_segwit_mode , load_program_config , 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 , \
TYPE_SEGWIT_LEGACY_WALLET_FIDELITY_BONDS
@ -324,9 +323,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 ] )
@ -338,7 +336,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 ) :
@ -383,7 +381,7 @@ def wallet_showutxos(wallet, showprivkey):
unsp [ us ] [ ' privkey ' ] = wallet . get_wif_path ( av [ ' path ' ] )
used_commitments , external_commitments = podle . get_podle_commitments ( )
for u , ec in iteritems ( external_commitments ) :
for u , ec in external_commitments . items ( ) :
success , us = utxo_to_utxostr ( u )
assert success
tries = podle . get_podle_tries ( utxo = u , max_tries = max_tries ,
@ -404,7 +402,7 @@ def wallet_display(wallet_service, showprivkey, displayall=False,
def get_addr_status ( addr_path , utxos , is_new , is_internal ) :
addr_balance = 0
status = [ ]
for utxo , utxodata in iteritems ( utxos ) :
for utxo , utxodata in utxos . items ( ) :
if addr_path != utxodata [ ' path ' ] :
continue
addr_balance + = utxodata [ ' value ' ]
@ -415,7 +413,7 @@ def wallet_display(wallet_service, showprivkey, displayall=False,
# 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 :
@ -774,7 +772,7 @@ def wallet_fetch_history(wallet, options):
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
@ -784,21 +782,21 @@ def wallet_fetch_history(wallet, options):
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 )
@ -866,7 +864,7 @@ def wallet_fetch_history(wallet, options):
amount = cj_amount
delta_balance = out_value - our_input_value
mixdepth_src = wallet . get_script_mixdepth ( list ( our_input_scripts ) [ 0 ] )
cj_script = list ( set ( [ a for a , v in iteritems ( output_script_values )
cj_script = list ( set ( [ a for a , v in output_script_values . items ( )
if v == cj_amount ] ) . intersection ( our_output_scripts ) ) [ 0 ]
mixdepth_dst = wallet . get_script_mixdepth ( cj_script )
else :