Skip to content

Commit 4f44cb6

Browse files
committed
qt: Network-specific example address
Generate an (invalid) example address for in the bitcoin address widgets, based on the network prefix, instead of hardcoding a mainnet address. - `1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L` for mainnet (same as now) - `n2wxQmfexkjwEPgdD6iJA7T7RtzkmHxhFc` for testnet
1 parent 6a87eb0 commit 4f44cb6

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/qt/guiutil.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@ QFont fixedPitchFont()
107107
#endif
108108
}
109109

110+
// Just some dummy data to generate an convincing random-looking (but consistent) address
111+
static const uint8_t dummydata[] = {0xeb,0x15,0x23,0x1d,0xfc,0xeb,0x60,0x92,0x58,0x86,0xb6,0x7d,0x06,0x52,0x99,0x92,0x59,0x15,0xae,0xb1,0x72,0xc0,0x66,0x47};
112+
113+
// Generate a dummy address with invalid CRC, starting with the network prefix.
114+
static std::string DummyAddress(const CChainParams &params)
115+
{
116+
std::vector<unsigned char> sourcedata = params.Base58Prefix(CChainParams::PUBKEY_ADDRESS);
117+
sourcedata.insert(sourcedata.end(), dummydata, dummydata + sizeof(dummydata));
118+
for(int i=0; i<256; ++i) { // Try every trailing byte
119+
std::string s = EncodeBase58(begin_ptr(sourcedata), end_ptr(sourcedata));
120+
if (!CBitcoinAddress(s).IsValid())
121+
return s;
122+
sourcedata[sourcedata.size()-1] += 1;
123+
}
124+
return "";
125+
}
126+
110127
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
111128
{
112129
parent->setFocusProxy(widget);
@@ -115,7 +132,8 @@ void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
115132
#if QT_VERSION >= 0x040700
116133
// We don't want translators to use own addresses in translations
117134
// and this is the only place, where this address is supplied.
118-
widget->setPlaceholderText(QObject::tr("Enter a Bitcoin address (e.g. %1)").arg("1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L"));
135+
widget->setPlaceholderText(QObject::tr("Enter a Bitcoin address (e.g. %1)").arg(
136+
QString::fromStdString(DummyAddress(Params()))));
119137
#endif
120138
widget->setValidator(new BitcoinAddressEntryValidator(parent));
121139
widget->setCheckValidator(new BitcoinAddressCheckValidator(parent));

0 commit comments

Comments
 (0)