Skip to content

Commit

Permalink
refactor: consolidate P2PK{H} types to P2PK_OR_P2PKH
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Sep 25, 2023
1 parent f011c31 commit 93ddd3f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/addressindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ bool AddressBytesFromScript(const CScript& script, AddressType& address_type, ui
address_type = AddressType::P2SH;
address_bytes = uint160(TrimScriptP2SH(script));
} else if (script.IsPayToPublicKeyHash()) {
address_type = AddressType::P2PKH;
address_type = AddressType::P2PK_OR_P2PKH;
address_bytes = uint160(TrimScriptP2PKH(script));
} else if (script.IsPayToPublicKey()) {
address_type = AddressType::P2PK;
address_type = AddressType::P2PK_OR_P2PKH;
address_bytes = Hash160(TrimScriptP2PK(script));
} else {
address_type = AddressType::UNKNOWN;
Expand Down
3 changes: 1 addition & 2 deletions src/addressindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
class CScript;

enum class AddressType : uint8_t {
P2PK = 1,
P2PKH = 1,
P2PK_OR_P2PKH = 1,
P2SH = 2,

UNKNOWN = 0
Expand Down
2 changes: 1 addition & 1 deletion src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
auto spentInfo = it->second;
in.pushKV("value", ValueFromAmount(spentInfo.m_amount));
in.pushKV("valueSat", spentInfo.m_amount);
if (spentInfo.m_address_type == AddressType::P2PK) {
if (spentInfo.m_address_type == AddressType::P2PK_OR_P2PKH) {
in.pushKV("address", EncodeDestination(PKHash(spentInfo.m_address_bytes)));
} else if (spentInfo.m_address_type == AddressType::P2SH) {
in.pushKV("address", EncodeDestination(ScriptHash(spentInfo.m_address_bytes)));
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ static bool getAddressFromIndex(const AddressType& type, const uint160 &hash, st
{
if (type == AddressType::P2SH) {
address = EncodeDestination(ScriptHash(hash));
} else if (type == AddressType::P2PK) {
} else if (type == AddressType::P2PK_OR_P2PKH) {
address = EncodeDestination(PKHash(hash));
} else {
return false;
Expand All @@ -615,7 +615,7 @@ static bool getIndexKey(const std::string& str, uint160& hashBytes, AddressType&
}
const PKHash *pkhash = std::get_if<PKHash>(&dest);
const ScriptHash *scriptID = std::get_if<ScriptHash>(&dest);
type = pkhash ? AddressType::P2PK : AddressType::P2SH;
type = pkhash ? AddressType::P2PK_OR_P2PKH : AddressType::P2SH;
hashBytes = pkhash ? uint160(*pkhash) : uint160(*scriptID);
return true;
}
Expand Down

0 comments on commit 93ddd3f

Please sign in to comment.