diff --git a/src/assets/assets.cpp b/src/assets/assets.cpp index 7c86f27d8..1b4658dd6 100644 --- a/src/assets/assets.cpp +++ b/src/assets/assets.cpp @@ -51,7 +51,7 @@ CAssetMetaData::CAssetMetaData(const std::string txid, const CNewAssetTx assetTx assetId = txid; circulatingSupply = 0; mintCount = 0; - if (assetTx.nVersion == 2 && !assetTx.isRoot){ + if (!assetTx.isRoot){ CAssetMetaData rootAsset; passetsCache->GetAssetMetaData(assetTx.rootId, rootAsset); name = rootAsset.name + "|" + assetTx.name; @@ -504,7 +504,7 @@ bool CAssetsCache::Flush() { void AddAssets(const CTransaction &tx, int nHeight, CAssetsCache *assetCache, std::pair *undoAssetData) { - if (Params().IsAssetsActive(::ChainActive().Tip()) && assetCache) { + if (Updates().IsAssetsActive(::ChainActive().Tip()) && assetCache) { if (tx.nType == TRANSACTION_NEW_ASSET) { CNewAssetTx assetTx; if (GetTxPayload(tx, assetTx)) { diff --git a/src/chainparams.cpp b/src/chainparams.cpp index b4baf7b60..eb1520f2a 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -204,8 +204,6 @@ class CMainParams : public CChainParams { consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing consensus.smartnodePaymentFixedBlock = 6800; consensus.nFutureForkBlock = 420420; - consensus.nAssetsForkBlock = 9999999; - consensus.nRootAssetsForkBlock = consensus.nAssetsForkBlock; updateManager.Add ( // V17 voting blocks 419328-427391 in mainnet, 4032 voting, 4032 grace period, active at 427392 @@ -371,17 +369,16 @@ class CTestNetParams : public CChainParams { consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing consensus.nFutureForkBlock = 1000; - consensus.nAssetsForkBlock = 411300; - consensus.nRootAssetsForkBlock = 9999999; updateManager.Add ( Update(EUpdate::DEPLOYMENT_V17, std::string("v17"), 0, 10, 0, 10, 100, 10, false, VoteThreshold(95, 95, 5), VoteThreshold(0, 0, 1)) ); - // updateManager.Add - // ( - // Update(EUpdate::ROUND_VOTING, std::string("Round Voting"), 7, 100, 100000, 5, 10, 5, false, VoteThreshold(85, 85, 1), VoteThreshold(95, 95, 1)) - // ); + //updateManager.Add + //( + //bit 1, 720 block/round, voting start at block 10080, 7 rounds to lock-in and 7 rounds off grace period + // Update(EUpdate::ROUND_VOTING, std::string("Round Voting"), 1, 720, 10080, 7, 720, 7, false, VoteThreshold(85, 85, 1), VoteThreshold(0, 0, 1)) + //); // The best chain should have at least this much work. consensus.nMinimumChainWork = uint256S("0x0"); // 0 @@ -523,8 +520,6 @@ class CDevNetParams : public CChainParams { consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing consensus.nFutureForkBlock = 1; - consensus.nAssetsForkBlock = 1; - consensus.nRootAssetsForkBlock = 1; updateManager.Add ( @@ -532,7 +527,7 @@ class CDevNetParams : public CChainParams { ); updateManager.Add ( - Update(EUpdate::ROUND_VOTING, std::string("Round Voting"), 1, 100, 2000, 5, 10, 5, false, VoteThreshold(85, 85, 1), VoteThreshold(0, 0, 1)) + Update(EUpdate::ROUND_VOTING, std::string("Round Voting"), 1, 10, 100, 5, 10, 5, false, VoteThreshold(85, 85, 1), VoteThreshold(0, 0, 1)) ); // The best chain should have at least this much work. @@ -694,17 +689,15 @@ class CRegTestParams : public CChainParams { consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016) consensus.nFutureForkBlock = 1; - consensus.nAssetsForkBlock = 1; - consensus.nRootAssetsForkBlock = 1; updateManager.Add ( Update(EUpdate::DEPLOYMENT_V17, std::string("v17"), 0, 10, 0, 10, 100, 10, false, VoteThreshold(95, 95, 5), VoteThreshold(0, 0, 1)) ); - // updateManager.Add - // ( - // Update(EUpdate::ROUND_VOTING, std::string("Round Voting"), 7, 100, 100000, 5, 10, 5, false, VoteThreshold(85, 85, 1), VoteThreshold(95, 95, 1)) - // ); + updateManager.Add + ( + Update(EUpdate::ROUND_VOTING, std::string("Round Voting"), 1, 10, 100, 10, 100, 10, false, VoteThreshold(95, 95, 5), VoteThreshold(0, 0, 1)) + ); // The best chain should have at least this much work. consensus.nMinimumChainWork = uint256S("0x00"); diff --git a/src/chainparams.h b/src/chainparams.h index aa943dde0..6fe04b3ea 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -147,15 +147,6 @@ class CChainParams { return height >= GetConsensus().nFutureForkBlock; }; - bool IsAssetsActive(CBlockIndex *index) const { - int height = index == nullptr ? 0 : index->nHeight; - return height >= GetConsensus().nAssetsForkBlock; - }; - - bool IsRootAssetsActive(CBlockIndex *index) const { - int height = index == nullptr ? 0 : index->nHeight; - return height >= GetConsensus().nRootAssetsForkBlock; - }; const std::vector &SporkAddresses() const { return vSporkAddresses; } int MinSporkKeys() const { return nMinSporkKeys; } diff --git a/src/consensus/params.h b/src/consensus/params.h index a08c2a603..9467d3b92 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -102,9 +102,6 @@ namespace Consensus { SmartnodeCollaterals nCollaterals; int smartnodePaymentFixedBlock; int nFutureForkBlock; - int nAssetsForkBlock; - int nRootAssetsForkBlock; - }; } // namespace Consensus diff --git a/src/consensus/tx_verify.cpp b/src/consensus/tx_verify.cpp index c1634158b..28d77cd4a 100644 --- a/src/consensus/tx_verify.cpp +++ b/src/consensus/tx_verify.cpp @@ -50,7 +50,7 @@ checkSpecialTxFee(const CTransaction &tx, CAmount &nFeeTotal, CAmount &specialTx case TRANSACTION_NEW_ASSET: { CNewAssetTx asset; if (GetTxPayload(tx.vExtraPayload, asset)) { - if (!Params().IsAssetsActive(::ChainActive().Tip())) { + if (!Updates().IsAssetsActive(::ChainActive().Tip())) { return false; } bool assetsEnabled = sporkManager.IsSporkActive(SPORK_22_SPECIAL_TX_FEE); @@ -65,7 +65,7 @@ checkSpecialTxFee(const CTransaction &tx, CAmount &nFeeTotal, CAmount &specialTx case TRANSACTION_UPDATE_ASSET: { CUpdateAssetTx asset; if (GetTxPayload(tx.vExtraPayload, asset)) { - if (!Params().IsAssetsActive(::ChainActive().Tip())) { + if (!Updates().IsAssetsActive(::ChainActive().Tip())) { return false; } bool assetsEnabled = sporkManager.IsSporkActive(SPORK_22_SPECIAL_TX_FEE); @@ -80,7 +80,7 @@ checkSpecialTxFee(const CTransaction &tx, CAmount &nFeeTotal, CAmount &specialTx case TRANSACTION_MINT_ASSET: { CMintAssetTx asset; if (GetTxPayload(tx.vExtraPayload, asset)) { - if (!Params().IsAssetsActive(::ChainActive().Tip())) { + if (!Updates().IsAssetsActive(::ChainActive().Tip())) { return false; } bool assetsEnabled = sporkManager.IsSporkActive(SPORK_22_SPECIAL_TX_FEE); diff --git a/src/evo/providertx.cpp b/src/evo/providertx.cpp index 6a4f4b70b..c1d758a62 100644 --- a/src/evo/providertx.cpp +++ b/src/evo/providertx.cpp @@ -124,7 +124,7 @@ inline bool checkNewUniqueAsset(CNewAssetTx &assetTx, CValidationState &state) { bool CheckNewAssetTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CValidationState &state, CAssetsCache *assetsCache) { - if (!Params().IsAssetsActive(::ChainActive().Tip())) { + if (!Updates().IsAssetsActive(::ChainActive().Tip())) { return state.DoS(100, false, REJECT_INVALID, "assets-not-enabled"); } @@ -141,14 +141,6 @@ bool CheckNewAssetTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CVal return state.DoS(100, false, REJECT_INVALID, "bad-assets-version"); } - if (Params().IsRootAssetsActive(::ChainActive().Tip()) && assetTx.nVersion != 2) { - return state.DoS(100, false, REJECT_INVALID, "bad-assets-invalid-version"); - } else { - if (!Params().IsRootAssetsActive(::ChainActive().Tip()) && assetTx.nVersion != 1) { - return state.DoS(100, false, REJECT_INVALID, "bad-assets-invalid-version"); - } - } - //validate asset name if (!IsAssetNameValid(assetTx.name, assetTx.isRoot)) { return state.DoS(100, false, REJECT_INVALID, "bad-assets-name"); @@ -157,7 +149,7 @@ bool CheckNewAssetTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CVal //Check if a asset already exist with give name std::string assetId = assetTx.name; CAssetMetaData rootAsset; - if (assetTx.nVersion == 2 && !assetTx.isRoot) { + if (!assetTx.isRoot) { //sub asset if (!assetsCache->GetAssetMetaData(assetTx.rootId, rootAsset)){ return state.DoS(100, false, REJECT_INVALID, "bad-assets-root-id"); } @@ -167,7 +159,7 @@ bool CheckNewAssetTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CVal return state.DoS(100, false, REJECT_INVALID, "bad-assets-dup-name"); } } - } else { //v1 or ROOT asset + } else { //ROOT asset if (assetsCache->GetAssetId(assetTx.name, assetId)) { if (assetsCache->CheckIfAssetExists(assetId)) { return state.DoS(100, false, REJECT_INVALID, "bad-assets-dup-name"); @@ -176,7 +168,7 @@ bool CheckNewAssetTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CVal } //check if the root asset is valid - if (assetTx.nVersion == 2 && !assetTx.isRoot) { + if (!assetTx.isRoot) { if (!rootAsset.isRoot) { return state.DoS(100, false, REJECT_INVALID, "bad-assets-invalid-root-id"); } @@ -226,25 +218,9 @@ bool CheckNewAssetTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CVal return true; } -inline bool checkAssetFeesPayment(const CTransaction &tx, CValidationState &state, const CCoinsViewCache &view, - CAssetMetaData asset) { - for (auto in: tx.vin) { - const Coin &coin = view.AccessCoin(in.prevout); - if (coin.IsSpent()) - return state.DoS(100, false, REJECT_INVALID, "bad-assets-invalid-input"); - CTxDestination dest; - ExtractDestination(coin.out.scriptPubKey, dest); - if (EncodeDestination(dest) != EncodeDestination(asset.ownerAddress)) { - return state.DoS(100, false, REJECT_INVALID, "bad-assets-invalid-input"); - } - } - - return true; -} - bool CheckUpdateAssetTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CValidationState &state, const CCoinsViewCache &view, CAssetsCache *assetsCache) { - if (!Params().IsAssetsActive(::ChainActive().Tip())) { + if (!Updates().IsAssetsActive(::ChainActive().Tip())) { return state.DoS(100, false, REJECT_INVALID, "assets-not-enabled"); } @@ -270,23 +246,11 @@ bool CheckUpdateAssetTx(const CTransaction &tx, const CBlockIndex *pindexPrev, C if (!asset.updatable) { return state.DoS(100, false, REJECT_INVALID, "bad-assets-not-updateable"); } - - if (Params().IsRootAssetsActive(::ChainActive().Tip())) { - if (assetTx.nVersion != 2) { - return state.DoS(100, false, REJECT_INVALID, "bad-assets-invalid-version"); - } - //check the asset owner signature - std::string strError; - if (!CMessageSigner::VerifyMessage(asset.ownerAddress, assetTx.vchSig, assetTx.MakeSignString(assetsCache), strError)) { - return state.DoS(100, false, REJECT_INVALID, "bad-assets-sig", false, strError); - } - } else { - if (assetTx.nVersion != 1) { - return state.DoS(100, false, REJECT_INVALID, "bad-assets-invalid-version"); - } - //Check if fees is paid by the owner address - if (!checkAssetFeesPayment(tx, state, view, asset)) - return false; + + //check the asset owner signature + std::string strError; + if (!CMessageSigner::VerifyMessage(asset.ownerAddress, assetTx.vchSig, assetTx.MakeSignString(assetsCache), strError)) { + return state.DoS(100, false, REJECT_INVALID, "bad-assets-sig", false, strError); } if (assetTx.ownerAddress.IsNull()) { @@ -379,7 +343,7 @@ inline bool checkAssetMintAmount(const CTransaction &tx, CValidationState &state bool CheckMintAssetTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CValidationState &state, const CCoinsViewCache &view, CAssetsCache *assetsCache) { - if (!Params().IsAssetsActive(::ChainActive().Tip())) { + if (!Updates().IsAssetsActive(::ChainActive().Tip())) { return state.DoS(100, false, REJECT_INVALID, "assets-not-enabled"); } @@ -402,25 +366,12 @@ bool CheckMintAssetTx(const CTransaction &tx, const CBlockIndex *pindexPrev, CVa return state.DoS(100, false, REJECT_INVALID, "bad-assets-invalid-asset-id"); } - if (asset.type == 0 || asset.isUnique) { // manual mint or unique - if (Params().IsRootAssetsActive(::ChainActive().Tip())) { - if (assetTx.nVersion != 2) { - return state.DoS(100, false, REJECT_INVALID, "bad-assets-invalid-version"); - } - //check the asset owner signature - std::string strError; - if (!CMessageSigner::VerifyMessage(asset.ownerAddress, assetTx.vchSig, assetTx.MakeSignString(assetsCache), strError)) { - return state.DoS(100, false, REJECT_INVALID, "bad-mint-assets-sig", false, strError); - } - } else { - if (assetTx.nVersion != 1) { - return state.DoS(100, false, REJECT_INVALID, "bad-assets-invalid-version"); - } - //Check if fees is paid by the owner address - if (!checkAssetFeesPayment(tx, state, view, asset)) - return false; + if (asset.type == 0 || asset.isUnique) { // manual mint or unique + //check the asset owner signature + std::string strError; + if (!CMessageSigner::VerifyMessage(asset.ownerAddress, assetTx.vchSig, assetTx.MakeSignString(assetsCache), strError)) { + return state.DoS(100, false, REJECT_INVALID, "bad-mint-assets-sig", false, strError); } - if (!checkAssetMintAmount(tx, state, asset)) return false; @@ -867,6 +818,5 @@ std::string CMintAssetTx::MakeSignString(CAssetsCache *assetsCache) const { // ... and also the full hash of the payload as a protection agains malleability and replays s += ::SerializeHash(*this).ToString(); - return s; } \ No newline at end of file diff --git a/src/evo/providertx.h b/src/evo/providertx.h index 5677616c8..861701539 100644 --- a/src/evo/providertx.h +++ b/src/evo/providertx.h @@ -251,7 +251,7 @@ class CFutureTx { class CNewAssetTx { public: - static const uint16_t CURRENT_VERSION = 2; + static const uint16_t CURRENT_VERSION = 1; uint16_t nVersion{CURRENT_VERSION}; // message version std::string name; @@ -285,14 +285,12 @@ class CNewAssetTx { READWRITE(obj.nVersion, obj.name, obj.updatable, obj.isUnique, obj.maxMintCount, obj.decimalPoint, obj.referenceHash, obj.fee, obj.type, obj.targetAddress, obj.issueFrequency, obj.amount, obj.ownerAddress, obj.collateralAddress); - if(obj.nVersion == 2 ) { //testnet use v1 and v2, mainnet v2 only - READWRITE(obj.isRoot); - if (!obj.isRoot) { - //sub asset: serialise the root id and owner signature - READWRITE(obj.rootId); - if (!(s.GetType() & SER_GETHASH)) { - READWRITE(obj.vchSig); - } + READWRITE(obj.isRoot); + if (!obj.isRoot) { + //sub asset: serialise the root id and owner signature + READWRITE(obj.rootId); + if (!(s.GetType() & SER_GETHASH)) { + READWRITE(obj.vchSig); } } READWRITE(obj.exChainType, obj.externalPayoutScript, obj.externalTxid, @@ -309,7 +307,7 @@ class CNewAssetTx { obj.pushKV("version", nVersion); obj.pushKV("name", name); obj.pushKV("isRoot", isRoot); - if (!isRoot && nVersion == 2) + if (!isRoot) obj.pushKV("rootId", rootId); obj.pushKV("isUnique", isUnique); obj.pushKV("maxMintCount", maxMintCount); @@ -343,7 +341,7 @@ class CNewAssetTx { class CUpdateAssetTx { public: - static const uint16_t CURRENT_VERSION = 2; + static const uint16_t CURRENT_VERSION = 1; uint16_t nVersion{CURRENT_VERSION}; // message version std::string assetId; @@ -374,10 +372,8 @@ class CUpdateAssetTx { obj.type, obj.targetAddress, obj.issueFrequency, obj.maxMintCount, obj.amount, obj.ownerAddress, obj.collateralAddress, obj.exChainType, obj.externalPayoutScript, obj.externalTxid, obj.externalConfirmations, obj.inputsHash); - if(obj.nVersion == 2 ) { //testnet use v1 and v2, mainnet v2 only - if (!(s.GetType() & SER_GETHASH)) { - READWRITE(obj.vchSig); - } + if (!(s.GetType() & SER_GETHASH)) { + READWRITE(obj.vchSig); } } @@ -419,7 +415,7 @@ class CUpdateAssetTx { class CMintAssetTx { public: - static const uint16_t CURRENT_VERSION = 2; + static const uint16_t CURRENT_VERSION = 1; uint16_t nVersion{CURRENT_VERSION}; // message version std::string assetId; @@ -433,10 +429,8 @@ class CMintAssetTx { ) { READWRITE(obj.nVersion, obj.assetId, obj.fee, obj.inputsHash); - if(obj.nVersion == 2 ) { //testnet use v1 and v2, mainnet v2 only - if (!(s.GetType() & SER_GETHASH)) { - READWRITE(obj.vchSig); - } + if (!(s.GetType() & SER_GETHASH)) { + READWRITE(obj.vchSig); } } diff --git a/src/qt/assetsdialog.cpp b/src/qt/assetsdialog.cpp index acb785ae2..92fb880e5 100644 --- a/src/qt/assetsdialog.cpp +++ b/src/qt/assetsdialog.cpp @@ -335,38 +335,6 @@ void AssetsDialog::mintAsset() { mintAsset.fee = getAssetsFees(); CCoinControl coinControl; - if (!Params().IsRootAssetsActive(::ChainActive().Tip())) { - CTxDestination ownerAddress = CTxDestination(tmpAsset.ownerAddress); - if (!IsValidDestination(ownerAddress)) { - QMessageBox msgBox; - msgBox.setText("ERROR: Invalid owner address"); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.exec(); - return; - } - - coinControl.destChange = ownerAddress; - coinControl.fRequireAllInputs = false; - - std::vector vecOutputs; - //select only confirmed inputs, nMinDepth >= 1 - walletModel->wallet().AvailableCoins(vecOutputs, true, nullptr, 1, MAX_MONEY , MAX_MONEY, 0, 1); - - for (const auto &out: vecOutputs) { - CTxDestination txDest; - if (ExtractDestination(out.tx->tx->vout[out.i].scriptPubKey, txDest) && txDest == ownerAddress) { - coinControl.Select(COutPoint(out.tx->tx->GetHash(), out.i)); - } - } - - if (!coinControl.HasSelected()) { - QMessageBox msgBox; - msgBox.setText(QString::fromStdString(strprintf("Error: No funds at specified address %s", EncodeDestination(ownerAddress)))); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.exec(); - return; - } - } CTransactionRef wtx; CAmount nFee; diff --git a/src/qt/createassetsdialog.cpp b/src/qt/createassetsdialog.cpp index a71c5e3c9..fa787a144 100644 --- a/src/qt/createassetsdialog.cpp +++ b/src/qt/createassetsdialog.cpp @@ -327,19 +327,17 @@ void CreateAssetsDialog::createAsset() { assetTx.maxMintCount = ui->maxmintSpinBox->value(); assetTx.issueFrequency = ui->IssueFrequencyBox->value(); - if (Params().IsRootAssetsActive(::ChainActive().Tip())) { - assetTx.isRoot = ui->AssetTypeBox->currentText() == "Root"; - if (!assetTx.isRoot) {//sub asset - if (ui->RootAssetBox->currentIndex() > 0) { - std::string assetId; - if (passetsCache->GetAssetId(ui->RootAssetBox->currentText().toStdString(), assetId)) { - assetTx.rootId = assetId; - } else { - //shold never hapen - return; - } - } - } + assetTx.isRoot = ui->AssetTypeBox->currentText() == "Root"; + if (!assetTx.isRoot) {//sub asset + if (ui->RootAssetBox->currentIndex() > 0) { + std::string assetId; + if (passetsCache->GetAssetId(ui->RootAssetBox->currentText().toStdString(), assetId)) { + assetTx.rootId = assetId; + } else { + //shold never hapen + return; + } + } } CTransactionRef newTx; @@ -416,28 +414,24 @@ bool CreateAssetsDialog::validateInputs() { bool retval{true}; std::string assetname = ui->assetnameText->text().toStdString(); - bool isRoot = false; - if (Params().IsRootAssetsActive(::ChainActive().Tip())){ - isRoot = ui->AssetTypeBox->currentText() == "Root"; - } - + bool isRoot = ui->AssetTypeBox->currentText() == "Root"; + //check if asset name is valid if (!IsAssetNameValid(assetname, isRoot)) { retval = false; ui->assetnameText->setValid(false); } - if (Params().IsRootAssetsActive(::ChainActive().Tip())) { - if (!isRoot) {//sub asset - if (ui->RootAssetBox->currentIndex() > 0) { - assetname = ui->RootAssetBox->currentText().toStdString() + "|" + assetname; - } else { - //root asset not selected, set name as invalid - ui->assetnameText->setValid(false); - retval = false; - } + if (!isRoot) {//sub asset + if (ui->RootAssetBox->currentIndex() > 0) { + assetname = ui->RootAssetBox->currentText().toStdString() + "|" + assetname; + } else { + //root asset not selected, set name as invalid + ui->assetnameText->setValid(false); + retval = false; } } + // check if asset already exist std::string assetId; if (passetsCache->GetAssetId(assetname, assetId)) { @@ -447,6 +441,7 @@ bool CreateAssetsDialog::validateInputs() { ui->assetnameText->setValid(false); } } + //check on mempool if asset already exist if (mempool.CheckForNewAssetConflict(assetname)) { retval = false; @@ -790,26 +785,23 @@ void CreateAssetsDialog::CoinControlUpdateLabels() { void CreateAssetsDialog::checkAvailabilityClicked() { std::string assetname = ui->assetnameText->text().toStdString(); - bool isRoot = false; - if (Params().IsRootAssetsActive(::ChainActive().Tip())) - isRoot = ui->AssetTypeBox->currentText() == "Root"; + bool isRoot = ui->AssetTypeBox->currentText() == "Root"; //check if asset name is valid if (!IsAssetNameValid(assetname, isRoot)) { ui->assetnameText->setValid(false); } - if (Params().IsRootAssetsActive(::ChainActive().Tip())) { - if (!isRoot) {//sub asset - if (ui->RootAssetBox->currentIndex() > 0) { - assetname = ui->RootAssetBox->currentText().toStdString() + "|" + assetname; - } else { - //root asset not selected, set name as invalid - ui->assetnameText->setValid(false); - return; - } + if (!isRoot) {//sub asset + if (ui->RootAssetBox->currentIndex() > 0) { + assetname = ui->RootAssetBox->currentText().toStdString() + "|" + assetname; + } else { + //root asset not selected, set name as invalid + ui->assetnameText->setValid(false); + return; } } + // check if asset already exist std::string assetId; if (passetsCache->GetAssetId(assetname, assetId)) { diff --git a/src/qt/updateassetsdialog.cpp b/src/qt/updateassetsdialog.cpp index eab4c659d..4950d1bf7 100644 --- a/src/qt/updateassetsdialog.cpp +++ b/src/qt/updateassetsdialog.cpp @@ -355,39 +355,6 @@ void UpdateAssetsDialog::updateAsset() { return; } - if (!Params().IsRootAssetsActive(::ChainActive().Tip())) { - CTxDestination ownerAddress = CTxDestination(assetData.ownerAddress); - if (!IsValidDestination(ownerAddress)) { - QMessageBox msgBox; - msgBox.setText("ERROR: Invalid owner address"); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.exec(); - return; - } - m_coin_control->destChange = ownerAddress; - - m_coin_control->fRequireAllInputs = false; - - std::vector vecOutputs; - //select only confirmed inputs, nMinDepth >= 1 - model->wallet().AvailableCoins(vecOutputs, true, nullptr, 1, MAX_MONEY , MAX_MONEY, 0, 1); - - for (const auto &out: vecOutputs) { - CTxDestination txDest; - if (ExtractDestination(out.tx->tx->vout[out.i].scriptPubKey, txDest) && txDest == ownerAddress) { - m_coin_control->Select(COutPoint(out.tx->tx->GetHash(), out.i)); - } - } - - if (!m_coin_control->HasSelected()) { - QMessageBox msgBox; - msgBox.setText(QString::fromStdString(strprintf("Error: No funds at specified address %s", EncodeDestination(ownerAddress)))); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.exec(); - return; - } - } - CTransactionRef newTx; CAmount nFee; int nChangePos = -1; diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index aaafd3c62..036f3a0ed 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -792,7 +792,7 @@ UniValue getaddressutxos(const JSONRPCRequest &request) { UniValue assetParam = find_value(request.params[0].get_obj(), "asset"); if (assetParam.isStr()) { - if (!Params().IsAssetsActive(::ChainActive().Tip())) + if (!Updates().IsAssetsActive(::ChainActive().Tip())) throw JSONRPCError(RPC_INVALID_PARAMETER, "Assets aren't active. assetId can't be specified."); assetId = assetParam.get_str(); if (assetId != "*" && !passetsCache->GetAssetId(assetId, assetId)) @@ -945,7 +945,7 @@ UniValue getaddressdeltas(const JSONRPCRequest &request) { if (request.params[0].isObject()) { UniValue assetParam = find_value(request.params[0].get_obj(), "asset"); if (assetParam.isStr()) { - if (!Params().IsAssetsActive(::ChainActive().Tip())) + if (!Updates().IsAssetsActive(::ChainActive().Tip())) throw JSONRPCError(RPC_INVALID_PARAMETER, "Assets aren't active. assetId can't be specified."); assetId = assetParam.get_str(); if (assetId != "*" && !passetsCache->GetAssetId(assetId, assetId)) @@ -1072,7 +1072,7 @@ static UniValue getaddressbalance(const JSONRPCRequest &request) { if (request.params[0].isObject()) { UniValue assetParam = find_value(request.params[0].get_obj(), "asset"); if (assetParam.isStr()) { - if (!Params().IsAssetsActive(::ChainActive().Tip())) + if (!Updates().IsAssetsActive(::ChainActive().Tip())) throw JSONRPCError(RPC_INVALID_PARAMETER, "Assets aren't active. assetId can't be specified."); assetId = assetParam.get_str(); if (assetId != "*" && !passetsCache->GetAssetId(assetId, assetId)) diff --git a/src/rpc/rpcassets.cpp b/src/rpc/rpcassets.cpp index 8c7d3435d..9741096d4 100644 --- a/src/rpc/rpcassets.cpp +++ b/src/rpc/rpcassets.cpp @@ -51,7 +51,7 @@ static std::string GetDistributionType(int t) { UniValue createasset(const JSONRPCRequest &request) { - if (request.fHelp || !Params().IsAssetsActive(::ChainActive().Tip()) || request.params.size() < 1 || + if (request.fHelp || !Updates().IsAssetsActive(::ChainActive().Tip()) || request.params.size() < 1 || request.params.size() > 1) throw std::runtime_error( "createasset asset_metadata\n" @@ -118,87 +118,65 @@ UniValue createasset(const JSONRPCRequest &request) { assetTx.updatable = true; } - if (Params().IsRootAssetsActive(::ChainActive().Tip())) { - const UniValue &isroot = find_value(asset, "is_root"); - if (!isroot.isNull()) { - assetTx.isRoot = isroot.get_bool(); - } else { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: asset type not found"); - } + const UniValue &isroot = find_value(asset, "is_root"); + if (!isroot.isNull()) { + assetTx.isRoot = isroot.get_bool(); + } else { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: asset type not found"); + } - //check if asset name is valid - if (!IsAssetNameValid(assetname, assetTx.isRoot)) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Invalid asset name"); - } + //check if asset name is valid + if (!IsAssetNameValid(assetname, assetTx.isRoot)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Invalid asset name"); + } - if (!assetTx.isRoot) { //sub asset - const UniValue &root_name = find_value(asset, "root_name"); - if (root_name.isNull()) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Root asset not found (required)"); + std::string tmpname = assetname; + if (!assetTx.isRoot) { //sub asset + const UniValue &root_name = find_value(asset, "root_name"); + if (root_name.isNull()) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Root asset not found (required)"); + } + std::string rootname = root_name.getValStr(); + // check if root asset exist + std::string assetId; + if (passetsCache->GetAssetId(rootname, assetId)) { + //set the root asset id + assetTx.rootId = assetId; + CAssetMetaData tmpAsset; + if (!passetsCache->GetAssetMetaData(assetId, tmpAsset)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Root asset metadata not found"); } - std::string rootname = root_name.getValStr(); - // check if root asset exist - std::string assetId; - if (passetsCache->GetAssetId(rootname, assetId)) { - //set the root asset id - assetTx.rootId = assetId; - CAssetMetaData tmpAsset; - if (!passetsCache->GetAssetMetaData(assetId, tmpAsset)) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Root asset metadata not found"); - } - - if (!tmpAsset.isRoot) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Invalid root asset name"); - } - //check if we own the root asset - if (!IsMine(*pwallet, tmpAsset.ownerAddress) & ISMINE_SPENDABLE) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Invalid root asset key"); - } - - //combine the root name with the asset name - std::string tmpname = tmpAsset.name + "|" + assetname; - - //check if asset already exist - std::string tmp_id; - if (passetsCache->GetAssetId(tmpname, tmp_id)) { - CAssetMetaData tmp_Asset; - if (passetsCache->GetAssetMetaData(tmp_id, tmp_Asset)) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Asset already exist"); - } - } - - //check on mempool if asset already exist - if (mempool.CheckForNewAssetConflict(tmpname)) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Asset already exist on mempool"); - } - } else { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Root asset metadata not found"); + if (!tmpAsset.isRoot) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Invalid root asset name"); } - } - } else { - //this section can be removed later on - //on testnet set version to 1 until new fork - assetTx.nVersion = 1; - //check if asset name is valid - if (!IsAssetNameValid(assetname, false)) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Invalid asset name v1"); - } - std::string assetId; - if (passetsCache->GetAssetId(assetname, assetId)) { - CAssetMetaData tmpAsset; - if (passetsCache->GetAssetMetaData(assetId, tmpAsset)) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Asset already exist"); + //check if we own the root asset + if (!IsMine(*pwallet, tmpAsset.ownerAddress) & ISMINE_SPENDABLE) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Invalid root asset key"); } + + //combine the root name with the asset name + tmpname = tmpAsset.name + "|" + assetname; + } else { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Root asset metadata not found"); } - - //check on mempool if asset already exist - if (mempool.CheckForNewAssetConflict(assetname)) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Asset already exist on mempool"); + } + + //check if asset already exist + std::string assetId; + if (passetsCache->GetAssetId(tmpname, assetId)) { + CAssetMetaData tmp_Asset; + if (passetsCache->GetAssetMetaData(assetId, tmp_Asset)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Asset already exist"); } } + //check on mempool if asset already exist + if (mempool.CheckForNewAssetConflict(tmpname)) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Asset already exist on mempool"); + } + const UniValue &referenceHash = find_value(asset, "referenceHash"); if (!referenceHash.isNull()) { std::string ref = referenceHash.get_str(); @@ -310,7 +288,7 @@ UniValue createasset(const JSONRPCRequest &request) { UniValue updateasset(const JSONRPCRequest &request) { - if (request.fHelp || !Params().IsAssetsActive(::ChainActive().Tip()) || request.params.size() < 1 || + if (request.fHelp || !Updates().IsAssetsActive(::ChainActive().Tip()) || request.params.size() < 1 || request.params.size() > 1) throw std::runtime_error( "updateasset asset_metadata\n" @@ -489,28 +467,6 @@ UniValue updateasset(const JSONRPCRequest &request) { } CCoinControl coinControl; - - if (!Params().IsRootAssetsActive(::ChainActive().Tip())) { - coinControl.destChange = ownerAddress; - coinControl.fRequireAllInputs = false; - - std::vector vecOutputs; - //select only confirmed inputs, nMinDepth >= 1 - pwallet->AvailableCoins(vecOutputs, true, nullptr, 1, MAX_MONEY , MAX_MONEY, 0, 1); - - for (const auto &out: vecOutputs) { - CTxDestination txDest; - if (ExtractDestination(out.tx->tx->vout[out.i].scriptPubKey, txDest) && txDest == ownerAddress) { - coinControl.Select(COutPoint(out.tx->tx->GetHash(), out.i)); - } - } - - if (!coinControl.HasSelected()) { - throw JSONRPCError(RPC_INTERNAL_ERROR, - strprintf("No funds at specified address %s", EncodeDestination(ownerAddress))); - } - } - CTransactionRef newTx; CAmount nFee; int nChangePos = -1; @@ -546,7 +502,7 @@ UniValue updateasset(const JSONRPCRequest &request) { } UniValue mintasset(const JSONRPCRequest &request) { - if (request.fHelp || !Params().IsAssetsActive(::ChainActive().Tip()) || request.params.size() < 1 || + if (request.fHelp || !Updates().IsAssetsActive(::ChainActive().Tip()) || request.params.size() < 1 || request.params.size() > 1) throw std::runtime_error( "mintasset txid\n" @@ -607,30 +563,8 @@ UniValue mintasset(const JSONRPCRequest &request) { if (!IsValidDestination(ownerAddress)) { throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address"); } - CCoinControl coinControl; - - if (!Params().IsRootAssetsActive(::ChainActive().Tip())) { - coinControl.destChange = ownerAddress; - coinControl.fRequireAllInputs = false; - - std::vector vecOutputs; - //select only confirmed inputs, nMinDepth >= 1 - pwallet->AvailableCoins(vecOutputs, true, nullptr, 1, MAX_MONEY , MAX_MONEY, 0, 1); - - for (const auto &out: vecOutputs) { - CTxDestination txDest; - if (ExtractDestination(out.tx->tx->vout[out.i].scriptPubKey, txDest) && txDest == ownerAddress) { - coinControl.Select(COutPoint(out.tx->tx->GetHash(), out.i)); - } - } - - if (!coinControl.HasSelected()) { - throw JSONRPCError(RPC_INTERNAL_ERROR, - strprintf("No funds at specified address %s", EncodeDestination(ownerAddress))); - } - } - + CCoinControl coinControl; CTransactionRef wtx; CAmount nFee; int nChangePos = -1; @@ -675,7 +609,7 @@ UniValue mintasset(const JSONRPCRequest &request) { } UniValue sendasset(const JSONRPCRequest &request) { - if (request.fHelp || !Params().IsAssetsActive(::ChainActive().Tip()) || request.params.size() < 3 || + if (request.fHelp || !Updates().IsAssetsActive(::ChainActive().Tip()) || request.params.size() < 3 || request.params.size() > 7) throw std::runtime_error( "sendasset \"asset_id\" \"qty\" \"to_address\" \"change_address\" \"asset_change_address\"\n" @@ -801,7 +735,7 @@ UniValue sendasset(const JSONRPCRequest &request) { UniValue getassetdetailsbyname(const JSONRPCRequest &request) { - if (request.fHelp || !Params().IsAssetsActive(::ChainActive().Tip()) || request.params.size() < 1 || + if (request.fHelp || !Updates().IsAssetsActive(::ChainActive().Tip()) || request.params.size() < 1 || request.params.size() > 1) throw std::runtime_error( "getassetdetailsbyname 'asset_name'\n" @@ -833,7 +767,7 @@ UniValue getassetdetailsbyname(const JSONRPCRequest &request) { } UniValue getassetdetailsbyid(const JSONRPCRequest &request) { - if (request.fHelp || !Params().IsAssetsActive(::ChainActive().Tip()) || request.params.size() < 1 || + if (request.fHelp || !Updates().IsAssetsActive(::ChainActive().Tip()) || request.params.size() < 1 || request.params.size() > 1) throw std::runtime_error( "getassetdetailsbyid 'asset_id'\n" @@ -861,7 +795,7 @@ UniValue getassetdetailsbyid(const JSONRPCRequest &request) { } UniValue listassetsbalance(const JSONRPCRequest &request) { - if (request.fHelp || !Params().IsAssetsActive(::ChainActive().Tip()) || request.params.size() > 0) + if (request.fHelp || !Updates().IsAssetsActive(::ChainActive().Tip()) || request.params.size() > 0) throw std::runtime_error( "listassetsbalance\n" "\nResult:\n" @@ -1203,7 +1137,7 @@ UniValue listaddressesbyasset(const JSONRPCRequest &request) return "_This rpc call is not functional unless -assetindex is enabled. To enable, please run the wallet with -assetindex, this will require a reindex to occur"; } - if (request.fHelp || !Params().IsAssetsActive(::ChainActive().Tip()) || request.params.size() > 4 || request.params.size() < 1) + if (request.fHelp || !Updates().IsAssetsActive(::ChainActive().Tip()) || request.params.size() > 4 || request.params.size() < 1) throw std::runtime_error( "listaddressesbyasset \"asset_name\" (onlytotal) (count) (start)\n" "\nReturns a list of all address that own the given asset (with balances)" @@ -1278,7 +1212,7 @@ UniValue listassetbalancesbyaddress(const JSONRPCRequest& request) return "_This rpc call is not functional unless -assetindex is enabled. To enable, please run the wallet with -assetindex, this will require a reindex to occur"; } - if (request.fHelp || !Params().IsAssetsActive(::ChainActive().Tip()) || request.params.size() < 1) + if (request.fHelp || !Updates().IsAssetsActive(::ChainActive().Tip()) || request.params.size() < 1) throw std::runtime_error( "listassetbalancesbyaddress \"address\" (onlytotal) (count) (start)\n" "\nReturns a list of all asset balances for an address.\n" diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 3a4d851f1..5503d7046 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -353,7 +353,7 @@ void CTxMemPool::AddTransactionsUpdated(unsigned int n) { } static inline std::string getAssetFullName(CNewAssetTx assetTx) { - if (assetTx.nVersion == 2 && !assetTx.isRoot) { + if (!assetTx.isRoot) { CAssetMetaData tmpAsset; if (passetsCache->GetAssetMetaData(assetTx.rootId, tmpAsset)) { return tmpAsset.name + "|" +assetTx.name; diff --git a/src/update/update.cpp b/src/update/update.cpp index 629bc2a38..aa953a482 100644 --- a/src/update/update.cpp +++ b/src/update/update.cpp @@ -285,6 +285,11 @@ bool UpdateManager::IsActive(enum EUpdate eUpdate, const CBlockIndex* blockIndex return State(eUpdate, blockIndex).State == EUpdateState::Active; } +bool UpdateManager::IsAssetsActive(const CBlockIndex* blockIndex) +{ + return IsActive(EUpdate::ROUND_VOTING, blockIndex); +} + StateInfo UpdateManager::State(enum EUpdate eUpdate, const CBlockIndex* blockIndex) { const Update* update = GetUpdate(eUpdate); diff --git a/src/update/update.h b/src/update/update.h index 0300b314f..6441591e3 100644 --- a/src/update/update.h +++ b/src/update/update.h @@ -310,6 +310,7 @@ class UpdateManager const Update* GetUpdate(enum EUpdate eUpdate) const; bool IsActive(enum EUpdate eUpdate, const CBlockIndex* blockIndex); + bool IsAssetsActive(const CBlockIndex* blockIndex); StateInfo State(enum EUpdate eUpdate, const CBlockIndex* blockIndex); diff --git a/src/validation.cpp b/src/validation.cpp index e1b75be1a..b47f2d0bd 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1747,7 +1747,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock &block, const CBlockI fClean = false; // transaction output mismatch } if (fAssetIndex) { - if (Params().IsAssetsActive(::ChainActive().Tip()) && assetsCache) { + if (Updates().IsAssetsActive(::ChainActive().Tip()) && assetsCache) { if (coin.out.scriptPubKey.IsAssetScript()) { assetsCache->RemoveAddressBalance(coin.out.scriptPubKey, out); } @@ -1756,7 +1756,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock &block, const CBlockI } } - if (Params().IsAssetsActive(::ChainActive().Tip()) && assetsCache) { + if (Updates().IsAssetsActive(::ChainActive().Tip()) && assetsCache) { if (tx.nType == TRANSACTION_NEW_ASSET) { CNewAssetTx assetTx; if (GetTxPayload(tx, assetTx)) { @@ -1811,7 +1811,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock &block, const CBlockI } if (fAssetIndex) { - if (Params().IsAssetsActive(::ChainActive().Tip()) && assetsCache) { + if (Updates().IsAssetsActive(::ChainActive().Tip()) && assetsCache) { const Coin &coin = view.AccessCoin(tx.vin[j].prevout); if (coin.out.scriptPubKey.IsAssetScript()) { assetsCache->AddAssetBlance(coin.out.scriptPubKey, tx.vin[j].prevout); @@ -2772,7 +2772,7 @@ bool CChainState::FlushStateToDisk(const CChainParams &chainparams, CValidationS if (!evoDb->CommitRootTransaction()) { return AbortNode(state, "Failed to commit EvoDB"); } - if (Params().IsAssetsActive(::ChainActive().Tip())) { + if (Updates().IsAssetsActive(::ChainActive().Tip())) { if (passetsCache && !passetsCache->DumpCacheToDatabase()) return AbortNode(state, "Failed to write to asset database"); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index affd56e50..33fd3b643 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1560,7 +1560,7 @@ void ListTransactions(CWallet *const pwallet, const CWalletTx &wtx, int nMinDept ret.push_back(entry); } } - if (Params().IsAssetsActive (::ChainActive().Tip())) { + if (Updates().IsAssetsActive (::ChainActive().Tip())) { if (listAssetsReceived.size() > 0 && wtx.GetDepthInMainChain() >= nMinDepth) { for (const CAssetOutputEntry &data: listAssetsReceived){ UniValue entry(UniValue::VOBJ); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 6b1ae235b..907865041 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1231,7 +1231,7 @@ bool CWallet::AddToWallet(const CWalletTx &wtxIn, bool fFlushOnClose, bool resca if (wtxIn.tx->nType == TRANSACTION_NEW_ASSET && fInsertedNew){ CNewAssetTx assetTx; if (GetTxPayload(wtxIn.tx->vExtraPayload, assetTx)) { - if (assetTx.nVersion == 2 && !assetTx.isRoot) { + if (!assetTx.isRoot) { CAssetMetaData rootAsset; if (passetsCache->GetAssetMetaData(assetTx.rootId, rootAsset)) mapAsset.emplace(hash, std::make_pair(rootAsset.name + "|" +assetTx.name, assetTx.ownerAddress)); @@ -1314,7 +1314,7 @@ void CWallet::LoadToWallet(CWalletTx &wtxIn) { if (wtx.tx->nType == TRANSACTION_NEW_ASSET && !wtx.isAbandoned()){ CNewAssetTx assetTx; if (GetTxPayload(wtxIn.tx->vExtraPayload, assetTx)) { - if (assetTx.nVersion == 2 && !assetTx.isRoot) { + if (!assetTx.isRoot) { CAssetMetaData rootAsset; if (passetsCache->GetAssetMetaData(assetTx.rootId, rootAsset)) mapAsset.emplace(hash, std::make_pair(rootAsset.name + "|" +assetTx.name, assetTx.ownerAddress)); @@ -2334,7 +2334,7 @@ void CWalletTx::GetAmounts(std::list &listReceived, listReceived.push_back(output); } - if (Params().IsAssetsActive(::ChainActive().Tip())) { + if (Updates().IsAssetsActive(::ChainActive().Tip())) { if (txout.scriptPubKey.IsAssetScript()) { CAssetOutputEntry assetoutput; assetoutput.vout = i; @@ -3099,7 +3099,7 @@ void CWallet::AvailableCoins(std::vector &vCoins, std::map mapOutPoints; std::set setAssetMaxFound; - bool fGetAssets = Params().IsAssetsActive(::ChainActive().Tip()) && fOnlyAssets; + bool fGetAssets = Updates().IsAssetsActive(::ChainActive().Tip()) && fOnlyAssets; for (auto pcoin: GetSpendableTXs()) { const uint256 &wtxid = pcoin->GetHash(); @@ -4190,7 +4190,7 @@ bool CWallet::CreateTransaction(const std::vector &vecSend, CTransa int &nChangePosInOut, std::string &strFailReason, const CCoinControl &coin_control, bool sign, int nExtraPayloadSize, FuturePartialPayload *fpp, CNewAssetTx *newAsset, CMintAssetTx *mint, CUpdateAssetTx *updateAsset) { - if (!Params().IsAssetsActive(::ChainActive().Tip()) && (newAsset || mint || updateAsset)) + if (!Updates().IsAssetsActive(::ChainActive().Tip()) && (newAsset || mint || updateAsset)) return false; uint32_t const height = chain().getHeight().get_value_or(-1); @@ -4272,19 +4272,19 @@ bool CWallet::CreateTransaction(const std::vector &vecSend, CTransa txNew.nVersion = 3; txNew.nType = TRANSACTION_NEW_ASSET; atx = *newAsset; - atx.nVersion = Params().IsRootAssetsActive(::ChainActive().Tip()) ? 2 : 1; + atx.nVersion = 1; specialFees = getAssetsFeesCoin(); } else if (mint) { txNew.nVersion = 3; txNew.nType = TRANSACTION_MINT_ASSET; mtx = *mint; - mtx.nVersion = Params().IsRootAssetsActive(::ChainActive().Tip()) ? 2 : 1; + mtx.nVersion = 1; specialFees = getAssetsFeesCoin(); } else if (updateAsset){ txNew.nVersion = 3; txNew.nType = TRANSACTION_UPDATE_ASSET; uptx = *updateAsset; - uptx.nVersion = Params().IsRootAssetsActive(::ChainActive().Tip()) ? 2 : 1; + uptx.nVersion = 1; specialFees = getAssetsFeesCoin(); } // Discourage fee sniping. @@ -4472,7 +4472,7 @@ bool CWallet::CreateTransaction(const std::vector &vecSend, CTransa return false; } vecCoins.assign(setCoinsTmp.begin(), setCoinsTmp.end()); - if (Params().IsAssetsActive(::ChainActive().Tip())) { + if (Updates().IsAssetsActive(::ChainActive().Tip())) { std::set setAssetsTmp; mapAssetsIn.clear(); if (!SelectAssets(mapAssetCoins, mapAssetValue, setAssetsTmp, mapAssetsIn)) { @@ -4635,7 +4635,7 @@ bool CWallet::CreateTransaction(const std::vector &vecSend, CTransa } }; - if (Params().IsAssetsActive(::ChainActive().Tip())) { + if (Updates().IsAssetsActive(::ChainActive().Tip())) { // Add the change for the assets std::map mapAssetChange; for (auto asset: mapAssetValue) { @@ -4787,7 +4787,7 @@ bool CWallet::CreateTransaction(const std::vector &vecSend, CTransa SetTxPayload(txNew, ftx); } else if (newAsset) { UpdateSpecialTxInputsHash(txNew, atx); - if (atx.nVersion == 2 && !atx.isRoot) { + if (!atx.isRoot) { atx.vchSig.clear(); CAssetMetaData assetData; @@ -4812,52 +4812,48 @@ bool CWallet::CreateTransaction(const std::vector &vecSend, CTransa SetTxPayload(txNew, atx); } else if (mint) { UpdateSpecialTxInputsHash(txNew, mtx); - if (mtx.nVersion == 2) { - mtx.vchSig.clear(); - - CAssetMetaData assetData; - if (passetsCache->GetAssetMetaData(mtx.assetId, assetData)) { - std::string m = mtx.MakeSignString(passetsCache.get()); - // lets prove we own the asset - CKey key; - if (!CCryptoKeyStore::GetKey(assetData.ownerAddress, key)) { - strFailReason = _("Asset owner key not in wallet"); - return false; - } - if(!CMessageSigner::SignMessage(m, mtx.vchSig, key)) - { - strFailReason = _("Failed to sign special tx"); - return false; - } - } else { - strFailReason = _("Failed to get root metadata"); + mtx.vchSig.clear(); + + CAssetMetaData assetData; + if (passetsCache->GetAssetMetaData(mtx.assetId, assetData)) { + std::string m = mtx.MakeSignString(passetsCache.get()); + // lets prove we own the asset + CKey key; + if (!CCryptoKeyStore::GetKey(assetData.ownerAddress, key)) { + strFailReason = _("Asset owner key not in wallet"); return false; } + if(!CMessageSigner::SignMessage(m, mtx.vchSig, key)) + { + strFailReason = _("Failed to sign special tx"); + return false; + } + } else { + strFailReason = _("Failed to get root metadata"); + return false; } SetTxPayload(txNew, mtx); } else if (updateAsset) { UpdateSpecialTxInputsHash(txNew, uptx); - if (uptx.nVersion == 2) { - uptx.vchSig.clear(); - - CAssetMetaData assetData; - if (passetsCache->GetAssetMetaData(uptx.assetId, assetData)) { - std::string m = uptx.MakeSignString(passetsCache.get()); - // lets prove we own the asset - CKey key; - if (!CCryptoKeyStore::GetKey(assetData.ownerAddress, key)) { - strFailReason = _("Asset owner key not in wallet"); - return false; - } - if(!CMessageSigner::SignMessage(m, uptx.vchSig, key)) - { - strFailReason = _("Failed to sign special tx"); - return false; - } - } else { - strFailReason = _("Failed to get root metadata"); + uptx.vchSig.clear(); + + CAssetMetaData assetData; + if (passetsCache->GetAssetMetaData(uptx.assetId, assetData)) { + std::string m = uptx.MakeSignString(passetsCache.get()); + // lets prove we own the asset + CKey key; + if (!CCryptoKeyStore::GetKey(assetData.ownerAddress, key)) { + strFailReason = _("Asset owner key not in wallet"); return false; } + if(!CMessageSigner::SignMessage(m, uptx.vchSig, key)) + { + strFailReason = _("Failed to sign special tx"); + return false; + } + } else { + strFailReason = _("Failed to get root metadata"); + return false; } SetTxPayload(txNew, uptx); }