Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt enums type bytes #1548

Merged
merged 6 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions bindings/nodejs/lib/types/block/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ enum AddressType {
Account = 8,
/** An NFT address. */
Nft = 16,
/** An implicit account creation address. */
ImplicitAccountCreation = 24,
/** An Anchor address. */
Anchor = 28,
Anchor = 24,
/** An implicit account creation address. */
ImplicitAccountCreation = 32,
/** An address with restricted capabilities. */
Restricted = 40,
Restricted = 48,
}

/**
Expand Down Expand Up @@ -62,13 +62,13 @@ abstract class Address {
) as any as AccountAddress;
} else if (data.type == AddressType.Nft) {
return plainToInstance(NftAddress, data) as any as NftAddress;
} else if (data.type == AddressType.Anchor) {
return plainToInstance(AnchorAddress, data) as any as AnchorAddress;
} else if (data.type == AddressType.ImplicitAccountCreation) {
return plainToInstance(
ImplicitAccountCreationAddress,
data,
) as any as ImplicitAccountCreationAddress;
} else if (data.type == AddressType.Anchor) {
return plainToInstance(AnchorAddress, data) as any as AnchorAddress;
} else if (data.type == AddressType.Restricted) {
return plainToInstance(
RestrictedAddress,
Expand Down Expand Up @@ -142,6 +142,27 @@ class NftAddress extends Address {
}
}

/**
* An Anchor address.
*/
class AnchorAddress extends Address {
/**
* The anchor ID.
*/
readonly anchorId: AnchorId;
/**
* @param address An anchor address as anchor ID.
*/
constructor(address: AnchorId) {
super(AddressType.Anchor);
this.anchorId = address;
}

toString(): string {
return this.anchorId;
}
}

/**
* An implicit account creation address that can be used to convert a Basic Output to an Account Output.
*/
Expand All @@ -164,27 +185,6 @@ class ImplicitAccountCreationAddress extends Address {
}
}

/**
* An Anchor address.
*/
class AnchorAddress extends Address {
/**
* The anchor ID.
*/
readonly anchorId: AnchorId;
/**
* @param address An anchor address as anchor ID.
*/
constructor(address: AnchorId) {
super(AddressType.Anchor);
this.anchorId = address;
}

toString(): string {
return this.anchorId;
}
}

const RestrictedAddressDiscriminator = {
property: 'type',
subTypes: [
Expand Down Expand Up @@ -255,11 +255,11 @@ const AddressDiscriminator = {
{ value: Ed25519Address, name: AddressType.Ed25519 as any },
{ value: AccountAddress, name: AddressType.Account as any },
{ value: NftAddress, name: AddressType.Nft as any },
{ value: AnchorAddress, name: AddressType.Anchor as any },
{
value: ImplicitAccountCreationAddress,
name: AddressType.ImplicitAccountCreation as any,
},
{ value: AnchorAddress, name: AddressType.Anchor as any },
{ value: RestrictedAddress, name: AddressType.Restricted as any },
],
};
Expand All @@ -273,4 +273,6 @@ export {
AccountAddress,
NftAddress,
AnchorAddress,
ImplicitAccountCreationAddress,
RestrictedAddress,
};
82 changes: 43 additions & 39 deletions bindings/nodejs/lib/types/block/output/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ enum OutputType {
Basic = 0,
/** An Account output. */
Account = 1,
/** An Anchor output. */
Anchor = 2,
/** A Foundry output. */
Foundry = 2,
Foundry = 3,
/** An NFT output. */
Nft = 3,
Nft = 4,
/** A Delegation output. */
Delegation = 4,
/** An Anchor output. */
Anchor = 5,
Delegation = 5,
}

/**
Expand Down Expand Up @@ -74,6 +74,8 @@ abstract class Output {
return plainToInstance(BasicOutput, data) as any as BasicOutput;
} else if (data.type == OutputType.Account) {
return plainToInstance(AccountOutput, data) as any as AccountOutput;
} else if (data.type == OutputType.Anchor) {
return plainToInstance(AnchorOutput, data) as any as AnchorOutput;
} else if (data.type == OutputType.Foundry) {
return plainToInstance(FoundryOutput, data) as any as FoundryOutput;
} else if (data.type == OutputType.Nft) {
Expand All @@ -83,8 +85,6 @@ abstract class Output {
DelegationOutput,
data,
) as any as DelegationOutput;
} else if (data.type == OutputType.Anchor) {
return plainToInstance(AnchorOutput, data) as any as AnchorOutput;
}
throw new Error('Invalid JSON');
}
Expand Down Expand Up @@ -144,6 +144,7 @@ abstract class CommonOutput extends Output {
return this.nativeTokens;
}
}

/**
* A Basic output.
*/
Expand Down Expand Up @@ -272,71 +273,73 @@ class AnchorOutput extends ImmutableFeaturesOutput {
}

/**
* An NFT output.
* A Foundry output.
*/
class NftOutput extends ImmutableFeaturesOutput {
class FoundryOutput extends ImmutableFeaturesOutput {
/**
* Unique identifier of the NFT, which is the BLAKE2b-256 hash of the Output ID that created it.
* Unless its newly minted, then the id is zeroed.
* The serial number of the Foundry with respect to the controlling alias.
*/
readonly nftId: NftId;
readonly serialNumber: number;

/**
* The amount of (stored) Mana held by the output.
* The token scheme for the Foundry.
*/
readonly mana: u64;
@Type(() => TokenScheme, {
discriminator: TokenSchemeDiscriminator,
})
readonly tokenScheme: TokenScheme;

/**
* @param amount The amount of the output.
* @param mana The amount of stored mana.
* @param nftId The NFT ID as hex-encoded string.
* @param serialNumber The serial number of the Foundry with respect to the controlling alias.
* @param unlockConditions The unlock conditions of the output.
* @param tokenScheme The token scheme for the Foundry.
*/
constructor(
amount: u64,
mana: u64,
nftId: NftId,
serialNumber: number,
unlockConditions: UnlockCondition[],
tokenScheme: TokenScheme,
) {
super(OutputType.Nft, amount, unlockConditions);
this.nftId = nftId;
this.mana = mana;
super(OutputType.Foundry, amount, unlockConditions);
this.serialNumber = serialNumber;
this.tokenScheme = tokenScheme;
}
}

/**
* A Foundry output.
* An NFT output.
*/
class FoundryOutput extends ImmutableFeaturesOutput {
class NftOutput extends ImmutableFeaturesOutput {
/**
* The serial number of the Foundry with respect to the controlling alias.
* Unique identifier of the NFT, which is the BLAKE2b-256 hash of the Output ID that created it.
* Unless its newly minted, then the id is zeroed.
*/
readonly serialNumber: number;
readonly nftId: NftId;

/**
* The token scheme for the Foundry.
* The amount of (stored) Mana held by the output.
*/
@Type(() => TokenScheme, {
discriminator: TokenSchemeDiscriminator,
})
readonly tokenScheme: TokenScheme;
readonly mana: u64;

/**
* @param amount The amount of the output.
* @param serialNumber The serial number of the Foundry with respect to the controlling alias.
* @param mana The amount of stored mana.
* @param nftId The NFT ID as hex-encoded string.
* @param unlockConditions The unlock conditions of the output.
* @param tokenScheme The token scheme for the Foundry.
*/
constructor(
amount: u64,
serialNumber: number,
mana: u64,
nftId: NftId,
unlockConditions: UnlockCondition[],
tokenScheme: TokenScheme,
) {
super(OutputType.Foundry, amount, unlockConditions);
this.serialNumber = serialNumber;
this.tokenScheme = tokenScheme;
super(OutputType.Nft, amount, unlockConditions);
this.nftId = nftId;
this.mana = mana;
}
}

/**
* A Delegation output.
*/
Expand Down Expand Up @@ -402,8 +405,9 @@ const OutputDiscriminator = {
subTypes: [
{ value: BasicOutput, name: OutputType.Basic as any },
{ value: AccountOutput, name: OutputType.Account as any },
{ value: NftOutput, name: OutputType.Nft as any },
{ value: AnchorOutput, name: OutputType.Anchor as any },
{ value: FoundryOutput, name: OutputType.Foundry as any },
{ value: NftOutput, name: OutputType.Nft as any },
{ value: DelegationOutput, name: OutputType.Delegation as any },
],
};
Expand All @@ -416,7 +420,7 @@ export {
BasicOutput,
AccountOutput,
AnchorOutput,
NftOutput,
FoundryOutput,
NftOutput,
DelegationOutput,
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ enum UnlockType {
*/
Account = 2,
/**
* An NFT unlock.
* An Anchor unlock.
*/
Nft = 3,
Anchor = 3,
/**
* An Anchor unlock.
* An NFT unlock.
*/
Anchor = 4,
Nft = 4,
}

/**
Expand Down Expand Up @@ -104,9 +104,9 @@ class AccountUnlock extends Unlock {
}

/**
* An unlock which must reference a previous unlock which unlocks the NFT that the input is locked to.
* An unlock which must reference a previous unlock which unlocks the anchor that the input is locked to.
*/
class NftUnlock extends Unlock {
class AnchorUnlock extends Unlock {
/**
* The reference.
*/
Expand All @@ -116,15 +116,15 @@ class NftUnlock extends Unlock {
* @param reference An index referencing a previous unlock.
*/
constructor(reference: number) {
super(UnlockType.Nft);
super(UnlockType.Anchor);
this.reference = reference;
}
}

/**
* An unlock which must reference a previous unlock which unlocks the anchor that the input is locked to.
* An unlock which must reference a previous unlock which unlocks the NFT that the input is locked to.
*/
class AnchorUnlock extends Unlock {
class NftUnlock extends Unlock {
/**
* The reference.
*/
Expand All @@ -134,7 +134,7 @@ class AnchorUnlock extends Unlock {
* @param reference An index referencing a previous unlock.
*/
constructor(reference: number) {
super(UnlockType.Anchor);
super(UnlockType.Nft);
this.reference = reference;
}
}
Expand All @@ -154,14 +154,14 @@ const UnlockDiscriminator = {
value: AccountUnlock,
name: UnlockType.Account as any,
},
{
value: NftUnlock,
name: UnlockType.Nft as any,
},
{
value: AnchorUnlock,
name: UnlockType.Anchor as any,
},
{
value: NftUnlock,
name: UnlockType.Nft as any,
},
],
};

Expand All @@ -171,7 +171,7 @@ export {
SignatureUnlock,
ReferenceUnlock,
AccountUnlock,
NftUnlock,
AnchorUnlock,
NftUnlock,
UnlockDiscriminator,
};
Loading
Loading