Skip to content
Draft
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to the Aptos TypeScript SDK will be captured in this file. T

# Unreleased

- Add `variants` field to `MoveStruct` now that the ABI fully describes enums.

## Added

- Add JWK caching for keyless authentication with 5-minute TTL to improve performance
Expand Down
6 changes: 3 additions & 3 deletions src/transactions/transactionBuilder/remoteAbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,10 @@ function parseArg(
);
}

// We are assuming that fieldless structs are enums, and therefore we cannot typecheck any further due
// to limited information from the ABI. This does not work for structs on other modules.
// Enums cannot be further type-checked from the ABI alone, so we pass through the raw bytes.
// TODO: The enum information is now present in the ABI, we could use that.
const structDefinition = moduleAbi?.structs.find((s) => s.name === param.value.name.identifier);
if (structDefinition?.fields.length === 0 && arg instanceof Uint8Array) {
if (structDefinition?.is_enum && arg instanceof Uint8Array) {
return new FixedBytes(arg);
}

Expand Down
19 changes: 18 additions & 1 deletion src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,18 @@ export type MoveStructField = {
type: string;
};

/**
* A variant of a Move enum, containing a name and its associated fields.
*/
export type MoveStructVariant = {
name: string;
/**
* Fields belonging to this variant. This will be empty if the enum variant has no
* fields. e.g. if enum MyEnum { A { field: u64 }, B }, then B will have no fields.
*/
fields: Array<MoveStructField>;
};

/**
* A Move module
*/
Expand Down Expand Up @@ -1613,9 +1625,14 @@ export type MoveStruct = {
*/
generic_type_params: Array<MoveFunctionGenericTypeParam>;
/**
* Fields associated with the struct
* Fields associated with the struct. Populated for regular structs, empty for enums.
*/
fields: Array<MoveStructField>;
/**
* Variants of the enum. Populated when `is_enum` is true, empty for regular structs.
* Each variant has a name and can have its own set of fields.
*/
variants: Array<MoveStructVariant>;
};

/**
Expand Down