(turn) "proficiency in bitcoin" source code analysis: Pycoin

Source: Internet
Author: User

https://github.com/bitcoinbook/bitcoinbook/blob/second_edition/code/pycoin_example.py

From Pycoin.key Import key to Pycoin.key.validate import Is_address_valid, is_wif_valid from pycoin.services import spe Ndables_for_address from pycoin.tx.tx_utils import Create_signed_tx 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") 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 (" Inv Alid wif, please try again ") Key = Key.from_text (wif) if src_address not in (key.address), 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]) pri
 NT ("Here is the signed output transaction") Print (Tx.as_hex ())

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.