Skip to content

Commit 03a536f

Browse files
committed
Merge bitcoin/bitcoin#28284: refactor: Remove confusing static_cast in address 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/bitcoin@fadf671 TheCharlatan: ACK fadf671 Tree-SHA512: 8fb9a72203a6461b1f4b38bb90943ca25a92b218fc87da2022b90802e7747350e3668a13db3189201ad30e2e39a51d6658fed4aad176fd52cecc1c7f972c3134
2 parents 38db2bd + fadf671 commit 03a536f

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/addresstype.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,42 @@
33
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
44

55
#include <addresstype.h>
6-
#include <script/script.h>
7-
#include <script/solver.h>
6+
7+
#include <crypto/sha256.h>
88
#include <hash.h>
99
#include <pubkey.h>
10+
#include <script/script.h>
11+
#include <script/solver.h>
1012
#include <uint256.h>
1113
#include <util/hash_type.h>
1214

15+
#include <cassert>
1316
#include <vector>
1417

1518
typedef std::vector<unsigned char> valtype;
1619

1720
ScriptHash::ScriptHash(const CScript& in) : BaseHash(Hash160(in)) {}
18-
ScriptHash::ScriptHash(const CScriptID& in) : BaseHash(static_cast<uint160>(in)) {}
21+
ScriptHash::ScriptHash(const CScriptID& in) : BaseHash{in} {}
1922

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

2326
WitnessV0KeyHash::WitnessV0KeyHash(const CPubKey& pubkey) : BaseHash(pubkey.GetID()) {}
24-
WitnessV0KeyHash::WitnessV0KeyHash(const PKHash& pubkey_hash) : BaseHash(static_cast<uint160>(pubkey_hash)) {}
27+
WitnessV0KeyHash::WitnessV0KeyHash(const PKHash& pubkey_hash) : BaseHash{pubkey_hash} {}
2528

2629
CKeyID ToKeyID(const PKHash& key_hash)
2730
{
28-
return CKeyID{static_cast<uint160>(key_hash)};
31+
return CKeyID{uint160{key_hash}};
2932
}
3033

3134
CKeyID ToKeyID(const WitnessV0KeyHash& key_hash)
3235
{
33-
return CKeyID{static_cast<uint160>(key_hash)};
36+
return CKeyID{uint160{key_hash}};
3437
}
3538

3639
CScriptID ToScriptID(const ScriptHash& script_hash)
3740
{
38-
return CScriptID{static_cast<uint160>(script_hash)};
41+
return CScriptID{uint160{script_hash}};
3942
}
4043

4144
WitnessV0ScriptHash::WitnessV0ScriptHash(const CScript& in)

src/script/solver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6-
#include <script/solver.h>
76
#include <pubkey.h>
87
#include <script/interpreter.h>
98
#include <script/script.h>
9+
#include <script/solver.h>
1010
#include <span.h>
1111

12-
#include <string>
1312
#include <algorithm>
13+
#include <cassert>
14+
#include <string>
1415

1516
typedef std::vector<unsigned char> valtype;
1617

0 commit comments

Comments
 (0)