Skip to content

Commit

Permalink
chore: make private fields readonly (#961)
Browse files Browse the repository at this point in the history
* chore: make private fields readonly

* fix: lint

* chore: changelog

* fix: comment

* chore: update changelog

* Nits

* fix: undo breaking change

* Update bindings/nodejs/lib/types/block/signature.ts

Co-authored-by: Abdulrahim Al Methiab <[email protected]>

---------

Co-authored-by: Thibault Martinez <[email protected]>
Co-authored-by: Abdulrahim Al Methiab <[email protected]>
  • Loading branch information
3 people authored Jul 28, 2023
1 parent 9b5adfb commit fffcdc5
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 46 deletions.
5 changes: 4 additions & 1 deletion bindings/nodejs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## 1.0.2 - 2023-MM-DD

### Changed

- Private properties on classes are now readonly;

### Fixed

- Constructor types in `RegularTransactionEssence`;
- `SenderFeature.getSender()` and `IssuerFeature.getIssuer()` now return the correct types;


## 1.0.1 - 2023-07-25

### Changed
Expand Down
8 changes: 4 additions & 4 deletions bindings/nodejs/lib/types/block/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum AddressType {
}

abstract class Address {
private type: AddressType;
readonly type: AddressType;

constructor(type: AddressType) {
this.type = type;
Expand Down Expand Up @@ -44,7 +44,7 @@ abstract class Address {
* Ed25519 Address.
*/
class Ed25519Address extends Address {
private pubKeyHash: HexEncodedString;
readonly pubKeyHash: HexEncodedString;

constructor(address: HexEncodedString) {
super(AddressType.Ed25519);
Expand All @@ -63,7 +63,7 @@ class Ed25519Address extends Address {
}

class AliasAddress extends Address {
private aliasId: AliasId;
readonly aliasId: AliasId;
constructor(address: AliasId) {
super(AddressType.Alias);
this.aliasId = address;
Expand All @@ -83,7 +83,7 @@ class AliasAddress extends Address {
* NFT address.
*/
class NftAddress extends Address {
private nftId: NftId;
readonly nftId: NftId;
constructor(address: NftId) {
super(AddressType.Nft);
this.nftId = address;
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/types/block/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum InputType {
}

abstract class Input {
private type: InputType;
readonly type: InputType;

constructor(type: InputType) {
this.type = type;
Expand Down
15 changes: 10 additions & 5 deletions bindings/nodejs/lib/types/block/output/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ enum FeatureType {
}

abstract class Feature {
private type: FeatureType;
readonly type: FeatureType;

constructor(type: FeatureType) {
this.type = type;
}
Expand All @@ -33,7 +34,8 @@ class SenderFeature extends Feature {
@Type(() => Address, {
discriminator: AddressDiscriminator,
})
private address: Address;
readonly address: Address;

constructor(sender: Address) {
super(FeatureType.Sender);
this.address = sender;
Expand All @@ -52,7 +54,8 @@ class IssuerFeature extends Feature {
@Type(() => Address, {
discriminator: AddressDiscriminator,
})
private address: Address;
readonly address: Address;

constructor(issuer: Address) {
super(FeatureType.Issuer);
this.address = issuer;
Expand All @@ -68,7 +71,8 @@ class IssuerFeature extends Feature {
* Metadata feature.
*/
class MetadataFeature extends Feature {
private data: string;
readonly data: string;

constructor(data: string) {
super(FeatureType.Metadata);
this.data = data;
Expand All @@ -84,7 +88,8 @@ class MetadataFeature extends Feature {
* Tag feature.
*/
class TagFeature extends Feature {
private tag: string;
readonly tag: string;

constructor(tag: string) {
super(FeatureType.Tag);
this.tag = tag;
Expand Down
26 changes: 13 additions & 13 deletions bindings/nodejs/lib/types/block/output/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ enum OutputType {
}

abstract class Output /*implements ICommonOutput*/ {
private amount: string;
readonly amount: string;

private type: OutputType;
readonly type: OutputType;

constructor(type: OutputType, amount: bigint | string) {
this.type = type;
Expand Down Expand Up @@ -80,14 +80,14 @@ abstract class CommonOutput extends Output /*implements ICommonOutput*/ {
@Type(() => UnlockCondition, {
discriminator: UnlockConditionDiscriminator,
})
private unlockConditions: UnlockCondition[];
readonly unlockConditions: UnlockCondition[];

private nativeTokens?: INativeToken[];
readonly nativeTokens?: INativeToken[];

@Type(() => Feature, {
discriminator: FeatureDiscriminator,
})
private features?: Feature[];
readonly features?: Feature[];

constructor(
type: OutputType,
Expand Down Expand Up @@ -149,7 +149,7 @@ abstract class ImmutableFeaturesOutput extends CommonOutput {
@Type(() => Feature, {
discriminator: FeatureDiscriminator,
})
private immutableFeatures?: Feature[];
readonly immutableFeatures?: Feature[];

constructor(
type: OutputType,
Expand All @@ -167,7 +167,7 @@ abstract class ImmutableFeaturesOutput extends CommonOutput {
}

abstract class StateMetadataOutput extends ImmutableFeaturesOutput /*implements IBasicOutput*/ {
private stateMetadata?: HexEncodedString;
readonly stateMetadata?: HexEncodedString;

constructor(
type: OutputType,
Expand All @@ -185,9 +185,9 @@ abstract class StateMetadataOutput extends ImmutableFeaturesOutput /*implements
}

class AliasOutput extends StateMetadataOutput /*implements IAliasOutput*/ {
private aliasId: HexEncodedString;
private stateIndex: number;
private foundryCounter: number;
readonly aliasId: HexEncodedString;
readonly stateIndex: number;
readonly foundryCounter: number;

constructor(
unlockConditions: UnlockCondition[],
Expand Down Expand Up @@ -225,7 +225,7 @@ class AliasOutput extends StateMetadataOutput /*implements IAliasOutput*/ {
* NFT output.
*/
class NftOutput extends ImmutableFeaturesOutput /*implements INftOutput*/ {
private nftId: HexEncodedString;
readonly nftId: HexEncodedString;

constructor(
amount: bigint,
Expand All @@ -247,12 +247,12 @@ class NftOutput extends ImmutableFeaturesOutput /*implements INftOutput*/ {
* Foundry output.
*/
class FoundryOutput extends ImmutableFeaturesOutput /*implements IFoundryOutput*/ {
private serialNumber: number;
readonly serialNumber: number;

@Type(() => TokenScheme, {
discriminator: TokenSchemeDiscriminator,
})
private tokenScheme: TokenScheme;
readonly tokenScheme: TokenScheme;

constructor(
amount: bigint,
Expand Down
8 changes: 4 additions & 4 deletions bindings/nodejs/lib/types/block/output/token-scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ enum TokenSchemeType {
}

abstract class TokenScheme {
private type: TokenSchemeType;
readonly type: TokenSchemeType;

constructor(type: TokenSchemeType) {
this.type = type;
Expand All @@ -26,9 +26,9 @@ abstract class TokenScheme {
* Simple token scheme.
*/
class SimpleTokenScheme extends TokenScheme {
private mintedTokens: bigint;
private meltedTokens: bigint;
private maximumSupply: bigint;
readonly mintedTokens: bigint;
readonly meltedTokens: bigint;
readonly maximumSupply: bigint;

constructor(
mintedTokens: bigint,
Expand Down
22 changes: 12 additions & 10 deletions bindings/nodejs/lib/types/block/output/unlock-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ enum UnlockConditionType {
}

abstract class UnlockCondition {
private type: UnlockConditionType;
readonly type: UnlockConditionType;

constructor(type: UnlockConditionType) {
this.type = type;
Expand Down Expand Up @@ -75,7 +75,8 @@ class AddressUnlockCondition extends UnlockCondition /*implements IAddressUnlock
@Type(() => Address, {
discriminator: AddressDiscriminator,
})
private address: Address;
readonly address: Address;

constructor(address: Address) {
super(UnlockConditionType.Address);
this.address = address;
Expand All @@ -92,12 +93,12 @@ class AddressUnlockCondition extends UnlockCondition /*implements IAddressUnlock
* Storage Deposit Return Unlock Condition.
*/
class StorageDepositReturnUnlockCondition extends UnlockCondition /*implements IStorageDepositReturnUnlockCondition*/ {
private amount: string;
readonly amount: string;

@Type(() => Address, {
discriminator: AddressDiscriminator,
})
private returnAddress: Address;
readonly returnAddress: Address;

constructor(returnAddress: Address, amount: bigint | string) {
super(UnlockConditionType.StorageDepositReturn);
Expand Down Expand Up @@ -126,7 +127,7 @@ class StorageDepositReturnUnlockCondition extends UnlockCondition /*implements I
* Timelock Unlock Condition.
*/
class TimelockUnlockCondition extends UnlockCondition /*implements ITimelockUnlockCondition*/ {
private unixTime: number;
readonly unixTime: number;

constructor(unixTime: number) {
super(UnlockConditionType.Timelock);
Expand All @@ -144,8 +145,8 @@ class ExpirationUnlockCondition extends UnlockCondition /*implements IExpiration
@Type(() => Address, {
discriminator: AddressDiscriminator,
})
private returnAddress: Address;
private unixTime: number;
readonly returnAddress: Address;
readonly unixTime: number;

constructor(returnAddress: Address, unixTime: number) {
super(UnlockConditionType.Expiration);
Expand Down Expand Up @@ -174,7 +175,7 @@ class StateControllerAddressUnlockCondition extends UnlockCondition /*implements
@Type(() => Address, {
discriminator: AddressDiscriminator,
})
private address: Address;
readonly address: Address;
constructor(address: Address) {
super(UnlockConditionType.StateControllerAddress);
this.address = address;
Expand All @@ -194,7 +195,7 @@ class GovernorAddressUnlockCondition extends UnlockCondition /*implements IGover
@Type(() => Address, {
discriminator: AddressDiscriminator,
})
private address: Address;
readonly address: Address;
constructor(address: Address) {
super(UnlockConditionType.GovernorAddress);
this.address = address;
Expand All @@ -214,7 +215,8 @@ class ImmutableAliasAddressUnlockCondition extends UnlockCondition /*implements
@Type(() => Address, {
discriminator: AddressDiscriminator,
})
private address: Address;
readonly address: Address;

constructor(address: AliasAddress) {
super(UnlockConditionType.ImmutableAliasAddress);
this.address = address;
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/types/block/payload/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum PayloadType {
}

abstract class Payload {
private type: PayloadType;
readonly type: PayloadType;

constructor(type: PayloadType) {
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum TransactionEssenceType {
}

abstract class TransactionEssence {
private type: TransactionEssenceType;
readonly type: TransactionEssenceType;

constructor(type: TransactionEssenceType) {
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum UnlockType {
}

abstract class Unlock {
private type: UnlockType;
readonly type: UnlockType;

constructor(type: UnlockType) {
this.type = type;
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/types/block/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum SignatureType {
}

abstract class Signature {
private type: SignatureType;
readonly type: SignatureType;

constructor(type: SignatureType) {
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum MilestoneOptionType {
}

abstract class MilestoneOption {
private type: MilestoneOptionType;
readonly type: MilestoneOptionType;

constructor(type: MilestoneOptionType) {
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { PreparedTransaction } from './prepared-transaction';
* The class PreparedCreateNativeTokenTransaction represents prepared data for issuing a transaction to create a native token.
*/
export class PreparedCreateNativeTokenTransaction extends PreparedTransaction {
private _tokenId: string;
readonly _tokenId: string;

constructor(
preparedData: PreparedCreateNativeTokenTransactionData,
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/lib/types/wallet/prepared-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
* the transaction and sign+submit/send the transaction.
*/
export class PreparedTransaction {
private _preparedData: PreparedTransactionData;
private _account: Account;
readonly _preparedData: PreparedTransactionData;
readonly _account: Account;

constructor(preparedData: PreparedTransactionData, account: Account) {
this._preparedData = preparedData;
Expand Down

0 comments on commit fffcdc5

Please sign in to comment.