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 "qvalidatedlineedit.h" | #include "qvalidatedlineedit.h" | ||||
#include "walletmodel.h" | #include "walletmodel.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" | ||||
#include "util.h" | #include "util.h" | ||||
#include "utilstrencodings.h" | |||||
#ifdef WIN32 | #ifdef WIN32 | ||||
#ifdef _WIN32_WINNT | #ifdef _WIN32_WINNT | ||||
#undef _WIN32_WINNT | #undef _WIN32_WINNT | ||||
#endif | #endif | ||||
#define _WIN32_WINNT 0x0501 | #define _WIN32_WINNT 0x0501 | ||||
#ifdef _WIN32_IE | #ifdef _WIN32_IE | ||||
#undef _WIN32_IE | #undef _WIN32_IE | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | #if QT_VERSION >= 0x040800 | ||||
font.setStyleHint(QFont::Monospace); | font.setStyleHint(QFont::Monospace); | ||||
#else | #else | ||||
font.setStyleHint(QFont::TypeWriter); | font.setStyleHint(QFont::TypeWriter); | ||||
#endif | #endif | ||||
return font; | return font; | ||||
#endif | #endif | ||||
} | } | ||||
// Just some dummy data to generate an convincing random-looking (but | static std::string MakeAddrInvalid(std::string addr) { | ||||
// consistent) address | if (addr.size() < 2) { | ||||
static const uint8_t dummydata[] = { | return ""; | ||||
0xeb, 0x15, 0x23, 0x1d, 0xfc, 0xeb, 0x60, 0x92, 0x58, 0x86, 0xb6, 0x7d, | |||||
0x06, 0x52, 0x99, 0x92, 0x59, 0x15, 0xae, 0xb1, 0x72, 0xc0, 0x66, 0x47}; | |||||
// Generate a dummy address with invalid CRC, starting with the network prefix. | |||||
static std::string DummyAddress(const CChainParams ¶ms) { | |||||
std::vector<unsigned char> sourcedata = | |||||
params.Base58Prefix(CChainParams::PUBKEY_ADDRESS); | |||||
sourcedata.insert(sourcedata.end(), dummydata, | |||||
dummydata + sizeof(dummydata)); | |||||
for (int i = 0; i < 256; ++i) { // Try every trailing byte | |||||
std::string s = EncodeBase58(sourcedata.data(), | |||||
sourcedata.data() + sourcedata.size()); | |||||
if (!IsValidDestinationString(s)) { | |||||
return s; | |||||
} | } | ||||
sourcedata[sourcedata.size() - 1] += 1; | |||||
// Checksum is at the end of the address. Swapping chars to make it invalid. | |||||
std::swap(addr[addr.size() - 1], addr[addr.size() - 2]); | |||||
if (!IsValidDestinationString(addr)) { | |||||
return addr; | |||||
} | } | ||||
return ""; | return ""; | ||||
} | } | ||||
std::string DummyAddress(const CChainParams ¶ms, const Config &cfg) { | |||||
// Just some dummy data to generate an convincing random-looking (but | |||||
// consistent) address | |||||
static const std::vector<uint8_t> dummydata = { | |||||
0xeb, 0x15, 0x23, 0x1d, 0xfc, 0xeb, 0x60, 0x92, 0x58, 0x86, | |||||
0xb6, 0x7d, 0x06, 0x52, 0x99, 0x92, 0x59, 0x15, 0xae, 0xb1}; | |||||
const CTxDestination dstKey = CKeyID(uint160(dummydata)); | |||||
return MakeAddrInvalid(EncodeDestination(dstKey, params, cfg)); | |||||
} | |||||
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent) { | void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent) { | ||||
parent->setFocusProxy(widget); | parent->setFocusProxy(widget); | ||||
widget->setFont(fixedPitchFont()); | widget->setFont(fixedPitchFont()); | ||||
#if QT_VERSION >= 0x040700 | #if QT_VERSION >= 0x040700 | ||||
// We don't want translators to use own addresses in translations | // We don't want translators to use own addresses in translations | ||||
// and this is the only place, where this address is supplied. | // and this is the only place, where this address is supplied. | ||||
widget->setPlaceholderText( | widget->setPlaceholderText(QObject::tr("Enter a Bitcoin address (e.g. %1)") | ||||
QObject::tr("Enter a Bitcoin address (e.g. %1)") | .arg(QString::fromStdString(DummyAddress( | ||||
.arg(QString::fromStdString(DummyAddress(Params())))); | Params(), GlobalConfig())))); | ||||
#endif | #endif | ||||
widget->setValidator(new BitcoinAddressEntryValidator(parent)); | widget->setValidator(new BitcoinAddressEntryValidator(parent)); | ||||
widget->setCheckValidator(new BitcoinAddressCheckValidator(parent)); | widget->setCheckValidator(new BitcoinAddressCheckValidator(parent)); | ||||
} | } | ||||
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); | ||||
▲ Show 20 Lines • Show All 836 Lines • Show Last 20 Lines |