From be4bd8692af12cbc72170ea54aef3d1c2ebce329 Mon Sep 17 00:00:00 2001 From: Block Mechanic Date: Mon, 11 Apr 2022 21:23:39 +0200 Subject: [PATCH] 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()); } }