Ejemplo n.º 1
0
    def finalize(self, parent, proposal, broadcast=False):

        with ConnCtx(parent.credentials, parent.critical) as cc:
            connection = cc.connection
            check_wallet_unlocked(connection)
            check_not_mine(proposal['u_address_r'], connection)

            (incomplete_tx, _, _, fee_p, _, _,
             _) = swap.parse_accepted(*[proposal[k] for k in ACCEPTED_KEYS],
                                      connection=connection)

            msg = 'Are you sure you want to execute this swap?\n\n' \
                  'Paying fees {:.8f} L-BTC.'.format(sat2btc(fee_p))
            ans = QMessageBox.question(parent, 'Confirm', msg)
            if ans != QMessageBox.Yes:
                return

            ret = swap.finalize(incomplete_tx, connection, broadcast)
            if broadcast:
                msg = 'Transaction ID: {}'.format(ret)
                QMessageBox.information(parent, 'Transaction sent', msg)
                InitialWindow(parent)
            else:
                parent.copy_dialog(text=ret,
                                   title='Copy Transaction Hex',
                                   suggested_name='transaction.txt')
Ejemplo n.º 2
0
def finalize(obj, payload, send):
    """Finalize a swap

    Sign the remaining inputs, print the transaction or broadcast it.
    """

    with ConnCtx(obj.credentials, critical) as cc:
        connection = cc.connection
        do_initial_checks(connection, obj.is_mainnet)
        proposal = decode_payload(payload.read())
        check_wallet_unlocked(connection)
        check_not_mine(proposal['u_address_r'], connection)

        (incomplete_tx, _, _, _, _, _,
         _) = swap.parse_accepted(*[proposal[k] for k in ACCEPTED_KEYS],
                                  connection)

        ret = swap.finalize(incomplete_tx, connection, broadcast=send)

        if send:
            d = {'broadcast': True, 'txid': ret}
        else:
            d = {'broadcast': False, 'transaction': ret}

        click.echo(json.dumps(d, indent=4))
Ejemplo n.º 3
0
def accept(obj, payload, output, fee_rate):
    """Accept a swap

    Fund and (partially) sign a proposed transaction.
    """

    with ConnCtx(obj.credentials, critical) as cc:
        connection = cc.connection
        do_initial_checks(connection, obj.is_mainnet)
        proposal = decode_payload(payload.read())

        check_wallet_unlocked(connection)
        check_not_mine(proposal['u_address_p'], connection)

        ret = swap.parse_proposed(*[proposal[k] for k in PROPOSED_KEYS],
                                  connection)
        accepted_swap = swap.accept(*ret, connection, fee_rate)
        encoded_payload = encode_payload(accepted_swap)
        click.echo(encoded_payload, file=output)
Ejemplo n.º 4
0
    def accept(self, parent, proposal):
        with ConnCtx(parent.credentials, parent.critical) as cc:
            connection = cc.connection
            check_wallet_unlocked(connection)
            check_not_mine(proposal['u_address_p'], connection)

            ret = swap.parse_proposed(*[proposal[k] for k in PROPOSED_KEYS],
                                      connection=connection)

            fee_rate = float(connection.getnetworkinfo()['relayfee'])
            accepted_swap = swap.accept(*ret, connection, fee_rate)
            encoded_payload = encode_payload(accepted_swap)

            tx = accepted_swap['tx']
            fee_p = ret[4]
            fee_r = compute_receiver_fee(connection, tx, fee_p)
            msg = 'Are you sure you want to accept this swap?\n\n' \
                  'Paying fees {:.8f} L-BTC.\n\nReceiving address: {}.'.format(
                    sat2btc(fee_r), accepted_swap['u_address_r'])
            ans = QMessageBox.question(parent, 'Confirm', msg)
            if ans == QMessageBox.Yes:
                parent.copy_dialog(text=encoded_payload,
                                   suggested_name='accepted.txt')
Ejemplo n.º 5
0
    def __init__(self, parent, proposal):
        QMainWindow.__init__(self, parent)
        self.setupUi(parent)

        setup_toolbar(parent, self)

        self.buttonExecute.clicked.connect(
            lambda: self.finalize(parent, proposal, broadcast=True))

        with ConnCtx(parent.credentials, parent.critical, True) as cc:
            connection = cc.connection
            parent.asset_data.update(connection)
            check_not_mine(proposal['u_address_r'], connection)

            (tx, amount_p, asset_p, fee_p, amount_r, asset_r,
             fee_r) = swap.parse_accepted(
                 *[proposal[k] for k in ACCEPTED_KEYS], connection=connection)

            self.labelProposerAmountValue.setText(f2s(sat2btc(amount_p)))
            self.labelProposerAssetValue.setText(
                parent.asset_data.get_label(asset_p))
            self.labelReceiverAmountValue.setText(f2s(sat2btc(amount_r)))
            self.labelReceiverAssetValue.setText(
                parent.asset_data.get_label(asset_r))
Ejemplo n.º 6
0
    def __init__(self, parent, proposal):
        QMainWindow.__init__(self, parent)
        self.setupUi(parent)

        setup_toolbar(parent, self)

        self.buttonAccept.clicked.connect(
            lambda: self.accept(parent, proposal))

        with ConnCtx(parent.credentials, parent.critical, True) as cc:
            connection = cc.connection
            parent.asset_data.update(connection)
            check_not_mine(proposal['u_address_p'], connection)

            (tx, address_p, amount_p, asset_p, fee_p, amount_r, asset_r,
             map_amount, map_asset, unspents_details) = swap.parse_proposed(
                 *[proposal[k] for k in PROPOSED_KEYS], connection=connection)

            self.labelProposerAmountValue.setText(f2s(sat2btc(amount_p)))
            self.labelProposerAssetValue.setText(
                parent.asset_data.get_label(asset_p))
            self.labelReceiverAmountValue.setText(f2s(sat2btc(amount_r)))
            self.labelReceiverAssetValue.setText(
                parent.asset_data.get_label(asset_r))