Skip to content

Commit

Permalink
Fixes various (#323)
Browse files Browse the repository at this point in the history
* fix future unique asset tx

* fix protx register_submit

* remove debug line

---------

Co-authored-by: nandofw <[email protected]>
  • Loading branch information
nandofw and nandofw authored Sep 23, 2023
1 parent 8892489 commit f9fcc11
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/qt/assetsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ void AssetsDialog::Asset_details_clicked() {
msgBox.setWindowTitle(tr("Details for asset: %1").arg(QString::fromStdString(asset.name)));
msgBox.setText(QString::fromStdString(json.write(2)));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setTextInteractionFlags(Qt::TextSelectableByMouse);
msgBox.exec();
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/qt/createassetsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <qt/addresstablemodel.h>
#include <qt/bitcoinunits.h>
#include <qt/clientmodel.h>
#include <txmempool.h>
#include <qt/coincontroldialog.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>
Expand Down Expand Up @@ -354,6 +355,7 @@ void CreateAssetsDialog::createAsset() {
return;
}
model->wallet().commitTransaction(newTx, {}, {});
clear();
}

void CreateAssetsDialog::onUniqueChanged() {
Expand Down Expand Up @@ -391,6 +393,11 @@ bool CreateAssetsDialog::validateInputs() {
ui->assetnameText->setValid(false);
}
}
//check on mempool if asset already exist
if (mempool.CheckForNewAssetConflict(assetname)) {
retval = false;
ui->assetnameText->setValid(false);
}

std::string ipfshash = ui->ipfsText->text().toStdString();
if (ipfshash.length() > 128) {
Expand Down Expand Up @@ -741,6 +748,10 @@ void CreateAssetsDialog::checkAvailabilityClicked()
ui->assetnameText->setValid(false);
}
}
// check if asset already exist on mempool
if (mempool.CheckForNewAssetConflict(assetname)) {
ui->assetnameText->setValid(false);
}
}

CreateAssetConfirmationDialog::CreateAssetConfirmationDialog(const QString &title, const QString &text, int _secDelay,
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/rpcevo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ UniValue protx(const JSONRPCRequest &request) {
#ifdef ENABLE_WALLET
if (command == "protxregister" || command == "protxregister_fund" || command == "protxregister_prepare") {
return protx_register(new_request);
} else if (command == "protxregisterkoubmit") {
} else if (command == "protxregister_submit") {
return protx_register_submit(new_request);
} else if (command == "protxupdate_service") {
return protx_update_service(new_request);
Expand Down
27 changes: 23 additions & 4 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ void CWallet::LoadToWallet(CWalletTx &wtxIn) {
}
}
}
if (wtx.tx->nType == TRANSACTION_NEW_ASSET){
if (wtx.tx->nType == TRANSACTION_NEW_ASSET && !wtx.isAbandoned()){
CNewAssetTx assetTx;
if (GetTxPayload(wtx.tx->vExtraPayload, assetTx))
mapAsset.emplace(hash, std::make_pair(assetTx.name, assetTx.ownerAddress));
Expand Down Expand Up @@ -4180,6 +4180,9 @@ bool CWallet::CreateTransaction(const std::vector <CRecipient> &vecSend, CTransa
bool fHasAsset = false;
std::map <std::string, CAmount> mapAssetValue;
std::map <std::string, std::vector<std::pair<CTxDestination, CAmount>>> mapUniqueValue;
std::pair<CTxDestination, std::string> toLock;
bool lockUnique = false;
CScript lockUniquePubKey;
CReserveKey reservekey(this);
int nChangePosRequest = nChangePosInOut;
unsigned int nSubtractFeeFromAmount = 0;
Expand All @@ -4206,6 +4209,10 @@ bool CWallet::CreateTransaction(const std::vector <CRecipient> &vecSend, CTransa
mapUniqueValue[assetTransfer.assetId] = tmp;
}
mapUniqueValue[assetTransfer.assetId].push_back(std::make_pair(dest,assetTransfer.nAmount));
if (fpp && recipient.scriptPubKey == fpp->futureRecScript) {
toLock = std::make_pair(dest, assetTransfer.assetId);
lockUnique = true;
}
}
}
}
Expand Down Expand Up @@ -4393,7 +4400,7 @@ bool CWallet::CreateTransaction(const std::vector <CRecipient> &vecSend, CTransa
strFailReason = _("Transaction amount too small");
return false;
}
if (fpp && recipient.scriptPubKey == fpp->futureRecScript) {
if (fpp && !lockUnique && recipient.scriptPubKey == fpp->futureRecScript) {
ftx.lockOutputIndex = txNew.vout.size();
CDataStream ds(SER_NETWORK, PROTOCOL_VERSION);
ds << ftx;
Expand Down Expand Up @@ -4470,6 +4477,7 @@ bool CWallet::CreateTransaction(const std::vector <CRecipient> &vecSend, CTransa
}

//build the outputs
bool toLockFound = false;
for (auto asset : mapUniqueIds){
for (auto dst: mapUniqueValue.at(asset.first)) {
CAmount vToSend = dst.second;
Expand Down Expand Up @@ -4497,7 +4505,16 @@ bool CWallet::CreateTransaction(const std::vector <CRecipient> &vecSend, CTransa
assetTransfer.BuildAssetTransaction(scriptPubKey);
CTxOut txout( 0, scriptPubKey);
txNew.vout.push_back(txout);

if (!toLockFound && fpp && lockUnique && toLock.first == dst.first && toLock.second == asset.first) {
toLockFound = true;
//copy the scriptPubKey to update the lockOutputIndex later on
lockUniquePubKey = scriptPubKey;
ftx.lockOutputIndex = txNew.vout.size();
CDataStream ds(SER_NETWORK, PROTOCOL_VERSION);
ds << ftx;
txNew.vExtraPayload.assign(ds.begin(), ds.end());
nExtraPayloadSize = txNew.vExtraPayload.size();
}
if (change) {
entry.first = entry.first + (amount / COIN);
mapUniqueIds.at(asset.first).push_back(entry);
Expand Down Expand Up @@ -4730,7 +4747,9 @@ bool CWallet::CreateTransaction(const std::vector <CRecipient> &vecSend, CTransa
ftx.lockOutputIndex = 0;
// this loop needed because vout may be in a different order then recipient list
for (const auto &txOut: txNew.vout) {
if (txOut.scriptPubKey == fpp->futureRecScript)
if (!lockUnique && txOut.scriptPubKey == fpp->futureRecScript)
break;
if (lockUnique && txOut.scriptPubKey == lockUniquePubKey)
break;
ftx.lockOutputIndex++;
}
Expand Down

0 comments on commit f9fcc11

Please sign in to comment.