def test_create_ps2h_unsigned(self):
     # This address I previously sent funds to but threw out the private key
     create_unsigned_tx(
             inputs=[
                 {
                     'pubkeys': [
                         '036f5ca449944655b5c580ff6686bdd19123d1003b41f49f4b603f53e33f70a2d1',
                         '03e93a754aa03dedbe032e5be051bce031db4337c48fbbcf970d1b27bb25a07964',
                         '02582061ab1dba9d6b5b4e6e29f9da2bd590862f1b1e8566f405eb1d92898eafee',
                         ],
                     'script_type': 'multisig-2-of-3'
                     },
                 ],
             outputs=[
                 {
                     'value': -1,
                     'address': 'CFr99841LyMkyX5ZTGepY58rjXJhyNGXHf',
                     },
                 ],
             change_address=None,
             include_tosigntx=True,
             # will test signature returned locally:
             verify_tosigntx=True,
             coin_symbol='bcy',
             api_key=BC_API_KEY,
             )
示例#2
0
def transferbitcoin(privatekey, address, pubkey):
    # address, pubkey = details_from_private_key(privatekey)
    details = blockcypher.get_address_details(address, coin_symbol=symbol)
    print("Balance: %d" % details['balance'])
    if not details['balance'] > 1000:
        print("no balance, skipping")
        return
    outputs = [
        {
            'value': details['balance']-fee,
            'address': myaddress,
            # 'script_type': 'pay-to-pubkey-hash',
            # 'script': address_to_script(myaddress),
        }
    ]
    inputs = [{'address': address}]
    pprint(details)
    transaction = blockcypher.create_unsigned_tx(
        inputs, outputs, change_address=myaddress, coin_symbol=symbol)
    pprint(transaction)
    input_addresses = blockcypher.get_input_addresses(transaction)
    privkeys, pubkeys = [], []
    for a in input_addresses:
        assert a == address
        privkeys.append(privatekey)
        pubkeys.append(pubkey)
    signatures = blockcypher.make_tx_signatures(
        transaction['tosign'], privkeys, pubkeys)
    r = blockcypher.broadcast_signed_transaction(
        transaction, signatures, pubkeys, coin_symbol=symbol)
    pprint(r)
 def test_create_basic_unsigned(self):
     # This address I previously sent funds to but threw out the private key
     create_unsigned_tx(
             inputs=[
                 {'address': 'BwvSPyMWVL1gkp5FZdrGXLpHj2ZJyJYLVB'},
                 ],
             outputs=[
                 {
                     'value': -1,
                     'address': 'CFr99841LyMkyX5ZTGepY58rjXJhyNGXHf',
                     },
                 ],
             change_address=None,
             include_tosigntx=True,
             verify_tosigntx=True,
             coin_symbol='bcy',
             api_key=BC_API_KEY,
             )
 def test_create_basic_unsigned(self):
     # This address I previously sent funds to but threw out the private key
     create_unsigned_tx(
             inputs=[
                 {'address': 'BwvSPyMWVL1gkp5FZdrGXLpHj2ZJyJYLVB'},
                 ],
             outputs=[
                 {
                     'value': -1,
                     # p2sh address for extra measure
                     'address': 'Dbc9fnf1Kqct7zvfNTiwr6HjvDfPYaFSNg',
                     },
                 ],
             change_address=None,
             include_tosigntx=True,
             # will test signature returned locally:
             verify_tosigntx=True,
             coin_symbol='bcy',
             api_key=BC_API_KEY,
             )
 def test_create_nulldata_unsigned(self):
     # This address I previously sent funds to but threw out the private key
     create_unsigned_tx(
             inputs=[
                 {'address': 'BwvSPyMWVL1gkp5FZdrGXLpHj2ZJyJYLVB'},
                 ],
             outputs=[
                 # embed some null-data
                 {
                     'value': 0,
                     'script_type': 'null-data',
                     'script': '6a06010203040506',
                     },
                 ],
             change_address='CFr99841LyMkyX5ZTGepY58rjXJhyNGXHf',
             include_tosigntx=True,
             # will test signature returned locally:
             verify_tosigntx=True,
             coin_symbol='bcy',
             api_key=BC_API_KEY,
             )
示例#6
0
 def test_create_basic_unsigned(self):
     # This address I previously sent funds to but threw out the private key
     create_unsigned_tx(
         inputs=[
             {
                 'address': 'BwvSPyMWVL1gkp5FZdrGXLpHj2ZJyJYLVB'
             },
         ],
         outputs=[
             {
                 'value': -1,
                 # p2sh address for extra measure
                 'address': 'Dbc9fnf1Kqct7zvfNTiwr6HjvDfPYaFSNg',
             },
         ],
         change_address=None,
         include_tosigntx=True,
         # will test signature returned locally:
         verify_tosigntx=True,
         coin_symbol='bcy',
         api_key=BC_API_KEY,
     )
示例#7
0
def create_transaction(username, addr, amount, coin_symbol):
    inputs = [
        {
            'wallet_name': username,
            'wallet_token': settings.TOKEN
        },
    ]
    outputs = [{'address': addr, 'value': amount}]
    unsigned_tx = create_unsigned_tx(inputs=inputs,
                                     outputs=outputs,
                                     coin_symbol=coin_symbol,
                                     preference='low')

    return unsigned_tx
示例#8
0
 def test_create_nulldata_unsigned(self):
     # This address I previously sent funds to but threw out the private key
     create_unsigned_tx(
         inputs=[
             {
                 'address': 'BwvSPyMWVL1gkp5FZdrGXLpHj2ZJyJYLVB'
             },
         ],
         outputs=[
             # embed some null-data
             {
                 'value': 0,
                 'script_type': 'null-data',
                 'script': '6a06010203040506',
             },
         ],
         change_address='CFr99841LyMkyX5ZTGepY58rjXJhyNGXHf',
         include_tosigntx=True,
         # will test signature returned locally:
         verify_tosigntx=True,
         coin_symbol='bcy',
         api_key=BC_API_KEY,
     )
示例#9
0
def proofOfBurnTransaction():

    data = "mdsw22"

    # OP RETURN and push data to stack
    prefix = "6a4c"

    # get the size of data in bytes and hex of the data itself
    hexdata = binascii.hexlify(bytes(data, 'ascii'))
    prefix += binascii.hexlify(bytes(chr(len(data)), 'ascii')).decode('ascii')
    prefix += hexdata.decode('ascii')

    inputs = [{'address': 'n1xrgmc48JBh31wYJmRadDyS5Lbh5gGqNu'}]
    outputs = [{'value': 0, 'script_type': "null-data", 'script': prefix}]

    #The next line creates the transaction shell, which is as yet unsigned
    unsigned_tx = blockcypher.create_unsigned_tx(
        inputs=inputs,
        outputs=outputs,
        coin_symbol='btc-testnet',
        api_key='141dbdc7350f4275900fd063fd56b6d3')

    #Now list the private and public keys corresponding to the inputs
    private_keys = [
        '61361420f531bf9e0893db1dbc061dcc00a22f5fb38f58d25f0fcaa1731d969e'
    ]
    public_keys = [
        '025929058c2e17d1983682cf884e6ee7a6319f5098128badd944a2b441bd82fe9e'
    ]

    #Next create the signatures
    tx_signatures = blockcypher.make_tx_signatures(
        txs_to_sign=unsigned_tx['tosign'],
        privkey_list=private_keys,
        pubkey_list=public_keys)

    #Finally push the transaction and signatures onto the network
    result = blockcypher.broadcast_signed_transaction(
        unsigned_tx=unsigned_tx,
        signatures=tx_signatures,
        pubkeys=public_keys,
        coin_symbol='btc-testnet',
        api_key='141dbdc7350f4275900fd063fd56b6d3')

    # get the transaction hash
    transaction_hash = result['tx']['hash']

    return transaction_hash
示例#10
0
	def Post_MerkleRoot(self):
		hex_to_post = self.root.encode("hex");
		output_script = '6a13' + hex_to_post;
		inputs = [{'address': self.Sender_addr}, ];
		outputs = [{'address': self.Address, 'value': 25},\
		{'value':0, 'script_type':'null-data',\
		'script': output_script},];

		unsigned_tx = create_unsigned_tx(inputs=inputs, outputs=outputs, coin_symbol='btc-testnet',\
			api_key = self.MyToken);


		tx_signatures = make_tx_signatures(txs_to_sign=unsigned_tx['tosign'], \
			privkey_list=self.privkey, pubkey_list=self.pubkey);

		Posted_Tx = broadcast_signed_transaction(unsigned_tx=unsigned_tx, signatures=tx_signatures, pubkeys=self.pubkey,\
			coin_symbol = 'btc-testnet',api_key = self.MyToken);

		self.Tx_hash = Posted_Tx['tx']['hash'];
		return self.Tx_hash;
示例#11
0
def send_multi_payment(payment_privkey, list_of_addresses,
                       payment_per_address):

    payment_address = get_address_from_privkey(payment_privkey)

    if dontuseAddress(payment_address):
        log.debug("Payment address %s not ready" % payment_address)
        return None

    inputs = [{'address': payment_address}]
    payment_in_satoshis = btc_to_satoshis(float(payment_per_address))
    outputs = []

    for address in list_of_addresses:
        outputs.append({'address': address, 'value': int(payment_in_satoshis)})

    unsigned_tx = create_unsigned_tx(inputs=inputs,
                                     outputs=outputs,
                                     api_key=BLOCKCYPHER_TOKEN)

    # iterate through unsigned_tx['tx']['inputs'] to find each address in order
    # need to include duplicates as many times as they may appear
    privkey_list = []
    pubkey_list = []

    for input in unsigned_tx['tx']['inputs']:
        privkey_list.append(payment_privkey)
        pubkey_list.append(get_pubkey_from_privkey(payment_privkey))

    tx_signatures = make_tx_signatures(txs_to_sign=unsigned_tx['tosign'],
                                       privkey_list=privkey_list,
                                       pubkey_list=pubkey_list)

    resp = broadcast_signed_transaction(unsigned_tx=unsigned_tx,
                                        signatures=tx_signatures,
                                        pubkeys=pubkey_list)

    if 'tx' in resp:
        return resp['tx']['hash']
    else:
        return None
示例#12
0
def send_multi_payment(payment_privkey, list_of_addresses, payment_per_address):

    payment_address = get_address_from_privkey(payment_privkey)

    if dontuseAddress(payment_address):
        log.debug("Payment address %s not ready" % payment_address)
        return None

    inputs = [{'address': payment_address}]
    payment_in_satoshis = btc_to_satoshis(float(payment_per_address))
    outputs = []

    for address in list_of_addresses:
        outputs.append({'address': address, 'value': int(payment_in_satoshis)})

    unsigned_tx = create_unsigned_tx(inputs=inputs, outputs=outputs,
                                     api_key=BLOCKCYPHER_TOKEN)

    # iterate through unsigned_tx['tx']['inputs'] to find each address in order
    # need to include duplicates as many times as they may appear
    privkey_list = []
    pubkey_list = []

    for input in unsigned_tx['tx']['inputs']:
        privkey_list.append(payment_privkey)
        pubkey_list.append(get_pubkey_from_privkey(payment_privkey))

    tx_signatures = make_tx_signatures(txs_to_sign=unsigned_tx['tosign'],
                                       privkey_list=privkey_list,
                                       pubkey_list=pubkey_list)

    resp = broadcast_signed_transaction(unsigned_tx=unsigned_tx,
                                        signatures=tx_signatures,
                                        pubkeys=pubkey_list,
                                        api_key=BLOCKCYPHER_TOKEN)

    if 'tx' in resp:
        return resp['tx']['hash']
    else:
        return None
示例#13
0
 def test_create_from_inputs(self):
     result = create_unsigned_tx(
         inputs=[{
             'prev_hash':
             '31746be47c39337b8c054a165da407122725162363e5b9d0b8062cde3ef06f7d',
             'output_index': 0
         }, {
             'prev_hash':
             '0affbdc61b86a05944ce0bc167be60106925d631abb38258c5cdc1764002796d',
             'output_index': 0
         }, {
             'prev_hash':
             '12f30c25afafcb42171e7052c9596c93a3e81b0d2b9051f8cf25ce44693e24ba',
             'output_index': 0
         }, {
             'prev_hash':
             'fe313e2c309b4f256157ec4ebcf55652eaedb8a16d429df26c5ba205dd40ad27',
             'output_index': 0
         }, {
             'prev_hash':
             '74ab2e2fd193df2a7de7db5de92559e814270e740aa5715a952fa16946626545',
             'output_index': 0
         }],
         outputs=[
             {
                 'value': 1,
                 'address': 'Dbc9fnf1Kqct7zvfNTiwr6HjvDfPYaFSNg',
             },
         ],
         preference="low",
         change_address='CFr99841LyMkyX5ZTGepY58rjXJhyNGXHf',
         include_tosigntx=True,
         verify_tosigntx=True,
         coin_symbol='bcy',
         api_key=BC_API_KEY,
     )
     self.assertNotIn('errors', result)
示例#14
0
    },
]
outputs = [
    {
        'address': 'myAg6VTDJN4ktQ8F7xYLxZBTSGYuy8vVGV',
        'value': 1
    },
    {
        'value': 0,
        'script_type': 'null-data',
        'data_string': 'My first op_return transactions',
        'script': output_script
    },
]
unsigned_tx = create_unsigned_tx(inputs=inputs,
                                 outputs=outputs,
                                 coin_symbol='btc-testnet',
                                 api_key='9ec8d9d06347455b833d04031f7b4c9a')

#embed_data(to_embed='I am the walrus', api_key='07b8071917974a62aeafd77880afe93b', coin_symbol='btc-testnet',data_is_hex=False);
#print unsigned_tx;

privkey_list = [
    '93021c6bc9ee89c06d57931a99341df6cadadb9d0e82ac4acb205b03f0afc03d'
]
pubkey_list = [
    '034cf1d96e5d632c64d987a5db49d1a0840c6fac7e138af2ce027ddee5bc787941'
]
print len(privkey_list), len(pubkey_list), len(unsigned_tx['tosign'])
tx_signatures = make_tx_signatures(txs_to_sign=unsigned_tx['tosign'],
                                   privkey_list=privkey_list,
                                   pubkey_list=pubkey_list)
示例#15
0
def send_funds(wallet_obj, change_address=None, destination_address=None, dest_satoshis=None, tx_preference=None):
    if not USER_ONLINE:
        puts(colored.red('Blockcypher connection needed to fetch unspents and broadcast signed transaction.'))
        puts(colored.red('You may dump all your addresses and private keys while offline by selecting option 0 on the home screen.'))
        return

    mpub = wallet_obj.serialize_b58(private=False)
    if not wallet_obj.private_key:
        print_pubwallet_notice(mpub=mpub)
        return

    coin_symbol = str(coin_symbol_from_mkey(mpub))
    verbose_print(coin_symbol)

    wallet_name = get_blockcypher_walletname_from_mpub(
            mpub=mpub,
            subchain_indices=[0, 1],
            )
    wallet_details = get_wallet_transactions(
            wallet_name=wallet_name,
            api_key=BLOCKCYPHER_API_KEY,
            coin_symbol=coin_symbol,
            )
    verbose_print(wallet_details)

    if wallet_details['final_balance'] == 0:
        puts(colored.red("0 balance. You can't send funds if you don't have them available!"))
        return

    mpriv = wallet_obj.serialize_b58(private=True)

    if not destination_address:
        display_shortname = COIN_SYMBOL_MAPPINGS[coin_symbol]['display_shortname']
        puts('What %s address do you want to send to?' % display_shortname)
        destination_address = get_crypto_address(coin_symbol=coin_symbol, quit_ok=True)
        if destination_address in ('q', 'Q'):
            puts(colored.red('Transaction Not Broadcast!'))
            return

    if not dest_satoshis:

        VALUE_PROMPT = 'Your current balance is %s. How much (in %s) do you want to send? Note that due to transaction fees your full balance may not be available to send.' % (
                format_crypto_units(
                    input_quantity=wallet_details['final_balance'],
                    input_type='satoshi',
                    output_type=UNIT_CHOICE,
                    coin_symbol=coin_symbol,
                    print_cs=True,
                    ),
                get_curr_symbol(
                        coin_symbol=coin_symbol,
                        output_type=UNIT_CHOICE,
                        ),
                )
        puts(VALUE_PROMPT)
        dest_crypto_qty = get_crypto_qty(
                max_num=from_satoshis(
                    input_satoshis=wallet_details['final_balance'],
                    output_type=UNIT_CHOICE,
                    ),
                input_type=UNIT_CHOICE,
                user_prompt=DEFAULT_PROMPT,
                quit_ok=True,
                )
        if dest_crypto_qty in ('q', 'Q'):
            puts(colored.red('Transaction Not Broadcast!'))
            return
        dest_satoshis = to_satoshis(
                input_quantity=dest_crypto_qty,
                input_type=UNIT_CHOICE,
                )

    inputs = [{
            'wallet_name': wallet_name,
            'wallet_token': BLOCKCYPHER_API_KEY,
            }, ]
    outputs = [{
            'value': dest_satoshis,
            'address': destination_address,
            }, ]

    if dest_satoshis == -1:
        sweep_funds = True
        change_address = None
    else:
        sweep_funds = False
        if not change_address:
            change_address = get_unused_change_addresses(
                    wallet_obj=wallet_obj,
                    num_addrs=1,
                    )[0]['pub_address']

    if not tx_preference:
        tx_preference = txn_preference_chooser(user_prompt=DEFAULT_PROMPT)

    verbose_print('Inputs:')
    verbose_print(inputs)
    verbose_print('Outputs:')
    verbose_print(outputs)
    verbose_print('Change Address: %s' % change_address)
    verbose_print('coin symbol: %s' % coin_symbol)
    verbose_print('TX Preference: %s' % tx_preference)

    unsigned_tx = create_unsigned_tx(
        inputs=inputs,
        outputs=outputs,
        change_address=change_address,
        preference=tx_preference,
        coin_symbol=coin_symbol,
        # will verify in the next step,
        # that way if there is an error here we can display that to user
        verify_tosigntx=False,
        include_tosigntx=True,
        )

    verbose_print('Unsigned TX:')
    verbose_print(unsigned_tx)

    if 'errors' in unsigned_tx:
        if any([x.get('error', '').startswith('Not enough funds after fees') for x in unsigned_tx['errors']]):
            puts("Sorry, after transaction fees there's not (quite) enough funds to send %s. Would you like to send the max you can instead?" % (
                format_crypto_units(
                    input_quantity=dest_satoshis,
                    input_type='satoshi',
                    output_type=UNIT_CHOICE,
                    coin_symbol=coin_symbol,
                    print_cs=True,
                )))
            if confirm(user_prompt=DEFAULT_PROMPT, default=False):
                return send_funds(
                        wallet_obj=wallet_obj,
                        change_address=change_address,
                        destination_address=destination_address,
                        dest_satoshis=-1,  # sweep
                        tx_preference=tx_preference,
                        )
            else:
                puts(colored.red('Transaction Not Broadcast!'))
                return

        else:
            puts(colored.red('TX Error(s): Tx NOT Signed or Broadcast'))
            for error in unsigned_tx['errors']:
                puts(colored.red(error['error']))
            # Abandon
            return

    # Verify TX requested to sign is as expected
    tx_is_correct, err_msg = verify_unsigned_tx(
            unsigned_tx=unsigned_tx,
            inputs=inputs,
            outputs=outputs,
            sweep_funds=sweep_funds,
            change_address=change_address,
            coin_symbol=coin_symbol,
            )
    if not tx_is_correct:
        puts(colored.red('TX Error: Tx NOT Signed or Broadcast'))
        puts(colored.red(err_msg))
        # Abandon
        return

    input_addresses = get_input_addresses(unsigned_tx)
    verbose_print('input_addresses')
    verbose_print(input_addresses)

    address_paths = [{'path': x['hd_path'], 'address': x['addresses'][0]} for x in unsigned_tx['tx']['inputs']]

    # be sure all addresses returned
    address_paths_filled = verify_and_fill_address_paths_from_bip32key(
            address_paths=address_paths,
            master_key=mpriv,
            network=guess_network_from_mkey(mpriv),
            )

    verbose_print('adress_paths_filled:')
    verbose_print(address_paths_filled)
    hexkeypair_dict = hexkeypair_list_to_dict(address_paths_filled)

    verbose_print('hexkeypair_dict:')
    verbose_print(hexkeypair_dict)

    if len(hexkeypair_dict.keys()) != len(set(input_addresses)):
        notfound_addrs = set(input_addresses) - set(hexkeypair_dict.keys())
        err_msg = "Couldn't find %s traversing bip32 key" % notfound_addrs
        raise Exception('Traversal Fail: %s' % err_msg)

    privkeyhex_list = [hexkeypair_dict[x]['privkeyhex'] for x in input_addresses]
    pubkeyhex_list = [hexkeypair_dict[x]['pubkeyhex'] for x in input_addresses]

    verbose_print('Private Key List: %s' % privkeyhex_list)
    verbose_print('Public Key List: %s' % pubkeyhex_list)

    # sign locally
    tx_signatures = make_tx_signatures(
            txs_to_sign=unsigned_tx['tosign'],
            privkey_list=privkeyhex_list,
            pubkey_list=pubkeyhex_list,
            )
    verbose_print('TX Signatures: %s' % tx_signatures)

    # final confirmation before broadcast

    if dest_satoshis == -1:
        # remember that sweep TXs cannot verify amounts client-side (only destination addresses)
        dest_satoshis_to_display = unsigned_tx['tx']['total'] - unsigned_tx['tx']['fees']
    else:
        dest_satoshis_to_display = dest_satoshis

    CONF_TEXT = "Send %s to %s with a fee of %s (%s%% of the amount you're sending)?" % (
            format_crypto_units(
                input_quantity=dest_satoshis_to_display,
                input_type='satoshi',
                output_type=UNIT_CHOICE,
                coin_symbol=coin_symbol,
                print_cs=True,
                ),
            destination_address,
            format_crypto_units(
                input_quantity=unsigned_tx['tx']['fees'],
                input_type='satoshi',
                output_type=UNIT_CHOICE,
                coin_symbol=coin_symbol,
                print_cs=True,
                ),
            round(100.0 * unsigned_tx['tx']['fees'] / dest_satoshis_to_display, 4),
            )
    puts(CONF_TEXT)

    if not confirm(user_prompt=DEFAULT_PROMPT, default=True):
        puts(colored.red('Transaction Not Broadcast!'))
        return

    broadcasted_tx = broadcast_signed_transaction(
            unsigned_tx=unsigned_tx,
            signatures=tx_signatures,
            pubkeys=pubkeyhex_list,
            coin_symbol=coin_symbol,
    )
    verbose_print('Broadcast TX Details:')
    verbose_print(broadcasted_tx)

    if 'errors' in broadcasted_tx:
        puts(colored.red('TX Error(s): Tx May NOT Have Been Broadcast'))
        for error in broadcasted_tx['errors']:
            puts(colored.red(error['error']))
        return

    tx_hash = broadcasted_tx['tx']['hash']
    tx_url = get_tx_url(
            tx_hash=tx_hash,
            coin_symbol=coin_symbol,
            )
    puts(colored.green('Transaction %s Broadcast' % tx_hash))
    puts(colored.blue(tx_url))

    # Display updated wallet balance info
    display_balance_info(wallet_obj=wallet_obj)
示例#16
0
def sweep_funds_from_privkey(wallet_obj):
    if not USER_ONLINE:
        puts(colored.red('BlockCypher connection needed to fetch unspents and broadcast signed transaction.'))
        return

    mpub = wallet_obj.serialize_b58(private=False)
    coin_symbol = str(coin_symbol_from_mkey(mpub))
    network = guess_network_from_mkey(mpub)

    puts('Enter a private key (in WIF format) to send from:')
    wif_obj = get_wif_obj(network=network, user_prompt=DEFAULT_PROMPT, quit_ok=True)

    if not wif_obj:
        return

    pkey_addr = wif_obj.get_public_key().to_address(compressed=True)

    inputs = [{
            'address': pkey_addr,
            }, ]
    verbose_print('Inputs:\n%s' % inputs)

    dest_addr = get_unused_receiving_addresses(
            wallet_obj=wallet_obj,
            num_addrs=1,
            )[0]['pub_address']

    outputs = [{
            'address': dest_addr,
            'value': -1,  # sweep value
            }, ]
    verbose_print('Outputs:\n%s' % outputs)

    unsigned_tx = create_unsigned_tx(
        inputs=inputs,
        outputs=outputs,
        change_address=None,
        coin_symbol=coin_symbol,
        # will verify in the next step,
        # that way if there is an error here we can display that to user
        verify_tosigntx=False,
        include_tosigntx=True,
        )
    verbose_print('Unsigned TX:')
    verbose_print(unsigned_tx)

    if 'errors' in unsigned_tx:
        puts(colored.red('TX Error(s): Tx NOT Signed or Broadcast'))
        for error in unsigned_tx['errors']:
            puts(colored.red(error['error']))
        # Abandon
        return

    # Verify TX requested to sign is as expected
    tx_is_correct, err_msg = verify_unsigned_tx(
            unsigned_tx=unsigned_tx,
            inputs=inputs,
            outputs=outputs,
            sweep_funds=True,
            change_address=None,
            coin_symbol=coin_symbol,
            )
    if not tx_is_correct:
        puts(colored.red('TX Error: Tx NOT Signed or Broadcast'))
        puts(colored.red(err_msg))
        # Abandon
        return

    privkeyhex_list, pubkeyhex_list = [], []
    for _ in unsigned_tx['tx']['inputs']:
        privkeyhex_list.append(wif_obj.get_key())
        pubkeyhex_list.append(wif_obj.get_public_key().get_key(
            compressed=True))
    verbose_print('Private Key List: %s' % privkeyhex_list)
    verbose_print('Public Key List: %s' % pubkeyhex_list)

    # sign locally
    tx_signatures = make_tx_signatures(
            txs_to_sign=unsigned_tx['tosign'],
            privkey_list=privkeyhex_list,
            pubkey_list=pubkeyhex_list,
            )
    verbose_print('TX Signatures: %s' % tx_signatures)

    # TODO: add final confirmation before broadcast

    broadcasted_tx = broadcast_signed_transaction(
            unsigned_tx=unsigned_tx,
            signatures=tx_signatures,
            pubkeys=pubkeyhex_list,
            coin_symbol=coin_symbol,
    )
    verbose_print('Broadcasted TX')
    verbose_print(broadcasted_tx)

    tx_hash = broadcasted_tx['tx']['hash']
    puts(colored.green('TX Broadcast: %s' % tx_hash))
    tx_url = get_tx_url(
            tx_hash=tx_hash,
            coin_symbol=coin_symbol,
            )
    puts(colored.blue(tx_url))

    # Display updated wallet balance info
    display_balance_info(wallet_obj=wallet_obj)
示例#17
0
print(addr)

#{'private': 'fc6bcef57f9ae29e25928641a9f70cfc2acbd734a5a445a94fa884bbdb20fb84', 'public': '02c18671d24509524bf64be7688b0cf745029951310de03e371e8eba743cca4cb6', 'address': 'muFrB2JPfA2yEAgi6y8eBo7SZQTCSvjXXV', 'wif': 'cW3NirDSBK8CJjRSDBJbpfpbSY9Kxvkm1Ljr8LB2S8ySySkQt6xx'}

#Specify the inputs and outputs below
#For convenince you can specify an address, and the backend will work out what transaction output that address has available to spend
#You do not need to list a change address, by default the transaction will be created with all change (minus the fees) going to the first input address
inputs = [{'address': 'muFrB2JPfA2yEAgi6y8eBo7SZQTCSvjXXV'}]
outputs = [{'value': 0, 'script_type': "null-data", 'script': ""}]
# outputs = [{'address': 'mpamtqLA66JFVSQNDaPHZ5xMiCz6T2MeNn', 'value': 100}]
"add"
print("OP_RETURN mjqf76".hex())
print(b'OP_RETURN mjqf76'.hex())
#The next line creates the transaction shell, which is as yet unsigned
unsigned_tx = blockcypher.create_unsigned_tx(
    inputs=inputs,
    outputs=outputs,
    coin_symbol='btc-testnet',
    api_key='32b0191e07db4a2eaf11dc6568c644b4')

#You can edit the transaction fields at this stage, before signing it.

# # Now list the private and public keys corresponding to the inputs
# private_keys=['fc6bcef57f9ae29e25928641a9f70cfc2acbd734a5a445a94fa884bbdb20fb84']
# public_keys=['02c18671d24509524bf64be7688b0cf745029951310de03e371e8eba743cca4cb6']
# #Next create the signatures
# tx_signatures = blockcypher.make_tx_signatures(txs_to_sign=unsigned_tx['tosign'], privkey_list=private_keys, pubkey_list=public_keys)
# #Finally push the transaction and signatures onto the network
# blockcypher.broadcast_signed_transaction(unsigned_tx=unsigned_tx, signatures=tx_signatures, pubkeys=public_keys, coin_symbol='btc-testnet', api_key='32b0191e07db4a2eaf11dc6568c644b4')
示例#18
0
# address = blockcypher.generate_new_address(coin_symbol='btc-testnet', api_key='0d7ace0138a0460baa3600a486dd7df8')

address = 'n1WMvqdsXvpMyQDxXd1XzpeY38XtZoSocm'
private = '489ebfb64928e90510bc9a05626ca60e0bbe8c3816e19673cf4aa9fb1f02a3c2'
public = '03768717a1baedf1b7a13de38be56eaecefca6c427e834327636bdde2655c7b472'

#Specify the inputs and outputs below
#For convenince you can specify an address, and the backend will work out what transaction output that address has available to spend
#You do not need to list a change address, by default the transaction will be created with all change (minus the fees) going to the first input address
inputs = [{'address': address}]
outputs = [{'value': 0, 'script_type': "null-data", 'script': ""}]
#The next line creates the transaction shell, which is as yet unsigned
unsigned_tx = blockcypher.create_unsigned_tx(
    inputs=inputs,
    outputs=outputs,
    coin_symbol='btc-testnet',
    api_key='0d7ace0138a0460baa3600a486dd7df8')

#You can edit the transaction fields at this stage, before signing it.
script = b'mmgw12 OP_RETURN'
script_HEX = script.hex()
unsigned_tx['outputs'][0]['script'] = script_HEX

#Now list the private and public keys corresponding to the inputs
private_keys = [private]
public_keys = [public]
#Next create the signatures
tx_signatures = blockcypher.make_tx_signatures(
    txs_to_sign=unsigned_tx['tosign'],
    privkey_list=private_keys,
import blockcypher

#Specify the inputs and outputs below
#For convenince you can specify an address, and the backend will work out what transaction output that address has available to spend
#You do not need to list a change address, by default the transaction will be created with all change (minus the fees) going to the first input address
inputs = [{'address': 'n4KqzBMw2tgTWJeib2AQGYBc2cqH3jyUx1'}]
outputs = [{
    'value': 0,
    'script_type': "null-data",
    'script': "6a4c06677663683438"
}]
#The next line creates the transaction shell, which is as yet unsigned
unsigned_tx = blockcypher.create_unsigned_tx(
    inputs=inputs,
    outputs=outputs,
    coin_symbol='btc-testnet',
    api_key='8c4d64277d0f4330913059a8d80f4526')

#You can edit the transaction fields at this stage, before signing it.

#Now list the private and public keys corresponding to the inputs
private_keys = [
    '6c51e22b3cc2c4965787463ec3057e22bcdf7fb4cdd2db928de052d0c8c1a4dc'
]
public_keys = [
    '035b3a06f1425bcf38005bb54cf77f23932ce36a20ce80cb430304f0e17a21dbf2'
]
#Next create the signatures
tx_signatures = blockcypher.make_tx_signatures(
    txs_to_sign=unsigned_tx['tosign'],
    privkey_list=private_keys,