2014-12-09 02:17:57 +01:00
|
|
|
|
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
|
|
// Copyright (c) 2009-2012 The Bitcoin developers
|
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef INSTANTX_H
|
|
|
|
#define INSTANTX_H
|
|
|
|
|
|
|
|
#include "bignum.h"
|
|
|
|
#include "sync.h"
|
|
|
|
#include "net.h"
|
|
|
|
#include "key.h"
|
|
|
|
#include "core.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "script.h"
|
|
|
|
#include "base58.h"
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace boost;
|
|
|
|
|
|
|
|
class CConsensusVote;
|
|
|
|
class CTransaction;
|
|
|
|
class CTransactionLock;
|
|
|
|
|
2015-02-06 17:03:50 +01:00
|
|
|
static const int MIN_INSTANTX_PROTO_VERSION = 70062;
|
2014-12-09 02:17:57 +01:00
|
|
|
|
|
|
|
extern map<uint256, CTransaction> mapTxLockReq;
|
|
|
|
extern map<uint256, CTransactionLock> mapTxLocks;
|
2015-02-04 21:20:13 +01:00
|
|
|
extern std::map<COutPoint, uint256> mapLockedInputs;
|
2015-02-01 21:04:20 +01:00
|
|
|
extern int nCompleteTXLocks;
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2015-02-04 22:59:19 +01:00
|
|
|
|
|
|
|
int64_t CreateNewLock(CTransaction tx);
|
|
|
|
|
2015-02-04 11:44:41 +01:00
|
|
|
bool IsIXTXValid(const CTransaction& txCollateral);
|
|
|
|
|
2015-02-05 17:48:57 +01:00
|
|
|
// if two conflicting locks are approved by the network, they will cancel out
|
|
|
|
bool CheckForConflictingLocks(CTransaction& tx);
|
|
|
|
|
2014-12-09 02:17:57 +01:00
|
|
|
void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
|
|
|
|
|
|
|
//check if we need to vote on this transaction
|
2015-02-04 22:59:19 +01:00
|
|
|
void DoConsensusVote(CTransaction& tx, int64_t nBlockHeight);
|
2014-12-09 02:17:57 +01:00
|
|
|
|
|
|
|
//process consensus vote message
|
2015-02-02 15:36:00 +01:00
|
|
|
bool ProcessConsensusVote(CConsensusVote& ctx);
|
2014-12-09 02:17:57 +01:00
|
|
|
|
|
|
|
// keep transaction locks in memory for an hour
|
|
|
|
void CleanTransactionLocksList();
|
|
|
|
|
2015-02-02 18:33:52 +01:00
|
|
|
int64_t GetAverageVoteTime();
|
|
|
|
|
2014-12-09 02:17:57 +01:00
|
|
|
class CConsensusVote
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CTxIn vinMasternode;
|
2015-02-02 13:24:04 +01:00
|
|
|
uint256 txHash;
|
2014-12-09 02:17:57 +01:00
|
|
|
int nBlockHeight;
|
2015-02-01 16:53:49 +01:00
|
|
|
std::vector<unsigned char> vchMasterNodeSignature;
|
|
|
|
|
|
|
|
uint256 GetHash() const;
|
2014-12-09 02:17:57 +01:00
|
|
|
|
|
|
|
bool SignatureValid();
|
|
|
|
bool Sign();
|
|
|
|
|
|
|
|
IMPLEMENT_SERIALIZE
|
|
|
|
(
|
2015-02-02 13:24:04 +01:00
|
|
|
READWRITE(txHash);
|
2014-12-09 02:17:57 +01:00
|
|
|
READWRITE(vinMasternode);
|
|
|
|
READWRITE(vchMasterNodeSignature);
|
|
|
|
READWRITE(nBlockHeight);
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
|
|
|
class CTransactionLock
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int nBlockHeight;
|
2015-02-02 13:24:04 +01:00
|
|
|
uint256 txHash;
|
2014-12-09 02:17:57 +01:00
|
|
|
std::vector<CConsensusVote> vecConsensusVotes;
|
2015-02-01 21:04:20 +01:00
|
|
|
int nExpiration;
|
2015-02-05 16:52:02 +01:00
|
|
|
int nTimeout;
|
2014-12-09 02:17:57 +01:00
|
|
|
|
|
|
|
bool SignaturesValid();
|
|
|
|
int CountSignatures();
|
|
|
|
void AddSignature(CConsensusVote cv);
|
2015-02-02 13:24:04 +01:00
|
|
|
|
2014-12-09 02:17:57 +01:00
|
|
|
uint256 GetHash()
|
|
|
|
{
|
2015-02-02 13:24:04 +01:00
|
|
|
return txHash;
|
2014-12-09 02:17:57 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|