Browse Source

update add_utxo for segwit

master
Adam Gibson 9 years ago
parent
commit
542e02871d
No known key found for this signature in database
GPG Key ID: B3AE09F1E9A3197A
  1. 10
      jmclient/jmclient/commitment_utils.py
  2. 8
      scripts/add-utxo.py

10
jmclient/jmclient/commitment_utils.py

@ -2,7 +2,7 @@ from __future__ import print_function
import sys, os import sys, os
import jmclient.btc as btc import jmclient.btc as btc
from jmclient import jm_single, get_p2pk_vbyte from jmclient import jm_single, get_p2pk_vbyte, get_p2sh_vbyte
def quit(parser, errmsg): #pragma: no cover def quit(parser, errmsg): #pragma: no cover
parser.error(errmsg) parser.error(errmsg)
@ -32,7 +32,7 @@ def get_utxo_info(upriv):
raise raise
return u, priv return u, priv
def validate_utxo_data(utxo_datas, retrieve=False): def validate_utxo_data(utxo_datas, retrieve=False, segwit=False):
"""For each txid: N, privkey, first """For each txid: N, privkey, first
convert the privkey and convert to address, convert the privkey and convert to address,
then use the blockchain instance to look up then use the blockchain instance to look up
@ -43,7 +43,11 @@ def validate_utxo_data(utxo_datas, retrieve=False):
for u, priv in utxo_datas: for u, priv in utxo_datas:
print('validating this utxo: ' + str(u)) print('validating this utxo: ' + str(u))
hexpriv = btc.from_wif_privkey(priv, vbyte=get_p2pk_vbyte()) hexpriv = btc.from_wif_privkey(priv, vbyte=get_p2pk_vbyte())
addr = btc.privkey_to_address(hexpriv, magicbyte=get_p2pk_vbyte()) if segwit:
addr = btc.pubkey_to_p2sh_p2wpkh_address(
btc.privkey_to_pubkey(hexpriv), get_p2sh_vbyte())
else:
addr = btc.privkey_to_address(hexpriv, magicbyte=get_p2pk_vbyte())
print('claimed address: ' + addr) print('claimed address: ' + addr)
res = jm_single().bc_interface.query_utxo_set([u]) res = jm_single().bc_interface.query_utxo_set([u])
print('blockchain shows this data: ' + str(res)) print('blockchain shows this data: ' + str(res))

8
scripts/add-utxo.py

@ -15,8 +15,8 @@ from pprint import pformat
from optparse import OptionParser from optparse import OptionParser
import jmclient.btc as btc import jmclient.btc as btc
from jmbase import get_password from jmbase import get_password
from jmclient import (load_program_config, jm_single, get_p2pk_vbyte, from jmclient import (load_program_config, jm_single, get_p2pk_vbyte, SegwitWallet,
Wallet, WalletError, sync_wallet, add_external_commitments, WalletError, sync_wallet, add_external_commitments,
generate_podle, update_commitments, PoDLE, generate_podle, update_commitments, PoDLE,
set_commitment_file, get_podle_commitments, set_commitment_file, get_podle_commitments,
get_utxo_info, validate_utxo_data, quit) get_utxo_info, validate_utxo_data, quit)
@ -177,7 +177,7 @@ def main():
while True: while True:
pwd = get_password("Enter wallet decryption passphrase: ") pwd = get_password("Enter wallet decryption passphrase: ")
try: try:
wallet = Wallet(options.loadwallet, wallet = SegwitWallet(options.loadwallet,
pwd, pwd,
options.maxmixdepth, options.maxmixdepth,
options.gaplimit) options.gaplimit)
@ -231,7 +231,7 @@ def main():
else: else:
quit(parser, 'Invalid syntax') quit(parser, 'Invalid syntax')
if options.validate or options.vonly: if options.validate or options.vonly:
if not validate_utxo_data(utxo_data): if not validate_utxo_data(utxo_data, segwit=True):
quit(parser, "Utxos did not validate, quitting") quit(parser, "Utxos did not validate, quitting")
if options.vonly: if options.vonly:
sys.exit(0) sys.exit(0)

Loading…
Cancel
Save