aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormerge-script <32963518+hebasto@users.noreply.github.com>2024-04-18 10:05:05 +0100
committermerge-script <32963518+hebasto@users.noreply.github.com>2024-04-18 10:05:05 +0100
commitc05c214f2e9cfd6070a3c7680bfa09358fd9d97a (patch)
tree6c67a6018eb55cbf83ccd8f20a02e1c232f86e5d
parentaaab5fb3c51c6a0fb96270fd6cfb0ba0bfbfe1c1 (diff)
parentc6d1b8de89d87fe4fd171dc85557299e429e6564 (diff)
Merge bitcoin-core/gui#808: Change example address from legacy (P2PKH) to bech32m (P2TR)
c6d1b8de89d87fe4fd171dc85557299e429e6564 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 c6d1b8de89d87fe4fd171dc85557299e429e6564 pablomartin4btc: tACK c6d1b8de89d87fe4fd171dc85557299e429e6564 Tree-SHA512: a53c267a3e0d29b9c41bf043b123e7152fbf297e2322d74ce047ba2582b54768187162d462cc334e91a84874731c2e0793726ad44d9970c10ecfe70a1d4f3f1c
-rw-r--r--src/qt/guiutil.cpp32
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 &params)
{
- 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)