diff options
author | Andrew Chow <github@achow101.com> | 2023-08-08 10:35:08 -0400 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-08-14 17:38:27 -0400 |
commit | b81ebff0d99c45c071b999796b8ae3f0f2517b22 (patch) | |
tree | 0c216069b0470df9c291f61c67a4d6cc367fa919 /src | |
parent | cba69dda3da0e4fa39cff5ce4dc81d1242fe651b (diff) | |
download | bitcoin-b81ebff0d99c45c071b999796b8ae3f0f2517b22.tar.xz |
Remove ScriptHash from CScriptID constructor
Replaces the constructor in CScriptID that converts a ScriptHash with a
function ToScriptID that does the same. This prepares for a move of
CScriptID to avoid a circular dependency.
Diffstat (limited to 'src')
-rw-r--r-- | src/script/signingprovider.cpp | 2 | ||||
-rw-r--r-- | src/script/standard.cpp | 6 | ||||
-rw-r--r-- | src/script/standard.h | 3 | ||||
-rw-r--r-- | src/wallet/rpc/addresses.cpp | 3 | ||||
-rw-r--r-- | src/wallet/rpc/coins.cpp | 2 |
5 files changed, 9 insertions, 7 deletions
diff --git a/src/script/signingprovider.cpp b/src/script/signingprovider.cpp index ef055573b9..fb5ae79c19 100644 --- a/src/script/signingprovider.cpp +++ b/src/script/signingprovider.cpp @@ -205,7 +205,7 @@ CKeyID GetKeyForDestination(const SigningProvider& store, const CTxDestination& } if (auto script_hash = std::get_if<ScriptHash>(&dest)) { CScript script; - CScriptID script_id(*script_hash); + CScriptID script_id = ToScriptID(*script_hash); CTxDestination inner_dest; if (store.GetCScript(script_id, script) && ExtractDestination(script, inner_dest)) { if (auto inner_witness_id = std::get_if<WitnessV0KeyHash>(&inner_dest)) { diff --git a/src/script/standard.cpp b/src/script/standard.cpp index 7c4a05b6e6..e13784e0fc 100644 --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -17,7 +17,6 @@ typedef std::vector<unsigned char> valtype; CScriptID::CScriptID(const CScript& in) : BaseHash(Hash160(in)) {} -CScriptID::CScriptID(const ScriptHash& in) : BaseHash(static_cast<uint160>(in)) {} ScriptHash::ScriptHash(const CScript& in) : BaseHash(Hash160(in)) {} ScriptHash::ScriptHash(const CScriptID& in) : BaseHash(static_cast<uint160>(in)) {} @@ -38,6 +37,11 @@ CKeyID ToKeyID(const WitnessV0KeyHash& key_hash) return CKeyID{static_cast<uint160>(key_hash)}; } +CScriptID ToScriptID(const ScriptHash& script_hash) +{ + return CScriptID{static_cast<uint160>(script_hash)}; +} + WitnessV0ScriptHash::WitnessV0ScriptHash(const CScript& in) { CSHA256().Write(in.data(), in.size()).Finalize(begin()); diff --git a/src/script/standard.h b/src/script/standard.h index 54065f6e30..3e60ea453d 100644 --- a/src/script/standard.h +++ b/src/script/standard.h @@ -20,7 +20,6 @@ static const bool DEFAULT_ACCEPT_DATACARRIER = true; class CKeyID; class CScript; -struct ScriptHash; /** A reference to a CScript: the Hash160 of its serialization (see script.h) */ class CScriptID : public BaseHash<uint160> @@ -29,7 +28,6 @@ public: CScriptID() : BaseHash() {} explicit CScriptID(const CScript& in); explicit CScriptID(const uint160& in) : BaseHash(in) {} - explicit CScriptID(const ScriptHash& in); }; /** @@ -80,6 +78,7 @@ struct ScriptHash : public BaseHash<uint160> explicit ScriptHash(const CScript& script); explicit ScriptHash(const CScriptID& script); }; +CScriptID ToScriptID(const ScriptHash& script_hash); struct WitnessV0ScriptHash : public BaseHash<uint256> { diff --git a/src/wallet/rpc/addresses.cpp b/src/wallet/rpc/addresses.cpp index a8ef0a5731..06f396a6d7 100644 --- a/src/wallet/rpc/addresses.cpp +++ b/src/wallet/rpc/addresses.cpp @@ -440,10 +440,9 @@ public: UniValue operator()(const ScriptHash& scripthash) const { - CScriptID scriptID(scripthash); UniValue obj(UniValue::VOBJ); CScript subscript; - if (provider && provider->GetCScript(scriptID, subscript)) { + if (provider && provider->GetCScript(ToScriptID(scripthash), subscript)) { ProcessSubScript(subscript, obj); } return obj; diff --git a/src/wallet/rpc/coins.cpp b/src/wallet/rpc/coins.cpp index 22f0f0b83c..521378e188 100644 --- a/src/wallet/rpc/coins.cpp +++ b/src/wallet/rpc/coins.cpp @@ -672,7 +672,7 @@ RPCHelpMan listunspent() std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey); if (provider) { if (scriptPubKey.IsPayToScriptHash()) { - const CScriptID& hash = CScriptID(std::get<ScriptHash>(address)); + const CScriptID hash = ToScriptID(std::get<ScriptHash>(address)); CScript redeemScript; if (provider->GetCScript(hash, redeemScript)) { entry.pushKV("redeemScript", HexStr(redeemScript)); |