Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockMechanic committed Apr 11, 2022
1 parent 364698a commit be4bd86
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/masternode/masternode-budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/platform/specialtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<CTxOut>::iterator it = std::find(tx.vout.begin(), tx.vout.end(), dummyTxOut);
/*std::vector<CTxOutAsset>::iterator it = std::find(tx.vout.begin(), tx.vout.end(), dummyTxOut);
assert(it != tx.vout.end());
tx.vout.erase(it);
tx.vout.erase(it);*/
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/primitives/asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 6 additions & 17 deletions src/primitives/asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AssetMetadata
ASSET_INFLATABLE = (1 << 5)
};

enum AssetType : uint32_t
enum AssetType : uint32_t
{
TOKEN = 1,
UNIQUE = 2,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions src/primitives/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand All @@ -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)
Expand Down
55 changes: 6 additions & 49 deletions src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -228,7 +183,8 @@ class CTxOutAsset : public CTxOut

void SetNull()
{
CTxOut::SetNull();
nValue=0;
scriptPubKey.clear();
nAsset.SetNull();
nVersion=0;
}
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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());
}
}
Expand Down

0 comments on commit be4bd86

Please sign in to comment.