def get_outputs(self, is_max):
        if self.payto_scriptpubkey:
            asset = self.win.get_asset_from_spend_tab()
            script = self.payto_scriptpubkey
            if is_max:
                amount_rval = sum([
                    txin.value_sats()
                    for txin in self.win.get_coins(asset=asset)
                ], RavenValue())
                if asset:
                    amount = amount_rval.assets.get(asset, Satoshis(0))
                else:
                    amount = amount_rval.rvn_value
            else:
                amount = Satoshis(self.amount_edit.get_amount())
            if asset:
                script = assets.create_transfer_asset_script(
                    script, asset, amount)
            if amount == 0:
                self.errors.append(
                    PayToLineError('The amount cannot be 0.', None))
                return []
            self.outputs = [
                PartialTxOutput(scriptpubkey=script,
                                value=amount,
                                asset=asset,
                                is_max=is_max)
            ]

        return self.outputs[:]
Esempio n. 2
0
    def refresh(self, reason: str):
        self.logger.info(f"refreshing... reason: {reason}")
        assert self.parent.gui_thread == threading.current_thread(
        ), 'must be called from GUI thread'
        assert self.view, 'view not set'
        if self.view.maybe_defer_update():
            return
        selected = self.view.selectionModel().currentIndex()
        selected_row = None
        if selected:
            selected_row = selected.row()
        fx = self.parent.fx
        if fx: fx.history_used_spot = False
        wallet = self.parent.wallet
        self.set_visibility_of_columns()
        transactions = wallet.get_full_history(
            self.parent.fx,
            onchain_domain=self.get_domain(),
            include_lightning=self.should_include_lightning_payments())
        if transactions == self.transactions:
            return
        old_length = self._root.childCount()
        if old_length != 0:
            self.beginRemoveRows(QModelIndex(), 0, old_length)
            self.transactions.clear()
            self._root = HistoryNode(self, None)
            self.endRemoveRows()
        parents = {}
        for tx_item in transactions.values():
            node = HistoryNode(self, tx_item)
            group_id = tx_item.get('group_id')
            if group_id is None:
                self._root.addChild(node)
            else:
                parent = parents.get(group_id)
                if parent is None:
                    # create parent if it does not exist
                    self._root.addChild(node)
                    parents[group_id] = node
                else:
                    # if parent has no children, create two children
                    if parent.childCount() == 0:
                        child_data = dict(parent.get_data())
                        node1 = HistoryNode(self, child_data)
                        parent.addChild(node1)
                        parent._data['label'] = child_data.get('group_label')
                        parent._data['bc_value'] = child_data.get(
                            'bc_value', Satoshis(0))
                        parent._data['ln_value'] = child_data.get(
                            'ln_value', Satoshis(0))
                    # add child to parent
                    parent.addChild(node)
                    # update parent data
                    parent._data['balance'] = tx_item['balance']
                    parent._data['value'] += tx_item['value']
                    if 'group_label' in tx_item:
                        parent._data['label'] = tx_item['group_label']
                    if 'bc_value' in tx_item:
                        parent._data['bc_value'] += tx_item['bc_value']
                    if 'ln_value' in tx_item:
                        parent._data['ln_value'] += tx_item['ln_value']
                    if 'fiat_value' in tx_item:
                        parent._data['fiat_value'] += tx_item['fiat_value']
                    if tx_item.get('txid') == group_id:
                        parent._data['lightning'] = False
                        parent._data['txid'] = tx_item['txid']
                        parent._data['timestamp'] = tx_item['timestamp']
                        parent._data['height'] = tx_item['height']
                        parent._data['confirmations'] = tx_item[
                            'confirmations']

        new_length = self._root.childCount()
        self.beginInsertRows(QModelIndex(), 0, new_length - 1)
        self.transactions = transactions
        self.endInsertRows()

        if selected_row:
            self.view.selectionModel().select(
                self.createIndex(selected_row, 0),
                QItemSelectionModel.Rows | QItemSelectionModel.SelectCurrent)
        self.view.filter()
        # update time filter
        if not self.view.years and self.transactions:
            start_date = date.today()
            end_date = date.today()
            if len(self.transactions) > 0:
                start_date = self.transactions.value_from_pos(0).get(
                    'date') or start_date
                end_date = self.transactions.value_from_pos(
                    len(self.transactions) - 1).get('date') or end_date
            self.view.years = [
                str(i) for i in range(start_date.year, end_date.year + 1)
            ]
            self.view.period_combo.insertItems(1, self.view.years)
        # update tx_status_cache
        self.tx_status_cache.clear()
        for txid, tx_item in self.transactions.items():
            if not tx_item.get('lightning', False):
                tx_mined_info = self.tx_mined_info_from_tx_item(tx_item)
                self.tx_status_cache[txid] = self.parent.wallet.get_tx_status(
                    txid, tx_mined_info)
Esempio n. 3
0
 def get_amount_sat(self) -> Optional[RavenValue]:
     # note that this has msat resolution potentially
     if self.amount is None:
         return None
     return RavenValue(Satoshis(self.amount * COIN))