mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 02:02:42 +02:00
Merge #11167: Full BIP173 (Bech32) support
8213838[Qt] tolerate BIP173/bech32 addresses during input validation (Jonas Schnelli)06eaca6[RPC] Wallet: test importing of native witness scripts (NicolasDorier)fd0041aUse BIP173 addresses in segwit.py test (Pieter Wuille)e278f12Support BIP173 in addwitnessaddress (Pieter Wuille)c091b99Implement BIP173 addresses and tests (Pieter Wuille)bd355b8Add regtest testing to base58_tests (Pieter Wuille)6565c55Convert base58_tests from type/payload to scriptPubKey comparison (Pieter Wuille)8fd2267Import Bech32 C++ reference code & tests (Pieter Wuille)1e46ebdImplement {Encode,Decode}Destination without CBitcoinAddress (Pieter Wuille) Pull request description: Builds on top of #11117. This adds support for: * Creating BIP173 addresses for testing (through `addwitnessaddress`, though by default it still produces P2SH versions) * Sending to BIP173 addresses (including non-v0 ones) * Analysing BIP173 addresses (through `validateaddress`) It includes a reformatted version of the [C++ Bech32 reference code](https://github.com/sipa/bech32/tree/master/ref/c%2B%2B) and an independent implementation of the address encoding/decoding logic (integrated with CTxDestination). All BIP173 test vectors are included. Not included (and intended for other PRs): * Full wallet support for SegWit (which would include automatically adding witness scripts to the wallet during automatic keypool topup, SegWit change outputs, ...) [see #11403] * Splitting base58.cpp and tests/base58_tests.cpp up into base58-specific code, and "address encoding"-code [see #11372] * Error locating in UI for BIP173 addresses. Tree-SHA512: 238031185fd07f3ac873c586043970cc2db91bf7735c3c168cb33a3db39a7bda81d4891b649685bb17ef90dc63af0328e7705d8cd3e8dafd6c4d3c08fb230341
This commit is contained in:
@@ -129,6 +129,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||
{ "logging", 0, "include" },
|
||||
{ "logging", 1, "exclude" },
|
||||
{ "disconnectnode", 1, "nodeid" },
|
||||
{ "addwitnessaddress", 1, "p2sh" },
|
||||
// Echo with conversion (For testing only)
|
||||
{ "echojson", 0, "arg0" },
|
||||
{ "echojson", 1, "arg1" },
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "chain.h"
|
||||
#include "clientversion.h"
|
||||
#include "core_io.h"
|
||||
#include "crypto/ripemd160.h"
|
||||
#include "init.h"
|
||||
#include "validation.h"
|
||||
#include "httpserver.h"
|
||||
@@ -45,6 +46,7 @@ public:
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
CPubKey vchPubKey;
|
||||
obj.push_back(Pair("isscript", false));
|
||||
obj.push_back(Pair("iswitness", false));
|
||||
if (pwallet && pwallet->GetPubKey(keyID, vchPubKey)) {
|
||||
obj.push_back(Pair("pubkey", HexStr(vchPubKey)));
|
||||
obj.push_back(Pair("iscompressed", vchPubKey.IsCompressed()));
|
||||
@@ -56,6 +58,7 @@ public:
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
CScript subscript;
|
||||
obj.push_back(Pair("isscript", true));
|
||||
obj.push_back(Pair("iswitness", false));
|
||||
if (pwallet && pwallet->GetCScript(scriptID, subscript)) {
|
||||
std::vector<CTxDestination> addresses;
|
||||
txnouttype whichType;
|
||||
@@ -73,6 +76,47 @@ public:
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
UniValue operator()(const WitnessV0KeyHash& id) const
|
||||
{
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
CPubKey pubkey;
|
||||
obj.push_back(Pair("isscript", false));
|
||||
obj.push_back(Pair("iswitness", true));
|
||||
obj.push_back(Pair("witness_version", 0));
|
||||
obj.push_back(Pair("witness_program", HexStr(id.begin(), id.end())));
|
||||
if (pwallet && pwallet->GetPubKey(CKeyID(id), pubkey)) {
|
||||
obj.push_back(Pair("pubkey", HexStr(pubkey)));
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
UniValue operator()(const WitnessV0ScriptHash& id) const
|
||||
{
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
CScript subscript;
|
||||
obj.push_back(Pair("isscript", true));
|
||||
obj.push_back(Pair("iswitness", true));
|
||||
obj.push_back(Pair("witness_version", 0));
|
||||
obj.push_back(Pair("witness_program", HexStr(id.begin(), id.end())));
|
||||
CRIPEMD160 hasher;
|
||||
uint160 hash;
|
||||
hasher.Write(id.begin(), 32).Finalize(hash.begin());
|
||||
if (pwallet && pwallet->GetCScript(CScriptID(hash), subscript)) {
|
||||
obj.push_back(Pair("hex", HexStr(subscript.begin(), subscript.end())));
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
UniValue operator()(const WitnessUnknown& id) const
|
||||
{
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
CScript subscript;
|
||||
obj.push_back(Pair("iswitness", true));
|
||||
obj.push_back(Pair("witness_version", (int)id.version));
|
||||
obj.push_back(Pair("witness_program", HexStr(id.program, id.program + id.length)));
|
||||
return obj;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user