diff options
author | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2024-03-22 10:28:53 +0100 |
---|---|---|
committer | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2024-03-28 11:22:23 +0100 |
commit | c6d1b8de89d87fe4fd171dc85557299e429e6564 (patch) | |
tree | 631f71ffbad5d366ff37350439a0febb809788aa | |
parent | bf1b6383dbbfdd0c96a161d4693a48bf3a6b6150 (diff) |
gui: change example address from legacy (P2PKH) to bech32m (P2TR)
The dummy addresses have been computed with the following Python script
(executed under ./test/functional):
--------------------------------------------------------------------------------------------------------
from test_framework.segwit_addr import CHARSET, decode_segwit_address, encode_segwit_address
from test_framework.messages import sha256
output_key = sha256(b'bitcoin dummy taproot output key')
for network, hrp in [('mainnet', 'bc'), ('signet', 'tb'), ('testnet', 'tb'), ('regtest', 'bcrt')]:
dummy_address = encode_segwit_address(hrp, 1, output_key)
while decode_segwit_address(hrp, dummy_address) != (None, None):
last_char = CHARSET[(CHARSET.index(dummy_address[-1]) + 1) % 32]
dummy_address = dummy_address[:-1] + last_char
print(f'{network:7} example address: {dummy_address}')
--------------------------------------------------------------------------------------------------------
Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
-rw-r--r-- | src/qt/guiutil.cpp | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 084b9a6615..1d1a84e375 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -109,22 +109,26 @@ QFont fixedPitchFont(bool use_embedded_font) return QFontDatabase::systemFont(QFontDatabase::FixedFont); } -// Just some dummy data to generate a convincing random-looking (but consistent) address -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}; - -// Generate a dummy address with invalid CRC, starting with the network prefix. +// Return a pre-generated dummy bech32m address (P2TR) with invalid checksum. 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); - if (!IsValidDestinationString(s)) { - return s; - } - sourcedata[sourcedata.size()-1] += 1; - } - return ""; + std::string addr; + switch (params.GetChainType()) { + case ChainType::MAIN: + addr = "bc1p35yvjel7srp783ztf8v6jdra7dhfzk5jaun8xz2qp6ws7z80n4tq2jku9f"; + break; + case ChainType::SIGNET: + case ChainType::TESTNET: + addr = "tb1p35yvjel7srp783ztf8v6jdra7dhfzk5jaun8xz2qp6ws7z80n4tqa6qnlg"; + break; + case ChainType::REGTEST: + addr = "bcrt1p35yvjel7srp783ztf8v6jdra7dhfzk5jaun8xz2qp6ws7z80n4tqsr2427"; + break; + } // no default case, so the compiler can warn about missing cases + assert(!addr.empty()); + + if (Assume(!IsValidDestinationString(addr))) return addr; + return {}; } void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent) |