Skip to content

Commit

Permalink
Use newly added Nimiq SDK enums for hardcoded values again
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Jan 13, 2025
1 parent 34fec1c commit cb2f92c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/lib/RequestParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/request/sign-swap/SignSwapApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/request/sign-transaction/SignTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
}
Expand Down

0 comments on commit cb2f92c

Please sign in to comment.