From e55b0dc2bae59e7dc6753b05e5bd5ea2cec70745 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Mon, 22 Nov 2021 23:04:51 +0100 Subject: [PATCH] Refactor: remove circ depend. primitives/transaction <-> script/standard by moving GetKeyIDFromUTXO to blocksignature.cpp, which is the only place using it --- src/blocksignature.cpp | 23 ++++++++++++++++++++--- src/primitives/transaction.cpp | 20 +------------------- src/primitives/transaction.h | 3 +-- test/lint/lint-circular-dependencies.sh | 1 - 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/blocksignature.cpp b/src/blocksignature.cpp index dc5f480fc7a12..dbd381a4f96d8 100644 --- a/src/blocksignature.cpp +++ b/src/blocksignature.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020 The PIVX developers +// Copyright (c) 2017-2021 The PIVX developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -7,6 +7,23 @@ #include "script/standard.h" #include "zpivchain.h" +static bool GetKeyIDFromUTXO(const CTxOut& utxo, CKeyID& keyIDRet) +{ + std::vector vSolutions; + txnouttype whichType; + if (utxo.scriptPubKey.empty() || !Solver(utxo.scriptPubKey, whichType, vSolutions)) + return false; + if (whichType == TX_PUBKEY) { + keyIDRet = CPubKey(vSolutions[0]).GetID(); + return true; + } + if (whichType == TX_PUBKEYHASH || whichType == TX_COLDSTAKE) { + keyIDRet = CKeyID(uint160(vSolutions[0])); + return true; + } + return false; +} + bool SignBlockWithKey(CBlock& block, const CKey& key) { if (!key.Sign(block.GetHash(), block.vchBlockSig)) @@ -21,7 +38,7 @@ bool SignBlock(CBlock& block, const CKeyStore& keystore) if (block.IsProofOfWork()) { bool fFoundID = false; for (const CTxOut& txout : block.vtx[0]->vout) { - if (!txout.GetKeyIDFromUTXO(keyID)) + if (!GetKeyIDFromUTXO(txout, keyID)) continue; fFoundID = true; break; @@ -29,7 +46,7 @@ bool SignBlock(CBlock& block, const CKeyStore& keystore) if (!fFoundID) return error("%s: failed to find key for PoW", __func__); } else { - if (!block.vtx[1]->vout[1].GetKeyIDFromUTXO(keyID)) + if (!GetKeyIDFromUTXO(block.vtx[1]->vout[1], keyID)) return error("%s: failed to find key for PoS", __func__); } diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 5e1457e50a109..e2f4d2e95c2fb 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -1,13 +1,12 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin developers -// Copyright (c) 2015-2020 The PIVX developers +// Copyright (c) 2015-2021 The PIVX developers // Distributed under the MIT software license, see the accompanying // file COPYING or https://www.opensource.org/licenses/mit-license.php. #include "primitives/transaction.h" #include "hash.h" -#include "script/standard.h" #include "tinyformat.h" #include "utilstrencodings.h" @@ -81,23 +80,6 @@ uint256 CTxOut::GetHash() const return SerializeHash(*this); } -bool CTxOut::GetKeyIDFromUTXO(CKeyID& keyIDRet) const -{ - std::vector vSolutions; - txnouttype whichType; - if (scriptPubKey.empty() || !Solver(scriptPubKey, whichType, vSolutions)) - return false; - if (whichType == TX_PUBKEY) { - keyIDRet = CPubKey(vSolutions[0]).GetID(); - return true; - } - if (whichType == TX_PUBKEYHASH || whichType == TX_COLDSTAKE) { - keyIDRet = CKeyID(uint160(vSolutions[0])); - return true; - } - return false; -} - bool CTxOut::IsZerocoinMint() const { return scriptPubKey.IsZerocoinMint(); diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 9409d67520af9..49c43a90aa5be 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin developers -// Copyright (c) 2015-2020 The PIVX developers +// Copyright (c) 2015-2021 The PIVX developers // Distributed under the MIT software license, see the accompanying // file COPYING or https://www.opensource.org/licenses/mit-license.php. @@ -172,7 +172,6 @@ class CTxOut } uint256 GetHash() const; - bool GetKeyIDFromUTXO(CKeyID& keyIDRet) const; bool IsZerocoinMint() const; diff --git a/test/lint/lint-circular-dependencies.sh b/test/lint/lint-circular-dependencies.sh index ded34050353fb..d0d4a396ac0e3 100755 --- a/test/lint/lint-circular-dependencies.sh +++ b/test/lint/lint-circular-dependencies.sh @@ -71,7 +71,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=( "kernel -> stakeinput -> wallet/wallet -> kernel" "legacy/validation_zerocoin_legacy -> wallet/wallet -> validation -> legacy/validation_zerocoin_legacy" "masternode-sync -> masternodeman -> net_processing -> masternode-sync" - "primitives/transaction -> script/standard -> script/interpreter -> primitives/transaction" "qt/askpassphrasedialog -> qt/pivx/pivxgui -> qt/pivx/topbar -> qt/askpassphrasedialog" "qt/pivx/coldstakingwidget -> qt/pivx/tooltipmenu -> qt/pivx/pivxgui -> qt/pivx/coldstakingwidget" "qt/pivx/masternodeswidget -> qt/pivx/tooltipmenu -> qt/pivx/pivxgui -> qt/pivx/masternodeswidget"