Skip to content

Commit

Permalink
Node/hex: bigint fixes (#1881)
Browse files Browse the repository at this point in the history
* fixed bigint on spots

* format

* changelog

* Prepare releases

---------

Co-authored-by: Thibault Martinez <[email protected]>
  • Loading branch information
Brord van Wierst and thibault-martinez authored Jan 29, 2024
1 parent 1539710 commit 4dcbc2b
Show file tree
Hide file tree
Showing 11 changed files with 8,060 additions and 7,814 deletions.
6 changes: 5 additions & 1 deletion bindings/nodejs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security -->

## 1.1.5 - 2024-01-DD
## 1.1.5 - 2024-01-29

### Added

- `Utils::{verifyTransactionSyntax(), blockBytes(), blockHashWithoutNonce()}`;

### Fixed

- `Output` and `SimpleTokenScheme` (sub)fields not setting the `bigint` properly;

## 1.1.4 - 2023-12-07

### Added
Expand Down
14 changes: 2 additions & 12 deletions bindings/nodejs/lib/types/block/output/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Feature, FeatureDiscriminator } from './feature';

// Temp solution for not double parsing JSON
import { plainToInstance, Type } from 'class-transformer';
import { HexEncodedString, hexToBigInt, NumericString } from '../../utils';
import { HexEncodedString, NumericString } from '../../utils';
import { TokenScheme, TokenSchemeDiscriminator } from './token-scheme';
import { INativeToken } from '../../models';

Expand Down Expand Up @@ -97,6 +97,7 @@ abstract class CommonOutput extends Output /*implements ICommonOutput*/ {
})
readonly unlockConditions: UnlockCondition[];

@Type(() => INativeToken)
readonly nativeTokens?: INativeToken[];

@Type(() => Feature, {
Expand Down Expand Up @@ -127,17 +128,6 @@ abstract class CommonOutput extends Output /*implements ICommonOutput*/ {
* The native tokens held by the output.
*/
getNativeTokens(): INativeToken[] | undefined {
if (!this.nativeTokens) {
return this.nativeTokens;
}

// Make sure the amount of native tokens are of bigint type.
for (let i = 0; i < this.nativeTokens.length; i++) {
const token = this.nativeTokens[i];
if (typeof token.amount === 'string') {
this.nativeTokens[i].amount = hexToBigInt(token.amount);
}
}
return this.nativeTokens;
}

Expand Down
4 changes: 4 additions & 0 deletions bindings/nodejs/lib/types/block/output/token-scheme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { Transform } from 'class-transformer';
import { hexToBigInt } from '../../utils/hex-encoding';

/**
Expand Down Expand Up @@ -36,8 +37,11 @@ abstract class TokenScheme {
* A simple token scheme.
*/
class SimpleTokenScheme extends TokenScheme {
@Transform((value) => hexToBigInt(value.value))
readonly mintedTokens: bigint;
@Transform((value) => hexToBigInt(value.value))
readonly meltedTokens: bigint;
@Transform((value) => hexToBigInt(value.value))
readonly maximumSupply: bigint;

/**
Expand Down
9 changes: 6 additions & 3 deletions bindings/nodejs/lib/types/models/native-token.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { Transform } from 'class-transformer';
import type { HexEncodedString } from '../utils/hex-encoding';
import { hexToBigInt } from '../utils/hex-encoding';
/**
* Native token.
*/
export interface INativeToken {
export class INativeToken {
/**
* Identifier of the native token.
*/
id: HexEncodedString;
id!: HexEncodedString;
/**
* Amount of native tokens of the given Token ID.
*/
amount: bigint;
@Transform((value) => hexToBigInt(value.value))
amount!: bigint;
}
Loading

0 comments on commit 4dcbc2b

Please sign in to comment.