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 6546d17
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion 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,7 +71,8 @@ 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) {
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("Memo exceeds maximum length");
}
CRecipient recipient = {script, CAmount(outputs[i].v), false, addr, memo};
results.emplace_back(recipient);
}
Expand Down

0 comments on commit 6546d17

Please sign in to comment.