Exemplo n.º 1
0
    def get_tx_details(self, tx_hash):
        import datetime

        if not tx_hash:
            return ""
        tx = self.transactions.get(tx_hash)
        is_mine, v, fee = self.get_tx_value(tx_hash)
        conf = self.verifier.get_confirmations(tx_hash)
        timestamp = tx.get("timestamp")
        if conf and timestamp:
            time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(" ")[:-3]
        else:
            time_str = "pending"

        inputs = map(lambda x: x.get("address"), tx["inputs"])
        outputs = map(lambda x: x.get("address"), tx["outputs"])
        tx_details = (
            "Transaction Details"
            + "\n\n"
            + "Transaction ID:\n"
            + tx_hash
            + "\n\n"
            + "Status: %d confirmations\n" % conf
        )
        if is_mine:
            if fee:
                tx_details += "Amount sent: %s\n" % format_satoshis(
                    v - fee, False
                ) + "Transaction fee: %s\n" % format_satoshis(fee, False)
            else:
                tx_details += "Amount sent: %s\n" % format_satoshis(v, False) + "Transaction fee: unknown\n"
        else:
            tx_details += "Amount received: %s\n" % format_satoshis(v, False)
        tx_details += (
            "Date: %s\n\n" % time_str + "Inputs:\n-" + "\n-".join(inputs) + "\n\n" + "Outputs:\n-" + "\n-".join(outputs)
        )

        r = self.receipts.get(tx_hash)
        if r:
            tx_details += (
                "\n_______________________________________"
                + "\n\nSigned URI: "
                + r[2]
                + "\n\nSigned by: "
                + r[0]
                + "\n\nSignature: "
                + r[1]
            )

        return tx_details
Exemplo n.º 2
0
 def listaddresses(self,
                   show_all=False,
                   show_labels=False,
                   frozen=False,
                   unused=False,
                   funded=False,
                   show_balance=False):
     """List wallet addresses. Returns your list of addresses."""
     out = []
     for addr in self.wallet.addresses(True):
         if frozen and not addr in self.wallet.frozen_addresses:
             continue
         if not show_all and self.wallet.is_change(addr):
             continue
         if unused and self.wallet.is_used(addr):
             continue
         if funded and self.wallet.is_empty(addr):
             continue
         item = addr
         if show_balance:
             item += ", " + format_satoshis(
                 sum(self.wallet.get_addr_balance(addr)))
         if show_labels:
             item += ', ' + repr(self.wallet.labels.get(addr, ''))
         out.append(item)
     return out
Exemplo n.º 3
0
    def get_tx_history(self):
        with self.lock:
            history = self.transactions.items()
        history.sort(key = lambda x: self.verifier.get_height(x[0]) if self.verifier.get_height(x[0]) else 1e12)
        result = []
    
        balance = 0
        for tx_hash, tx in history:
            is_mine, v, fee = self.get_tx_value(tx)
            if v is not None: balance += v
        c, u = self.get_balance()

        if balance != c+u:
            v_str = format_satoshis( c+u - balance, True, self.num_zeros)
            result.append( ('', 1000, 0, c+u-balance, None, c+u-balance, None ) )

        balance = c + u - balance
        for tx_hash, tx in history:
            conf, timestamp = self.verifier.get_confirmations(tx_hash) if self.verifier else (None, None)
            is_mine, value, fee = self.get_tx_value(tx)
            if value is not None:
                balance += value

            result.append( (tx_hash, conf, is_mine, value, fee, balance, timestamp) )

        return result
Exemplo n.º 4
0
    def get_tx_history(self):
        with self.lock:
            history = self.transactions.values()
        history.sort(key=lambda x: x.get("timestamp") if x.get("timestamp") else 1e12)
        result = []

        balance = 0
        for tx in history:
            is_mine, v, fee = self.get_tx_value(tx["tx_hash"])
            if v is not None:
                balance += v
        c, u = self.get_balance()

        if balance != c + u:
            v_str = format_satoshis(c + u - balance, True, self.num_zeros)
            result.append(("", 1000, 0, c + u - balance, None, c + u - balance, None))

        balance = c + u - balance
        for tx in history:
            tx_hash = tx["tx_hash"]
            timestamp = tx.get("timestamp")
            conf = self.verifier.get_confirmations(tx_hash) if self.verifier else None
            is_mine, value, fee = self.get_tx_value(tx_hash)
            if value is not None:
                balance += value

            result.append((tx_hash, conf, is_mine, value, fee, balance, timestamp))

        return result
 def listaddresses(
     self,
     receiving=False,
     change=False,
     show_labels=False,
     frozen=False,
     unused=False,
     funded=False,
     show_balance=False,
 ):
     """List wallet addresses. Returns the list of all addresses in your wallet. Use optional arguments to filter the results."""
     out = []
     for addr in self.wallet.addresses(True):
         if frozen and not self.wallet.is_frozen(addr):
             continue
         if receiving and self.wallet.is_change(addr):
             continue
         if change and not self.wallet.is_change(addr):
             continue
         if unused and self.wallet.is_used(addr):
             continue
         if funded and self.wallet.is_empty(addr):
             continue
         item = addr
         if show_balance:
             item += ", " + format_satoshis(sum(self.wallet.get_addr_balance(addr)))
         if show_labels:
             item += ", " + repr(self.wallet.labels.get(addr, ""))
         out.append(item)
     return out
Exemplo n.º 6
0
 def listaddresses(self,
                   receiving=False,
                   change=False,
                   show_labels=False,
                   frozen=False,
                   unused=False,
                   funded=False,
                   show_balance=False):
     """List wallet addresses. Returns the list of all addresses in your wallet. Use optional arguments to filter the results."""
     out = []
     for addr in self.wallet.get_addresses():
         if frozen and not self.wallet.is_frozen(addr):
             continue
         if receiving and self.wallet.is_change(addr):
             continue
         if change and not self.wallet.is_change(addr):
             continue
         if unused and self.wallet.is_used(addr):
             continue
         if funded and self.wallet.is_empty(addr):
             continue
         item = addr
         if show_balance:
             item += ", " + format_satoshis(
                 sum(self.wallet.get_addr_balance(addr)))
         if show_labels:
             item += ', ' + repr(self.wallet.labels.get(addr, ''))
         out.append(item)
     return out
Exemplo n.º 7
0
 def _format_request(self, v, show_status=False):
     from paymentrequest import PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED
     pr_str = {
         PR_UNKNOWN: 'Unknown',
         PR_UNPAID: 'Pending',
         PR_PAID: 'Paid',
         PR_EXPIRED: 'Expired',
     }
     addr = v.get('address')
     amount = v.get('amount')
     timestamp = v.get('time')
     expiration = v.get('expiration')
     out = {
         'address': addr,
         'amount': format_satoshis(amount),
         'time': timestamp,
         'reason': self.wallet.get_label(addr)[0],
         'expiration': expiration,
     }
     if v.get('path'):
         url = 'file://' + v.get('path')
         r = self.config.get('url_rewrite')
         if r:
             a, b = r
             url = url.replace(a, b)
         URI = 'bitcoin:?r=' + url
         out['URI'] = URI
     if show_status:
         status = self.wallet.get_request_status(addr, amount, timestamp, expiration)
         out['status'] = pr_str[status]
     return out
Exemplo n.º 8
0
 def update_history(self, tx_history):
     from util import format_satoshis
     for item in tx_history[-10:]:
         tx_hash, conf, is_mine, value, fee, balance, timestamp = item
         label = self.actuator.wallet.get_label(tx_hash)[0]
         #amount = D(value) / 10**8
         v_str = format_satoshis(value, True)
         self.history_list.append(label, v_str)
Exemplo n.º 9
0
 def update_history(self, tx_history):
     from util import format_satoshis
     for item in tx_history[-10:]:
         tx_hash, conf, is_mine, value, fee, balance, timestamp = item
         label = self.actuator.wallet.get_label(tx_hash)[0]
         #amount = D(value) / 10**8
         v_str = format_satoshis(value, True)
         self.history_list.append(label, v_str)
Exemplo n.º 10
0
 def _format_request(self, out):
     pr_str = {
         PR_UNKNOWN: 'Unknown',
         PR_UNPAID: 'Pending',
         PR_PAID: 'Paid',
         PR_EXPIRED: 'Expired',
     }
     out['amount (BTC)'] = format_satoshis(out.get('amount'))
     out['status'] = pr_str[out.get('status', PR_UNKNOWN)]
     return out
Exemplo n.º 11
0
 def _format_request(self, out):
     pr_str = {
         PR_UNKNOWN: 'Unknown',
         PR_UNPAID: 'Pending',
         PR_PAID: 'Paid',
         PR_EXPIRED: 'Expired',
     }
     out['amount'] = format_satoshis(out.get('amount')) + ' BTC'
     out['status'] = pr_str[out.get('status', PR_UNKNOWN)]
     return out
Exemplo n.º 12
0
 def settings_dialog(self):
     out = self.run_dialog('Settings', [
         {'label':'Default GUI', 'type':'list', 'choices':['classic','lite','gtk','text'], 'value':self.config.get('gui')},
         {'label':'Default fee', 'type':'satoshis', 'value': format_satoshis(self.config.get('fee')).strip() }
         ], buttons = 1)
     if out:
         if out.get('Default GUI'):
             self.config.set_key('gui', out['Default GUI'], True)
         if out.get('Default fee'):
             fee = int ( Decimal( out['Default fee']) *10000000 )
             self.config.set_key('fee', fee, True)
Exemplo n.º 13
0
def print_pr(pr):
    if pr.error:
        print(pr.error)
        exit()
    else:
        pr.verify()
        print()
        print("Payment request data")
        print("Network: " + pr.details.network)
        print("Requestor: " + pr.get_requestor())
        print("Memo: " + pr.get_memo())
        print("Expiration: " + util.format_time(pr.get_expiration_date()))
        print("Creation Time: " + util.format_time(pr.details.time))
        print("Verification Status: " + pr.get_verify_status())
        print("Merchant Data: " + str(pr.details.merchant_data))
        print("Outputs:")
        for out in pr.get_outputs():
            if out[0] == util.TYPE_ADDRESS:
                print("  Type: Address")
                print("  Address: " + out[1])
            elif out[0] == util.TYPE_PUBKEY:
                print("  Type: Public Key")
                print("  Public Key: " + out[1])
            elif out[0] == util.TYPE_SCRIPT:
                print("  Type: Script")
                print("  Script: " + out[1])
            else:
                print("  Type: Unknown")
                print("  Data: " + out[1])
            print("  Amount: " + util.format_satoshis(out[2]) + " BTC")

        # Prompt to send transaction
        print(
            "To continue, send the necessary amounts of Bitcoin to the addresses specified in the 'Outputs' field above. Once broadcast, press ENTER to continue or CTRL+C to exit."
        )
        input()

        # Only do this if there is a Payment URL
        if pr.details.payment_url:
            # Get raw tx and refund address for Payment message
            raw_tx = input(
                "Enter the hex of the transaction that was just made: ").strip(
                )
            ref_addr = input("Enter a refund address: ").strip()

            # Send payment message and wait for ACK
            result = pr.send_ack(raw_tx, ref_addr)
            if result[0]:
                print(result[1])
            else:
                print(result[1])
                exit()
Exemplo n.º 14
0
    def print_history(self):
        width = [20, 40, 14, 14]
        delta = (self.maxx - sum(width) - 4)/3
        format_str = "%"+"%d"%width[0]+"s"+"%"+"%d"%(width[1]+delta)+"s"+"%"+"%d"%(width[2]+delta)+"s"+"%"+"%d"%(width[3]+delta)+"s"

        b = 0 
        messages = []

        for item in self.wallet.get_tx_history():
            tx_hash, conf, is_mine, value, fee, balance, timestamp = item
            if conf:
                try:
                    time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3]
                except:
                    time_str = "------"
            else:
                time_str = 'pending'

            label, is_default_label = self.wallet.get_label(tx_hash)
            messages.append( format_str%( time_str, label, format_satoshis(value), format_satoshis(balance) ) )

        self.print_list(messages[::-1], format_str%( _("Date"), _("Description"), _("Amount"), _("Balance")))
Exemplo n.º 15
0
    def print_history(self):
        width = [20, 40, 14, 14]
        delta = (self.maxx - sum(width) - 4)/3
        format_str = "%"+"%d"%width[0]+"s"+"%"+"%d"%(width[1]+delta)+"s"+"%"+"%d"%(width[2]+delta)+"s"+"%"+"%d"%(width[3]+delta)+"s"

        b = 0 
        messages = []
        for tx in self.wallet.get_tx_history():
            v = self.wallet.get_tx_value(tx['tx_hash'])
            b += v
            try:
                time_str = str( datetime.datetime.fromtimestamp( tx['timestamp']))
            except:
                print tx['timestamp']
                time_str = 'pending'
            tx_hash = tx['tx_hash']

            label, is_default_label = self.wallet.get_label(tx_hash)
            #label += ' '*(40 - len(label) )
            messages.append( format_str%( time_str, label, format_satoshis(v), format_satoshis(b) ) )

        self.print_list(messages[::-1], format_str%( _("Date"), _("Description"), _("Amount"), _("Balance")))
Exemplo n.º 16
0
    def get_tx_details(self, tx_hash):
        import datetime
        if not tx_hash: return ''
        tx = self.transactions.get(tx_hash)
        is_mine, v, fee = self.get_tx_value(tx)
        conf, timestamp = self.verifier.get_confirmations(tx_hash)

        if timestamp:
            time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
        else:
            time_str = 'pending'

        inputs = map(lambda x: x.get('address'), tx.inputs)
        outputs = map(lambda x: x.get('address'), tx.d['outputs'])
        tx_details = "Transaction Details" +"\n\n" \
            + "Transaction ID:\n" + tx_hash + "\n\n" \
            + "Status: %d confirmations\n"%conf
        if is_mine:
            if fee: 
                tx_details += "Amount sent: %s\n"% format_satoshis(v-fee, False) \
                              + "Transaction fee: %s\n"% format_satoshis(fee, False)
            else:
                tx_details += "Amount sent: %s\n"% format_satoshis(v, False) \
                              + "Transaction fee: unknown\n"
        else:
            tx_details += "Amount received: %s\n"% format_satoshis(v, False) \

        tx_details += "Date: %s\n\n"%time_str \
            + "Inputs:\n-"+ '\n-'.join(inputs) + "\n\n" \
            + "Outputs:\n-"+ '\n-'.join(outputs)

        r = self.receipts.get(tx_hash)
        if r:
            tx_details += "\n_______________________________________" \
                + '\n\nSigned URI: ' + r[2] \
                + "\n\nSigned by: " + r[0] \
                + '\n\nSignature: ' + r[1]

        return tx_details
Exemplo n.º 17
0
    def history(self):
        balance = 0
        out = []
        for item in self.wallet.get_tx_history():
            tx_hash, conf, is_mine, value, fee, balance, timestamp = item
            try:
                time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
            except Exception:
                time_str = "----"

            label, is_default_label = self.wallet.get_label(tx_hash)

            out.append({'txid': tx_hash, 'date': "%16s" % time_str, 'label': label,
                        'value': format_satoshis(value), 'confirmations': conf})
        return out
Exemplo n.º 18
0
 def listaddresses(self, show_all=False, show_labels=False, frozen=False, unused=False, funded=False, show_balance=False):
     """List wallet addresses. Returns your list of addresses."""
     out = []
     for addr in self.wallet.addresses(True):
         if frozen and not self.wallet.is_frozen(addr):
             continue
         if not show_all and self.wallet.is_change(addr):
             continue
         if unused and self.wallet.is_used(addr):
             continue
         if funded and self.wallet.is_empty(addr):
             continue
         item = addr
         if show_balance:
             item += ", "+ format_satoshis(sum(self.wallet.get_addr_balance(addr)))
         if show_labels:
             item += ', ' + self.wallet.labels.get(addr,'')
         out.append(item)
     return out
Exemplo n.º 19
0
 def settings_dialog(self):
     out = self.run_dialog(
         'Settings',
         [{
             'label': 'Default GUI',
             'type': 'list',
             'choices': ['classic', 'lite', 'gtk', 'text'],
             'value': self.config.get('gui')
         }, {
             'label': 'Default fee',
             'type': 'satoshis',
             'value': format_satoshis(self.config.get('fee')).strip()
         }],
         buttons=1)
     if out:
         if out.get('Default GUI'):
             self.config.set_key('gui', out['Default GUI'], True)
         if out.get('Default fee'):
             fee = int(Decimal(out['Default fee']) * 10000000)
             self.config.set_key('fee', fee, True)
Exemplo n.º 20
0
    def history(self):
        balance = 0
        out = []
        for item in self.wallet.get_history():
            tx_hash, conf, value, timestamp, balance = item
            try:
                time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(" ")[:-3]
            except Exception:
                time_str = "----"

            label, is_default_label = self.wallet.get_label(tx_hash)

            out.append(
                {
                    "txid": tx_hash,
                    "date": "%16s" % time_str,
                    "label": label,
                    "value": format_satoshis(value),
                    "confirmations": conf,
                }
            )
        return out
Exemplo n.º 21
0
    def display_pr(self, pr):
        if pr.error:
            print(pr.error)
            exit()
        else:
            pr.verify()
            self.payment_data_box.setTitle("Payment Request Data")
            pr_data_layout = QGridLayout()

            pr_data_layout.addWidget(QLabel("Network:"), 0, 0)
            network_lbl = QLabel(pr.details.network)
            network_lbl.setTextInteractionFlags(Qt.TextSelectableByMouse)
            pr_data_layout.addWidget(network_lbl, 0, 1)

            pr_data_layout.addWidget(QLabel("Requestor:"), 1, 0)
            requestor_lbl = QLabel(pr.get_requestor())
            requestor_lbl.setTextInteractionFlags(Qt.TextSelectableByMouse)
            pr_data_layout.addWidget(requestor_lbl, 1, 1)

            pr_data_layout.addWidget(QLabel("Memo:"), 2, 0)
            memo_lbl = QLabel(pr.get_memo())
            memo_lbl.setTextInteractionFlags(Qt.TextSelectableByMouse)
            pr_data_layout.addWidget(memo_lbl, 2, 1)

            pr_data_layout.addWidget(QLabel("Expiration:"), 3, 0)
            expire_lbl = QLabel(util.format_time(pr.get_expiration_date()))
            expire_lbl.setTextInteractionFlags(Qt.TextSelectableByMouse)
            pr_data_layout.addWidget(expire_lbl, 3, 1)

            pr_data_layout.addWidget(QLabel("Creation Time:"), 4, 0)
            creation_lbl = QLabel(util.format_time(pr.details.time))
            creation_lbl.setTextInteractionFlags(Qt.TextSelectableByMouse)
            pr_data_layout.addWidget(creation_lbl, 4, 1)

            pr_data_layout.addWidget(QLabel("Verification status:"), 5, 0)
            verification_lbl = QLabel(pr.get_verify_status())
            verification_lbl.setTextInteractionFlags(Qt.TextSelectableByMouse)
            pr_data_layout.addWidget(verification_lbl, 5, 1)

            pr_data_layout.addWidget(QLabel("Merchant Data:"), 6, 0)
            merch_lbl = QLabel(str(pr.details.merchant_data))
            merch_lbl.setTextInteractionFlags(Qt.TextSelectableByMouse)
            pr_data_layout.addWidget(merch_lbl, 6, 1)

            pr_data_layout.addWidget(QLabel("Outputs:"), 7, 0)
            i = 0
            for out in pr.get_outputs():
                type_lbl = QLabel()
                if out[0] == util.TYPE_ADDRESS:
                    pr_data_layout.addWidget(QLabel("  Type:"), 8 + i, 0)
                    type_lbl.setText("Address")
                    pr_data_layout.addWidget(QLabel("  Address:"), 8 + i + 1,
                                             0)
                elif out[0] == util.TYPE_PUBKEY:
                    pr_data_layout.addWidget(QLabel("  Type:"), 8 + i, 0)
                    type_lbl.setText("Public Key")
                    pr_data_layout.addWidget(QLabel("  Public Key:"),
                                             8 + i + 1, 0)
                elif out[0] == util.TYPE_SCRIPT:
                    pr_data_layout.addWidget(QLabel("  Type:"), 8 + i, 0)
                    type_lbl.setText("Script")
                    pr_data_layout.addWidget(QLabel("  Script:"), 8 + i + 1, 0)
                else:
                    pr_data_layout.addWidget(QLabel("  Type:"), 8 + i, 0)
                    type_lbl.setText("Unknown")
                    pr_data_layout.addWidget(QLabel("  Data:"), 8 + i + 1, 0)

                type_lbl.setTextInteractionFlags(Qt.TextSelectableByMouse)
                pr_data_layout.addWidget(type_lbl, 8 + i, 1)

                data_lbl = QLabel(out[1])
                data_lbl.setTextInteractionFlags(Qt.TextSelectableByMouse)
                pr_data_layout.addWidget(data_lbl, 8 + i + 1, 1)

                amt_lbl = QLabel(util.format_satoshis(out[2]) + " BTC")
                amt_lbl.setTextInteractionFlags(Qt.TextSelectableByMouse)
                pr_data_layout.addWidget(QLabel("  Amount:"), 8 + i + 2, 0)
                pr_data_layout.addWidget(amt_lbl, 8 + i + 2, 1)

                i += 3
            next_button = QPushButton("Next")
            next_button.clicked.connect(self.make_further_instructions(pr))
            pr_data_layout.addWidget(next_button, 8 + i, 0)
            self.payment_data_box.setLayout(pr_data_layout)
 def _format_request(self, out):
     pr_str = {PR_UNKNOWN: "Unknown", PR_UNPAID: "Pending", PR_PAID: "Paid", PR_EXPIRED: "Expired"}
     out["amount (GMC)"] = format_satoshis(out.get("amount"))
     out["status"] = pr_str[out.get("status", PR_UNKNOWN)]
     return out