Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockMechanic committed Jul 19, 2022
1 parent 2c644bc commit 9d9a52f
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 78 deletions.
4 changes: 2 additions & 2 deletions src/assetdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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__);
Expand Down
4 changes: 2 additions & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
10 changes: 0 additions & 10 deletions src/primitives/asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
5 changes: 1 addition & 4 deletions src/primitives/asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/qt/sendcoinsentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
}

Expand Down
47 changes: 25 additions & 22 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<unsigned char> hashBytes;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<uint8_t> hashBytes;
Expand Down Expand Up @@ -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<unsigned char> hashBytes;
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <amount.h>
#include <assetdb.h>

#include <core_io.h>
#include <interfaces/chain.h>
#include <key_io.h>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
61 changes: 33 additions & 28 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3315,7 +3315,7 @@ bool CWallet::CreateAsset(CAsset& asset, CTransactionRef& tx, std::string& asset
std::vector<CAsset> 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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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<CTxData> out0 = MAKE_OUTPUT<CTxData>();
CTxData *s = (CTxData*) &datar;
out0->nType = s->nType;
out0->vData = s->vData;
txNew.vdata.push_back(out0);
break;
}
case OUTPUT_CONTRACT:{
OUTPUT_PTR<CContract> out0 = MAKE_OUTPUT<CContract>();
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<CTxData> out0 = MAKE_OUTPUT<CTxData>();
CTxData *s = (CTxData*) &datar;
out0->nType = s->nType;
out0->vData = s->vData;
txNew.vdata.push_back(out0);
break;
}
case OUTPUT_CONTRACT:{
OUTPUT_PTR<CContract> out0 = MAKE_OUTPUT<CContract>();
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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9d9a52f

Please sign in to comment.