Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/absolute-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ static int CommandLineRawTx(int argc, char* argv[])
argv++;
}

CMutableTransaction tx;
CTransaction txDecodeTmp;
int startArg;

if (!fCreateBlank) {
Expand All @@ -620,13 +620,15 @@ static int CommandLineRawTx(int argc, char* argv[])
if (strHexTx == "-") // "-" implies standard input
strHexTx = readStdin();

if (!DecodeHexTx(tx, strHexTx))
if (!DecodeHexTx(txDecodeTmp, strHexTx))
throw std::runtime_error("invalid transaction encoding");

startArg = 2;
} else
startArg = 1;

CMutableTransaction tx(txDecodeTmp);

for (int i = startArg; i < argc; i++) {
std::string arg = argv[i];
std::string key, value;
Expand Down
2 changes: 1 addition & 1 deletion src/bench/coin_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static void addCoin(const CAmount& nValue, const CWallet& wallet, vector<COutput
tx.nLockTime = nextLockTime++; // so all transactions get different hashes
tx.vout.resize(nInput + 1);
tx.vout[nInput].nValue = nValue;
CWalletTx* wtx = new CWalletTx(&wallet, MakeTransactionRef(std::move(tx)));
CWalletTx* wtx = new CWalletTx(&wallet, tx);

int nAge = 6 * 24;
COutput output(wtx, nInput, nAge, true, true);
Expand Down
3 changes: 1 addition & 2 deletions src/core_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
class CBlock;
class CScript;
class CTransaction;
struct CMutableTransaction;
class uint256;
class UniValue;

// core_read.cpp
CScript ParseScript(const std::string& s);
std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDecode = false);
bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx);
bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx);
bool DecodeHexBlk(CBlock&, const std::string& strHexBlk);
uint256 ParseHashUV(const UniValue& v, const std::string& strName);
uint256 ParseHashStr(const std::string&, const std::string& strName);
Expand Down
2 changes: 1 addition & 1 deletion src/core_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ CScript ParseScript(const std::string& s)
return result;
}

bool DecodeHexTx(CMutableTransaction& tx, const std::string& strHexTx)
bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx)
{
if (!IsHex(strHexTx))
return false;
Expand Down
16 changes: 8 additions & 8 deletions src/governance-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,19 +511,19 @@ bool CGovernanceObject::IsCollateralValid(std::string& strError, bool& fMissingC
CAmount nMinFee = GetMinCollateralFee();
uint256 nExpectedHash = GetHash();

CTransactionRef txCollateral;
CTransaction txCollateral;
uint256 nBlockHash;

// RETRIEVE TRANSACTION IN QUESTION

if(!GetTransaction(nCollateralHash, txCollateral, Params().GetConsensus(), nBlockHash, true)){
strError = strprintf("Can't find collateral tx %s", txCollateral->ToString());
strError = strprintf("Can't find collateral tx %s", txCollateral.ToString());
LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError);
return false;
}

if(txCollateral->vout.size() < 1) {
strError = strprintf("tx vout size less than 1 | %d", txCollateral->vout.size());
if(txCollateral.vout.size() < 1) {
strError = strprintf("tx vout size less than 1 | %d", txCollateral.vout.size());
LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError);
return false;
}
Expand All @@ -533,21 +533,21 @@ bool CGovernanceObject::IsCollateralValid(std::string& strError, bool& fMissingC
CScript findScript;
findScript << OP_RETURN << ToByteVector(nExpectedHash);

DBG( cout << "IsCollateralValid: txCollateral->vout.size() = " << txCollateral->vout.size() << endl; );
DBG( cout << "IsCollateralValid: txCollateral.vout.size() = " << txCollateral.vout.size() << endl; );

DBG( cout << "IsCollateralValid: findScript = " << ScriptToAsmStr( findScript, false ) << endl; );

DBG( cout << "IsCollateralValid: nMinFee = " << nMinFee << endl; );


bool foundOpReturn = false;
BOOST_FOREACH(const CTxOut o, txCollateral->vout) {
BOOST_FOREACH(const CTxOut o, txCollateral.vout) {
DBG( cout << "IsCollateralValid txout : " << o.ToString()
<< ", o.nValue = " << o.nValue
<< ", o.scriptPubKey = " << ScriptToAsmStr( o.scriptPubKey, false )
<< endl; );
if(!o.scriptPubKey.IsPayToPublicKeyHash() && !o.scriptPubKey.IsUnspendable()) {
strError = strprintf("Invalid Script %s", txCollateral->ToString());
strError = strprintf("Invalid Script %s", txCollateral.ToString());
LogPrintf ("CGovernanceObject::IsCollateralValid -- %s\n", strError);
return false;
}
Expand All @@ -562,7 +562,7 @@ bool CGovernanceObject::IsCollateralValid(std::string& strError, bool& fMissingC
}

if(!foundOpReturn){
strError = strprintf("Couldn't find opReturn %s in %s", nExpectedHash.ToString(), txCollateral->ToString());
strError = strprintf("Couldn't find opReturn %s in %s", nExpectedHash.ToString(), txCollateral.ToString());
LogPrintf ("CGovernanceObject::IsCollateralValid -- %s\n", strError);
return false;
}
Expand Down
36 changes: 18 additions & 18 deletions src/instantx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ bool CInstantSend::ProcessTxLockRequest(const CTxLockRequest& txLockRequest, CCo
uint256 txHash = txLockRequest.GetHash();

// Check to see if we conflict with existing completed lock
BOOST_FOREACH(const CTxIn& txin, txLockRequest.tx->vin) {
BOOST_FOREACH(const CTxIn& txin, txLockRequest.vin) {
std::map<COutPoint, uint256>::iterator it = mapLockedOutpoints.find(txin.prevout);
if(it != mapLockedOutpoints.end() && it->second != txLockRequest.GetHash()) {
// Conflicting with complete lock, proceed to see if we should cancel them both
Expand All @@ -103,7 +103,7 @@ bool CInstantSend::ProcessTxLockRequest(const CTxLockRequest& txLockRequest, CCo

// Check to see if there are votes for conflicting request,
// if so - do not fail, just warn user
BOOST_FOREACH(const CTxIn& txin, txLockRequest.tx->vin) {
BOOST_FOREACH(const CTxIn& txin, txLockRequest.vin) {
std::map<COutPoint, std::set<uint256> >::iterator it = mapVotedOutpoints.find(txin.prevout);
if(it != mapVotedOutpoints.end()) {
BOOST_FOREACH(const uint256& hash, it->second) {
Expand Down Expand Up @@ -146,7 +146,7 @@ bool CInstantSend::CreateTxLockCandidate(const CTxLockRequest& txLockRequest)

CTxLockCandidate txLockCandidate(txLockRequest);
// all inputs should already be checked by txLockRequest.IsValid() above, just use them now
BOOST_REVERSE_FOREACH(const CTxIn& txin, txLockRequest.tx->vin) {
BOOST_REVERSE_FOREACH(const CTxIn& txin, txLockRequest.vin) {
txLockCandidate.AddOutPointLock(txin.prevout);
}
mapTxLockCandidates.insert(std::make_pair(txHash, txLockCandidate));
Expand All @@ -160,7 +160,7 @@ bool CInstantSend::CreateTxLockCandidate(const CTxLockRequest& txLockRequest)
LogPrintf("CInstantSend::CreateTxLockCandidate -- update empty, txid=%s\n", txHash.ToString());

// all inputs should already be checked by txLockRequest.IsValid() above, just use them now
BOOST_REVERSE_FOREACH(const CTxIn& txin, txLockRequest.tx->vin) {
BOOST_REVERSE_FOREACH(const CTxIn& txin, txLockRequest.vin) {
itLockCandidate->second.AddOutPointLock(txin.prevout);
}
} else {
Expand Down Expand Up @@ -447,7 +447,7 @@ bool CInstantSend::IsEnoughOrphanVotesForTx(const CTxLockRequest& txLockRequest)
// There could be a situation when we already have quite a lot of votes
// but tx lock request still wasn't received. Let's scan through
// orphan votes to check if this is the case.
BOOST_FOREACH(const CTxIn& txin, txLockRequest.tx->vin) {
BOOST_FOREACH(const CTxIn& txin, txLockRequest.vin) {
if(!IsEnoughOrphanVotesForTxAndOutPoint(txLockRequest.GetHash(), txin.prevout)) {
return false;
}
Expand Down Expand Up @@ -484,7 +484,7 @@ void CInstantSend::TryToFinalizeLockCandidate(const CTxLockCandidate& txLockCand
#endif
LOCK(cs_instantsend);

uint256 txHash = txLockCandidate.txLockRequest.tx->GetHash();
uint256 txHash = txLockCandidate.txLockRequest.GetHash();
if(txLockCandidate.IsAllOutPointsReady() && !IsLockedInstantSendTransaction(txHash)) {
// we have enough votes now
LogPrint("instantsend", "CInstantSend::TryToFinalizeLockCandidate -- Transaction Lock is ready to complete, txid=%s\n", txHash.ToString());
Expand Down Expand Up @@ -521,7 +521,7 @@ void CInstantSend::UpdateLockedTransaction(const CTxLockCandidate& txLockCandida
}
#endif

GetMainSignals().NotifyTransactionLock(*txLockCandidate.txLockRequest.tx);
GetMainSignals().NotifyTransactionLock(txLockCandidate.txLockRequest);

LogPrint("instantsend", "CInstantSend::UpdateLockedTransaction -- done, txid=%s\n", txHash.ToString());
}
Expand Down Expand Up @@ -565,7 +565,7 @@ bool CInstantSend::ResolveConflicts(const CTxLockCandidate& txLockCandidate)

LOCK(mempool.cs); // protect mempool.mapNextTx

BOOST_FOREACH(const CTxIn& txin, txLockCandidate.txLockRequest.tx->vin) {
BOOST_FOREACH(const CTxIn& txin, txLockCandidate.txLockRequest.vin) {
uint256 hashConflicting;
if(GetLockedOutPointTxHash(txin.prevout, hashConflicting) && txHash != hashConflicting) {
// completed lock which conflicts with another completed one?
Expand Down Expand Up @@ -609,14 +609,14 @@ bool CInstantSend::ResolveConflicts(const CTxLockCandidate& txLockCandidate)
}
} // FOREACH
// No conflicts were found so far, check to see if it was already included in block
CTransactionRef txTmp;
CTransaction txTmp;
uint256 hashBlock;
if(GetTransaction(txHash, txTmp, Params().GetConsensus(), hashBlock, true) && hashBlock != uint256()) {
LogPrint("instantsend", "CInstantSend::ResolveConflicts -- Done, %s is included in block %s\n", txHash.ToString(), hashBlock.ToString());
return true;
}
// Not in block yet, make sure all its inputs are still unspent
BOOST_FOREACH(const CTxIn& txin, txLockCandidate.txLockRequest.tx->vin) {
BOOST_FOREACH(const CTxIn& txin, txLockCandidate.txLockRequest.vin) {
Coin coin;
if(!GetUTXOCoin(txin.prevout, coin)) {
// Not in UTXO anymore? A conflicting tx was mined while we were waiting for votes.
Expand Down Expand Up @@ -928,21 +928,21 @@ std::string CInstantSend::ToString()

bool CTxLockRequest::IsValid() const
{
if(tx->vout.size() < 1) return false;
if(vout.size() < 1) return false;

if(tx->vin.size() > WARN_MANY_INPUTS) {
if(vin.size() > WARN_MANY_INPUTS) {
LogPrint("instantsend", "CTxLockRequest::IsValid -- WARNING: Too many inputs: tx=%s", ToString());
}

LOCK(cs_main);
if(!CheckFinalTx(*tx)) {
if(!CheckFinalTx(*this)) {
LogPrint("instantsend", "CTxLockRequest::IsValid -- Transaction is not final: tx=%s", ToString());
return false;
}

CAmount nValueIn = 0;

BOOST_FOREACH(const CTxIn& txin, tx->vin) {
BOOST_FOREACH(const CTxIn& txin, vin) {

Coin coin;

Expand All @@ -969,7 +969,7 @@ bool CTxLockRequest::IsValid() const
return false;
}

CAmount nValueOut = tx->GetValueOut();
CAmount nValueOut = GetValueOut();

if(nValueIn - nValueOut < GetMinFee()) {
LogPrint("instantsend", "CTxLockRequest::IsValid -- did not include enough fees in transaction: fees=%d, tx=%s", nValueOut - nValueIn, ToString());
Expand All @@ -982,12 +982,12 @@ bool CTxLockRequest::IsValid() const
CAmount CTxLockRequest::GetMinFee() const
{
CAmount nMinFee = MIN_FEE;
return std::max(nMinFee, CAmount(tx->vin.size() * nMinFee));
return std::max(nMinFee, CAmount(vin.size() * nMinFee));
}

int CTxLockRequest::GetMaxSignatures() const
{
return tx->vin.size() * COutPointLock::SIGNATURES_TOTAL;
return vin.size() * COutPointLock::SIGNATURES_TOTAL;
}

//
Expand Down Expand Up @@ -1205,7 +1205,7 @@ bool CTxLockCandidate::IsTimedOut() const

void CTxLockCandidate::Relay(CConnman& connman) const
{
connman.RelayTransaction(*txLockRequest.tx);
connman.RelayTransaction(txLockRequest);
std::map<COutPoint, COutPointLock>::const_iterator itOutpointLock = mapOutPointLocks.begin();
while(itOutpointLock != mapOutPointLocks.end()) {
itOutpointLock->second.Relay(connman);
Expand Down
33 changes: 3 additions & 30 deletions src/instantx.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,48 +120,21 @@ class CInstantSend
std::string ToString();
};

class CTxLockRequest
class CTxLockRequest : public CTransaction
{
private:
static const CAmount MIN_FEE = 0.0001 * COIN;

public:
static const int WARN_MANY_INPUTS = 100;

CTransactionRef tx;

CTxLockRequest() : tx(MakeTransactionRef()) {}
CTxLockRequest(const CTransaction& _tx) : tx(MakeTransactionRef(_tx)) {};

ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(tx);
}
CTxLockRequest() = default;
CTxLockRequest(const CTransaction& tx) : CTransaction(tx) {};

bool IsValid() const;
CAmount GetMinFee() const;
int GetMaxSignatures() const;

const uint256 &GetHash() const {
return tx->GetHash();
}

std::string ToString() const {
return tx->ToString();
}

friend bool operator==(const CTxLockRequest& a, const CTxLockRequest& b)
{
return *a.tx == *b.tx;
}

friend bool operator!=(const CTxLockRequest& a, const CTxLockRequest& b)
{
return *a.tx != *b.tx;
}

explicit operator bool() const
{
return *this != CTxLockRequest();
Expand Down
6 changes: 3 additions & 3 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,

deque<COutPoint> vWorkQueue;
vector<uint256> vEraseQueue;
CMutableTransaction tx;
CTransaction tx;
CTxLockRequest txLockRequest;
CDarksendBroadcastTx dstx;
int nInvType = MSG_TX;
Expand All @@ -1623,11 +1623,11 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
vRecv >> tx;
} else if(strCommand == NetMsgType::TXLOCKREQUEST) {
vRecv >> txLockRequest;
tx = *txLockRequest.tx;
tx = txLockRequest;
nInvType = MSG_TXLOCK_REQUEST;
} else if (strCommand == NetMsgType::DSTX) {
vRecv >> dstx;
tx = *dstx.tx;
tx = dstx.tx;
nInvType = MSG_DSTX;
}

Expand Down
26 changes: 20 additions & 6 deletions src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,29 @@ std::string CMutableTransaction::ToString() const
return str;
}

uint256 CTransaction::ComputeHash() const
void CTransaction::UpdateHash() const
{
return SerializeHash(*this);
*const_cast<uint256*>(&hash) = SerializeHash(*this);
}

CTransaction::CTransaction() : nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0) { }

CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime) {
UpdateHash();
}

/* For backward compatibility, the hash is initialized to 0. TODO: remove the need for this default constructor entirely. */
CTransaction::CTransaction() : nVersion(CTransaction::CURRENT_VERSION), vin(), vout(), nLockTime(0), hash() {}
CTransaction::CTransaction(const CMutableTransaction &tx) : nVersion(tx.nVersion), vin(tx.vin), vout(tx.vout), nLockTime(tx.nLockTime), hash(ComputeHash()) {}
CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), vin(std::move(tx.vin)), vout(std::move(tx.vout)), nLockTime(tx.nLockTime), hash(ComputeHash()) {}
CTransaction::CTransaction(CMutableTransaction &&tx) : nVersion(tx.nVersion), vin(std::move(tx.vin)), vout(std::move(tx.vout)), nLockTime(tx.nLockTime) {
UpdateHash();
}

CTransaction& CTransaction::operator=(const CTransaction &tx) {
*const_cast<int*>(&nVersion) = tx.nVersion;
*const_cast<std::vector<CTxIn>*>(&vin) = tx.vin;
*const_cast<std::vector<CTxOut>*>(&vout) = tx.vout;
*const_cast<unsigned int*>(&nLockTime) = tx.nLockTime;
*const_cast<uint256*>(&hash) = tx.hash;
return *this;
}

CAmount CTransaction::GetValueOut() const
{
Expand Down
Loading