forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5762 from knst/bitcoinserver-15639-p2
refactor: pull libbitcoin_server (governance) code out of wallet code 4/N
- Loading branch information
Showing
23 changed files
with
257 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) 2014-2023 The Dash Core developers | ||
// Distributed under the MIT/X11 software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <governance/common.h> | ||
|
||
#include <util/strencodings.h> | ||
#include <util/underlying.h> | ||
#include <hash.h> | ||
#include <univalue.h> | ||
|
||
namespace Governance | ||
{ | ||
|
||
Object::Object(const uint256& nHashParent, int nRevision, int64_t nTime, const uint256& nCollateralHash, const std::string& strDataHex) : | ||
hashParent{nHashParent}, | ||
revision{nRevision}, | ||
time{nTime}, | ||
collateralHash{nCollateralHash}, | ||
masternodeOutpoint{}, | ||
vchSig{}, | ||
vchData{ParseHex(strDataHex)} | ||
{ | ||
} | ||
|
||
uint256 Object::GetHash() const | ||
{ | ||
// Note: doesn't match serialization | ||
|
||
// CREATE HASH OF ALL IMPORTANT PIECES OF DATA | ||
|
||
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); | ||
ss << hashParent; | ||
ss << revision; | ||
ss << time; | ||
ss << HexStr(vchData); | ||
ss << masternodeOutpoint << uint8_t{} << 0xffffffff; // adding dummy values here to match old hashing | ||
ss << vchSig; | ||
// fee_tx is left out on purpose | ||
|
||
return ss.GetHash(); | ||
} | ||
|
||
UniValue Object::ToJson() const | ||
{ | ||
UniValue obj(UniValue::VOBJ); | ||
obj.pushKV("objectHash", GetHash().ToString()); | ||
obj.pushKV("parentHash", hashParent.ToString()); | ||
obj.pushKV("collateralHash", collateralHash.ToString()); | ||
obj.pushKV("createdAt", time); | ||
obj.pushKV("revision", revision); | ||
UniValue data; | ||
if (!data.read(GetDataAsPlainString())) { | ||
data.clear(); | ||
data.setObject(); | ||
data.pushKV("plain", GetDataAsPlainString()); | ||
} | ||
data.pushKV("hex", GetDataAsHexString()); | ||
obj.pushKV("data", data); | ||
return obj; | ||
} | ||
|
||
std::string Object::GetDataAsHexString() const | ||
{ | ||
return HexStr(vchData); | ||
} | ||
|
||
std::string Object::GetDataAsPlainString() const | ||
{ | ||
return std::string(vchData.begin(), vchData.end()); | ||
} | ||
|
||
} // namespace Governance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright (c) 2014-2023 The Dash Core developers | ||
// Distributed under the MIT/X11 software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_GOVERNANCE_COMMON_H | ||
#define BITCOIN_GOVERNANCE_COMMON_H | ||
|
||
#include <primitives/transaction.h> | ||
#include <uint256.h> | ||
|
||
#include <serialize.h> | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
/** | ||
* This module is a public interface of governance module that can be used | ||
* in other components such as wallet | ||
*/ | ||
|
||
class UniValue; | ||
|
||
enum class GovernanceObject : int { | ||
UNKNOWN = 0, | ||
PROPOSAL, | ||
TRIGGER | ||
}; | ||
template<> struct is_serializable_enum<GovernanceObject> : std::true_type {}; | ||
|
||
namespace Governance | ||
{ | ||
class Object | ||
{ | ||
public: | ||
Object() = default; | ||
|
||
Object(const uint256& nHashParent, int nRevision, int64_t nTime, const uint256& nCollateralHash, const std::string& strDataHex); | ||
|
||
UniValue ToJson() const; | ||
|
||
uint256 GetHash() const; | ||
|
||
std::string GetDataAsHexString() const; | ||
std::string GetDataAsPlainString() const; | ||
|
||
/// Object typecode | ||
GovernanceObject type{GovernanceObject::UNKNOWN}; | ||
|
||
/// parent object, 0 is root | ||
uint256 hashParent{}; | ||
|
||
/// object revision in the system | ||
int revision{0}; | ||
|
||
/// time this object was created | ||
int64_t time{0}; | ||
|
||
/// fee-tx | ||
uint256 collateralHash{}; | ||
|
||
/// Masternode info for signed objects | ||
COutPoint masternodeOutpoint; | ||
std::vector<unsigned char> vchSig{}; | ||
|
||
/// Data field - can be used for anything | ||
std::vector<unsigned char> vchData; | ||
|
||
SERIALIZE_METHODS(Object, obj) | ||
{ | ||
READWRITE( | ||
obj.hashParent, | ||
obj.revision, | ||
obj.time, | ||
obj.collateralHash, | ||
obj.vchData, | ||
obj.type, | ||
obj.masternodeOutpoint | ||
); | ||
if (!(s.GetType() & SER_GETHASH)) { | ||
READWRITE(obj.vchSig); | ||
} | ||
} | ||
}; | ||
|
||
} // namespace Governance | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.