From 89db6842684cd9169b2e87e49aa39d45615c10bf Mon Sep 17 00:00:00 2001 From: Richard Kiss Date: Thu, 23 Aug 2018 19:16:18 -0700 Subject: [PATCH] Improve recipes (but 4 not working yet). --- recipes/multisig/1_create_address.py | 13 +++++++------ recipes/multisig/2_create_coinbase_tx.py | 11 +++++------ recipes/multisig/3_create_unsigned_tx.py | 8 ++++---- recipes/multisig/4_sign_tx.py | 8 ++++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/recipes/multisig/1_create_address.py b/recipes/multisig/1_create_address.py index d1b934199..98fa457c5 100755 --- a/recipes/multisig/1_create_address.py +++ b/recipes/multisig/1_create_address.py @@ -6,9 +6,10 @@ import os import sys -from pycoin.key.BIP32Node import BIP32Node from pycoin.encoding.hexbytes import b2h -from pycoin.ui.ui import address_for_p2s, script_for_multisig +from pycoin.symbols.btc import network + +BIP32Node = network.extras.BIP32Node def main(): @@ -19,7 +20,7 @@ def main(): hwif = f.readline().strip() # turn the bip32 text into a BIP32Node object - BIP32_KEY = BIP32Node.from_hwif(hwif) + BIP32_KEY = network.ui.parse(hwif) # create three sec_keys (these are public keys, streamed using the SEC format) @@ -31,17 +32,17 @@ def main(): # create the 2-of-3 multisig script # any 2 signatures can release the funds - pay_to_multisig_script = script_for_multisig(2, public_key_sec_list) + pay_to_multisig_script = network.ui._script_info.script_for_multisig(2, public_key_sec_list) # create a "2-of-3" multisig address_for_multisig - the_address = address_for_p2s(pay_to_multisig_script) + the_address = network.ui.address_for_p2s(pay_to_multisig_script) print("Here is your pay 2-of-3 address: %s" % the_address) print("Here is the pay 2-of-3 script: %s" % b2h(pay_to_multisig_script)) print("The hex script should go into p2sh_lookup.hex") - base_dir = os.path.dirname(sys.argv[1]) + base_dir = os.path.abspath(os.path.dirname(sys.argv[1])) print("The three WIFs are written into %s as wif0, wif1 and wif2" % base_dir) for i in range(3): wif = BIP32_KEY.subkey_for_path("0/%d/0" % i).wif() diff --git a/recipes/multisig/2_create_coinbase_tx.py b/recipes/multisig/2_create_coinbase_tx.py index e76b7cf9f..d76d4c32f 100755 --- a/recipes/multisig/2_create_coinbase_tx.py +++ b/recipes/multisig/2_create_coinbase_tx.py @@ -5,9 +5,8 @@ import sys -from pycoin.key.validate import is_address_valid -from pycoin.tx.Tx import Tx, TxIn, TxOut -from pycoin.ui import script_for_address +from pycoin.symbols.btc import network +from pycoin.ui.validate import is_address_valid def main(): @@ -21,9 +20,9 @@ def main(): print("creating coinbase transaction to %s" % address) - tx_in = TxIn.coinbase_tx_in(script=b'') - tx_out = TxOut(50*1e8, script_for_address(address)) - tx = Tx(1, [tx_in], [tx_out]) + tx_in = network.tx.TxIn.coinbase_tx_in(script=b'') + tx_out = network.tx.TxOut(50*1e8, network.ui.script_for_address(address)) + tx = network.tx(1, [tx_in], [tx_out]) print("Here is the tx as hex:\n%s" % tx.as_hex()) diff --git a/recipes/multisig/3_create_unsigned_tx.py b/recipes/multisig/3_create_unsigned_tx.py index 86b74cc00..62dde6a36 100755 --- a/recipes/multisig/3_create_unsigned_tx.py +++ b/recipes/multisig/3_create_unsigned_tx.py @@ -9,9 +9,9 @@ import sys -from pycoin.tx.Tx import Tx -from pycoin.tx.tx_utils import create_tx -from pycoin.key.validate import is_address_valid +from pycoin.coins.tx_utils import create_tx +from pycoin.ui.validate import is_address_valid +from pycoin.symbols.btc import network def main(): @@ -23,7 +23,7 @@ def main(): tx_hex = f.readline().strip() # get the spendable from the prior transaction - tx = Tx.from_hex(tx_hex) + tx = network.tx.from_hex(tx_hex) tx_out_index = int(sys.argv[2]) spendable = tx.tx_outs_as_spendable()[tx_out_index] diff --git a/recipes/multisig/4_sign_tx.py b/recipes/multisig/4_sign_tx.py index 3dcd07dbc..345a8088d 100755 --- a/recipes/multisig/4_sign_tx.py +++ b/recipes/multisig/4_sign_tx.py @@ -2,11 +2,11 @@ import sys +from pycoin.coins.tx_utils import sign_tx from pycoin.encoding.hexbytes import h2b -from pycoin.key.validate import is_wif_valid +from pycoin.ui.validate import is_wif_valid from pycoin.solve.utils import build_p2sh_lookup -from pycoin.tx.Tx import Tx -from pycoin.tx.tx_utils import sign_tx +from pycoin.symbols.btc import network def main(): @@ -17,7 +17,7 @@ def main(): # get the tx with open(sys.argv[1], "r") as f: tx_hex = f.readline().strip() - tx = Tx.from_hex(tx_hex) + tx = network.tx.from_hex(tx_hex) # get the WIF with open(sys.argv[2], "r") as f: