コード例 #1
0
    def test_register_btc_wallet(self):
        result = create_hd_wallet(
            "blockcypher-testsuite-btc",
            "xpub661MyMwAqRbcGHGJXmM5jX85xJtNmjLgyzs7LpCwBnpfK8SF7TktReXmEt2NzuDhi4NCRanpCRynoewDE6Psuptz7gDW1Uxbfsf56GEfmgo",
            coin_symbol='btc',
            api_key=BC_API_KEY)
        wallets = list_wallet_names(api_key=BC_API_KEY)['wallet_names']
        self.assertIn('blockcypher-testsuite-btc', wallets)
        derivation_response = derive_hd_address(
            api_key=BC_API_KEY,
            wallet_name="blockcypher-testsuite-btc",
            num_addresses=1,
            subchain_index=0,
            coin_symbol="btc",
        )
        list_addresses = [
            "14a2zs9YhAxEo3xworxiJML47STab1LZMe",
            "18ZNuW7HEdMrM7ASfDESN7r5mTBHPPEjyo"
        ]
        self.assertIn(
            derivation_response['chains'][0]['chain_addresses'][0]['address'],
            list_addresses)

        delete_wallet('blockcypher-testsuite-btc',
                      coin_symbol='btc',
                      api_key=BC_API_KEY,
                      is_hd_wallet=True)
コード例 #2
0
 def test_register_btc_wallet(self):
     result = create_hd_wallet(
         "blockcypher-testsuite-btc",
         "xpub661MyMwAqRbcGHGJXmM5jX85xJtNmjLgyzs7LpCwBnpfK8SF7TktReXmEt2NzuDhi4NCRanpCRynoewDE6Psuptz7gDW1Uxbfsf56GEfmgo",
         coin_symbol='btc',
         api_key=BC_API_KEY)
     wallets = list_wallet_names(api_key=BC_API_KEY)['wallet_names']
     self.assertIn('blockcypher-testsuite-btc', wallets)
     delete_wallet('blockcypher-testsuite-btc',
                   coin_symbol='btc',
                   api_key=BC_API_KEY,
                   is_hd_wallet=True)
コード例 #3
0
 def gen(self):
     try:
         wallet = Wallet.objects.get(id=1)
         self.get_wallet(wallet)
     except:
         new_wallet = blockcypher.create_hd_wallet(
             wallet_name=self.wallet_name,
             xpubkey=self.xpubkey,
             api_key=self.api,
             coin_symbol=coin_symbol_from_mkey(self.xpubkey))
         wallet = Wallet()
         wallet.create(key=new_wallet['extended_public_key'],
                       hd=new_wallet['hd'],
                       name=new_wallet['name'],
                       token=new_wallet['token'])
         wallet.save()
         self.wallet = new_wallet
コード例 #4
0
ファイル: views.py プロジェクト: Bithome/explorer
def wallet_overview(request, coin_symbol, pubkey):

    subchain_indices = request.GET.get('subchain-indices')
    if subchain_indices:
        subchain_indices = subchain_indices.split('-')
        if subchain_indices == ['']:
            subchain_indices = []
        else:
            subchain_indices = [int(x) for x in subchain_indices]

    # TODO: confirm it's a pubkey and not a privkey

    TXNS_PER_PAGE = 100

    # 1 indexed page
    current_page = request.GET.get('page')
    if current_page:
        current_page = int(current_page)
    else:
        current_page = 1

    # transaction pagination: 0-indexed and inclusive
    tx_start_num = (current_page - 1) * TXNS_PER_PAGE
    tx_end_num = current_page * TXNS_PER_PAGE - 1

    wallet_name = get_blockcypher_walletname_from_mpub(mpub=pubkey,
            subchain_indices=subchain_indices)

    # TODO: could store in DB whether created or not
    create_hd_wallet(
            wallet_name=wallet_name,
            xpubkey=pubkey,
            api_key=BLOCKCYPHER_API_KEY,
            subchain_indices=subchain_indices,
            coin_symbol=coin_symbol,
            )

    wallet_details = get_wallet_transactions(
            wallet_name=wallet_name,
            api_key=BLOCKCYPHER_API_KEY,
            coin_symbol=coin_symbol,
            txn_limit=TXNS_PER_PAGE,
            )
    # import pprint; pprint.pprint(wallet_details, width=1)

    assert 'error' not in wallet_details, wallet_details

    all_transactions = wallet_details.get('unconfirmed_txrefs', []) + wallet_details.get('txrefs', [])

    # filter address details for pagination. HACK!
    all_transactions = all_transactions[tx_start_num:tx_end_num]

    flattened_txs = flatten_txns_by_hash(all_transactions, nesting=False)

    return {
            'is_wallet_page': True,  # shared template
            'coin_symbol': coin_symbol,
            'pubkey': pubkey,
            'subchain_indices': subchain_indices,
            'current_page': current_page,
            'max_pages': get_max_pages(num_items=wallet_details['final_n_tx'], items_per_page=TXNS_PER_PAGE),
            'total_sent_satoshis': wallet_details['total_sent'],
            'total_received_satoshis': wallet_details['total_received'],
            'unconfirmed_balance_satoshis': wallet_details['unconfirmed_balance'],
            'confirmed_balance_satoshis': wallet_details['balance'],
            'total_balance_satoshis': wallet_details['final_balance'],
            'flattened_txs': flattened_txs,
            'num_confirmed_txns': wallet_details['n_tx'],
            'num_unconfirmed_txns': wallet_details['unconfirmed_n_tx'],
            'num_all_txns': wallet_details['final_n_tx'],
            }
コード例 #5
0
ファイル: bcwallet.py プロジェクト: SpiritStones/bcwallet
def wallet_home(wallet_obj):
    '''
    Loaded on bootup (and loops until quitting)
    '''
    mpub = wallet_obj.serialize_b58(private=False)

    if wallet_obj.private_key is None:
        print_pubwallet_notice(mpub=mpub)
    else:
        puts("You've opened your wallet in PRIVATE key mode, so you CAN sign transactions.")
        puts("If you like, you can always open your wallet in PUBLIC key mode like this:\n")
        print_bcwallet_basic_pub_opening(mpub=mpub)

    coin_symbol = coin_symbol_from_mkey(mpub)
    if USER_ONLINE:
        wallet_name = get_blockcypher_walletname_from_mpub(
                mpub=mpub,
                subchain_indices=[0, 1],
                )

        # Instruct blockcypher to track the wallet by pubkey
        create_hd_wallet(
                wallet_name=wallet_name,
                xpubkey=mpub,
                api_key=BLOCKCYPHER_API_KEY,
                coin_symbol=coin_symbol,
                subchain_indices=[0, 1],  # for internal and change addresses
                )

        # Display balance info
        display_balance_info(wallet_obj=wallet_obj)

    # Go to home screen
    while True:
        puts('-' * 70 + '\n')

        if coin_symbol in ('bcy', 'btc-testnet'):
            display_shortname = COIN_SYMBOL_MAPPINGS[coin_symbol]['display_shortname']
            if coin_symbol == 'bcy':
                faucet_url = 'https://accounts.blockcypher.com/blockcypher-faucet'
            elif coin_symbol == 'btc-testnet':
                faucet_url = 'https://accounts.blockcypher.com/testnet-faucet'
            puts(colored.blue('Get free %s faucet coins at %s\n' % (
                display_shortname,
                faucet_url,
                )))

        puts('What do you want to do?:')
        if not USER_ONLINE:
            puts("(since you are NOT connected to BlockCypher, many choices are disabled)")
        with indent(2):
            puts(colored.cyan('1: Show balance and transactions'))
            puts(colored.cyan('2: Show new receiving addresses'))
            puts(colored.cyan('3: Send funds (more options here)'))

        if wallet_obj.private_key:
            with indent(2):
                puts(colored.cyan('0: Dump private keys and addresses (advanced users only)'))
        else:
            with indent(2):
                puts(colored.cyan('0: Dump addresses (advanced users only)'))

        choice = choice_prompt(
                user_prompt=DEFAULT_PROMPT,
                acceptable_responses=range(0, 3+1),
                quit_ok=True,
                default_input='1',
                )
        verbose_print('Choice: %s' % choice)

        if choice in ('q', 'Q'):
            puts(colored.green('Thanks for using bcwallet!'))
            break
        elif choice == '1':
            display_recent_txs(wallet_obj=wallet_obj)
        elif choice == '2':
            display_new_receiving_addresses(wallet_obj=wallet_obj)
        elif choice == '3':
            send_chooser(wallet_obj=wallet_obj)
        elif choice == '0':
            dump_private_keys_or_addrs_chooser(wallet_obj=wallet_obj)
コード例 #6
0
def wallet_overview(request, coin_symbol, pubkey):

    subchain_indices = request.GET.get('subchain-indices')
    if subchain_indices:
        subchain_indices = subchain_indices.split('-')
        if subchain_indices == ['']:
            subchain_indices = []
        else:
            subchain_indices = [int(x) for x in subchain_indices]

    # TODO: confirm it's a pubkey and not a privkey

    TXNS_PER_PAGE = 100

    # 1 indexed page
    current_page = request.GET.get('page')
    if current_page:
        current_page = int(current_page)
    else:
        current_page = 1

    # transaction pagination: 0-indexed and inclusive
    tx_start_num = (current_page - 1) * TXNS_PER_PAGE
    tx_end_num = current_page * TXNS_PER_PAGE - 1

    wallet_name = get_blockcypher_walletname_from_mpub(
        mpub=pubkey, subchain_indices=subchain_indices)

    # TODO: could store in DB whether created or not
    create_hd_wallet(
        wallet_name=wallet_name,
        xpubkey=pubkey,
        api_key=BLOCKCYPHER_API_KEY,
        subchain_indices=subchain_indices,
        coin_symbol=coin_symbol,
    )

    wallet_details = get_wallet_details(
        wallet_name=wallet_name,
        coin_symbol=coin_symbol,
        txn_limit=TXNS_PER_PAGE,
        api_key=BLOCKCYPHER_API_KEY,
    )
    #import pprint; pprint.pprint(wallet_details, width=1)

    assert 'error' not in wallet_details, wallet_details

    all_transactions = wallet_details.get(
        'unconfirmed_txrefs', []) + wallet_details.get('txrefs', [])

    # filter address details for pagination. HACK!
    all_transactions = all_transactions[tx_start_num:tx_end_num]

    return {
        'is_wallet_page':
        True,  # shared template
        'coin_symbol':
        coin_symbol,
        'pubkey':
        pubkey,
        'subchain_indices':
        subchain_indices,
        'current_page':
        current_page,
        'max_pages':
        get_max_pages(num_items=wallet_details['final_n_tx'],
                      items_per_page=TXNS_PER_PAGE),
        'total_sent_satoshis':
        wallet_details['total_sent'],
        'total_received_satoshis':
        wallet_details['total_received'],
        'unconfirmed_balance_satoshis':
        wallet_details['unconfirmed_balance'],
        'confirmed_balance_satoshis':
        wallet_details['balance'],
        'total_balance_satoshis':
        wallet_details['final_balance'],
        'all_transactions':
        all_transactions,
        'num_confirmed_txns':
        wallet_details['n_tx'],
        'num_unconfirmed_txns':
        wallet_details['unconfirmed_n_tx'],
        'num_all_txns':
        wallet_details['final_n_tx'],
    }