diff --git a/src/assets/assets.cpp b/src/assets/assets.cpp index 841d8948d7..fe062ab0c4 100644 --- a/src/assets/assets.cpp +++ b/src/assets/assets.cpp @@ -1700,13 +1700,13 @@ bool CheckIssueBurnTx(const CTxOut& txOut, const AssetType& type, const int numb CAmount burnAmount = 0; std::string burnAddress = ""; - if (type == AssetType::SUB) { + if (type == SUB) { burnAmount = GetIssueSubAssetBurnAmount(); burnAddress = Params().IssueSubAssetBurnAddress(); - } else if (type == AssetType::ROOT) { + } else if (type == ROOT) { burnAmount = GetIssueAssetBurnAmount(); burnAddress = Params().IssueAssetBurnAddress(); - } else if (type == AssetType::UNIQUE) { + } else if (type == UNIQUE) { burnAmount = GetIssueUniqueAssetBurnAmount(); burnAddress = Params().IssueUniqueAssetBurnAddress(); } else { @@ -2173,44 +2173,54 @@ CAmount GetIssueUniqueAssetBurnAmount() return Params().IssueUniqueAssetBurnAmount(); } +CAmount GetBurnAmount(const int nType) +{ + return GetBurnAmount((AssetType(nType))); +} + CAmount GetBurnAmount(const AssetType type) { switch (type) { - case AssetType::ROOT: + case ROOT: return GetIssueAssetBurnAmount(); - case AssetType::SUB: + case SUB: return GetIssueSubAssetBurnAmount(); - case AssetType::MSGCHANNEL: + case MSGCHANNEL: return 0; - case AssetType::OWNER: + case OWNER: return 0; - case AssetType::UNIQUE: + case UNIQUE: return GetIssueUniqueAssetBurnAmount(); - case AssetType::VOTE: + case VOTE: return 0; - case AssetType::REISSUE: + case REISSUE: return GetReissueAssetBurnAmount(); default: return 0; } } +std::string GetBurnAddress(const int nType) +{ + return GetBurnAddress((AssetType(nType))); +} + std::string GetBurnAddress(const AssetType type) { switch (type) { - case AssetType::ROOT: + case ROOT: return Params().IssueAssetBurnAddress(); - case AssetType::SUB: + case SUB: return Params().IssueSubAssetBurnAddress(); - case AssetType::MSGCHANNEL: + case MSGCHANNEL: return ""; - case AssetType::OWNER: + case OWNER: return ""; - case AssetType::UNIQUE: + case UNIQUE: return Params().IssueUniqueAssetBurnAddress(); - case AssetType::VOTE: + case VOTE: return ""; - case AssetType::REISSUE: + case REISSUE: return Params().ReissueAssetBurnAddress(); default: return ""; diff --git a/src/assets/assets.h b/src/assets/assets.h index f095d30368..c3882904fb 100644 --- a/src/assets/assets.h +++ b/src/assets/assets.h @@ -308,7 +308,9 @@ CAmount GetReissueAssetBurnAmount(); CAmount GetIssueSubAssetBurnAmount(); CAmount GetIssueUniqueAssetBurnAmount(); CAmount GetBurnAmount(const AssetType type); +CAmount GetBurnAmount(const int nType); std::string GetBurnAddress(const AssetType type); +std::string GetBurnAddress(const int nType); bool IsAssetNameValid(const std::string& name); bool IsAssetNameValid(const std::string& name, AssetType& assetType); diff --git a/src/assets/assettypes.h b/src/assets/assettypes.h index 54266832c0..396842f1a3 100644 --- a/src/assets/assettypes.h +++ b/src/assets/assettypes.h @@ -17,37 +17,30 @@ class CAssetsCache; enum AssetType { - ROOT, - OWNER, - SUB, - UNIQUE, - MSGCHANNEL, - VOTE, - INVALID, - REISSUE + ROOT = 0, + SUB = 1, + UNIQUE = 2, + OWNER = 3, + MSGCHANNEL = 4, + VOTE = 5, + REISSUE = 6, + INVALID = 7 }; std::string PrintAssetType(AssetType& assetType) { switch (assetType) { case ROOT: return "ROOT"; - case OWNER: return "OWNER"; case SUB: return "SUB"; case UNIQUE: return "UNIQUE"; + case OWNER: return "OWNER"; case MSGCHANNEL: return "MSGCHANNEL"; case VOTE: return "VOTE"; - case INVALID: return "INVALID"; case REISSUE: return "REISSUE"; + case INVALID: return "INVALID"; default: return "UNKNOWN"; } } -enum IssueAssetType -{ - ISSUE_ROOT = 0, - ISSUE_SUB = 1, - ISSUE_UNIQUE = 2 -}; - class CNewAsset { public: std::string strName; // MAX 31 Bytes diff --git a/src/qt/createassetdialog.cpp b/src/qt/createassetdialog.cpp index c2b1704142..2d53f6b982 100644 --- a/src/qt/createassetdialog.cpp +++ b/src/qt/createassetdialog.cpp @@ -76,9 +76,9 @@ void CreateAssetDialog::setUpValues() QStringList list; list.append(tr("Main Asset")); list.append(tr("Sub Asset")); -// list.append(tr("Unique Asset")); + list.append(tr("Unique Asset")); ui->assetType->addItems(list); - type = ISSUE_ROOT; + type = ROOT; ui->assetTypeLabel->setText(tr("Asset Type") + ":"); // Setup the asset list @@ -161,13 +161,13 @@ void CreateAssetDialog::CheckFormState() AssetType assetType; bool assetNameValid = IsAssetNameValid(name.toStdString(), assetType); - if (assetNameValid && assetType == ROOT && type != ISSUE_ROOT) + if (assetNameValid && assetType == ROOT && type != ROOT) return; - if (assetNameValid && assetType == SUB && type != ISSUE_SUB) + if (assetNameValid && assetType == SUB && type != SUB) return; - if (assetNameValid && assetType == UNIQUE && type != ISSUE_UNIQUE) + if (assetNameValid && assetType == UNIQUE && type != UNIQUE) return; if (!(IsValidDestination(dest) || ui->addressText->text().isEmpty()) && assetNameValid) { @@ -237,7 +237,7 @@ void CreateAssetDialog::checkAvailabilityClicked() void CreateAssetDialog::onNameChanged(QString name) { // Update the displayed name to uppercase if the type only accepts uppercase - name = name.toUpper(); + name = type == UNIQUE ? name : name.toUpper(); UpdateAssetNameToUpper(); QString assetName = name; @@ -252,7 +252,7 @@ void CreateAssetDialog::onNameChanged(QString name) return; } - if (type == ISSUE_ROOT) { + if (type == ROOT) { if (name.size() < 3) { ui->nameText->setStyleSheet("border: 1px solid red"); showMessage("Invalid: Minimum of 3 character in length"); @@ -269,7 +269,7 @@ void CreateAssetDialog::onNameChanged(QString name) ui->nameText->setStyleSheet("border: 1px solid red"); showMessage("Invalid: Max Size 30 Characters. Allowed characters include: A-Z 0-9 . _"); } - } else if (type == ISSUE_SUB || type == ISSUE_UNIQUE) { + } else if (type == SUB || type == UNIQUE) { if (name.size() == 0) { hideMessage(); ui->availabilityButton->setDisabled(true); @@ -288,7 +288,7 @@ void CreateAssetDialog::onNameChanged(QString name) } // Set the assetName - updatePresentedAssetName(format.arg(type == ISSUE_ROOT ? "" : ui->assetList->currentText(), identifier, name)); + updatePresentedAssetName(format.arg(type == ROOT ? "" : ui->assetList->currentText(), identifier, name)); checkedAvailablity = false; disableCreateButton(); @@ -346,10 +346,10 @@ void CreateAssetDialog::onCreateAssetClicked() QStringList formatted; // generate bold amount string - QString amount = "" + QString::fromStdString(ValueFromAmountString(GetIssueAssetBurnAmount(), 8)) + " RVN"; + QString amount = "" + QString::fromStdString(ValueFromAmountString(GetBurnAmount(type), 8)) + " RVN"; amount.append(""); // generate monospace address string - QString addressburn = "" + QString::fromStdString(Params().IssueAssetBurnAddress()); + QString addressburn = "" + QString::fromStdString(GetBurnAddress(type)); addressburn.append(""); QString recipientElement1; @@ -410,7 +410,7 @@ void CreateAssetDialog::onCreateAssetClicked() // Create the transaction and broadcast it std::string txid; if (!SendAssetTransaction(model->getWallet(), tx, reservekey, error, txid)) { - showMessage("Invalid: " + QString::fromStdString(error.second)); + showMessage(tr("Invalid: ") + QString::fromStdString(error.second)); } else { QMessageBox msgBox; QPushButton *copyButton = msgBox.addButton(tr("Copy"), QMessageBox::ActionRole); @@ -478,6 +478,11 @@ void CreateAssetDialog::onAssetTypeActivated(int index) // Update the selected type type = index; + // Make sure the type is only the the supported issue types + if(!(type == ROOT || type == SUB || type == UNIQUE)) + type = ROOT; + + // Get the identifier for the asset type QString identifier = GetSpecialCharacter(); @@ -490,7 +495,7 @@ void CreateAssetDialog::onAssetTypeActivated(int index) UpdateAssetNameMaxSize(); // Set assetName - updatePresentedAssetName(format.arg(type == ISSUE_ROOT ? "" : ui->assetList->currentText(), identifier, ui->nameText->text())); + updatePresentedAssetName(format.arg(type == ROOT ? "" : ui->assetList->currentText(), identifier, ui->nameText->text())); if (ui->nameText->text().size()) ui->availabilityButton->setDisabled(false); @@ -507,7 +512,7 @@ void CreateAssetDialog::onAssetListActivated(int index) UpdateAssetNameMaxSize(); // Set assetName - updatePresentedAssetName(format.arg(type == ISSUE_ROOT ? "" : ui->assetList->currentText(), identifier, ui->nameText->text())); + updatePresentedAssetName(format.arg(type == ROOT ? "" : ui->assetList->currentText(), identifier, ui->nameText->text())); if (ui->nameText->text().size()) ui->availabilityButton->setDisabled(false); @@ -523,9 +528,9 @@ void CreateAssetDialog::updatePresentedAssetName(QString name) QString CreateAssetDialog::GetSpecialCharacter() { - if (type == ISSUE_SUB) + if (type == SUB) return "/"; - else if (type == ISSUE_UNIQUE) + else if (type == UNIQUE) return "#"; return ""; @@ -533,27 +538,27 @@ QString CreateAssetDialog::GetSpecialCharacter() QString CreateAssetDialog::GetAssetName() { - if (type == ISSUE_ROOT) + if (type == ROOT) return ui->nameText->text(); - else if (type == ISSUE_SUB) + else if (type == SUB) return ui->assetList->currentText() + "/" + ui->nameText->text(); - else if (type == ISSUE_UNIQUE) + else if (type == UNIQUE) return ui->assetList->currentText() + "#" + ui->nameText->text(); return ""; } void CreateAssetDialog::UpdateAssetNameMaxSize() { - if (type == ISSUE_ROOT) { + if (type == ROOT) { ui->nameText->setMaxLength(30); - } else if (type == ISSUE_SUB || type == ISSUE_UNIQUE) { + } else if (type == SUB || type == UNIQUE) { ui->nameText->setMaxLength(30 - (ui->assetList->currentText().size() + 1)); } } void CreateAssetDialog::UpdateAssetNameToUpper() { - if (type == ISSUE_ROOT || type == ISSUE_SUB) { + if (type == ROOT || type == SUB) { ui->nameText->setText(ui->nameText->text().toUpper()); } } \ No newline at end of file diff --git a/src/script/standard.h b/src/script/standard.h index f7e692b41f..8babd59b8e 100644 --- a/src/script/standard.h +++ b/src/script/standard.h @@ -56,20 +56,20 @@ static const unsigned int MANDATORY_SCRIPT_VERIFY_FLAGS = SCRIPT_VERIFY_P2SH; enum txnouttype { - TX_NONSTANDARD, + TX_NONSTANDARD = 0, // 'standard' transaction types: - TX_PUBKEY, - TX_PUBKEYHASH, - TX_SCRIPTHASH, - TX_MULTISIG, - TX_NULL_DATA, //!< unspendable OP_RETURN script that carries data - TX_WITNESS_V0_SCRIPTHASH, - TX_WITNESS_V0_KEYHASH, + TX_PUBKEY = 1, + TX_PUBKEYHASH = 2, + TX_SCRIPTHASH = 3, + TX_MULTISIG = 4, + TX_NULL_DATA = 5, //!< unspendable OP_RETURN script that carries data + TX_WITNESS_V0_SCRIPTHASH = 6, + TX_WITNESS_V0_KEYHASH = 7, /** RVN START */ - TX_NEW_ASSET, - TX_REISSUE_ASSET, - TX_TRANSFER_ASSET, - TX_RESERVED_ASSET + TX_NEW_ASSET = 8, + TX_REISSUE_ASSET = 9, + TX_TRANSFER_ASSET = 10, + TX_RESERVED_ASSET = 11 /** RVN END */ };