Skip to content

Commit

Permalink
Refactor: remove circ depend. primitives/transaction <-> script/standard
Browse files Browse the repository at this point in the history
by moving GetKeyIDFromUTXO to blocksignature.cpp, which is the only
place using it
  • Loading branch information
random-zebra committed Nov 25, 2021
1 parent 9c67b0a commit e55b0dc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
23 changes: 20 additions & 3 deletions src/blocksignature.cpp
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -7,6 +7,23 @@
#include "script/standard.h"
#include "zpivchain.h"

static bool GetKeyIDFromUTXO(const CTxOut& utxo, CKeyID& keyIDRet)
{
std::vector<valtype> 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))
Expand All @@ -21,15 +38,15 @@ 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;
}
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__);
}

Expand Down
20 changes: 1 addition & 19 deletions src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -81,23 +80,6 @@ uint256 CTxOut::GetHash() const
return SerializeHash(*this);
}

bool CTxOut::GetKeyIDFromUTXO(CKeyID& keyIDRet) const
{
std::vector<valtype> 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();
Expand Down
3 changes: 1 addition & 2 deletions src/primitives/transaction.h
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -172,7 +172,6 @@ class CTxOut
}

uint256 GetHash() const;
bool GetKeyIDFromUTXO(CKeyID& keyIDRet) const;

bool IsZerocoinMint() const;

Expand Down
1 change: 0 additions & 1 deletion test/lint/lint-circular-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit e55b0dc

Please sign in to comment.