Skip to content

Commit

Permalink
fix: export the underlying types with the composite types
Browse files Browse the repository at this point in the history
update the exports so that when a composite type is exported, the underlying
one is also exported. This helps users to check the types and to use it. It
also improves the documentation
  • Loading branch information
0xknwn committed Apr 23, 2024
1 parent 3354807 commit 7587417
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/types/lib/contract/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type AbiEntry = { name: string; type: 'felt' | 'felt*' | string };

export type EventEntry = { name: string; type: 'felt' | 'felt*' | string; kind: 'key' | 'data' };

enum FunctionAbiType {
export enum FunctionAbiType {
'function',
'l1_handler',
'constructor',
Expand Down
14 changes: 14 additions & 0 deletions src/types/provider/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import {
TransactionWithHash,
} from './spec';

export type { BLOCK_HASH, BLOCK_NUMBER, RESOURCE_PRICE, TXN_HASH };

export { BlockWithTxHashes, ContractClassPayload, FeeEstimate, TransactionReceipt } from './spec';

export type GetBlockResponse = PendingBlock | Block;
Expand Down Expand Up @@ -102,18 +104,24 @@ export type SuccessfulTransactionReceiptResponse =
| DeployTransactionReceiptResponse
| DeclareTransactionReceiptResponse;

export type { TransactionWithHash };
export type GetTransactionResponse = TransactionWithHash;
// Spread individual types for usage convenience
export type { INVOKE_TXN_RECEIPT, PENDING_INVOKE_TXN_RECEIPT };
export type InvokeTransactionReceiptResponse = INVOKE_TXN_RECEIPT | PENDING_INVOKE_TXN_RECEIPT;
export type { DECLARE_TXN_RECEIPT, PENDING_DECLARE_TXN_RECEIPT };
export type DeclareTransactionReceiptResponse = DECLARE_TXN_RECEIPT | PENDING_DECLARE_TXN_RECEIPT;
export type DeployTransactionReceiptResponse = InvokeTransactionReceiptResponse;
export type { DEPLOY_ACCOUNT_TXN_RECEIPT, PENDING_DEPLOY_ACCOUNT_TXN_RECEIPT };
export type DeployAccountTransactionReceiptResponse =
| DEPLOY_ACCOUNT_TXN_RECEIPT
| PENDING_DEPLOY_ACCOUNT_TXN_RECEIPT;
export type { L1_HANDLER_TXN_RECEIPT, PENDING_L1_HANDLER_TXN_RECEIPT };
export type L1HandlerTransactionReceiptResponse =
| L1_HANDLER_TXN_RECEIPT
| PENDING_L1_HANDLER_TXN_RECEIPT;

export type { PRICE_UNIT };
export interface EstimateFeeResponse {
gas_consumed: bigint;
overall_fee: bigint;
Expand All @@ -127,19 +135,23 @@ export interface EstimateFeeResponse {

export type EstimateFeeResponseBulk = Array<EstimateFeeResponse>;

export type { InvokedTransaction };
export type InvokeFunctionResponse = InvokedTransaction;

export type { DeclaredTransaction };
export type DeclareContractResponse = DeclaredTransaction;

export type CallContractResponse = string[];

export type { FELT };
export type Storage = FELT;

export type Nonce = string;

export type { SIMULATION_FLAG };
export type SimulationFlags = Array<SIMULATION_FLAG>;

export type { SimulateTransaction, ResourceBounds };
export type SimulatedTransaction = SimulateTransaction & {
suggestedMaxFee: bigint;
resourceBounds: ResourceBounds;
Expand All @@ -148,7 +160,9 @@ export type SimulatedTransaction = SimulateTransaction & {
export type SimulateTransactionResponse = SimulatedTransaction[];

export type StateUpdateResponse = StateUpdate | PendingStateUpdate;
export type { STATE_UPDATE };
export type StateUpdate = STATE_UPDATE;
export type { PENDING_STATE_UPDATE };
export type PendingStateUpdate = PENDING_STATE_UPDATE;

/**
Expand Down
1 change: 1 addition & 0 deletions src/utils/calldata/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export * as cairo from './cairo';
export * as byteArray from './byteArray';
export { parseCalldataField } from './requestParser';

export { AbiParserInterface };
export class CallData {
abi: Abi;

Expand Down
20 changes: 11 additions & 9 deletions src/utils/hash/transactionHash/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function isV3InvokeTx(args: CalcInvokeTxHashArgs): args is CalcV3InvokeTxHashArg
);
}

type CalcV2InvokeTxHashArgs = {
export type CalcV2InvokeTxHashArgs = {
senderAddress: BigNumberish;
version: `${ETransactionVersion2}`;
compiledCalldata: Calldata;
Expand All @@ -41,7 +41,7 @@ type CalcV2InvokeTxHashArgs = {
nonce: BigNumberish;
};

type CalcV3InvokeTxHashArgs = {
export type CalcV3InvokeTxHashArgs = {
senderAddress: BigNumberish;
version: `${ETransactionVersion3}`;
compiledCalldata: Calldata;
Expand All @@ -55,7 +55,7 @@ type CalcV3InvokeTxHashArgs = {
paymasterData: BigNumberish[];
};

type CalcInvokeTxHashArgs = CalcV2InvokeTxHashArgs | CalcV3InvokeTxHashArgs;
export type CalcInvokeTxHashArgs = CalcV2InvokeTxHashArgs | CalcV3InvokeTxHashArgs;

export function calculateInvokeTransactionHash(args: CalcInvokeTxHashArgs) {
if (isV3InvokeTx(args)) {
Expand Down Expand Up @@ -92,7 +92,7 @@ function isV3DeclareTx(args: CalcDeclareTxHashArgs): args is CalcV3DeclareTxHash
);
}

type CalcV2DeclareTxHashArgs = {
export type CalcV2DeclareTxHashArgs = {
classHash: string;
senderAddress: BigNumberish;
version: `${ETransactionVersion2}`;
Expand All @@ -102,7 +102,7 @@ type CalcV2DeclareTxHashArgs = {
compiledClassHash?: string;
};

type CalcV3DeclareTxHashArgs = {
export type CalcV3DeclareTxHashArgs = {
classHash: string;
compiledClassHash: string;
senderAddress: BigNumberish;
Expand All @@ -117,7 +117,7 @@ type CalcV3DeclareTxHashArgs = {
paymasterData: BigNumberish[];
};

type CalcDeclareTxHashArgs = CalcV2DeclareTxHashArgs | CalcV3DeclareTxHashArgs;
export type CalcDeclareTxHashArgs = CalcV2DeclareTxHashArgs | CalcV3DeclareTxHashArgs;

export function calculateDeclareTransactionHash(args: CalcDeclareTxHashArgs) {
if (isV3DeclareTx(args)) {
Expand Down Expand Up @@ -160,7 +160,7 @@ function isV3DeployAccountTx(
);
}

type CalcV2DeployAccountTxHashArgs = {
export type CalcV2DeployAccountTxHashArgs = {
contractAddress: BigNumberish;
classHash: BigNumberish;
constructorCalldata: Calldata;
Expand All @@ -171,7 +171,7 @@ type CalcV2DeployAccountTxHashArgs = {
nonce: BigNumberish;
};

type CalcV3DeployAccountTxHashArgs = {
export type CalcV3DeployAccountTxHashArgs = {
contractAddress: BigNumberish;
classHash: BigNumberish;
compiledConstructorCalldata: Calldata;
Expand All @@ -186,7 +186,9 @@ type CalcV3DeployAccountTxHashArgs = {
paymasterData: BigNumberish[];
};

type CalcDeployAccountTxHashArgs = CalcV2DeployAccountTxHashArgs | CalcV3DeployAccountTxHashArgs;
export type CalcDeployAccountTxHashArgs =
| CalcV2DeployAccountTxHashArgs
| CalcV3DeployAccountTxHashArgs;

export function calculateDeployAccountTransactionHash(args: CalcDeployAccountTxHashArgs) {
if (isV3DeployAccountTx(args)) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/typedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { encodeShortString, isString } from './shortString';
/** @deprecated prefer importing from 'types' over 'typedData' */
export * from '../types/typedData';

interface Context {
export interface Context {
parent?: string;
key?: string;
}
Expand Down
1 change: 1 addition & 0 deletions src/wallet/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
import { StarknetWalletProvider } from './types';
import { StarknetChainId } from '../constants';

export { StarknetWalletProvider };
// Represent 'Selected Active' Account inside Connected Wallet
export class WalletAccount extends Account implements AccountInterface {
public address: string = '';
Expand Down

0 comments on commit 7587417

Please sign in to comment.