2014-09-28 18:36:24 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2017-07-23 08:21:30 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2014-09-28 18:36:24 +00:00
|
|
|
from pycoin.key import Key
|
|
|
|
|
|
|
|
from pycoin.key.validate import is_address_valid, is_wif_valid
|
|
|
|
from pycoin.services import spendables_for_address
|
|
|
|
from pycoin.tx.tx_utils import create_signed_tx
|
|
|
|
|
2018-02-03 00:33:46 +00:00
|
|
|
|
2014-09-28 18:36:24 +00:00
|
|
|
def get_address(which):
|
|
|
|
while 1:
|
|
|
|
print("enter the %s address=> " % which, end='')
|
|
|
|
address = input()
|
|
|
|
is_valid = is_address_valid(address)
|
|
|
|
if is_valid:
|
|
|
|
return address
|
|
|
|
print("invalid address, please try again")
|
|
|
|
|
2018-02-03 00:33:46 +00:00
|
|
|
|
2014-09-28 18:36:24 +00:00
|
|
|
src_address = get_address("source")
|
|
|
|
spendables = spendables_for_address(src_address)
|
|
|
|
print(spendables)
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
print("enter the WIF for %s=> " % src_address, end='')
|
|
|
|
wif = input()
|
|
|
|
is_valid = is_wif_valid(wif)
|
|
|
|
if is_valid:
|
|
|
|
break
|
|
|
|
print("invalid wif, please try again")
|
|
|
|
|
|
|
|
key = Key.from_text(wif)
|
|
|
|
if src_address not in (key.address(use_uncompressed=False), key.address(use_uncompressed=True)):
|
|
|
|
print("** WIF doesn't correspond to %s" % src_address)
|
|
|
|
print("The secret exponent is %d" % key.secret_exponent())
|
|
|
|
|
|
|
|
dst_address = get_address("destination")
|
|
|
|
|
|
|
|
tx = create_signed_tx(spendables, payables=[dst_address], wifs=[wif])
|
|
|
|
|
|
|
|
print("here is the signed output transaction")
|
|
|
|
print(tx.as_hex())
|