From 30543942d855719418c3c2cc24b2408228d31098 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 24 Mar 2022 14:36:16 +0100 Subject: [PATCH] check for valid min/max length of memeo before executing transaction --- backend/src/graphql/resolver/TransactionResolver.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index ed9528b48..0ff43486c 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -34,6 +34,9 @@ import { virtualLinkTransaction, virtualDecayTransaction } from '@/util/virtualT import Decimal from 'decimal.js-light' import { calculateDecay } from '@/util/decay' +const MEMO_MAX_CHARS = 255 +const MEMO_MIN_CHARS = 5 + export const executeTransaction = async ( amount: Decimal, memo: string, @@ -45,6 +48,14 @@ export const executeTransaction = async ( throw new Error('Sender and Recipient are the same.') } + if (memo.length > MEMO_MAX_CHARS) { + throw new Error(`memo text is too long (${MEMO_MAX_CHARS} characters maximum)`) + } + + if (memo.length < MEMO_MIN_CHARS) { + throw new Error(`memo text is too short (${MEMO_MIN_CHARS} characters minimum)`) + } + // validate amount const receivedCallDate = new Date() const sendBalance = await calculateBalance(sender.id, amount.mul(-1), receivedCallDate)