From be4bd8692af12cbc72170ea54aef3d1c2ebce329 Mon Sep 17 00:00:00 2001 From: Block Mechanic Date: Mon, 11 Apr 2022 21:23:39 +0200 Subject: [PATCH 1/2] Minor fixes --- src/masternode/masternode-budget.cpp | 2 +- src/platform/specialtx.h | 6 +-- src/primitives/asset.cpp | 2 +- src/primitives/asset.h | 23 +++--------- src/primitives/transaction.cpp | 10 ++--- src/primitives/transaction.h | 55 +++------------------------- src/rpc/client.cpp | 6 +++ src/validation.cpp | 5 +-- 8 files changed, 30 insertions(+), 79 deletions(-) diff --git a/src/masternode/masternode-budget.cpp b/src/masternode/masternode-budget.cpp index 491ca7a..7747b9f 100755 --- a/src/masternode/masternode-budget.cpp +++ b/src/masternode/masternode-budget.cpp @@ -116,7 +116,7 @@ bool IsBudgetCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, s CTransactionRef txCollateral = GetTransaction(nullptr, nullptr, nTxCollateralHash, Params().GetConsensus(), nBlockHash); if(!txCollateral){ - strError = strprintf("Can't find collateral tx %s", txCollateral->ToString()); + strError = strprintf("Can't find collateral tx %s", nTxCollateralHash.ToString()); LogPrintf ("CBudgetProposalBroadcast::IsBudgetCollateralValid - %s\n", strError); return false; } diff --git a/src/platform/specialtx.h b/src/platform/specialtx.h index d5c5d07..57160c8 100755 --- a/src/platform/specialtx.h +++ b/src/platform/specialtx.h @@ -75,7 +75,7 @@ static void FundSpecialTx(CMutableTransaction& tx, SpecialTxPayload payload) ds << payload; tx.extraPayload.assign(ds.begin(), ds.end()); - static CTxOut dummyTxOut(0, CScript() << OP_RETURN); + static CTxOutAsset dummyTxOut(CAsset(), 0, CScript() << OP_RETURN); bool dummyTxOutAdded = false; if (tx.vout.empty()) { // add dummy txout as FundTransaction requires at least one output @@ -95,9 +95,9 @@ static void FundSpecialTx(CMutableTransaction& tx, SpecialTxPayload payload) if (dummyTxOutAdded && tx.vout.size() > 1) { // FundTransaction added a change output, so we don't need the dummy txout anymore // Removing it results in slight overpayment of fees, but we ignore this for now (as it's a very low amount) - std::vector::iterator it = std::find(tx.vout.begin(), tx.vout.end(), dummyTxOut); + /*std::vector::iterator it = std::find(tx.vout.begin(), tx.vout.end(), dummyTxOut); assert(it != tx.vout.end()); - tx.vout.erase(it); + tx.vout.erase(it);*/ } } diff --git a/src/primitives/asset.cpp b/src/primitives/asset.cpp index f4b146d..af74745 100755 --- a/src/primitives/asset.cpp +++ b/src/primitives/asset.cpp @@ -237,7 +237,7 @@ CAmount valueFor(const CAmountMap& mapValue, const CAsset& asset) { bool AssetMetadata::IsEmpty() const { - return ( nVersion==0 && nFlags==0 && getAssetName() == ""); + return ( nVersion==0 && nFlags==0 && nType==0 && getAssetName() == ""); } void AssetMetadata::setName(const std::string& _sAssetName) diff --git a/src/primitives/asset.h b/src/primitives/asset.h index 9367ef8..af3028c 100755 --- a/src/primitives/asset.h +++ b/src/primitives/asset.h @@ -52,7 +52,7 @@ class AssetMetadata ASSET_INFLATABLE = (1 << 5) }; - enum AssetType : uint32_t + enum AssetType : uint32_t { TOKEN = 1, UNIQUE = 2, @@ -89,13 +89,13 @@ class AssetMetadata bool isTransferable() const; bool isConvertable() const; - + bool isLimited() const; - + bool isRestricted() const; - + bool isStakeable() const; - + bool isInflatable() const; CAssetID getInputAssetID() const; @@ -149,24 +149,13 @@ struct CAsset : public AssetMetadata READWRITE(obj.assetID); } - bool IsNull() const { return assetID.IsNull() && AssetMetadata::IsEmpty(); } + bool IsNull() const { return assetID.IsNull() && IsEmpty(); } void SetNull() { assetID.SetNull(); AssetMetadata::SetEmpty(); } - void SetEmpty() - { - assetID.SetNull(); - AssetMetadata::SetEmpty(); - } - - bool IsEmpty() const - { - return (assetID.IsNull() && AssetMetadata::IsEmpty()); - } - const std::string getName() const; const std::string getSymbol() const; diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index a93ae77..f51e13f 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -291,7 +291,7 @@ bool CTransaction::IsCoinBase() const bool CTransaction::IsCoinStake() const { - if (vin.size() != 1 || (nVersion == TX_ELE_VERSION ? vpout.size() != 1 : vout.size() != 1)) + if (vin.size() != 1 || (nVersion >= TX_ELE_VERSION ? vpout.size() != 1 : vout.size() != 1)) return false; if (!vin[0].prevout.IsNull()) @@ -308,9 +308,9 @@ std::string CTransaction::ToString() const nVersion, nType, vin.size(), - (nVersion == TX_ELE_VERSION ? vpout.size() : vout.size()), + (nVersion >= TX_ELE_VERSION ? vpout.size() : vout.size()), nLockTime, - extraPayload.size()); + (nVersion >= TX_ELE_VERSION ? 0 : extraPayload.size())); for (const auto& tx_in : vin) str +=tx_in.ToString() + "\n"; for (const auto& tx_in : witness.vtxinwit) @@ -332,9 +332,9 @@ std::string CMutableTransaction::ToString() const nVersion, nType, vin.size(), - (nVersion == TX_ELE_VERSION ? vpout.size() : vout.size()), + (nVersion >= TX_ELE_VERSION ? vpout.size() : vout.size()), nLockTime, - extraPayload.size()); + (nVersion >= TX_ELE_VERSION ? 0 : extraPayload.size())); for (const auto& tx_in : vin) str += tx_in.ToString() + "\n"; for (const auto& tx_in : witness.vtxinwit) diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 22b16b5..1a6b34b 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -151,59 +151,14 @@ class CTxOut CAmount nValue; CScript scriptPubKey; - CTxOut() - { - SetNull(); - } + CTxOut(){} CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn); SERIALIZE_METHODS(CTxOut, obj) { READWRITE(obj.nValue, obj.scriptPubKey);} - void SetNull() - { - nValue=0; - scriptPubKey.clear(); - } - - /*bool IsNull() const - { - return nValue==0 && scriptPubKey.empty(); - }*/ - - void SetEmpty() - { - nValue = 0; - scriptPubKey.clear(); - } - - bool IsFee() const { - return scriptPubKey == CScript() && !nValue==0; - } - - bool IsEmpty() const - { - return (nValue == 0 && scriptPubKey.empty()); - } - - CAmount GetValue() const - { - return nValue; - } - uint256 GetHash() const; - friend bool operator==(const CTxOut& a, const CTxOut& b) - { - return (a.nValue == b.nValue && - a.scriptPubKey == b.scriptPubKey); - } - - friend bool operator!=(const CTxOut& a, const CTxOut& b) - { - return !(a == b); - } - std::string ToString() const; }; @@ -228,7 +183,8 @@ class CTxOutAsset : public CTxOut void SetNull() { - CTxOut::SetNull(); + nValue=0; + scriptPubKey.clear(); nAsset.SetNull(); nVersion=0; } @@ -240,13 +196,14 @@ class CTxOutAsset : public CTxOut void SetEmpty() { - CTxOut::SetEmpty(); + nValue = 0; + scriptPubKey.clear(); nAsset.SetNull(); nVersion=0; } bool IsFee() const { - return scriptPubKey == CScript() && !nValue==0 && !nAsset.IsNull(); + return scriptPubKey == CScript() && !nValue==0; } bool IsEmpty() const diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index b33972f..3b2fab5 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -189,6 +189,12 @@ static const CRPCConvertParam vRPCConvertParams[] = { "getnodeaddresses", 0, "count"}, { "addpeeraddress", 1, "port"}, { "spork", 1, "value" }, + { "mnbudget", 3, "value" }, + { "mnbudget", 4, "value1" }, + { "mnbudget", 6, "value2" }, + { "mnbudget", 8, "value3" }, + { "mnbudgetvoteraw", 1, "value" }, + { "mnbudgetvoteraw", 4, "value1" }, { "stop", 0, "wait" } }; // clang-format on diff --git a/src/validation.cpp b/src/validation.cpp index 6b8246e..af4797e 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1691,8 +1691,7 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const C const COutPoint& prevout = txin.prevout; const Coin& coin = inputs.AccessCoin(prevout); assert(!coin.IsSpent()); - - spent_outputs.emplace_back(coin.out); + spent_outputs.emplace_back(coin.out); } txdata.Init(tx, std::move(spent_outputs)); } @@ -1927,7 +1926,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI bool is_spent = view.SpendCoin(out, &coin); if (!is_spent || bout != coin.out || pindex->nHeight != coin.nHeight || is_coinbase != coin.fCoinBase || is_coinstake != coin.fCoinStake) { fClean = false; // transaction output mismatch - LogPrintf("VPOUT %s , SPENT %s , OUT %s\n", fClean ? "true": "false", is_spent ? "true": "false", bout != coin.out ? "true": "false"); + LogPrintf("VPOUT %s , SPENT %s , OUT %s, CB %s, CS %s\n", fClean ? "true": "false", is_spent ? "true": "false", bout != coin.out ? "true": "false", is_coinbase != coin.fCoinBase ? "true": "false",is_coinstake != coin.fCoinStake ? "true": "false"); LogPrintf("VOUT %s \n %s \n", bout.ToString(), coin.out.ToString()); } } From bc7398bc7be984c930ca92734d46adaf1841a304 Mon Sep 17 00:00:00 2001 From: Block Mechanic Date: Tue, 12 Apr 2022 09:51:12 +0200 Subject: [PATCH 2/2] Remove debug lines --- src/crown/nodewallet.cpp | 12 ------------ src/qt/transactionrecord.cpp | 7 ++++--- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/crown/nodewallet.cpp b/src/crown/nodewallet.cpp index 2dfbd77..53c466a 100644 --- a/src/crown/nodewallet.cpp +++ b/src/crown/nodewallet.cpp @@ -233,7 +233,6 @@ bool NodeWallet::CreateCoinStake(const int nHeight, const uint32_t& nBits, const template bool GetPointers(stakingnode* pstaker, std::vector& vStakePointers, int nPaymentSlot) { - LogPrintf("%s: 1\n", __func__); bool found = false; // get block index of last mn payment std::vector vBlocksLastPaid; @@ -241,12 +240,10 @@ bool GetPointers(stakingnode* pstaker, std::vector& vStakePointers LogPrintf("GetRecentStakePointer -- Couldn't find last paid block\n"); return false; } - LogPrintf("%s: 2\n", __func__); int nBestHeight = ::ChainActive().Height(); for (auto pindex : vBlocksLastPaid) { if (budget.IsBudgetPaymentBlock(pindex->nHeight)) continue; - LogPrintf("%s: 2.1\n", __func__); // Pointer has to be at least deeper than the max reorg depth const int nMaxReorganizationDepth = 100; @@ -258,22 +255,16 @@ bool GetPointers(stakingnode* pstaker, std::vector& vStakePointers LogPrintf("GetRecentStakePointer -- Failed reading block from disk\n"); return false; } - LogPrintf("%s: 2.2\n", __func__); CScript scriptMNPubKey; scriptMNPubKey = GetScriptForDestination(PKHash(pstaker->pubkey)); - LogPrintf("%s: 2.3\n", __func__); for (auto& tx : blockLastPaid.vtx) { - LogPrintf("%s: 2.4.0\n", __func__); - auto stakeSource = COutPoint(tx->GetHash(), nPaymentSlot); uint256 hashPointer = stakeSource.GetHash(); if (mapUsedStakePointers.count(hashPointer)) continue; - LogPrintf("%s: 2.4.1\n", __func__); - if (tx->IsCoinBase()) { CTxOutAsset mout = (tx->nVersion >= TX_ELE_VERSION ? tx->vpout[nPaymentSlot] : tx->vout[nPaymentSlot]); if(mout.scriptPubKey == scriptMNPubKey){ @@ -287,11 +278,8 @@ bool GetPointers(stakingnode* pstaker, std::vector& vStakePointers continue; } } - LogPrintf("%s: 2.4.2\n", __func__); - } } - LogPrintf("%s: 3\n", __func__); return found; } diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index 7f1da83..b98d695 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -40,9 +40,10 @@ QList TransactionRecord::decomposeTransaction(const interface // // Credit // - for(unsigned int i = 0; i < wtx.tx->vout.size(); i++) - { - const CTxOut& txout = wtx.tx->vout[i]; + for (unsigned int i = 0; i < (wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout.size() : wtx.tx->vout.size()); i++) { + CTxOutAsset txout = (wtx.tx->nVersion >= TX_ELE_VERSION ? wtx.tx->vpout[i] : wtx.tx->vout[i]); + + //const CTxOut& txout = wtx.tx->vout[i]; const CAsset& asset = wtx.txout_assets[i]; if (txout.IsFee()) { // explicit fee; ignore