Changeset View
Changeset View
Standalone View
Standalone View
src/qt/guiutil.cpp
// Copyright (c) 2011-2016 The Bitcoin Core developers | // Copyright (c) 2011-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <qt/guiutil.h> | #include <qt/guiutil.h> | ||||
#include <cashaddr.h> | |||||
#include <cashaddrenc.h> | #include <cashaddrenc.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <dstencode.h> | #include <dstencode.h> | ||||
#include <fs.h> | #include <fs.h> | ||||
#include <interfaces/node.h> | #include <interfaces/node.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <protocol.h> | #include <protocol.h> | ||||
▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | |||||
void setupAmountWidget(QLineEdit *widget, QWidget *parent) { | void setupAmountWidget(QLineEdit *widget, QWidget *parent) { | ||||
QDoubleValidator *amountValidator = new QDoubleValidator(parent); | QDoubleValidator *amountValidator = new QDoubleValidator(parent); | ||||
amountValidator->setDecimals(8); | amountValidator->setDecimals(8); | ||||
amountValidator->setBottom(0.0); | amountValidator->setBottom(0.0); | ||||
widget->setValidator(amountValidator); | widget->setValidator(amountValidator); | ||||
widget->setAlignment(Qt::AlignRight | Qt::AlignVCenter); | widget->setAlignment(Qt::AlignRight | Qt::AlignVCenter); | ||||
} | } | ||||
static bool IsCashAddrEncoded(const QUrl &uri) { | |||||
const std::string addr = (uri.scheme() + ":" + uri.path()).toStdString(); | |||||
auto decoded = cashaddr::Decode(addr, ""); | |||||
return !decoded.first.empty(); | |||||
} | |||||
bool parseBitcoinURI(const QString &scheme, const QUrl &uri, | bool parseBitcoinURI(const QString &scheme, const QUrl &uri, | ||||
SendCoinsRecipient *out) { | SendCoinsRecipient *out) { | ||||
// return if URI has wrong scheme. | // return if URI has wrong scheme. | ||||
if (!uri.isValid() || uri.scheme() != scheme) { | if (!uri.isValid() || uri.scheme() != scheme) { | ||||
return false; | return false; | ||||
} | } | ||||
SendCoinsRecipient rv; | SendCoinsRecipient rv; | ||||
if (IsCashAddrEncoded(uri)) { | |||||
rv.address = uri.scheme() + ":" + uri.path(); | rv.address = uri.scheme() + ":" + uri.path(); | ||||
} else { | |||||
// strip out uri scheme for base58 encoded addresses | |||||
rv.address = uri.path(); | |||||
} | |||||
// Trim any following forward slash which may have been added by the OS | // Trim any following forward slash which may have been added by the OS | ||||
if (rv.address.endsWith("/")) { | if (rv.address.endsWith("/")) { | ||||
rv.address.truncate(rv.address.length() - 1); | rv.address.truncate(rv.address.length() - 1); | ||||
} | } | ||||
rv.amount = Amount::zero(); | rv.amount = Amount::zero(); | ||||
QUrlQuery uriQuery(uri); | QUrlQuery uriQuery(uri); | ||||
QList<QPair<QString, QString>> items = uriQuery.queryItems(); | QList<QPair<QString, QString>> items = uriQuery.queryItems(); | ||||
▲ Show 20 Lines • Show All 831 Lines • Show Last 20 Lines |