From cb2f92cb193554de46be78d818796c03d80d4bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren?= Date: Mon, 13 Jan 2025 16:40:22 +0100 Subject: [PATCH] Use newly added Nimiq SDK enums for hardcoded values again --- src/lib/RequestParser.js | 10 +++++----- src/request/sign-swap/SignSwapApi.js | 4 ++-- src/request/sign-transaction/SignTransaction.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/RequestParser.js b/src/lib/RequestParser.js index c07f85445..cda3cbecb 100644 --- a/src/lib/RequestParser.js +++ b/src/lib/RequestParser.js @@ -132,7 +132,7 @@ class RequestParser { // eslint-disable-line no-unused-vars Nimiq.AccountType.Basic, Nimiq.AccountType.Vesting, Nimiq.AccountType.HTLC, - 3 /* Staking */, + Nimiq.AccountType.Staking, ]); if (!object || typeof object !== 'object' || object === null) { throw new Errors.InvalidRequestError('Request must be an object'); @@ -158,16 +158,16 @@ class RequestParser { // eslint-disable-line no-unused-vars ? Utf8Tools.stringToUtf8ByteArray(object.recipientData) : object.recipientData || new Uint8Array(0); - const flags = object.flags || 0/* Nimiq.Transaction.Flag.NONE */; + const flags = object.flags || Nimiq.TransactionFlag.None; if ( - flags === 0 /* Nimiq.Transaction.Flag.NONE */ + flags === Nimiq.TransactionFlag.None && recipientType !== Nimiq.AccountType.Staking && recipientData.byteLength > 64 ) { throw new Errors.InvalidRequestError('Data must not exceed 64 bytes'); } - if (flags === 1 /* Nimiq.Transaction.Flag.CONTRACT_CREATION */ + if (flags === Nimiq.TransactionFlag.ContractCreation && recipientData.byteLength !== 82 // HTLC && recipientData.byteLength !== 28 // Vesting && recipientData.byteLength !== 44 // Vesting @@ -177,7 +177,7 @@ class RequestParser { // eslint-disable-line no-unused-vars ); } if ( - flags === 1 /* Nimiq.Transaction.Flag.CONTRACT_CREATION */ + flags === Nimiq.TransactionFlag.ContractCreation && recipient !== 'CONTRACT_CREATION' ) { throw new Errors.InvalidRequestError( diff --git a/src/request/sign-swap/SignSwapApi.js b/src/request/sign-swap/SignSwapApi.js index ef1bcfa0c..adb002b88 100644 --- a/src/request/sign-swap/SignSwapApi.js +++ b/src/request/sign-swap/SignSwapApi.js @@ -47,7 +47,7 @@ class SignSwapApi extends PolygonRequestParserMixin(BitcoinRequestParserMixin(To // Enforced properties recipient: 'CONTRACT_CREATION', recipientType: Nimiq.AccountType.HTLC, - flags: 1 /* Nimiq.Transaction.Flag.CONTRACT_CREATION */, + flags: Nimiq.TransactionFlag.ContractCreation, }), senderLabel: /** @type {string} */ (this.parseLabel( request.fund.senderLabel, false, 'fund.senderLabel', @@ -127,7 +127,7 @@ class SignSwapApi extends PolygonRequestParserMixin(BitcoinRequestParserMixin(To // Enforced properties senderType: Nimiq.AccountType.HTLC, recipientType: Nimiq.AccountType.Basic, - flags: 0 /* Nimiq.Transaction.Flag.NONE */, + flags: Nimiq.TransactionFlag.None, }), recipientLabel: /** @type {string} */ (this.parseLabel( request.redeem.recipientLabel, false, 'recipientLabel', diff --git a/src/request/sign-transaction/SignTransaction.js b/src/request/sign-transaction/SignTransaction.js index 13b6383f4..725acd8dd 100644 --- a/src/request/sign-transaction/SignTransaction.js +++ b/src/request/sign-transaction/SignTransaction.js @@ -215,7 +215,7 @@ class SignTransaction { return I18n.translatePhrase('funding-cashlink'); } - if (transaction.flags === 1 /* Nimiq.Transaction.Flag.CONTRACT_CREATION */) { + if (transaction.flags === Nimiq.TransactionFlag.ContractCreation) { // TODO: Decode contract creation transactions // return ... }