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 "guiutil.h" | #include "guiutil.h" | ||||
#include "bitcoinaddressvalidator.h" | #include "bitcoinaddressvalidator.h" | ||||
#include "bitcoinunits.h" | #include "bitcoinunits.h" | ||||
#include "dstencode.h" | #include "dstencode.h" | ||||
#include "qvalidatedlineedit.h" | #include "qvalidatedlineedit.h" | ||||
#include "walletmodel.h" | #include "walletmodel.h" | ||||
#include "cashaddr.h" | |||||
#include "config.h" | #include "config.h" | ||||
#include "dstencode.h" | #include "dstencode.h" | ||||
#include "init.h" | #include "init.h" | ||||
#include "policy/policy.h" | #include "policy/policy.h" | ||||
#include "primitives/transaction.h" | #include "primitives/transaction.h" | ||||
#include "protocol.h" | #include "protocol.h" | ||||
#include "script/script.h" | #include "script/script.h" | ||||
#include "script/standard.h" | #include "script/standard.h" | ||||
▲ Show 20 Lines • Show All 139 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 QUrl &uri, SendCoinsRecipient *out) { | bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out) { | ||||
// return if URI is not valid or is no bitcoincash: URI | // return if URI is not valid or is no bitcoincash: URI | ||||
if (!uri.isValid() || uri.scheme() != URI_SCHEME) return false; | if (!uri.isValid() || uri.scheme() != URI_SCHEME) return false; | ||||
SendCoinsRecipient rv; | SendCoinsRecipient rv; | ||||
if (IsCashAddrEncoded(uri)) { | |||||
rv.address = uri.scheme() + ":" + uri.path(); | |||||
} else { | |||||
// strip out uri scheme for base58 encoded addresses | |||||
rv.address = uri.path(); | 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 = 0; | rv.amount = 0; | ||||
#if QT_VERSION < 0x050000 | #if QT_VERSION < 0x050000 | ||||
QList<QPair<QString, QString>> items = uri.queryItems(); | QList<QPair<QString, QString>> items = uri.queryItems(); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | bool parseBitcoinURI(QString uri, SendCoinsRecipient *out) { | ||||
// which will lower-case it (and thus invalidate the address). | // which will lower-case it (and thus invalidate the address). | ||||
if (uri.startsWith(URI_SCHEME + "://", Qt::CaseInsensitive)) { | if (uri.startsWith(URI_SCHEME + "://", Qt::CaseInsensitive)) { | ||||
uri.replace(0, URI_SCHEME.length() + 3, URI_SCHEME + ":"); | uri.replace(0, URI_SCHEME.length() + 3, URI_SCHEME + ":"); | ||||
} | } | ||||
QUrl uriInstance(uri); | QUrl uriInstance(uri); | ||||
return parseBitcoinURI(uriInstance, out); | return parseBitcoinURI(uriInstance, out); | ||||
} | } | ||||
QString formatBitcoinURI(const Config &cfg, const SendCoinsRecipient &info) { | QString formatBitcoinURI(const SendCoinsRecipient &info) { | ||||
QString ret = info.address; | QString ret = (URI_SCHEME + ":%1").arg(info.address); | ||||
if (!cfg.UseCashAddrEncoding()) { | |||||
// prefix address with uri scheme for base58 encoded addresses. | |||||
ret = (URI_SCHEME + ":%1").arg(ret); | |||||
} | |||||
int paramCount = 0; | int paramCount = 0; | ||||
if (info.amount) { | if (info.amount) { | ||||
ret += | ret += | ||||
QString("?amount=%1") | QString("?amount=%1") | ||||
.arg(BitcoinUnits::format(BitcoinUnits::BCH, info.amount, false, | .arg(BitcoinUnits::format(BitcoinUnits::BCH, info.amount, false, | ||||
BitcoinUnits::separatorNever)); | BitcoinUnits::separatorNever)); | ||||
paramCount++; | paramCount++; | ||||
▲ Show 20 Lines • Show All 755 Lines • Show Last 20 Lines |