Example #1
0
    def prepare_transaction(cls,
                            address,
                            outputs,
                            compressed=True,
                            fee=None,
                            leftover=None,
                            combine=True,
                            message=None,
                            unspents=None):  # pragma: no cover
        """Prepares a P2PKH transaction for offline signing.

        :param address: The address the funds will be sent from.
        :type address: ``str``
        :param outputs: A sequence of outputs you wish to send in the form
                        ``(destination, amount, currency)``. The amount can
                        be either an int, float, or string as long as it is
                        a valid input to ``decimal.Decimal``. The currency
                        must be :ref:`supported <supported currencies>`.
        :type outputs: ``list`` of ``tuple``
        :param compressed: Whether or not the ``address`` corresponds to a
                           compressed public key. This influences the fee.
        :type compressed: ``bool``
        :param fee: The number of satoshi per byte to pay to miners. By default
                    Bit will poll `<https://bitcoinfees.21.co>`_ and use a fee
                    that will allow your transaction to be confirmed as soon as
                    possible.
        :type fee: ``int``
        :param leftover: The destination that will receive any change from the
                         transaction. By default Bit will send any change to
                         the same address you sent from.
        :type leftover: ``str``
        :param combine: Whether or not Bit should use all available UTXOs to
                        make future transactions smaller and therefore reduce
                        fees. By default Bit will consolidate UTXOs.
        :type combine: ``bool``
        :param message: A message to include in the transaction. This will be
                        stored in the blockchain forever. Due to size limits,
                        each message will be stored in chunks of 40 bytes.
        :type message: ``str``
        :param unspents: The UTXOs to use as the inputs. By default Bit will
                         communicate with the blockchain itself.
        :type unspents: ``list`` of :class:`~bit.network.meta.Unspent`
        :returns: JSON storing data required to create an offline transaction.
        :rtype: ``str``
        """
        unspents, outputs = sanitize_tx_data(
            unspents or NetworkAPI.get_unspent(address),
            outputs,
            fee or get_fee_cached(),
            leftover or address,
            combine=combine,
            message=message,
            compressed=compressed)

        data = {
            'unspents': [unspent.to_dict() for unspent in unspents],
            'outputs': outputs
        }

        return json.dumps(data, separators=(',', ':'))
Example #2
0
 def get_utxo(self, addr):
     """查询,当返回时发射信号sig_unspents_arrived"""
     try:
         unspents = NetworkAPI.get_unspent(addr)
     except:
         unspents = '查询失败'
     self.sig_unspents_arrived.emit(unspents)
Example #3
0
    def get_unspents(self):
        """Fetches all available unspent transaction outputs.

        :rtype: ``list`` of :class:`~bit.network.meta.Unspent`
        """
        self.unspents[:] = NetworkAPI.get_unspent(self.address)
        self.balance = sum(unspent.amount for unspent in self.unspents)
        return self.unspents
    def get_account(self):
        # 查询时界面设置
        self.label_2.setText( '查询中......' )
        self.pushButton.setEnabled(False)
        self.treeWidget.setHidden(True)

        # 网络查询余额
        addr = self.lineEdit.text()
        unspents = NetworkAPI.get_unspent(addr)

        # 查询后界面展现
        self.pushButton.setEnabled(True)
        if len(unspents)==0:
            self.label_2.setText( '<html><head/><body><p><span style=" color:#00aa00;">0</span></p></body></html>' )
        else:
            self.treeWidget.clear()
            self.treeWidget.setHidden(False)
            s=sum(unspent.amount for unspent in unspents)
            self.label_2.setText( '<html><head/><body><p><span style=" color:#00aa00;">%d</span></p></body></html>'%(s) )
            for utxo in unspents:
                root=QTreeWidgetItem(self.treeWidget)
                root.setText(0,'amount')
                root.setText(1,str(utxo.amount))
                txid = QTreeWidgetItem(root)
                txid.setText(0,'txid')
                txid.setText(1,utxo.txid)
                txindex = QTreeWidgetItem(root)
                txindex.setText(0,'txindex')
                txindex.setText(1,str(utxo.txindex))
                script = QTreeWidgetItem(root)
                script.setText(0,'script')
                script.setText(1,utxo.script)
                confirmations = QTreeWidgetItem(root)
                confirmations.setText(0,'confirmations')
                confirmations.setText(1,str(utxo.confirmations))
                segwit = QTreeWidgetItem(root)
                segwit.setText(0,'segwit')
                segwit.setText(1,str(utxo.segwit))
Example #5
0
 def get_utxo(self, addr):
     """查询,当返回时发射信号sig_unspents_arrived"""
     unspents = NetworkAPI.get_unspent(addr)
     self.sig_unspents_arrived.emit(unspents)
Example #6
0
 def get_action_utxo(self):
     if not self.check_input_arguments(["address"]):
         return self._response(error_msg.PARAMS_ERROR)
     unspent = NetworkAPI.get_unspent(self._input["address"])
     return self._response(data=[i.to_dict() for i in unspent])