Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/assets/assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,10 +846,7 @@ bool CAssetsCache::TrySpendCoin(const COutPoint& out, const CTxOut& txOut)

// Update the cache so we can save to database
vSpentAssets.push_back(spend);
} else {
return error("%s : ERROR Failed to find current assets address amount. Asset %s: , Address : %s", __func__, assetName, address);
}

} else {
return error("%s : ERROR Failed to get asset from the OutPoint: %s", __func__, out.ToString());
}
Expand Down Expand Up @@ -1952,12 +1949,17 @@ void GetAssetData(const CScript& script, CAssetOutputEntry& data)
}
}

void GetAllOwnedAssets(std::vector<std::string>& names)
void GetAllOwnedAssets(CWallet* pwallet, std::vector<std::string>& names)
{
for (auto owned : passets->mapMyUnspentAssets) {
if (IsAssetNameAnOwner(owned.first)) {
names.emplace_back(owned.first);
}
if(!pwallet)
return;

std::map<std::string, std::vector<COutput> > mapAssets;
pwallet->AvailableAssets(mapAssets);

for (auto item : mapAssets) {
if (IsAssetNameAnOwner(item.first))
names.emplace_back(item.first);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/assets/assets.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ bool IsScriptTransferAsset(const CScript& scriptPubKey);

bool IsNewOwnerTxValid(const CTransaction& tx, const std::string& assetName, const std::string& address, std::string& errorMsg);

void GetAllOwnedAssets(std::vector<std::string>& names);
void GetAllOwnedAssets(CWallet* pwallet, std::vector<std::string>& names);
void GetAllMyAssets(std::vector<std::string>& names);

void UpdatePossibleAssets();
Expand Down
7 changes: 7 additions & 0 deletions src/assets/assettypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ enum AssetType
REISSUE
};

enum IssueAssetType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these be moved somewhere into qt codebase since they only seem to apply there?

{
ISSUE_ROOT = 0,
ISSUE_SUB = 1,
ISSUE_UNIQUE = 2
};

class CNewAsset {
public:
std::string strName; // MAX 31 Bytes
Expand Down
187 changes: 172 additions & 15 deletions src/qt/createassetdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ CreateAssetDialog::CreateAssetDialog(const PlatformStyle *_platformStyle, QWidge
connect(ui->unitBox, SIGNAL(valueChanged(int)), this, SLOT(onUnitChanged(int)));
connect(ui->rvnChangeBox, SIGNAL(clicked()), this, SLOT(onCustomAddressClicked()));
connect(ui->changeAddressText, SIGNAL(textChanged(QString)), this, SLOT(onChangeAddressChanged(QString)));
connect(ui->assetType, SIGNAL(activated(int)), this, SLOT(onAssetTypeActivated(int)));
connect(ui->assetList, SIGNAL(activated(int)), this, SLOT(onAssetListActivated(int)));

// Setup the default values
setUpValues();

format = "%1<font color=green>%2%3</font>";
}

CreateAssetDialog::~CreateAssetDialog()
Expand All @@ -67,6 +71,30 @@ void CreateAssetDialog::setUpValues()
CheckFormState();

ui->unitExampleLabel->setStyleSheet("font-weight: bold");

// Setup the asset types
QStringList list;
list.append(tr("Main Asset"));
list.append(tr("Sub Asset"));
// list.append(tr("Unique Asset"));
ui->assetType->addItems(list);
type = ISSUE_ROOT;
ui->assetTypeLabel->setText(tr("Asset Type") + ":");

// Setup the asset list
ui->assetList->hide();
std::vector<std::string> names;
GetAllOwnedAssets(model->getWallet(), names);
for (auto item : names) {
std::string name = QString::fromStdString(item).split("!").first().toStdString();
if (name.size() != 30)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this check for? I think we could have a 30-char asset name (plus !)..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. So, I am splitting the ! off of these assets names. Then after that if they are < 30 characters. They won't show up because the asset name is already at the limit

ui->assetList->addItem(QString::fromStdString(name));
}
ui->assetFullName->setTextFormat(Qt::RichText);
ui->assetFullName->setStyleSheet("font-weight: bold");

ui->assetType->setStyleSheet("font-weight: bold");

}

void CreateAssetDialog::toggleIPFSText()
Expand Down Expand Up @@ -129,8 +157,19 @@ void CreateAssetDialog::CheckFormState()

const CTxDestination dest = DecodeDestination(ui->addressText->text().toStdString());

QString name = GetAssetName();

AssetType assetType;
bool assetNameValid = IsAssetNameValid(ui->nameText->text().toStdString(), assetType) && assetType == AssetType::ROOT;
bool assetNameValid = IsAssetNameValid(name.toStdString(), assetType);
if (assetNameValid && assetType == ROOT && type != ISSUE_ROOT)
return;

if (assetNameValid && assetType == SUB && type != ISSUE_SUB)
return;

if (assetNameValid && assetType == UNIQUE && type != ISSUE_UNIQUE)
return;

if (!(IsValidDestination(dest) || ui->addressText->text().isEmpty()) && assetNameValid) {
ui->addressText->setStyleSheet("border: 1px solid red");
showMessage("Warning: Invalid Raven address");
Expand Down Expand Up @@ -170,7 +209,7 @@ void CreateAssetDialog::ipfsStateChanged()

void CreateAssetDialog::checkAvailabilityClicked()
{
QString name = ui->nameText->text();
QString name = GetAssetName();

LOCK(cs_main);
if (passets) {
Expand All @@ -197,26 +236,60 @@ void CreateAssetDialog::checkAvailabilityClicked()

void CreateAssetDialog::onNameChanged(QString name)
{
// Update the displayed name to uppercase if the type only accepts uppercase
name = name.toUpper();
UpdateAssetNameToUpper();

QString assetName = name;

// Get the identifier for the asset type
QString identifier = GetSpecialCharacter();

if (name.size() == 0) {
hideMessage();
ui->availabilityButton->setDisabled(true);
updatePresentedAssetName(name);
return;
}

if (name.size() < 3) {
ui->nameText->setStyleSheet("border: 1px solid red");
showMessage("Invalid: Minimum of 3 character in length");
return;
}
if (type == ISSUE_ROOT) {
if (name.size() < 3) {
ui->nameText->setStyleSheet("border: 1px solid red");
showMessage("Invalid: Minimum of 3 character in length");
ui->availabilityButton->setDisabled(true);
return;
}

AssetType assetType;
if (!IsAssetNameValid(name.toStdString(), assetType) || assetType != AssetType::ROOT) {
ui->nameText->setStyleSheet("border: 1px solid red");
showMessage("Invalid: Max Size 30 Characters. Allowed characters include: A-Z 0-9 . _");
} else {
hideMessage();
ui->availabilityButton->setDisabled(false);
AssetType assetType;
if (IsAssetNameValid(name.toStdString(), assetType) && assetType == ROOT) {
hideMessage();
ui->availabilityButton->setDisabled(false);

} else {
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) {
if (name.size() == 0) {
hideMessage();
ui->availabilityButton->setDisabled(true);
return;
}

AssetType assetType;
if (IsAssetNameValid(ui->assetList->currentText().toStdString() + identifier.toStdString() + name.toStdString(), assetType) && (assetType == SUB || assetType == UNIQUE)) {
hideMessage();
ui->availabilityButton->setDisabled(false);
} else {
ui->nameText->setStyleSheet("border: 1px solid red");
showMessage("Invalid: Max Size 30 Characters. Allowed characters include: A-Z 0-9 . _");
ui->availabilityButton->setDisabled(true);
}
}

// Set the assetName
updatePresentedAssetName(format.arg(type == ISSUE_ROOT ? "" : ui->assetList->currentText(), identifier, name));

checkedAvailablity = false;
disableCreateButton();
}
Expand Down Expand Up @@ -244,8 +317,8 @@ void CreateAssetDialog::onCreateAssetClicked()
} else {
address = ui->addressText->text();
}
QString name = GetAssetName();

QString name = ui->nameText->text();
CAmount quantity = ui->quantitySpinBox->value() * COIN;
int units = ui->unitBox->value();
bool reissuable = ui->reissuableBox->isChecked();
Expand Down Expand Up @@ -398,4 +471,88 @@ void CreateAssetDialog::onCustomAddressClicked()
void CreateAssetDialog::onChangeAddressChanged(QString changeAddress)
{
CheckFormState();
}

void CreateAssetDialog::onAssetTypeActivated(int index)
{
// Update the selected type
type = index;

// Get the identifier for the asset type
QString identifier = GetSpecialCharacter();

if (index != 0) {
ui->assetList->show();
} else {
ui->assetList->hide();
}

UpdateAssetNameMaxSize();

// Set assetName
updatePresentedAssetName(format.arg(type == ISSUE_ROOT ? "" : ui->assetList->currentText(), identifier, ui->nameText->text()));

if (ui->nameText->text().size())
ui->availabilityButton->setDisabled(false);
else
ui->availabilityButton->setDisabled(true);
ui->createAssetButton->setDisabled(true);
}

void CreateAssetDialog::onAssetListActivated(int index)
{
// Get the identifier for the asset type
QString identifier = GetSpecialCharacter();

UpdateAssetNameMaxSize();

// Set assetName
updatePresentedAssetName(format.arg(type == ISSUE_ROOT ? "" : ui->assetList->currentText(), identifier, ui->nameText->text()));

if (ui->nameText->text().size())
ui->availabilityButton->setDisabled(false);
else
ui->availabilityButton->setDisabled(true);
ui->createAssetButton->setDisabled(true);
}

void CreateAssetDialog::updatePresentedAssetName(QString name)
{
ui->assetFullName->setText(name);
}

QString CreateAssetDialog::GetSpecialCharacter()
{
if (type == ISSUE_SUB)
return "/";
else if (type == ISSUE_UNIQUE)
return "#";

return "";
}

QString CreateAssetDialog::GetAssetName()
{
if (type == ISSUE_ROOT)
return ui->nameText->text();
else if (type == ISSUE_SUB)
return ui->assetList->currentText() + "/" + ui->nameText->text();
else if (type == ISSUE_UNIQUE)
return ui->assetList->currentText() + "#" + ui->nameText->text();
}

void CreateAssetDialog::UpdateAssetNameMaxSize()
{
if (type == ISSUE_ROOT) {
ui->nameText->setMaxLength(30);
} else if (type == ISSUE_SUB || type == ISSUE_UNIQUE) {
ui->nameText->setMaxLength(30 - (ui->assetList->currentText().size() + 1));
}
}

void CreateAssetDialog::UpdateAssetNameToUpper()
{
if (type == ISSUE_ROOT || type == ISSUE_SUB) {
ui->nameText->setText(ui->nameText->text().toUpper());
}
}
11 changes: 10 additions & 1 deletion src/qt/createassetdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ Q_OBJECT
explicit CreateAssetDialog(const PlatformStyle *platformStyle, QWidget *parent = 0, WalletModel *model = NULL);
~CreateAssetDialog();

int type;
QString format;

private:
Ui::CreateAssetDialog *ui;
WalletModel *model;
const PlatformStyle *platformStyle;

bool checkedAvailablity = false;


void toggleIPFSText();
void setUpValues();
void showMessage(QString string);
Expand All @@ -44,6 +46,11 @@ Q_OBJECT
void disableCreateButton();
void enableCreateButton();
void CheckFormState();
void updatePresentedAssetName(QString name);
QString GetSpecialCharacter();
QString GetAssetName();
void UpdateAssetNameMaxSize();
void UpdateAssetNameToUpper();

private Q_SLOTS:
void ipfsStateChanged();
Expand All @@ -56,6 +63,8 @@ private Q_SLOTS:
void onUnitChanged(int value);
void onCustomAddressClicked();
void onChangeAddressChanged(QString changeAddress);
void onAssetTypeActivated(int index);
void onAssetListActivated(int index);
};

#endif // RAVEN_QT_CREATEASSETDIALOG_H
Loading