Skip to content

Commit

Permalink
Merge bitcoin#28284: refactor: Remove confusing static_cast in addres…
Browse files Browse the repository at this point in the history
…s types

fadf671 Refactor: Remove confusing static_cast (MarcoFalke)
faeea1a refactor: Add missing includes (MarcoFalke)

Pull request description:

  It seems confusing to use `static_cast<uint160>(bla)` to call the constructor of `uint160`. The normal and common way to call a constructor is by simply calling it. (`uint160{bla}`).

  Do this, and also drop the constructor completely where the existing `const&` reference is enough.

  Also, add missing includes while touching the file.

ACKs for top commit:
  vincenzopalazzo:
    ACK bitcoin@fadf671
  TheCharlatan:
    ACK fadf671

Tree-SHA512: 8fb9a72203a6461b1f4b38bb90943ca25a92b218fc87da2022b90802e7747350e3668a13db3189201ad30e2e39a51d6658fed4aad176fd52cecc1c7f972c3134
  • Loading branch information
fanquake committed Aug 22, 2023
2 parents 38db2bd + fadf671 commit 03a536f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 10 additions & 7 deletions src/addresstype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,42 @@
// file COPYING or https://www.opensource.org/licenses/mit-license.php.

#include <addresstype.h>
#include <script/script.h>
#include <script/solver.h>

#include <crypto/sha256.h>
#include <hash.h>
#include <pubkey.h>
#include <script/script.h>
#include <script/solver.h>
#include <uint256.h>
#include <util/hash_type.h>

#include <cassert>
#include <vector>

typedef std::vector<unsigned char> valtype;

ScriptHash::ScriptHash(const CScript& in) : BaseHash(Hash160(in)) {}
ScriptHash::ScriptHash(const CScriptID& in) : BaseHash(static_cast<uint160>(in)) {}
ScriptHash::ScriptHash(const CScriptID& in) : BaseHash{in} {}

PKHash::PKHash(const CPubKey& pubkey) : BaseHash(pubkey.GetID()) {}
PKHash::PKHash(const CKeyID& pubkey_id) : BaseHash(pubkey_id) {}

WitnessV0KeyHash::WitnessV0KeyHash(const CPubKey& pubkey) : BaseHash(pubkey.GetID()) {}
WitnessV0KeyHash::WitnessV0KeyHash(const PKHash& pubkey_hash) : BaseHash(static_cast<uint160>(pubkey_hash)) {}
WitnessV0KeyHash::WitnessV0KeyHash(const PKHash& pubkey_hash) : BaseHash{pubkey_hash} {}

CKeyID ToKeyID(const PKHash& key_hash)
{
return CKeyID{static_cast<uint160>(key_hash)};
return CKeyID{uint160{key_hash}};
}

CKeyID ToKeyID(const WitnessV0KeyHash& key_hash)
{
return CKeyID{static_cast<uint160>(key_hash)};
return CKeyID{uint160{key_hash}};
}

CScriptID ToScriptID(const ScriptHash& script_hash)
{
return CScriptID{static_cast<uint160>(script_hash)};
return CScriptID{uint160{script_hash}};
}

WitnessV0ScriptHash::WitnessV0ScriptHash(const CScript& in)
Expand Down
5 changes: 3 additions & 2 deletions src/script/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <script/solver.h>
#include <pubkey.h>
#include <script/interpreter.h>
#include <script/script.h>
#include <script/solver.h>
#include <span.h>

#include <string>
#include <algorithm>
#include <cassert>
#include <string>

typedef std::vector<unsigned char> valtype;

Expand Down

0 comments on commit 03a536f

Please sign in to comment.