Skip to content

Commit

Permalink
Merge pull request #54 from BlockMechanic/segwit
Browse files Browse the repository at this point in the history
Segwit
  • Loading branch information
BlockMechanic authored Apr 12, 2022
2 parents b417bcd + bc7398b commit 721fc8f
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 94 deletions.
12 changes: 0 additions & 12 deletions src/crown/nodewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,17 @@ bool NodeWallet::CreateCoinStake(const int nHeight, const uint32_t& nBits, const
template <typename stakingnode>
bool GetPointers(stakingnode* pstaker, std::vector<StakePointer>& vStakePointers, int nPaymentSlot)
{
LogPrintf("%s: 1\n", __func__);
bool found = false;
// get block index of last mn payment
std::vector<const CBlockIndex*> vBlocksLastPaid;
if (!pstaker->GetRecentPaymentBlocks(vBlocksLastPaid, false)) {
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;
Expand All @@ -258,22 +255,16 @@ bool GetPointers(stakingnode* pstaker, std::vector<StakePointer>& 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){
Expand All @@ -287,11 +278,8 @@ bool GetPointers(stakingnode* pstaker, std::vector<StakePointer>& vStakePointers
continue;
}
}
LogPrintf("%s: 2.4.2\n", __func__);

}
}
LogPrintf("%s: 3\n", __func__);
return found;
}

Expand Down
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
7 changes: 4 additions & 3 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ QList<TransactionRecord> 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
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 721fc8f

Please sign in to comment.