PRCYCoin  2.0.0.7rc1
P2P Digital Currency
swifttx.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2012 The Dash developers
2 // Copyright (c) 2015-2018 The PIVX developers
3 // Copyright (c) 2018-2020 The DAPS Project developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef SWIFTTX_H
8 #define SWIFTTX_H
9 
10 #include "base58.h"
11 #include "key.h"
12 #include "main.h"
13 #include "net.h"
14 #include "sync.h"
15 #include "util.h"
16 
17 /*
18  At 15 signatures, 1/2 of the masternode network can be owned by
19  one party without comprimising the security of SwiftX
20  (1000/2150.0)**10 = 0.00047382219560689856
21  (1000/2900.0)**10 = 2.3769498616783657e-05
22 
23  ### getting 5 of 10 signatures w/ 1000 nodes of 2900
24  (1000/2900.0)**5 = 0.004875397277841433
25 */
26 #define SWIFTTX_SIGNATURES_REQUIRED 6
27 #define SWIFTTX_SIGNATURES_TOTAL 10
28 
29 
30 class CConsensusVote;
31 class CTransaction;
32 class CTransactionLock;
33 
34 static const int MIN_SWIFTTX_PROTO_VERSION = 70103;
35 
36 extern std::map<uint256, CTransaction> mapTxLockReq;
37 extern std::map<uint256, CTransaction> mapTxLockReqRejected;
38 extern std::map<uint256, CConsensusVote> mapTxLockVote;
39 extern std::map<uint256, CTransactionLock> mapTxLocks;
40 extern std::map<COutPoint, uint256> mapLockedInputs;
41 extern int nCompleteTXLocks;
42 
43 
44 int64_t CreateNewLock(CTransaction tx);
45 
46 bool IsIXTXValid(const CTransaction& txCollateral);
47 
48 // if two conflicting locks are approved by the network, they will cancel out
50 
51 void ProcessMessageSwiftTX(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
52 
53 //check if we need to vote on this transaction
54 void DoConsensusVote(CTransaction& tx, int64_t nBlockHeight);
55 
56 //process consensus vote message
57 bool ProcessConsensusVote(CNode* pnode, CConsensusVote& ctx);
58 
59 // keep transaction locks in memory for an hour
61 
62 // get the accepted transaction lock signatures
64 
65 int64_t GetAverageVoteTime();
66 
68 {
69 public:
73  std::vector<unsigned char> vchMasterNodeSignature;
74 
75  uint256 GetHash() const;
76 
77  bool SignatureValid();
78  bool Sign();
79 
81 
82  template <typename Stream, typename Operation>
83  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
84  {
89  }
90 };
91 
93 {
94 public:
97  std::vector<CConsensusVote> vecConsensusVotes;
99  int nTimeout;
100 
101  bool SignaturesValid();
102  int CountSignatures();
103  void AddSignature(CConsensusVote& cv);
104 
106  {
107  return txHash;
108  }
109 };
110 
111 
112 #endif
CTxIn
An input of a transaction.
Definition: transaction.h:83
IsIXTXValid
bool IsIXTXValid(const CTransaction &txCollateral)
Definition: swifttx.cpp:175
CConsensusVote::SignatureValid
bool SignatureValid()
Definition: swifttx.cpp:470
CTransactionLock
Definition: swifttx.h:92
CConsensusVote::Sign
bool Sign()
Definition: swifttx.cpp:490
sync.h
CConsensusVote::GetHash
uint256 GetHash() const
Definition: swifttx.cpp:464
CTransactionLock::vecConsensusVotes
std::vector< CConsensusVote > vecConsensusVotes
Definition: swifttx.h:97
CConsensusVote::txHash
uint256 txHash
Definition: swifttx.h:71
DoConsensusVote
void DoConsensusVote(CTransaction &tx, int64_t nBlockHeight)
Definition: swifttx.cpp:255
CNode
Information about a peer.
Definition: net.h:306
mapLockedInputs
std::map< COutPoint, uint256 > mapLockedInputs
Definition: swifttx.cpp:28
CConsensusVote::SerializationOp
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: swifttx.h:83
mapTxLockReqRejected
std::map< uint256, CTransaction > mapTxLockReqRejected
Definition: swifttx.cpp:25
CConsensusVote::vinMasternode
CTxIn vinMasternode
Definition: swifttx.h:70
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:269
CheckForConflictingLocks
bool CheckForConflictingLocks(CTransaction &tx)
Definition: swifttx.cpp:386
CTransactionLock::txHash
uint256 txHash
Definition: swifttx.h:96
CTransactionLock::nTimeout
int nTimeout
Definition: swifttx.h:99
CTransactionLock::GetHash
uint256 GetHash()
Definition: swifttx.h:105
mapTxLockReq
std::map< uint256, CTransaction > mapTxLockReq
Definition: swifttx.cpp:24
CleanTransactionLocksList
void CleanTransactionLocksList()
Definition: swifttx.cpp:424
ProcessMessageSwiftTX
void ProcessMessageSwiftTX(CNode *pfrom, std::string &strCommand, CDataStream &vRecv)
Definition: swifttx.cpp:39
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
CConsensusVote
Definition: swifttx.h:67
CConsensusVote::nBlockHeight
int nBlockHeight
Definition: swifttx.h:72
CTransactionLock::nExpiration
int nExpiration
Definition: swifttx.h:98
CTransactionLock::AddSignature
void AddSignature(CConsensusVote &cv)
Definition: swifttx.cpp:538
CTransactionLock::nBlockHeight
int nBlockHeight
Definition: swifttx.h:95
CreateNewLock
int64_t CreateNewLock(CTransaction tx)
Definition: swifttx.cpp:217
mapTxLockVote
std::map< uint256, CConsensusVote > mapTxLockVote
Definition: swifttx.cpp:26
CConsensusVote::ADD_SERIALIZE_METHODS
ADD_SERIALIZE_METHODS
Definition: swifttx.h:80
key.h
READWRITE
#define READWRITE(obj)
Definition: serialize.h:164
GetTransactionLockSignatures
int GetTransactionLockSignatures(uint256 txHash)
Definition: swifttx.cpp:454
main.h
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:34
base58.h
ProcessConsensusVote
bool ProcessConsensusVote(CNode *pnode, CConsensusVote &ctx)
Definition: swifttx.cpp:296
net.h
mapTxLocks
std::map< uint256, CTransactionLock > mapTxLocks
Definition: swifttx.cpp:27
CConsensusVote::vchMasterNodeSignature
std::vector< unsigned char > vchMasterNodeSignature
Definition: swifttx.h:73
GetAverageVoteTime
int64_t GetAverageVoteTime()
Definition: swifttx.cpp:409
util.h
CTransactionLock::SignaturesValid
bool SignaturesValid()
Definition: swifttx.cpp:514
CTransactionLock::CountSignatures
int CountSignatures()
Definition: swifttx.cpp:543
nCompleteTXLocks
int nCompleteTXLocks
Definition: swifttx.cpp:30