Example #1
0
    def __init__(self, wallet_dir):
        super(BitcoinWallet, self).__init__()

        if self.TESTNET:
            bitcoin.set_testnet()
            network.set_testnet()

        self.wallet_dir = wallet_dir
        self.wallet_file = 'tbtc_wallet' if self.TESTNET else 'btc_wallet'
        self.min_confirmations = 0
        self.created = False
        self.daemon = None
        keychain_pw = self.get_wallet_password()
        self.wallet_password = keychain_pw if keychain_pw else None  # Convert empty passwords to None
        self.storage = None
        self.wallet = None
        self.load_wallet(self.wallet_dir, self.wallet_file)
Example #2
0
    def __init__(self, wallet_dir):
        super(BitcoinWallet, self).__init__()

        if self.TESTNET:
            bitcoin.set_testnet()
            network.set_testnet()

        self.wallet_dir = wallet_dir
        self.wallet_file = 'tbtc_wallet' if self.TESTNET else 'btc_wallet'
        self.min_confirmations = 0
        self.daemon = None
        self.wallet_password = None
        self.storage = None
        self.wallet = None

        self.initialize_storage(self.wallet_dir, self.wallet_file)
        if self.created:
            # If the wallet has been created already, we try to unlock it.
            self.unlock_wallet()
Example #3
0
    def extract_info(url):
        """
        Extracts amount and BitCoin address from a BitPay URL.
        :param url: the BitPay URL like "https://bitpay.com/invoice?id=J3qU6XapEqevfSCW35zXXX"
        :return: a tuple of the amount in BitCoin along with the address
        """
        # https://bitpay.com/ or https://test.bitpay.com
        uspl = urlsplit(url)
        base_url = "{0.scheme}://{0.netloc}".format(uspl)
        print(base_url)
        invoice_id = uspl.query.split("=")[1]

        # On the browser, users have to select between Bitcoin and Bitcoin cash
        # trigger bitcoin selection for successful transaction
        trigger_url = "{}/invoice-noscript?id={}&buyerSelectedTransactionCurrency=BTC".format(
            base_url, invoice_id)
        print(trigger_url)
        request.urlopen(trigger_url)

        # Make the payment
        payment_url = "bitcoin:?r={}/i/{}".format(base_url, invoice_id)
        print(payment_url)

        # Check for testnet mode
        if os.getenv('TESTNET',
                     '0') == '1' and uspl.netloc == 'test.bitpay.com':
            bitcoin.set_testnet()

        # get payment request using Electrum's lib
        pq = parse_qs(urlsplit(payment_url).query)
        out = {k: v[0] for k, v in pq.items()}
        payreq = pr.get_payment_request(out.get('r')).get_dict()

        # amount is in satoshis (1/10e8 Bitcoin)
        amount = float(payreq.get('amount')) / pow(10, 8)
        address = payreq.get('requestor')

        return PaymentInfo(amount, address)