From 9d9a52fe596fde41db40094a77f71e116fb8512f Mon Sep 17 00:00:00 2001 From: Block Mechanic Date: Tue, 19 Jul 2022 21:47:57 +0200 Subject: [PATCH] More --- src/assetdb.cpp | 4 +-- src/chainparams.cpp | 4 +-- src/init.cpp | 10 +++---- src/primitives/asset.cpp | 10 ------- src/primitives/asset.h | 5 +--- src/qt/sendcoinsentry.cpp | 4 +-- src/validation.cpp | 47 ++++++++++++++++-------------- src/wallet/rpcwallet.cpp | 8 +++-- src/wallet/wallet.cpp | 61 +++++++++++++++++++++------------------ 9 files changed, 75 insertions(+), 78 deletions(-) diff --git a/src/assetdb.cpp b/src/assetdb.cpp index 3ed61ea..1bfe3e3 100755 --- a/src/assetdb.cpp +++ b/src/assetdb.cpp @@ -54,7 +54,7 @@ bool CAssetsDB::WriteAssetData(const CAsset &asset, const CTransactionRef& asset { CCoinsViewCache view(&::ChainstateActive().CoinsTip()); CAssetData data(asset, assetTx, nOut, view, _nTime); - return Write(std::make_pair(ASSET_FLAG, asset.getName()), data); + return Write(std::make_pair(ASSET_FLAG, asset.getAssetName()), data); } bool CAssetsDB::ReadAssetData(const std::string& strName, CAssetData &data) @@ -91,7 +91,7 @@ bool CAssetsDB::LoadAssets() if (pcursor->GetKey(key) && key.first == ASSET_FLAG) { CAssetData data; if (pcursor->GetValue(data)) { - passetsCache->Put(data.asset.getName(), data); + passetsCache->Put(data.asset.getAssetName(), data); pcursor->Next(); } else { return error("%s: failed to read asset", __func__); diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 4b0dd80..8138613 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -301,10 +301,10 @@ class CTestNetParams : public CChainParams { CScript genscript(addrdata.begin(), addrdata.end()); consensus.mandatory_coinbase_destination = genscript; - genesis = CreateGenesisBlock(1657811432, 98, 0x1e0ffff0, 1, 10 * COIN, consensus); + genesis = CreateGenesisBlock(1658230992, 101888, 0x1e0ffff0, 1, 10 * COIN, consensus); consensus.hashGenesisBlock = genesis.GetHash(); //MineNewGenesisBlock(consensus,genesis); - assert(consensus.hashGenesisBlock == uint256S("0x00000850f701bcce35569afca8e518568761b56920050a1d4167741448ec7a99")); + assert(consensus.hashGenesisBlock == uint256S("0x00000aa9bebd66a90abc3128e76295782707f2119f0beba0447b9693c682403a")); assert(genesis.hashMerkleRoot == uint256S("0x80ad356118a9ab8db192db66ef77146cc36d958f959251feace550e4ca3d1446")); vFixedSeeds.clear(); diff --git a/src/init.cpp b/src/init.cpp index 20faf75..9ab69c6 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -392,15 +392,15 @@ void checkAndAddDefaultAsset(){ CAsset asset = Params().GetConsensus().subsidy_asset; for(auto const& x : passetsCache->GetItemsMap()){ CAsset checkasset = x.second->second.asset; - if(iequals(asset.getName(), checkasset.getName()) || iequals(asset.getName(), checkasset.getSymbol())) + if(iequals(asset.getAssetName(), checkasset.getAssetName()) || iequals(asset.getAssetName(), checkasset.getShortName())) exists = true; - if(iequals("", checkasset.getName()) || iequals("", checkasset.getSymbol())) + if(iequals("", checkasset.getAssetName()) || iequals("", checkasset.getShortName())) dummy = true; } CCoinsViewCache view(&::ChainstateActive().CoinsTip()); - if (!exists && !passetsCache->Exists(asset.getName())){ - LogPrintf("NOTIFICATION: %s: ADDING ASSET %s\n", __func__, asset.getName()); - passetsCache->Put(asset.getName(), CAssetData(asset, Params().GenesisBlock().vtx[0], 0, view, Params().GenesisBlock().nTime)); + if (!exists && !passetsCache->Exists(asset.getAssetName())){ + LogPrintf("NOTIFICATION: %s: ADDING ASSET %s\n", __func__, asset.getAssetName()); + passetsCache->Put(asset.getAssetName(), CAssetData(asset, Params().GenesisBlock().vtx[0], 0, view, Params().GenesisBlock().nTime)); } if (dummy){ diff --git a/src/primitives/asset.cpp b/src/primitives/asset.cpp index af74745..1c78f40 100755 --- a/src/primitives/asset.cpp +++ b/src/primitives/asset.cpp @@ -323,16 +323,6 @@ uint256 CAsset::GetHash() const return SerializeHash(*this); } -const std::string CAsset::getName() const -{ - return getAssetName(); -} - -const std::string CAsset::getSymbol() const -{ - return getShortName(); -} - const std::string CAsset::getSignature() const { //std::string data (vchAssetSig.begin(),vchAssetSig.end()); diff --git a/src/primitives/asset.h b/src/primitives/asset.h index 6af3163..f69b72b 100755 --- a/src/primitives/asset.h +++ b/src/primitives/asset.h @@ -156,9 +156,6 @@ struct CAsset : public AssetMetadata AssetMetadata::SetEmpty(); } - const std::string getName() const; - const std::string getSymbol() const; - unsigned char* begin() { return assetID.begin(); } unsigned char* end() { return assetID.end(); } const unsigned char* begin() const { return assetID.begin(); } @@ -272,7 +269,7 @@ inline std::string mapToString(CAmountMap& map) { std::string result = ""; for (auto it = map.begin(); it != map.end(); it++) { - result += it->first.GetHex() + " " + it->first.getName() + " " + strprintf("%d", it->second)+ " "; + result += it->first.GetHex() + " " + it->first.getAssetName() + " " + strprintf("%d", it->second)+ " "; } return result; } diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp index ca542e7..a592869 100644 --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -67,7 +67,7 @@ void SendCoinsEntry::assetList(){ QStringList list; for(auto const& x : m_balances.balance){ - list << QString::fromStdString(x.first.getName()); + list << QString::fromStdString(x.first.getAssetName()); } std::sort(list.begin(), list.end()); @@ -200,7 +200,7 @@ SendAssetsRecipient SendCoinsEntry::getValue() recipient.fSubtractFeeFromAmount = (ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked); for(auto const& x : passetsCache->GetItemsMap()){ - if(QString::fromStdString(x.second->second.asset.getName()) == ui->assetBox->currentText()) + if(QString::fromStdString(x.second->second.asset.getAssetName()) == ui->assetBox->currentText()) recipient.asset = x.second->second.asset; } diff --git a/src/validation.cpp b/src/validation.cpp index 7b99995..be24663 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -639,12 +639,12 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws) LogPrintf("%s: Subsidy asset found \n", __func__); else LogPrintf("%s: Subsidy asset not found %s vs %s \n", __func__, txout.nAsset.assetID.ToString(), Params().GetConsensus().subsidy_asset.assetID.ToString()); - + bool sub_fee = false; sub_fee = txout.nValue == 10.0001 * COIN; if(sub_fee) LogPrintf("%s: Subsidy fee found \n", __func__); - + if(sub_address /*&& sub_asset*/ && sub_fee) fHasFee = true; } @@ -1917,7 +1917,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI uint160 hashBytes; for (unsigned int k = (tx.nVersion >= TX_ELE_VERSION ? tx.vpout.size() : tx.vout.size()); k-- > 0;) { const CTxOutAsset &out = (tx.nVersion >= TX_ELE_VERSION ? tx.vpout[k] : tx.vout[k]); - std::string sAssetName = out.nAsset.getName(); + std::string sAssetName = out.nAsset.getAssetName(); const CScript *pScript; std::vector hashBytes; @@ -1980,7 +1980,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI const Coin &coin = view.AccessCoin(tx.vin[j].prevout); const CTxOutAsset &prevout = coin.out; //(tx.nVersion >= TX_ELE_VERSION ? coin.out2 : coin.out); - std::string sAssetName = prevout.nAsset.getName(); + std::string sAssetName = prevout.nAsset.getAssetName(); const CScript *pScript = &prevout.scriptPubKey; @@ -2624,7 +2624,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state, const CTxIn input = tx.vin[j]; const Coin& coin = view.AccessCoin(tx.vin[j].prevout); const CTxOutAsset &prevout = coin.out; //(tx.nVersion >= TX_ELE_VERSION ? coin.out2 : coin.out); - std::string sAssetName = prevout.nAsset.getName(); + std::string sAssetName = prevout.nAsset.getAssetName(); const CScript *pScript = &prevout.scriptPubKey; std::vector hashBytes; @@ -2679,7 +2679,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state, for (unsigned int k = 0; k < (tx.nVersion >= TX_ELE_VERSION ? tx.vpout.size() : tx.vout.size()) ; k++) { const CTxOutAsset &out = (tx.nVersion >= TX_ELE_VERSION ? tx.vpout[k] : tx.vout[k]); - std::string sAssetName = out.nAsset.getName(); + std::string sAssetName = out.nAsset.getAssetName(); const CScript *pScript; std::vector hashBytes; @@ -2754,29 +2754,32 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state, //Asset DB { for(unsigned int i = 0; i < block.vtx.size(); i++){ - const CTransactionRef &tx = block.vtx[i]; - for(unsigned int j = 0; j < (tx->nVersion >= TX_ELE_VERSION ? tx->vpout.size() : tx->vout.size()) ; j++){ - const CTxOutAsset &out = (tx->nVersion >= TX_ELE_VERSION ? tx->vpout[j] : tx->vout[j]); + LogPrintf("TRANSACTION: \n %s\n", block.vtx[i]->ToString()); + if(block.vtx[i]->nVersion >= TX_ELE_VERSION ){ + for(unsigned int j = 0; j < block.vtx[i]->vpout.size(); j++){ + CAsset out = block.vtx[i]->vpout[j].nAsset; - CAsset asset = out.nAsset; - bool exists = false; - LogPrintf("NOTIFICATION: %s: FOUND ASSET %s\n", __func__, asset.ToString()); + bool exists = false; + LogPrintf("%s: FOUND ASSET %s \n", __func__, out.ToString()); - for(auto const& x : passetsCache->GetItemsMap()){ - CAsset checkasset = x.second->second.asset; - if(iequals(asset.getName(), checkasset.getName()) || iequals(asset.getName(), checkasset.getSymbol())) - if(!fJustCheck) + for(auto const& x : passetsCache->GetItemsMap()){ + CAsset checkasset = x.second->second.asset; + if(iequals(out.getAssetName(), checkasset.getAssetName()) || iequals(out.getAssetName(), checkasset.getShortName())) exists = true; - } + } - if (!exists && !passetsCache->Exists(asset.getName())){ - if(!fJustCheck){ - LogPrintf("NOTIFICATION: %s: ADDING ASSET %s\n", __func__, asset.getName()); - passetsCache->Put(asset.getName(), CAssetData(asset, tx, j, view, block.nTime)); + if (exists) + LogPrintf("%s: EXISTS ASSET %s.\n", __func__, out.getAssetName()); + + if (!exists && !passetsCache->Exists(out.getAssetName())){ + if(!fJustCheck){ + LogPrintf("%s: ADDING ASSET %s\n", __func__, out.getAssetName()); + passetsCache->Put(out.getAssetName(), CAssetData(out, block.vtx[i], j, view, block.nTime)); + } } } } - + const CTransactionRef &tx = block.vtx[i]; for (unsigned int i = 0; i < tx->vdata.size(); i++){ uint8_t vers = tx->vdata[i].get()->GetVersion(); switch (vers) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4ad4ab4..093b517 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4,6 +4,8 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include + #include #include #include @@ -496,10 +498,10 @@ static RPCHelpMan sendtoaddress() if (request.params[2].get_str().empty() || request.params[2].isNull()) asset = Params().GetConsensus().subsidy_asset; else - asset = pwallet->chain().getAsset(request.params[2].get_str()); + asset = GetAsset(request.params[2].get_str()); //pwallet->chain().getAsset(request.params[2].get_str()); if (asset.IsNull()) { - throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Unknown or invalid asset: %s %s", asset.GetHex(), asset.getName())); + throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Unknown or invalid asset: %s %s", asset.GetHex(), asset.getAssetName())); } // Wallet comments @@ -3213,7 +3215,7 @@ static RPCHelpMan listunspent() entry.pushKV("scriptPubKey", HexStr(scriptPubKey)); entry.pushKV("amount", ValueFromAmount(out.tx->tx->vout[out.i].nValue)); - entry.pushKV("asset", assetid.getName()); + entry.pushKV("asset", assetid.getAssetName()); entry.pushKV("confirmations", out.nDepth); entry.pushKV("spendable", out.fSpendable); entry.pushKV("solvable", out.fSolvable); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d0496b1..72da4bb 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3315,7 +3315,7 @@ bool CWallet::CreateAsset(CAsset& asset, CTransactionRef& tx, std::string& asset std::vector AllAssets = chain().getAllAssets(); for(auto const& x : AllAssets){ - if(chain().isequals(x.getName() , assetname)){ + if(chain().isequals(x.getAssetName() , assetname)){ strFailReason = "Asset name already reserved"; return false; } @@ -3325,7 +3325,7 @@ bool CWallet::CreateAsset(CAsset& asset, CTransactionRef& tx, std::string& asset return false; } - if(chain().isequals(x.getName() , shortname)){ + if(chain().isequals(x.getAssetName() , shortname)){ strFailReason = "Code already reserved as another asset's name'"; return false; } @@ -3475,36 +3475,40 @@ bool CWallet::CreateTransactionInternal( txNew.nLockTime = GetLocktimeForNewTransaction(chain(), GetLastBlockHash(), GetLastBlockHeight()); txNew.nVersion=chain().getTxVersion(); - uint8_t vers = datar.GetVersion(); - switch (vers) { - case OUTPUT_DATA:{ - OUTPUT_PTR out0 = MAKE_OUTPUT(); - CTxData *s = (CTxData*) &datar; - out0->nType = s->nType; - out0->vData = s->vData; - txNew.vdata.push_back(out0); - break; - } - case OUTPUT_CONTRACT:{ - OUTPUT_PTR out0 = MAKE_OUTPUT(); - CContract *s = (CContract*) &datar; + if(fNewAsset){ - if(chain().existsContract(s->asset_name)){ - error = _("Contract name already reserved"); - return false; + uint8_t vers = datar.GetVersion(); + switch (vers) { + case OUTPUT_DATA:{ + OUTPUT_PTR out0 = MAKE_OUTPUT(); + CTxData *s = (CTxData*) &datar; + out0->nType = s->nType; + out0->vData = s->vData; + txNew.vdata.push_back(out0); + break; } + case OUTPUT_CONTRACT:{ + OUTPUT_PTR out0 = MAKE_OUTPUT(); + CContract *s = (CContract*) &datar; - out0->contract_url = s->contract_url; - out0->website_url = s->website_url; - out0->description = s->description; - out0->scriptcode = s->scriptcode; - out0->asset_symbol = s->asset_symbol; - out0->asset_name = s->asset_name; - out0->sIssuingaddress = s->sIssuingaddress; - out0->vchContractSig = s->vchContractSig; - txNew.vdata.push_back(out0); - break; + if(chain().existsContract(s->asset_name)){ + error = _("Contract name already reserved"); + return false; + } + + out0->contract_url = s->contract_url; + out0->website_url = s->website_url; + out0->description = s->description; + out0->scriptcode = s->scriptcode; + out0->asset_symbol = s->asset_symbol; + out0->asset_name = s->asset_name; + out0->sIssuingaddress = s->sIssuingaddress; + out0->vchContractSig = s->vchContractSig; + txNew.vdata.push_back(out0); + break; + } } + } FeeCalculation feeCalc; CAmount nFeeNeeded; @@ -3600,6 +3604,7 @@ bool CWallet::CreateTransactionInternal( if (!coin_selection_params.m_subtract_fee_outputs) { coin_selection_params.tx_noinputs_size = 11; // Static vsize overhead + outputs vsize. 4 nVersion, 4 nLocktime, 1 input count, 1 output count, 1 witness overhead (dummy, flag, stack size) } + for (const auto& recipient : vecSend) { CTxOutAsset txout(fNewAsset ? recipient.OutAsset : recipient.asset, fNewAsset ? recipient.OutAmount : recipient.nAmount, recipient.scriptPubKey);