Skip to content

Commit

Permalink
fix: revert companion pattern except constants (#1193)
Browse files Browse the repository at this point in the history
* chore: use unbuild & revert enums replacement

* chore: revert constants & build

* chore: tsup adjustments
  • Loading branch information
lukasaric authored Sep 3, 2024
1 parent 84f9f02 commit ebf9f35
Show file tree
Hide file tree
Showing 14 changed files with 296 additions and 190 deletions.
61 changes: 61 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/types/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ export type SimulateTransactionDetails = {

export type EstimateFeeAction =
| {
type: TransactionType.INVOKE;
type: typeof TransactionType.INVOKE;
payload: AllowArray<Call>;
}
| {
type: TransactionType.DECLARE;
type: typeof TransactionType.DECLARE;
payload: DeclareContractPayload;
}
| {
type: TransactionType.DEPLOY_ACCOUNT;
type: typeof TransactionType.DEPLOY_ACCOUNT;
payload: DeployAccountContractPayload;
}
| {
type: TransactionType.DEPLOY;
type: typeof TransactionType.DEPLOY;
payload: UniversalDeployerContractPayload;
};

Expand Down
24 changes: 11 additions & 13 deletions src/types/api/rpcspec_0_6/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type ABI = Array<
FUNCTION | CONSTRUCTOR | L1_HANDLER | EVENT | STRUCT | ENUM | INTERFACE | IMPL
>;

export type FUNCTION = {
type FUNCTION = {
type: 'function';
name: string;
inputs: Array<{
Expand All @@ -24,7 +24,7 @@ export type FUNCTION = {
state_mutability: 'view' | 'external';
};

export type CONSTRUCTOR = {
type CONSTRUCTOR = {
type: 'constructor';
name: 'constructor';
inputs: Array<{
Expand All @@ -33,7 +33,7 @@ export type CONSTRUCTOR = {
}>;
};

export type L1_HANDLER = {
type L1_HANDLER = {
type: 'l1_handler';
name: string;
inputs: Array<{
Expand All @@ -46,22 +46,22 @@ export type L1_HANDLER = {
state_mutability: 'view' | 'external';
};

export type EVENT = {
type EVENT = {
type: 'event';
name: string;
} & (ENUM_EVENT | STRUCT_EVENT);

export type STRUCT_EVENT = {
type STRUCT_EVENT = {
kind: 'struct';
members: Array<EVENT_FIELD>;
};

export type ENUM_EVENT = {
type ENUM_EVENT = {
kind: 'enum';
variants: Array<EVENT_FIELD>;
};

export type STRUCT = {
type STRUCT = {
type: 'struct';
name: string;
members: Array<{
Expand All @@ -70,7 +70,7 @@ export type STRUCT = {
}>;
};

export type ENUM = {
type ENUM = {
type: 'enum';
name: string;
variants: Array<{
Expand All @@ -79,21 +79,19 @@ export type ENUM = {
}>;
};

export type INTERFACE = {
type INTERFACE = {
type: 'interface';
name: string;
items: Array<FUNCTION>;
};

export type IMPL = {
type IMPL = {
type: 'impl';
name: string;
interface_name: string;
};

export type EVENT_KIND = 'struct' | 'enum';

export type EVENT_FIELD = {
type EVENT_FIELD = {
name: string;
type: string;
kind: 'key' | 'data' | 'nested';
Expand Down
4 changes: 2 additions & 2 deletions src/types/api/rpcspec_0_6/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* version 0.6.0
*/

export { Methods } from './methods';
export { ABI } from './contract';
export * from './methods';
export * from './contract';
export * as Errors from './errors';
export * as SPEC from './components';
export * from './nonspec';
4 changes: 2 additions & 2 deletions src/types/api/rpcspec_0_6/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import {
TransactionWithHash,
} from './nonspec';

export type Methods = ReadMethods & WriteMethods & TraceMethods;

type ReadMethods = {
// Returns the version of the Starknet JSON-RPC specification being used
starknet_specVersion: {
Expand Down Expand Up @@ -328,3 +326,5 @@ type TraceMethods = {
errors: Errors.BLOCK_NOT_FOUND | Errors.TRANSACTION_EXECUTION_ERROR;
};
};

export type Methods = ReadMethods & WriteMethods & TraceMethods;
151 changes: 87 additions & 64 deletions src/types/api/rpcspec_0_6/nonspec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
TXN_RECEIPT,
TXN_STATUS,
} from './components';
import { ValuesType } from '../../helpers/valuesType';

// METHOD RESPONSES
// response starknet_getClass
Expand Down Expand Up @@ -107,84 +108,106 @@ export type NonceUpdates = NONCE_UPDATE[];
export type ReplacedClasses = REPLACED_CLASS[];

// Enums Derived From Spec Types (require manual check for changes)
export enum ETransactionType {
DECLARE = 'DECLARE',
DEPLOY = 'DEPLOY',
DEPLOY_ACCOUNT = 'DEPLOY_ACCOUNT',
INVOKE = 'INVOKE',
L1_HANDLER = 'L1_HANDLER',
}

export enum ESimulationFlag {
SKIP_VALIDATE = 'SKIP_VALIDATE',
SKIP_FEE_CHARGE = 'SKIP_FEE_CHARGE',
}

export enum ETransactionStatus {
RECEIVED = 'RECEIVED',
REJECTED = 'REJECTED',
ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2',
ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1',
}

export enum ETransactionFinalityStatus {
ACCEPTED_ON_L2 = 'ACCEPTED_ON_L2',
ACCEPTED_ON_L1 = 'ACCEPTED_ON_L1',
}

export enum ETransactionExecutionStatus {
SUCCEEDED = 'SUCCEEDED',
REVERTED = 'REVERTED',
}

export enum EBlockTag {
PENDING = 'pending',
LATEST = 'latest',
}
export const ETransactionType = {
DECLARE: 'DECLARE',
DEPLOY: 'DEPLOY',
DEPLOY_ACCOUNT: 'DEPLOY_ACCOUNT',
INVOKE: 'INVOKE',
L1_HANDLER: 'L1_HANDLER',
} as const;

export type ETransactionType = ValuesType<typeof ETransactionType>;

export const ESimulationFlag = {
SKIP_VALIDATE: 'SKIP_VALIDATE',
SKIP_FEE_CHARGE: 'SKIP_FEE_CHARGE',
} as const;

export type ESimulationFlag = ValuesType<typeof ESimulationFlag>;

export const ETransactionStatus = {
RECEIVED: 'RECEIVED',
REJECTED: 'REJECTED',
ACCEPTED_ON_L2: 'ACCEPTED_ON_L2',
ACCEPTED_ON_L1: 'ACCEPTED_ON_L1',
} as const;

export type ETransactionStatus = ValuesType<typeof ETransactionStatus>;

export const ETransactionFinalityStatus = {
ACCEPTED_ON_L2: 'ACCEPTED_ON_L2',
ACCEPTED_ON_L1: 'ACCEPTED_ON_L1',
} as const;

export type ETransactionFinalityStatus = ValuesType<typeof ETransactionFinalityStatus>;

export const ETransactionExecutionStatus = {
SUCCEEDED: 'SUCCEEDED',
REVERTED: 'REVERTED',
} as const;

export type ETransactionExecutionStatus = ValuesType<typeof ETransactionExecutionStatus>;

export const EBlockTag = {
PENDING: 'pending',
LATEST: 'latest',
} as const;

export type EBlockTag = ValuesType<typeof EBlockTag>;

// 'L1' | 'L2'
export enum EDataAvailabilityMode {
L1 = 'L1',
L2 = 'L2',
}
export const EDataAvailabilityMode = {
L1: 'L1',
L2: 'L2',
} as const;

export type EDataAvailabilityMode = ValuesType<typeof EDataAvailabilityMode>;

// 0 | 1
export enum EDAMode {
L1,
L2,
}
export const EDAMode = {
L1: 0,
L2: 1,
} as const;

export type EDAMode = ValuesType<typeof EDAMode>;

/**
* V_ Transaction versions HexString
* F_ Fee Transaction Versions HexString (2 ** 128 + TRANSACTION_VERSION)
*/
export enum ETransactionVersion {
V0 = '0x0',
V1 = '0x1',
V2 = '0x2',
V3 = '0x3',
F0 = '0x100000000000000000000000000000000',
F1 = '0x100000000000000000000000000000001',
F2 = '0x100000000000000000000000000000002',
F3 = '0x100000000000000000000000000000003',
}
export const ETransactionVersion = {
V0: '0x0',
V1: '0x1',
V2: '0x2',
V3: '0x3',
F0: '0x100000000000000000000000000000000',
F1: '0x100000000000000000000000000000001',
F2: '0x100000000000000000000000000000002',
F3: '0x100000000000000000000000000000003',
} as const;

export type ETransactionVersion = ValuesType<typeof ETransactionVersion>;

/**
* Old Transaction Versions
*/
export enum ETransactionVersion2 {
V0 = '0x0',
V1 = '0x1',
V2 = '0x2',
F0 = '0x100000000000000000000000000000000',
F1 = '0x100000000000000000000000000000001',
F2 = '0x100000000000000000000000000000002',
}
export const ETransactionVersion2 = {
V0: '0x0',
V1: '0x1',
V2: '0x2',
F0: '0x100000000000000000000000000000000',
F1: '0x100000000000000000000000000000001',
F2: '0x100000000000000000000000000000002',
} as const;

export type ETransactionVersion2 = ValuesType<typeof ETransactionVersion2>;

/**
* V3 Transaction Versions
*/
export enum ETransactionVersion3 {
V3 = '0x3',
F3 = '0x100000000000000000000000000000003',
}
export const ETransactionVersion3 = {
V3: '0x3',
F3: '0x100000000000000000000000000000003',
} as const;

export type ETransactionVersion3 = ValuesType<typeof ETransactionVersion3>;
Loading

0 comments on commit ebf9f35

Please sign in to comment.