Skip to content

Commit

Permalink
Add additional checks for memo
Browse files Browse the repository at this point in the history
  • Loading branch information
levoncrypto committed Nov 11, 2024
1 parent 3e7f4ec commit fd6a779
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/qt/sendcoinsentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "optionsmodel.h"
#include "platformstyle.h"
#include "walletmodel.h"
#include "../spark/sparkwallet.h"
#include "../wallet/wallet.h"

#include <QApplication>
Expand Down Expand Up @@ -70,15 +71,22 @@ SendCoinsEntry::~SendCoinsEntry()

void SendCoinsEntry::on_MemoTextChanged(const QString &text)
{
int maxLength = 256;
const spark::Params* params = spark::Params::get_default();
int maxLength = params->get_memo_bytes();
bool isOverLimit = text.length() > maxLength;

if (isOverLimit) {
ui->messageWarning->setText("Message exceeds character 256 character limit");
ui->messageWarning->setText(QString("Message exceeds %1 bytes limit").arg(maxLength));
ui->messageWarning->setVisible(true);
ui->messageTextLabel->setStyleSheet("border: 1px solid red;");
ui->iconMessageWarning->setVisible(true);
} else {
QString sanitized = text;
sanitized.remove(QRegExp("[\\x00-\\x1F\\x7F]"));
if (sanitized != text) {
ui->messageTextLabel->setText(sanitized);
return;
}
ui->messageWarning->clear();
ui->messageWarning->setVisible(false);
ui->messageTextLabel->setStyleSheet("");
Expand Down
10 changes: 9 additions & 1 deletion src/spark/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,15 @@ class CSparkOutputTx
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(address);
READWRITE(amount);
READWRITE(memo);
if (ser_action.ForRead()) {
if (!s.empty()) {
READWRITE(memo);
} else {
memo = "";
}
} else {
READWRITE(memo);
}
}
};

Expand Down
4 changes: 4 additions & 0 deletions src/spark/sparkwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,10 @@ std::vector<CRecipient> CSparkWallet::CreateSparkMintRecipients(
unsigned char network = spark::GetNetworkType();
std::string addr = outputs[i].address.encode(network);
std::string memo = outputs[i].memo;
const std::size_t max_memo_size = outputs[i].address.get_params()->get_memo_bytes();
if (memo.length() > max_memo_size) {
throw std::runtime_error(strprintf("Memo exceeds maximum length of %d bytes", max_memo_size));
}
CRecipient recipient = {script, CAmount(outputs[i].v), false, addr, memo};
results.emplace_back(recipient);
}
Expand Down

0 comments on commit fd6a779

Please sign in to comment.