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 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
parser.error(errmsg)
@ -32,7 +32,7 @@ def get_utxo_info(upriv):
raise
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
convert the privkey and convert to address,
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:
print('validating this utxo: ' + str(u))
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)
res = jm_single().bc_interface.query_utxo_set([u])
print('blockchain shows this data: ' + str(res))

8
scripts/add-utxo.py

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

Loading…
Cancel
Save