Skip to content

Commit e55b0dc

Browse files
committed
Refactor: remove circ depend. primitives/transaction <-> script/standard
by moving GetKeyIDFromUTXO to blocksignature.cpp, which is the only place using it
1 parent 9c67b0a commit e55b0dc

File tree

4 files changed

+22
-25
lines changed

4 files changed

+22
-25
lines changed

src/blocksignature.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2020 The PIVX developers
1+
// Copyright (c) 2017-2021 The PIVX developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -7,6 +7,23 @@
77
#include "script/standard.h"
88
#include "zpivchain.h"
99

10+
static bool GetKeyIDFromUTXO(const CTxOut& utxo, CKeyID& keyIDRet)
11+
{
12+
std::vector<valtype> vSolutions;
13+
txnouttype whichType;
14+
if (utxo.scriptPubKey.empty() || !Solver(utxo.scriptPubKey, whichType, vSolutions))
15+
return false;
16+
if (whichType == TX_PUBKEY) {
17+
keyIDRet = CPubKey(vSolutions[0]).GetID();
18+
return true;
19+
}
20+
if (whichType == TX_PUBKEYHASH || whichType == TX_COLDSTAKE) {
21+
keyIDRet = CKeyID(uint160(vSolutions[0]));
22+
return true;
23+
}
24+
return false;
25+
}
26+
1027
bool SignBlockWithKey(CBlock& block, const CKey& key)
1128
{
1229
if (!key.Sign(block.GetHash(), block.vchBlockSig))
@@ -21,15 +38,15 @@ bool SignBlock(CBlock& block, const CKeyStore& keystore)
2138
if (block.IsProofOfWork()) {
2239
bool fFoundID = false;
2340
for (const CTxOut& txout : block.vtx[0]->vout) {
24-
if (!txout.GetKeyIDFromUTXO(keyID))
41+
if (!GetKeyIDFromUTXO(txout, keyID))
2542
continue;
2643
fFoundID = true;
2744
break;
2845
}
2946
if (!fFoundID)
3047
return error("%s: failed to find key for PoW", __func__);
3148
} else {
32-
if (!block.vtx[1]->vout[1].GetKeyIDFromUTXO(keyID))
49+
if (!GetKeyIDFromUTXO(block.vtx[1]->vout[1], keyID))
3350
return error("%s: failed to find key for PoS", __func__);
3451
}
3552

src/primitives/transaction.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
22
// Copyright (c) 2009-2014 The Bitcoin developers
3-
// Copyright (c) 2015-2020 The PIVX developers
3+
// Copyright (c) 2015-2021 The PIVX developers
44
// Distributed under the MIT software license, see the accompanying
55
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
66

77
#include "primitives/transaction.h"
88

99
#include "hash.h"
10-
#include "script/standard.h"
1110
#include "tinyformat.h"
1211
#include "utilstrencodings.h"
1312

@@ -81,23 +80,6 @@ uint256 CTxOut::GetHash() const
8180
return SerializeHash(*this);
8281
}
8382

84-
bool CTxOut::GetKeyIDFromUTXO(CKeyID& keyIDRet) const
85-
{
86-
std::vector<valtype> vSolutions;
87-
txnouttype whichType;
88-
if (scriptPubKey.empty() || !Solver(scriptPubKey, whichType, vSolutions))
89-
return false;
90-
if (whichType == TX_PUBKEY) {
91-
keyIDRet = CPubKey(vSolutions[0]).GetID();
92-
return true;
93-
}
94-
if (whichType == TX_PUBKEYHASH || whichType == TX_COLDSTAKE) {
95-
keyIDRet = CKeyID(uint160(vSolutions[0]));
96-
return true;
97-
}
98-
return false;
99-
}
100-
10183
bool CTxOut::IsZerocoinMint() const
10284
{
10385
return scriptPubKey.IsZerocoinMint();

src/primitives/transaction.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
22
// Copyright (c) 2009-2014 The Bitcoin developers
3-
// Copyright (c) 2015-2020 The PIVX developers
3+
// Copyright (c) 2015-2021 The PIVX developers
44
// Distributed under the MIT software license, see the accompanying
55
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
66

@@ -172,7 +172,6 @@ class CTxOut
172172
}
173173

174174
uint256 GetHash() const;
175-
bool GetKeyIDFromUTXO(CKeyID& keyIDRet) const;
176175

177176
bool IsZerocoinMint() const;
178177

test/lint/lint-circular-dependencies.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
7171
"kernel -> stakeinput -> wallet/wallet -> kernel"
7272
"legacy/validation_zerocoin_legacy -> wallet/wallet -> validation -> legacy/validation_zerocoin_legacy"
7373
"masternode-sync -> masternodeman -> net_processing -> masternode-sync"
74-
"primitives/transaction -> script/standard -> script/interpreter -> primitives/transaction"
7574
"qt/askpassphrasedialog -> qt/pivx/pivxgui -> qt/pivx/topbar -> qt/askpassphrasedialog"
7675
"qt/pivx/coldstakingwidget -> qt/pivx/tooltipmenu -> qt/pivx/pivxgui -> qt/pivx/coldstakingwidget"
7776
"qt/pivx/masternodeswidget -> qt/pivx/tooltipmenu -> qt/pivx/pivxgui -> qt/pivx/masternodeswidget"

0 commit comments

Comments
 (0)