Skip to content

Commit c05c214

Browse files
committed
Merge #808: Change example address from legacy (P2PKH) to bech32m (P2TR)
c6d1b8d gui: change example address from legacy (P2PKH) to bech32m (P2TR) (Sebastian Falbesoner) Pull request description: Legacy addresses are less and less common these days and not recommended to use, so it seems senseful to also reflect that in the example addresses and update to the most recent address / output type (bech32m / P2TR). Also, as I couldn't see any value in computing these at runtime, they are pre-generated. This was done with the following Python script, executed in `./test/functional` (it's also included in the commit body, though without the she-bang): ```python #!/usr/bin/env python3 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}') ``` Note that the last bech32 character is modified in order to make the checksum fail. master (mainnet): ![image](https://github.com/bitcoin-core/gui/assets/91535/8c94cc1e-5649-47ed-8b2d-33b18654f6a2) PR (mainnet): ![image](https://github.com/bitcoin-core/gui/assets/91535/1ce208a6-1218-4850-93e0-5323c73e9049) ACKs for top commit: maflcko: lgtm ACK c6d1b8d pablomartin4btc: tACK c6d1b8d Tree-SHA512: a53c267a3e0d29b9c41bf043b123e7152fbf297e2322d74ce047ba2582b54768187162d462cc334e91a84874731c2e0793726ad44d9970c10ecfe70a1d4f3f1c
2 parents aaab5fb + c6d1b8d commit c05c214

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src/qt/guiutil.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,26 @@ QFont fixedPitchFont(bool use_embedded_font)
109109
return QFontDatabase::systemFont(QFontDatabase::FixedFont);
110110
}
111111

112-
// Just some dummy data to generate a convincing random-looking (but consistent) address
113-
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};
114-
115-
// Generate a dummy address with invalid CRC, starting with the network prefix.
112+
// Return a pre-generated dummy bech32m address (P2TR) with invalid checksum.
116113
static std::string DummyAddress(const CChainParams &params)
117114
{
118-
std::vector<unsigned char> sourcedata = params.Base58Prefix(CChainParams::PUBKEY_ADDRESS);
119-
sourcedata.insert(sourcedata.end(), dummydata, dummydata + sizeof(dummydata));
120-
for(int i=0; i<256; ++i) { // Try every trailing byte
121-
std::string s = EncodeBase58(sourcedata);
122-
if (!IsValidDestinationString(s)) {
123-
return s;
124-
}
125-
sourcedata[sourcedata.size()-1] += 1;
126-
}
127-
return "";
115+
std::string addr;
116+
switch (params.GetChainType()) {
117+
case ChainType::MAIN:
118+
addr = "bc1p35yvjel7srp783ztf8v6jdra7dhfzk5jaun8xz2qp6ws7z80n4tq2jku9f";
119+
break;
120+
case ChainType::SIGNET:
121+
case ChainType::TESTNET:
122+
addr = "tb1p35yvjel7srp783ztf8v6jdra7dhfzk5jaun8xz2qp6ws7z80n4tqa6qnlg";
123+
break;
124+
case ChainType::REGTEST:
125+
addr = "bcrt1p35yvjel7srp783ztf8v6jdra7dhfzk5jaun8xz2qp6ws7z80n4tqsr2427";
126+
break;
127+
} // no default case, so the compiler can warn about missing cases
128+
assert(!addr.empty());
129+
130+
if (Assume(!IsValidDestinationString(addr))) return addr;
131+
return {};
128132
}
129133

130134
void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)

0 commit comments

Comments
 (0)