Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lorisleiva committed Apr 15, 2024
1 parent d3a3e4b commit 2bbf06e
Show file tree
Hide file tree
Showing 6 changed files with 437 additions and 161 deletions.
19 changes: 18 additions & 1 deletion src/renderers/js-experimental/fragments/programErrors.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@
{% endfor %}

export type {{ programErrorUnion }} =
{% for error in errors | sort(false, false, 'code') %}
{% for error in errors | sort(false, false, 'name') %}
| typeof {{ getProgramErrorConstant(error.name) }}
{% endfor %};

let {{ programErrorMessagesMap }}: Record<{{ programErrorUnion }}, string> | undefined;
if (__DEV__) {
{{ programErrorMessagesMap }} = {
{% for error in errors | sort(false, false, 'name') %}
[{{ getProgramErrorConstant(error.name) }}]: `{{ error.message }}`,
{% endfor %}
};
}

export function {{ programGetErrorMessageFunction }}(code: {{ programErrorUnion }}): string {
if (__DEV__) {
return ({{ programErrorMessagesMap }} as Record<{{ programErrorUnion }}, string>)[code];
}

return 'Error message not available in production bundles. Compile with `__DEV__` set to true to see more information.';
}
4 changes: 4 additions & 0 deletions src/renderers/js-experimental/fragments/programErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export function getProgramErrorsFragment(
return fragmentFromTemplate('programErrors.njk', {
errors: programNode.errors,
programErrorUnion: nameApi.programErrorUnion(programNode.name),
programErrorMessagesMap: nameApi.programErrorMessagesMap(programNode.name),
programGetErrorMessageFunction: nameApi.programGetErrorMessageFunction(
programNode.name
),
getProgramErrorConstant: (name: string) =>
nameApi.programErrorConstantPrefix(programNode.name) +
nameApi.programErrorConstant(name),
Expand Down
5 changes: 5 additions & 0 deletions src/renderers/js-experimental/nameTransformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export type NameTransformerKey =
| 'programErrorConstantPrefix'
| 'programErrorConstant'
| 'programErrorUnion'
| 'programErrorMessagesMap'
| 'programGetErrorMessageFunction'
| 'resolverFunction';

export type NameTransformers = Record<NameTransformerKey, NameTransformer>;
Expand Down Expand Up @@ -132,5 +134,8 @@ export const DEFAULT_NAME_TRANSFORMERS: NameTransformers = {
`${snakeCase(name)}_ERROR__`.toUpperCase(),
programErrorConstant: (name) => snakeCase(name).toUpperCase(),
programErrorUnion: (name) => `${pascalCase(name)}Error`,
programErrorMessagesMap: (name) => `${camelCase(name)}ErrorMessages`,
programGetErrorMessageFunction: (name) =>
`get${pascalCase(name)}ErrorMessage`,
resolverFunction: (name) => `${camelCase(name)}`,
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,68 @@ export const MPL_CANDY_MACHINE_CORE_ERROR__COULD_NOT_RETRIEVE_CONFIG_LINE_DATA =
export const MPL_CANDY_MACHINE_CORE_ERROR__NOT_FULLY_LOADED = 0x1784; // 6020

export type MplCandyMachineCoreError =
| typeof MPL_CANDY_MACHINE_CORE_ERROR__INCORRECT_OWNER
| typeof MPL_CANDY_MACHINE_CORE_ERROR__UNINITIALIZED
| typeof MPL_CANDY_MACHINE_CORE_ERROR__MINT_MISMATCH
| typeof MPL_CANDY_MACHINE_CORE_ERROR__INDEX_GREATER_THAN_LENGTH
| typeof MPL_CANDY_MACHINE_CORE_ERROR__NUMERICAL_OVERFLOW_ERROR
| typeof MPL_CANDY_MACHINE_CORE_ERROR__TOO_MANY_CREATORS
| typeof MPL_CANDY_MACHINE_CORE_ERROR__CANDY_MACHINE_EMPTY
| typeof MPL_CANDY_MACHINE_CORE_ERROR__HIDDEN_SETTINGS_DO_NOT_HAVE_CONFIG_LINES
| typeof MPL_CANDY_MACHINE_CORE_ERROR__CANNOT_CHANGE_NUMBER_OF_LINES
| typeof MPL_CANDY_MACHINE_CORE_ERROR__CANNOT_SWITCH_TO_HIDDEN_SETTINGS
| typeof MPL_CANDY_MACHINE_CORE_ERROR__INCORRECT_COLLECTION_AUTHORITY
| typeof MPL_CANDY_MACHINE_CORE_ERROR__METADATA_ACCOUNT_MUST_BE_EMPTY
| typeof MPL_CANDY_MACHINE_CORE_ERROR__NO_CHANGING_COLLECTION_DURING_MINT
| typeof MPL_CANDY_MACHINE_CORE_ERROR__EXCEEDED_LENGTH_ERROR
| typeof MPL_CANDY_MACHINE_CORE_ERROR__MISSING_CONFIG_LINES_SETTINGS
| typeof MPL_CANDY_MACHINE_CORE_ERROR__CANNOT_CHANGE_SEQUENTIAL_INDEX_GENERATION
| typeof MPL_CANDY_MACHINE_CORE_ERROR__CANNOT_INCREASE_LENGTH
| typeof MPL_CANDY_MACHINE_CORE_ERROR__CANNOT_SWITCH_FROM_HIDDEN_SETTINGS
| typeof MPL_CANDY_MACHINE_CORE_ERROR__CANNOT_CHANGE_SEQUENTIAL_INDEX_GENERATION
| typeof MPL_CANDY_MACHINE_CORE_ERROR__CANNOT_SWITCH_TO_HIDDEN_SETTINGS
| typeof MPL_CANDY_MACHINE_CORE_ERROR__COLLECTION_KEY_MISMATCH
| typeof MPL_CANDY_MACHINE_CORE_ERROR__COULD_NOT_RETRIEVE_CONFIG_LINE_DATA
| typeof MPL_CANDY_MACHINE_CORE_ERROR__NOT_FULLY_LOADED;
| typeof MPL_CANDY_MACHINE_CORE_ERROR__EXCEEDED_LENGTH_ERROR
| typeof MPL_CANDY_MACHINE_CORE_ERROR__HIDDEN_SETTINGS_DO_NOT_HAVE_CONFIG_LINES
| typeof MPL_CANDY_MACHINE_CORE_ERROR__INCORRECT_COLLECTION_AUTHORITY
| typeof MPL_CANDY_MACHINE_CORE_ERROR__INCORRECT_OWNER
| typeof MPL_CANDY_MACHINE_CORE_ERROR__INDEX_GREATER_THAN_LENGTH
| typeof MPL_CANDY_MACHINE_CORE_ERROR__METADATA_ACCOUNT_MUST_BE_EMPTY
| typeof MPL_CANDY_MACHINE_CORE_ERROR__MINT_MISMATCH
| typeof MPL_CANDY_MACHINE_CORE_ERROR__MISSING_CONFIG_LINES_SETTINGS
| typeof MPL_CANDY_MACHINE_CORE_ERROR__NO_CHANGING_COLLECTION_DURING_MINT
| typeof MPL_CANDY_MACHINE_CORE_ERROR__NOT_FULLY_LOADED
| typeof MPL_CANDY_MACHINE_CORE_ERROR__NUMERICAL_OVERFLOW_ERROR
| typeof MPL_CANDY_MACHINE_CORE_ERROR__TOO_MANY_CREATORS
| typeof MPL_CANDY_MACHINE_CORE_ERROR__UNINITIALIZED;

let mplCandyMachineCoreErrorMessages:
| Record<MplCandyMachineCoreError, string>
| undefined;
if (__DEV__) {
mplCandyMachineCoreErrorMessages = {
[MPL_CANDY_MACHINE_CORE_ERROR__CANDY_MACHINE_EMPTY]: `Candy machine is empty`,
[MPL_CANDY_MACHINE_CORE_ERROR__CANNOT_CHANGE_NUMBER_OF_LINES]: `Cannot change number of lines unless is a hidden config`,
[MPL_CANDY_MACHINE_CORE_ERROR__CANNOT_CHANGE_SEQUENTIAL_INDEX_GENERATION]: `Cannot change sequential index generation after items have begun to be minted`,
[MPL_CANDY_MACHINE_CORE_ERROR__CANNOT_INCREASE_LENGTH]: `Cannot increase the length in config lines settings`,
[MPL_CANDY_MACHINE_CORE_ERROR__CANNOT_SWITCH_FROM_HIDDEN_SETTINGS]: `Cannot switch from hidden settings`,
[MPL_CANDY_MACHINE_CORE_ERROR__CANNOT_SWITCH_TO_HIDDEN_SETTINGS]: `Cannot switch to hidden settings after items available is greater than 0`,
[MPL_CANDY_MACHINE_CORE_ERROR__COLLECTION_KEY_MISMATCH]: `Collection public key mismatch`,
[MPL_CANDY_MACHINE_CORE_ERROR__COULD_NOT_RETRIEVE_CONFIG_LINE_DATA]: `Could not retrive config line data`,
[MPL_CANDY_MACHINE_CORE_ERROR__EXCEEDED_LENGTH_ERROR]: `Value longer than expected maximum value`,
[MPL_CANDY_MACHINE_CORE_ERROR__HIDDEN_SETTINGS_DO_NOT_HAVE_CONFIG_LINES]: `Candy machines using hidden uris do not have config lines, they have a single hash representing hashed order`,
[MPL_CANDY_MACHINE_CORE_ERROR__INCORRECT_COLLECTION_AUTHORITY]: `Incorrect collection NFT authority`,
[MPL_CANDY_MACHINE_CORE_ERROR__INCORRECT_OWNER]: `Account does not have correct owner`,
[MPL_CANDY_MACHINE_CORE_ERROR__INDEX_GREATER_THAN_LENGTH]: `Index greater than length`,
[MPL_CANDY_MACHINE_CORE_ERROR__METADATA_ACCOUNT_MUST_BE_EMPTY]: `The metadata account has data in it, and this must be empty to mint a new NFT`,
[MPL_CANDY_MACHINE_CORE_ERROR__MINT_MISMATCH]: `Mint Mismatch`,
[MPL_CANDY_MACHINE_CORE_ERROR__MISSING_CONFIG_LINES_SETTINGS]: `Missing config lines settings`,
[MPL_CANDY_MACHINE_CORE_ERROR__NO_CHANGING_COLLECTION_DURING_MINT]: `Can't change collection settings after items have begun to be minted`,
[MPL_CANDY_MACHINE_CORE_ERROR__NOT_FULLY_LOADED]: `Not all config lines were added to the candy machine`,
[MPL_CANDY_MACHINE_CORE_ERROR__NUMERICAL_OVERFLOW_ERROR]: `Numerical overflow error`,
[MPL_CANDY_MACHINE_CORE_ERROR__TOO_MANY_CREATORS]: `Can only provide up to 4 creators to candy machine (because candy machine is one)`,
[MPL_CANDY_MACHINE_CORE_ERROR__UNINITIALIZED]: `Account is not initialized`,
};
}

export function getMplCandyMachineCoreErrorMessage(
code: MplCandyMachineCoreError
): string {
if (__DEV__) {
return (
mplCandyMachineCoreErrorMessages as Record<
MplCandyMachineCoreError,
string
>
)[code];
}

return 'Error message not available in production bundles. Compile with `__DEV__` set to true to see more information.';
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,53 @@ export const MPL_TOKEN_AUTH_RULES_ERROR__NOT_IMPLEMENTED = 0xd; // 13
export const MPL_TOKEN_AUTH_RULES_ERROR__BORSH_SERIALIZATION_ERROR = 0xe; // 14

export type MplTokenAuthRulesError =
| typeof MPL_TOKEN_AUTH_RULES_ERROR__NUMERICAL_OVERFLOW
| typeof MPL_TOKEN_AUTH_RULES_ERROR__ADDITIONAL_SIGNER_CHECK_FAILED
| typeof MPL_TOKEN_AUTH_RULES_ERROR__AMOUNT_CHECK_FAILED
| typeof MPL_TOKEN_AUTH_RULES_ERROR__BORSH_SERIALIZATION_ERROR
| typeof MPL_TOKEN_AUTH_RULES_ERROR__DATA_TYPE_MISMATCH
| typeof MPL_TOKEN_AUTH_RULES_ERROR__INCORRECT_OWNER
| typeof MPL_TOKEN_AUTH_RULES_ERROR__PAYLOAD_VEC_INDEX_ERROR
| typeof MPL_TOKEN_AUTH_RULES_ERROR__DERIVED_KEY_INVALID
| typeof MPL_TOKEN_AUTH_RULES_ERROR__ADDITIONAL_SIGNER_CHECK_FAILED
| typeof MPL_TOKEN_AUTH_RULES_ERROR__PUBKEY_MATCH_CHECK_FAILED
| typeof MPL_TOKEN_AUTH_RULES_ERROR__DERIVED_KEY_MATCH_CHECK_FAILED
| typeof MPL_TOKEN_AUTH_RULES_ERROR__PROGRAM_OWNED_CHECK_FAILED
| typeof MPL_TOKEN_AUTH_RULES_ERROR__AMOUNT_CHECK_FAILED
| typeof MPL_TOKEN_AUTH_RULES_ERROR__FREQUENCY_CHECK_FAILED
| typeof MPL_TOKEN_AUTH_RULES_ERROR__PUBKEY_TREE_MATCH_CHECK_FAILED
| typeof MPL_TOKEN_AUTH_RULES_ERROR__PAYER_IS_NOT_SIGNER
| typeof MPL_TOKEN_AUTH_RULES_ERROR__INCORRECT_OWNER
| typeof MPL_TOKEN_AUTH_RULES_ERROR__NOT_IMPLEMENTED
| typeof MPL_TOKEN_AUTH_RULES_ERROR__BORSH_SERIALIZATION_ERROR;
| typeof MPL_TOKEN_AUTH_RULES_ERROR__NUMERICAL_OVERFLOW
| typeof MPL_TOKEN_AUTH_RULES_ERROR__PAYER_IS_NOT_SIGNER
| typeof MPL_TOKEN_AUTH_RULES_ERROR__PAYLOAD_VEC_INDEX_ERROR
| typeof MPL_TOKEN_AUTH_RULES_ERROR__PROGRAM_OWNED_CHECK_FAILED
| typeof MPL_TOKEN_AUTH_RULES_ERROR__PUBKEY_MATCH_CHECK_FAILED
| typeof MPL_TOKEN_AUTH_RULES_ERROR__PUBKEY_TREE_MATCH_CHECK_FAILED;

let mplTokenAuthRulesErrorMessages:
| Record<MplTokenAuthRulesError, string>
| undefined;
if (__DEV__) {
mplTokenAuthRulesErrorMessages = {
[MPL_TOKEN_AUTH_RULES_ERROR__ADDITIONAL_SIGNER_CHECK_FAILED]: `Additional Signer check failed`,
[MPL_TOKEN_AUTH_RULES_ERROR__AMOUNT_CHECK_FAILED]: `Amount checked failed`,
[MPL_TOKEN_AUTH_RULES_ERROR__BORSH_SERIALIZATION_ERROR]: `Borsh Serialization Error`,
[MPL_TOKEN_AUTH_RULES_ERROR__DATA_TYPE_MISMATCH]: `Data type mismatch`,
[MPL_TOKEN_AUTH_RULES_ERROR__DERIVED_KEY_INVALID]: `Derived key invalid`,
[MPL_TOKEN_AUTH_RULES_ERROR__DERIVED_KEY_MATCH_CHECK_FAILED]: `Derived Key Match check failed`,
[MPL_TOKEN_AUTH_RULES_ERROR__FREQUENCY_CHECK_FAILED]: `Frequency check failed`,
[MPL_TOKEN_AUTH_RULES_ERROR__INCORRECT_OWNER]: `Incorrect account owner`,
[MPL_TOKEN_AUTH_RULES_ERROR__NOT_IMPLEMENTED]: ``,
[MPL_TOKEN_AUTH_RULES_ERROR__NUMERICAL_OVERFLOW]: `Numerical Overflow`,
[MPL_TOKEN_AUTH_RULES_ERROR__PAYER_IS_NOT_SIGNER]: `Payer is not a signer`,
[MPL_TOKEN_AUTH_RULES_ERROR__PAYLOAD_VEC_INDEX_ERROR]: `Could not index into PayloadVec`,
[MPL_TOKEN_AUTH_RULES_ERROR__PROGRAM_OWNED_CHECK_FAILED]: `Program Owned check failed`,
[MPL_TOKEN_AUTH_RULES_ERROR__PUBKEY_MATCH_CHECK_FAILED]: `Pubkey Match check failed`,
[MPL_TOKEN_AUTH_RULES_ERROR__PUBKEY_TREE_MATCH_CHECK_FAILED]: `Pubkey Tree Match check failed`,
};
}

export function getMplTokenAuthRulesErrorMessage(
code: MplTokenAuthRulesError
): string {
if (__DEV__) {
return (
mplTokenAuthRulesErrorMessages as Record<MplTokenAuthRulesError, string>
)[code];
}

return 'Error message not available in production bundles. Compile with `__DEV__` set to true to see more information.';
}
Loading

0 comments on commit 2bbf06e

Please sign in to comment.