diff --git a/__tests__/contract.test.ts b/__tests__/contract.test.ts index 357da7052..773978313 100644 --- a/__tests__/contract.test.ts +++ b/__tests__/contract.test.ts @@ -2,9 +2,9 @@ import { BigNumberish, Contract, ContractFactory, + GetTransactionReceiptResponse, ParsedEvents, RawArgs, - SuccessfulTransactionReceiptResponse, json, stark, } from '../src'; @@ -720,7 +720,7 @@ describe('Complex interaction', () => { test('invoke compiled data', async () => { const result = await erc20Echo20Contract.iecho(CallData.compile(request)); const transaction = await provider.waitForTransaction(result.transaction_hash); - expect((transaction as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined(); + expect((transaction as GetTransactionReceiptResponse).execution_status).toBeDefined(); }); // skip on live for performance @@ -730,19 +730,19 @@ describe('Complex interaction', () => { const result = await erc20Echo20Contract.iecho(calldata); const transaction = await provider.waitForTransaction(result.transaction_hash); - expect((transaction as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined(); + expect((transaction as GetTransactionReceiptResponse).execution_status).toBeDefined(); const result1 = await erc20Echo20Contract.iecho(...args); const transaction1 = await provider.waitForTransaction(result1.transaction_hash); - expect((transaction1 as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined(); + expect((transaction1 as GetTransactionReceiptResponse).execution_status).toBeDefined(); const result2 = await erc20Echo20Contract.invoke('iecho', calldata); const transaction2 = await provider.waitForTransaction(result2.transaction_hash); - expect((transaction2 as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined(); + expect((transaction2 as GetTransactionReceiptResponse).execution_status).toBeDefined(); const result3 = await erc20Echo20Contract.invoke('iecho', args); const transaction3 = await provider.waitForTransaction(result3.transaction_hash); - expect((transaction3 as SuccessfulTransactionReceiptResponse).execution_status).toBeDefined(); + expect((transaction3 as GetTransactionReceiptResponse).execution_status).toBeDefined(); }); describe('speedup live tests', () => { @@ -795,9 +795,7 @@ describe('Complex interaction', () => { { formatResponse } ); const transaction = await provider.waitForTransaction(result.transaction_hash); - expect( - (transaction as SuccessfulTransactionReceiptResponse).execution_status - ).toBeDefined(); + expect((transaction as GetTransactionReceiptResponse).execution_status).toBeDefined(); }); }); diff --git a/__tests__/defaultProvider.test.ts b/__tests__/defaultProvider.test.ts index b081ec4a7..aae724900 100644 --- a/__tests__/defaultProvider.test.ts +++ b/__tests__/defaultProvider.test.ts @@ -181,7 +181,7 @@ describe('defaultProvider', () => { }), }) .then((res) => { - expect(Array.isArray(res.result)).toBe(true); + expect(Array.isArray(res)).toBe(true); }) ).resolves.not.toThrow(); }); diff --git a/src/contract/default.ts b/src/contract/default.ts index d47227a35..df421d514 100644 --- a/src/contract/default.ts +++ b/src/contract/default.ts @@ -248,14 +248,14 @@ export class Contract implements ContractInterface { }, blockIdentifier ) - .then((x) => { + .then((it) => { if (!parseResponse) { - return x.result; + return it; } if (formatResponse) { - return this.callData.format(method, x.result, formatResponse); + return this.callData.format(method, it, formatResponse); } - return this.callData.parse(method, x.result); + return this.callData.parse(method, it); }); } diff --git a/src/provider/extensions/starknetId.ts b/src/provider/extensions/starknetId.ts index b75c53b00..0728a5cdc 100644 --- a/src/provider/extensions/starknetId.ts +++ b/src/provider/extensions/starknetId.ts @@ -38,7 +38,7 @@ export class StarknetId { address, }), }); - const decimalDomain = hexDomain.result.map((element) => BigInt(element)).slice(1); + const decimalDomain = hexDomain.map((element) => BigInt(element)).slice(1); const stringDomain = useDecoded(decimalDomain); @@ -72,7 +72,7 @@ export class StarknetId { }), }); - return addressData.result[0]; + return addressData[0]; } catch { throw Error('Could not get address from stark name'); } diff --git a/src/provider/rpc.ts b/src/provider/rpc.ts index 9171440cf..44b5ae512 100644 --- a/src/provider/rpc.ts +++ b/src/provider/rpc.ts @@ -119,9 +119,7 @@ export class RpcProvider implements ProviderInterface { } public async getTransaction(txHash: BigNumberish) { - return this.channel - .getTransactionByHash(txHash) - .then(this.responseParser.parseGetTransactionResponse); + return this.channel.getTransactionByHash(txHash); } public async getTransactionByHash(txHash: BigNumberish) { @@ -161,7 +159,9 @@ export class RpcProvider implements ProviderInterface { options?: getSimulateTransactionOptions ) { // can't be named simulateTransaction because of argument conflict with account - return this.channel.simulateTransaction(invocations, options); + return this.channel + .simulateTransaction(invocations, options) + .then(this.responseParser.parseSimulateTransactionResponse); } public async waitForTransaction(txHash: BigNumberish, options?: waitForTransactionOptions) { @@ -340,9 +340,8 @@ export class RpcProvider implements ProviderInterface { } public async callContract(call: Call, blockIdentifier?: BlockIdentifier) { - return this.channel - .callContract(call, blockIdentifier) - .then(this.responseParser.parseCallContractResponse); + return this.channel.callContract(call, blockIdentifier); + // .then(this.responseParser.parseCallContractResponse); } /** diff --git a/src/types/account.ts b/src/types/account.ts index f4f9beca7..a54a56247 100644 --- a/src/types/account.ts +++ b/src/types/account.ts @@ -1,5 +1,15 @@ import { EDataAvailabilityMode, ETransactionVersion, ResourceBounds } from './api'; -import { BigNumberish, BlockIdentifier, V3TransactionDetails } from './lib'; +import { + AllowArray, + BigNumberish, + BlockIdentifier, + Call, + DeclareContractPayload, + DeployAccountContractPayload, + TransactionType, + UniversalDeployerContractPayload, + V3TransactionDetails, +} from './lib'; import { DeclareTransactionReceiptResponse, EstimateFeeResponse } from './provider'; export interface EstimateFee extends EstimateFeeResponse {} @@ -69,3 +79,21 @@ export enum SIMULATION_FLAG { SKIP_VALIDATE = 'SKIP_VALIDATE', SKIP_EXECUTE = 'SKIP_EXECUTE', } + +export type EstimateFeeAction = + | { + type: TransactionType.INVOKE; + payload: AllowArray; + } + | { + type: TransactionType.DECLARE; + payload: DeclareContractPayload; + } + | { + type: TransactionType.DEPLOY_ACCOUNT; + payload: DeployAccountContractPayload; + } + | { + type: TransactionType.DEPLOY; + payload: UniversalDeployerContractPayload; + }; diff --git a/src/types/api/rpcspec_0_6/methods.ts b/src/types/api/rpcspec_0_6/methods.ts index 471b681f8..0350b0360 100644 --- a/src/types/api/rpcspec_0_6/methods.ts +++ b/src/types/api/rpcspec_0_6/methods.ts @@ -11,11 +11,9 @@ import { FELT, FUNCTION_CALL, MSG_FROM_L1, - PENDING_STATE_UPDATE, RESULT_PAGE_REQUEST, SIMULATION_FLAG, SIMULATION_FLAG_FOR_ESTIMATE_FEE, - STATE_UPDATE, STORAGE_KEY, TXN_HASH, } from './components'; @@ -33,6 +31,7 @@ import { InvokedTransaction, Nonce, SimulateTransactionResponse, + StateUpdate, Syncing, TransactionReceipt, TransactionStatus, @@ -72,7 +71,7 @@ type ReadMethods = { params: { block_id: BLOCK_ID; }; - result: STATE_UPDATE | PENDING_STATE_UPDATE; + result: StateUpdate; errors: Errors.BLOCK_NOT_FOUND; }; diff --git a/src/types/api/rpcspec_0_6/nonspec.ts b/src/types/api/rpcspec_0_6/nonspec.ts index 251f1e201..3242d1d3d 100644 --- a/src/types/api/rpcspec_0_6/nonspec.ts +++ b/src/types/api/rpcspec_0_6/nonspec.ts @@ -42,10 +42,11 @@ import { // response starknet_getClass export type ContractClass = CONTRACT_CLASS | DEPRECATED_CONTRACT_CLASS; // response starknet_simulateTransactions -export type SimulateTransactionResponse = { +export type SimulateTransaction = { transaction_trace: TRANSACTION_TRACE; fee_estimation: FEE_ESTIMATE; -}[]; +}; +export type SimulateTransactionResponse = SimulateTransaction[]; // response starknet_estimateFee export type FeeEstimate = FEE_ESTIMATE; // response starknet_getTransactionByHash, starknet_getTransactionByBlockIdAndIndex @@ -79,6 +80,8 @@ export type TransactionHash = TXN_HASH; export type TransactionTrace = TRANSACTION_TRACE; export type BlockHash = BLOCK_HASH; export type TransactionReceipt = TXN_RECEIPT | PENDING_TXN_RECEIPT; +export type Receipt = TXN_RECEIPT; +export type PendingReceipt = PENDING_TXN_RECEIPT; export type EventFilter = EVENT_FILTER & RESULT_PAGE_REQUEST; export type SimulationFlags = Array; export type L1Message = MSG_FROM_L1; diff --git a/src/types/api/sequencer.ts b/src/types/api/sequencer.ts deleted file mode 100644 index 1b1f9e786..000000000 --- a/src/types/api/sequencer.ts +++ /dev/null @@ -1,517 +0,0 @@ -import { - Abi, - AllowArray, - BigNumberish, - BlockIdentifier, - BlockNumber, - BlockStatus, - ByteCode, - CairoAssembly, - CompiledContract, - ContractClass, - EntryPointType, - RawCalldata, - TransactionExecutionStatus, - TransactionFinalityStatus, - TransactionStatus, - TransactionType, -} from '../lib'; - -// #region | originally not included in the namespace -export type GetTransactionStatusResponse = { - tx_status: TransactionStatus; - execution_status: TransactionExecutionStatus; - finality_status: TransactionFinalityStatus; - block_hash?: string; - tx_failure_reason?: { - code: string; - error_message: string; - }; - tx_revert_reason?: string; -}; - -export type GetContractAddressesResponse = { - Starknet: string; - GpsStatementVerifier: string; -}; - -export type FunctionInvocation = { - caller_address: string; - contract_address: string; - calldata: RawCalldata; - call_type?: string; - class_hash?: string; - selector?: string; - entry_point_type?: EntryPointType.EXTERNAL; // TODO: check this - result: Array; - execution_resources: ExecutionResources; - internal_calls: Array; - events: Array; - messages: Array; -}; - -export type ExecutionResources = { - n_steps: number; - builtin_instance_counter: { - pedersen_builtin: number; - range_check_builtin: number; - bitwise_builtin: number; - output_builtin: number; - ecdsa_builtin: number; - ec_op_builtin?: number; - }; - n_memory_holes: number; -}; - -export type CallL1Handler = { - from_address: string; - to_address: string; - entry_point_selector: string; - payload: Array; -}; - -export type DeployedContractItem = { - address: string; - class_hash: string; -}; - -export type SequencerIdentifier = { blockHash: string } | { blockNumber: BlockNumber }; -// #endregion - -export type TransactionTraceResponse = { - validate_invocation?: FunctionInvocation; - function_invocation?: FunctionInvocation; - fee_transfer_invocation?: FunctionInvocation; - constructor_invocation?: FunctionInvocation; - signature: string[]; -}; - -export type DeclareTransaction = { - type: TransactionType.DECLARE; - sender_address: string; - contract_class: ContractClass; - signature?: string[]; - nonce: BigNumberish; - max_fee?: BigNumberish; - version?: BigNumberish; - compiled_class_hash?: string; // v2 declare -}; - -export type DeployTransaction = { - type: TransactionType.DEPLOY; - contract_definition: ContractClass; - contract_address_salt: BigNumberish; - constructor_calldata: string[]; - nonce?: BigNumberish; -}; - -export type DeployAccountTransaction = { - type: TransactionType.DEPLOY_ACCOUNT; - class_hash: string; - contract_address_salt: BigNumberish; - constructor_calldata: string[]; - signature?: string[]; - max_fee?: BigNumberish; - version?: BigNumberish; - nonce?: BigNumberish; -}; - -export type InvokeFunctionTransaction = { - type: TransactionType.INVOKE; - sender_address: string; - signature?: string[]; - entry_point_type?: EntryPointType.EXTERNAL; // TODO: check this - calldata?: RawCalldata; - nonce: BigNumberish; - max_fee?: BigNumberish; - version?: BigNumberish; -}; - -export type Transaction = - | DeclareTransaction - | DeployTransaction - | InvokeFunctionTransaction - | DeployAccountTransaction; - -export type AddTransactionResponse = { - transaction_hash: string; - code?: 'TRANSACTION_RECEIVED'; - address?: string; - class_hash?: string; -}; - -export type GetCodeResponse = { - bytecode: ByteCode; - abi: Abi; -}; - -export interface InvokeFunctionTransactionResponse extends InvokeFunctionTransaction { - transaction_hash: string; - entry_point_selector: string; -} - -export type TransactionResponse = - | DeclareTransaction - | DeployTransaction - | InvokeFunctionTransactionResponse; - -export type SuccessfulTransactionResponse = { - execution_status: TransactionExecutionStatus.SUCCEEDED; - finality_status: TransactionFinalityStatus; - status: TransactionStatus; - block_hash: string; - block_number: BlockNumber; - transaction_index: number; - transaction: TransactionResponse; -}; - -export type RevertedTransactionResponse = { - execution_status: TransactionExecutionStatus.REVERTED; - finality_status: TransactionFinalityStatus; - status: TransactionStatus; - block_hash: string; - block_number: BlockNumber; - transaction_index: number; - transaction: TransactionResponse; - revert_error: string; -}; - -export type FailedTransactionResponse = { - status: TransactionStatus.REJECTED; - transaction_failure_reason: { - code: string; - error_message: string; - }; - transaction: TransactionResponse; -}; - -export type GetTransactionResponse = - | SuccessfulTransactionResponse - | RevertedTransactionResponse - | FailedTransactionResponse; - -export type TransactionReceiptResponse = - | SuccessfulTransactionReceiptResponse - | RevertedTransactionReceiptResponse - | RejectedTransactionReceiptResponse; - -export type SuccessfulTransactionReceiptResponse = { - execution_status: TransactionExecutionStatus.SUCCEEDED; - finality_status: TransactionFinalityStatus; - status: TransactionStatus; - actual_fee: string; - block_hash: string; - block_number: BlockNumber; - transaction_hash: string; - transaction_index: number; - l2_to_l1_messages: string[]; - events: string[]; - execution_resources?: ExecutionResources; // INVOKE ONLY -}; - -export type RevertedTransactionReceiptResponse = { - execution_status: TransactionExecutionStatus.REVERTED; - finality_status: TransactionFinalityStatus; - status: TransactionStatus.REVERTED; - actual_fee: string; - block_hash: string; - block_number: BlockNumber; - transaction_hash: string; - transaction_index: number; - l2_to_l1_messages: string[]; - events: string[]; - revert_error: string; -}; - -export type RejectedTransactionReceiptResponse = { - execution_status: TransactionExecutionStatus.REJECTED; - finality_status: TransactionFinalityStatus; - status: TransactionStatus.REJECTED; - transaction_hash: string; - l2_to_l1_messages: string[]; - events: string[]; - transaction_failure_reason: { - code: string; - error_message: string; - }; -}; - -export type GetBlockResponse = { - block_number: number; - state_root: string; - block_hash: string; - transactions: { - [txHash: string]: TransactionResponse; - }; - timestamp: number; - transaction_receipts: { - [txHash: string]: { - block_hash: string; - transaction_hash: string; - l2_to_l1_messages: { - to_address: string; - payload: string[]; - from_address: string; - }[]; - block_number: BlockNumber; - status: TransactionStatus; - transaction_index: number; - }; - }; - parent_block_hash: string; - status: BlockStatus; - gas_price: string; - sequencer_address: string; - starknet_version: string; -}; - -export type CallContractTransaction = { - calldata?: RawCalldata; - max_fee?: BigNumberish; - version?: BigNumberish; - entry_point_selector: string; -} & ( - | { - sender_address: string; - signature: string[]; - } - | { - contract_address: string; - signature?: never; - } -); - -export type CallContractResponse = { - result: string[]; -}; - -export type InvokeEstimateFee = Omit; -export type DeclareEstimateFee = Omit; -export type DeployAccountEstimateFee = Omit; -export type DeployEstimateFee = DeployTransaction; - -export type SimulateTransactionResponse = { - trace: TransactionTraceResponse; // diff with OPENRPC "transaction_trace" - fee_estimation: EstimateFeeResponse; -}; - -export type AccountTransactionItem = - | InvokeEstimateFee - | DeclareEstimateFee - | DeployEstimateFee - | DeployAccountEstimateFee; - -/** - * Transaction filled with account data - */ -export type AccountTransaction = AllowArray; - -// Support 0.9.1 changes in a backward-compatible way -export type EstimateFeeResponse = - | { - overall_fee: number; - gas_price: number; - gas_usage: number; - uint: string; - } - | { - amount: bigint; - unit: string; - }; - -export type EstimateFeeResponseBulk = AllowArray; - -export type BlockTransactionTracesResponse = { - traces: Array; -}; - -export type Storage = string; - -export type StateUpdateResponse = { - block_hash: string; - new_root: string; - old_root: string; - state_diff: { - storage_diffs: StorageDiffs; - nonces: Nonces; - deployed_contracts: Array; - old_declared_contracts: OldDeclaredContracts; - declared_classes: DeclaredClasses; - replaced_classes: ReplacedClasses; // no definition is it array of string - }; -}; - -export type StorageDiffs = { [address: string]: Array }; - -export type StateDiffItem = { key: string; value: string }; - -export type Nonces = { [address: string]: Nonce }; - -export type Nonce = string; - -export type DeployedContracts = DeployedContractItem[]; - -export type OldDeclaredContracts = string[]; - -export type DeclaredClasses = DeclaredClass[]; - -export type DeclaredClass = { class_hash: string; compiled_class_hash: string }; - -export type ReplacedClasses = string[]; // no definition is it array of string ? - -export type Endpoints = { - get_contract_addresses: { - QUERY: never; - REQUEST: never; - RESPONSE: GetContractAddressesResponse; - }; - add_transaction: { - QUERY: never; - REQUEST: Transaction; - RESPONSE: AddTransactionResponse; - }; - get_transaction: { - QUERY: { - transactionHash: string; - }; - REQUEST: never; - RESPONSE: GetTransactionResponse; - }; - get_transaction_status: { - QUERY: { - transactionHash: string; - }; - REQUEST: never; - RESPONSE: GetTransactionStatusResponse; - }; - get_transaction_trace: { - QUERY: { - transactionHash: string; - }; - REQUEST: never; - RESPONSE: TransactionTraceResponse; - }; - get_transaction_receipt: { - QUERY: { - transactionHash: string; - }; - REQUEST: never; - RESPONSE: TransactionReceiptResponse; - }; - get_nonce: { - QUERY: { - contractAddress: string; - blockIdentifier: BlockIdentifier; - }; - REQUEST: never; - RESPONSE: Nonce; - }; - get_storage_at: { - QUERY: { - contractAddress: string; - key: BigNumberish; - blockIdentifier: BlockIdentifier; - }; - REQUEST: never; - RESPONSE: Storage; - }; - get_code: { - QUERY: { - contractAddress: string; - blockIdentifier: BlockIdentifier; - }; - REQUEST: never; - RESPONSE: GetCodeResponse; - }; - get_block: { - QUERY: { - blockIdentifier: BlockIdentifier; - }; - REQUEST: never; - RESPONSE: GetBlockResponse; - }; - call_contract: { - QUERY: { - blockIdentifier: BlockIdentifier; - }; - REQUEST: CallContractTransaction; - RESPONSE: CallContractResponse; - }; - estimate_fee: { - QUERY: { - blockIdentifier: BlockIdentifier; - skipValidate: boolean; - }; - REQUEST: AccountTransactionItem; - RESPONSE: EstimateFeeResponse; - }; - get_class_by_hash: { - QUERY: { - classHash: string; - blockIdentifier?: BlockIdentifier; - }; - REQUEST: never; - RESPONSE: CompiledContract; - }; - get_class_hash_at: { - QUERY: { - contractAddress: string; - blockIdentifier?: BlockIdentifier; - }; - REQUEST: never; - RESPONSE: string; - }; - get_state_update: { - QUERY: { - blockHash?: string; - blockNumber?: BlockNumber; - }; - REQUEST: never; - RESPONSE: StateUpdateResponse; - }; - get_full_contract: { - QUERY: { - contractAddress: string; - blockIdentifier?: BlockIdentifier; - }; - REQUEST: never; - RESPONSE: CompiledContract; - }; - estimate_message_fee: { - QUERY: any; - REQUEST: any; - RESPONSE: EstimateFeeResponse; - }; - simulate_transaction: { - QUERY: { - blockIdentifier: BlockIdentifier; - skipValidate: boolean; - }; - REQUEST: AccountTransaction; - RESPONSE: SimulateTransactionResponse; - }; - estimate_fee_bulk: { - QUERY: { - blockIdentifier: BlockIdentifier; - skipValidate: boolean; - }; - REQUEST: AccountTransaction; - RESPONSE: EstimateFeeResponseBulk; - }; - get_block_traces: { - QUERY: { - blockHash?: string; - blockNumber?: BlockNumber; - }; - REQUEST: never; - RESPONSE: BlockTransactionTracesResponse; - }; - get_compiled_class_by_class_hash: { - QUERY: { - classHash: string; - blockIdentifier?: BlockIdentifier; - }; - REQUEST: any; - RESPONSE: CairoAssembly; - }; -}; diff --git a/src/types/index.ts b/src/types/index.ts index 02f824e4c..a096ffccc 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -8,13 +8,3 @@ export * from './typedData'; export * from './cairoEnum'; export * as RPC from './api'; -export { - CallL1Handler, - DeployedContractItem, - ExecutionResources, - FunctionInvocation, - GetContractAddressesResponse, - GetTransactionStatusResponse, - SequencerIdentifier, -} from './api/sequencer'; -export * as Sequencer from './api/sequencer'; diff --git a/src/types/provider/response.ts b/src/types/provider/response.ts index a73f26ea1..79184ae41 100644 --- a/src/types/provider/response.ts +++ b/src/types/provider/response.ts @@ -4,25 +4,8 @@ */ import * as RPC from '../api'; -import * as Sequencer from '../api/sequencer'; -import { - AllowArray, - BlockNumber, - Call, - CompiledSierra, - DeclareContractPayload, - DeployAccountContractPayload, - LegacyContractClass, - RawCalldata, - Signature, - TransactionExecutionStatus, - TransactionFinalityStatus, - TransactionStatus, - TransactionType, - UniversalDeployerContractPayload, -} from '../lib'; - -// OK +import { CompiledSierra, LegacyContractClass } from '../lib'; + export type GetBlockResponse = PendingBlock | Block; export type PendingBlock = { @@ -48,126 +31,32 @@ export type Block = { transactions: RPC.SPEC.TXN_HASH[]; }; -export type GetTransactionResponse = - | InvokeTransactionResponse - | DeclareTransactionResponse - | RejectedTransactionResponse; - -export interface CommonTransactionResponse { - transaction_hash?: string; - version?: string; - signature?: Signature; - max_fee?: string; - nonce?: string; -} - -export interface InvokeTransactionResponse extends CommonTransactionResponse { - contract_address?: string; // TODO: Added for RPC comp, remove when rpc update to sender_address - sender_address?: string; - entry_point_selector?: string; - calldata: RawCalldata; -} - -export interface DeclareTransactionResponse extends CommonTransactionResponse { - contract_class?: any; - sender_address?: string; -} - -export interface MessageToL1 { - to_address: string; - payload: Array; -} +export type GetTransactionResponse = RPC.TransactionWithHash; +// TODO: solve this one export interface Event { from_address: string; keys: Array; data: Array; } -export interface MessageToL2 { - from_address: string; - payload: Array; -} - -export type RejectedTransactionResponse = { - status: `${TransactionStatus.REJECTED}`; - transaction_failure_reason: { - code: string; - error_message: string; - }; -}; - -export type GetTransactionReceiptResponse = - | SuccessfulTransactionReceiptResponse - | RevertedTransactionReceiptResponse - | RejectedTransactionReceiptResponse; - -export type SuccessfulTransactionReceiptResponse = - | InvokeTransactionReceiptResponse - | DeployTransactionReceiptResponse - | DeclareTransactionReceiptResponse; - -export interface InvokeTransactionReceiptResponse { - type?: TransactionType; // RPC only - execution_status: TransactionExecutionStatus; - finality_status: TransactionFinalityStatus; - status?: `${TransactionStatus}`; // SEQ only - actual_fee: RPC.FeePayment; - block_hash: RPC.BlockHash; - block_number: BlockNumber; - transaction_hash: string; - transaction_index?: number; // SEQ only - messages_sent: Array; // Casted SEQ l2_to_l1_messages - events: any[]; - execution_resources?: any; // SEQ Only -} - -export type DeclareTransactionReceiptResponse = { - type?: TransactionType; // RPC only - execution_status: TransactionExecutionStatus; - finality_status: TransactionFinalityStatus; - status?: `${TransactionStatus}`; // SEQ only - actual_fee: RPC.FeePayment; - block_hash: RPC.BlockHash; - block_number: BlockNumber; - transaction_hash: string; - transaction_index?: number; // SEQ only - messages_sent: Array; // Casted SEQ l2_to_l1_messages - events: any[]; -}; - +// TODO Check if can be pending discriminated +export type GetTransactionReceiptResponse = RPC.Receipt | RPC.PendingReceipt; +// Spread individual types for usage convenience +export type InvokeTransactionReceiptResponse = + | RPC.SPEC.INVOKE_TXN_RECEIPT + | RPC.SPEC.PENDING_INVOKE_TXN_RECEIPT; +export type DeclareTransactionReceiptResponse = + | RPC.SPEC.DECLARE_TXN_RECEIPT + | RPC.SPEC.PENDING_DECLARE_TXN_RECEIPT; export type DeployTransactionReceiptResponse = InvokeTransactionReceiptResponse; +export type DeployAccountTransactionReceiptResponse = + | RPC.SPEC.DEPLOY_ACCOUNT_TXN_RECEIPT + | RPC.SPEC.PENDING_DEPLOY_ACCOUNT_TXN_RECEIPT; +export type L1HandlerTransactionReceiptResponse = + | RPC.SPEC.L1_HANDLER_TXN_RECEIPT + | RPC.SPEC.PENDING_L1_HANDLER_TXN_RECEIPT; -// TODO: Missing RPC DEPLOY_ACCOUNT_TXN_RECEIPT - -// TODO: Missing RPC PENDING_TXN_RECEIPT - -// TODO: Missing RPC L1_HANDLER_TXN_RECEIPT - -export type RejectedTransactionReceiptResponse = { - status: `${TransactionStatus.REJECTED}`; - transaction_failure_reason: { - code: string; - error_message: string; - }; -}; - -export type RevertedTransactionReceiptResponse = { - type?: TransactionType | any; // RPC only // any due to RPC Spec issue - execution_status: TransactionExecutionStatus.REVERTED | any; // any due to RPC Spec issue - finality_status: TransactionFinalityStatus | any; - status?: TransactionStatus; // SEQ only - actual_fee: RPC.FeePayment; - block_hash?: string; // ?~ optional due to RPC spec issue - block_number?: BlockNumber; // ?~ optional due to RCP spec issue - transaction_hash: string; - transaction_index?: number; // SEQ only - messages_sent: Array; // SEQ Casted l2_to_l1_messages - events: any[]; - revert_reason?: string; // SEQ Casted revert_error // ?~ optional due to RCP spec issue -}; - -// OK 12.12.2023 export interface EstimateFeeResponse { gas_consumed: bigint; overall_fee: bigint; @@ -177,68 +66,31 @@ export interface EstimateFeeResponse { resourceBounds: RPC.ResourceBounds; } -export interface InvokeFunctionResponse { - transaction_hash: string; -} - -export interface DeclareContractResponse { - transaction_hash: string; - class_hash: string; -} +export type EstimateFeeResponseBulk = Array; -export type CallContractResponse = { - result: Array; -}; +export type InvokeFunctionResponse = RPC.InvokedTransaction; -export type EstimateFeeAction = - | { - type: TransactionType.INVOKE; - payload: AllowArray; - } - | { - type: TransactionType.DECLARE; - payload: DeclareContractPayload; - } - | { - type: TransactionType.DEPLOY_ACCOUNT; - payload: DeployAccountContractPayload; - } - | { - type: TransactionType.DEPLOY; - payload: UniversalDeployerContractPayload; - }; +export type DeclareContractResponse = RPC.DeclaredTransaction; -export type EstimateFeeResponseBulk = Array; +export type CallContractResponse = string[]; -export type Storage = Sequencer.Storage; +export type Storage = RPC.Felt; -export type Nonce = Sequencer.Nonce; +export type Nonce = string; export type SimulationFlags = RPC.SimulationFlags; -export type SimulatedTransaction = { - transaction_trace: RPC.TransactionTrace | Sequencer.TransactionTraceResponse; - fee_estimation: RPC.FeeEstimate | Sequencer.EstimateFeeResponse; - suggestedMaxFee?: string | bigint; +export type SimulatedTransaction = RPC.SimulateTransaction & { + suggestedMaxFee: bigint; + resourceBounds: RPC.ResourceBounds; }; export type SimulateTransactionResponse = SimulatedTransaction[]; -// As RPC and Sequencer response diverge, use RPC as common response -export interface StateUpdateResponse { - block_hash?: string; - new_root?: string; - old_root: string; - state_diff: { - storage_diffs: RPC.StorageDiffs; // API DIFF - deployed_contracts: Sequencer.DeployedContracts; - nonces: RPC.NonceUpdates; // API DIFF - old_declared_contracts?: Sequencer.OldDeclaredContracts; // Sequencer Only - declared_classes?: Sequencer.DeclaredClasses; - replaced_classes?: Sequencer.ReplacedClasses | RPC.ReplacedClasses; - deprecated_declared_classes?: RPC.DeprecatedDeclaredClasses; // RPC Only - }; -} +// TODO: Make discriminator key +export type StateUpdateResponse = StateUpdate | PendingStateUpdate; +export type StateUpdate = RPC.SPEC.STATE_UPDATE; +export type PendingStateUpdate = RPC.SPEC.PENDING_STATE_UPDATE; /** * Standardized type diff --git a/src/utils/provider.ts b/src/utils/provider.ts index e94d87c2e..ddcb8db3d 100644 --- a/src/utils/provider.ts +++ b/src/utils/provider.ts @@ -2,7 +2,6 @@ import { NetworkName, RPC_NODES } from '../constants'; import { BigNumberish, BlockIdentifier, - BlockNumber, BlockTag, CompiledContract, CompiledSierra, @@ -10,7 +9,6 @@ import { InvocationsDetailsWithNonce, LegacyContractClass, RPC, - SequencerIdentifier, SierraContractClass, V3TransactionDetails, } from '../types'; @@ -163,11 +161,11 @@ export class Block { toString = () => this.hash; - get sequencerIdentifier(): SequencerIdentifier { + /* get sequencerIdentifier(): SequencerIdentifier { return this.hash !== null ? { blockHash: this.hash as string } : { blockNumber: (this.number ?? this.tag) as BlockNumber }; - } + } */ } export function defStateUpdate( diff --git a/src/utils/responseParser/rpc.ts b/src/utils/responseParser/rpc.ts index 6cc674b7e..e4cd2cc8f 100644 --- a/src/utils/responseParser/rpc.ts +++ b/src/utils/responseParser/rpc.ts @@ -3,23 +3,14 @@ * Intersection (sequencer response ∩ (∪ rpc responses)) */ import { - CallContractResponse, ContractClassResponse, EstimateFeeResponse, EstimateFeeResponseBulk, GetBlockResponse, GetTransactionReceiptResponse, - GetTransactionResponse, RPC, SimulateTransactionResponse, } from '../../types'; -import { - BlockWithTxHashes, - ContractClass, - FeeEstimate, - SimulateTransactionResponse as RPCSimulateTransactionResponse, - TransactionWithHash, -} from '../../types/api/rpcspec_0_6'; import { toBigInt } from '../num'; import { estimateFeeToBounds, estimatedFeeToMaxFee } from '../stark'; import { ResponseParser } from '.'; @@ -32,15 +23,18 @@ export class RPCResponseParser | 'parseDeployContractResponse' | 'parseInvokeFunctionResponse' | 'parseGetTransactionReceiptResponse' + | 'parseGetTransactionResponse' + | 'parseCallContractResponse' > { - public parseGetBlockResponse(res: BlockWithTxHashes): GetBlockResponse { + public parseGetBlockResponse(res: RPC.BlockWithTxHashes): GetBlockResponse { return 'status' in res ? res : { ...res, status: 'PENDING' }; } public parseTransactionReceipt(res: RPC.TransactionReceipt): GetTransactionReceiptResponse { - if (typeof res.actual_fee === 'string') { - // This case is RPC 0.5. It can be only v2 thx with FRI units + // HOTFIX RPC 0.5 to align with RPC 0.6 + // This case is RPC 0.5. It can be only v2 thx with FRI units + if ('actual_fee' in res && typeof res.actual_fee === 'string') { return { ...res, actual_fee: { @@ -53,20 +47,7 @@ export class RPCResponseParser return res; } - public parseGetTransactionResponse(res: TransactionWithHash): GetTransactionResponse { - return { - calldata: 'calldata' in res ? res.calldata : [], - contract_address: 'contract_address' in res ? res.contract_address : '', - sender_address: 'sender_address' in res ? res.sender_address : '', - max_fee: 'max_fee' in res ? res.max_fee : '', - nonce: 'nonce' in res ? res.nonce : '', - signature: 'signature' in res ? res.signature : [], - transaction_hash: res.transaction_hash, - version: res.version, - }; - } - - public parseFeeEstimateResponse(res: FeeEstimate[]): EstimateFeeResponse { + public parseFeeEstimateResponse(res: RPC.FeeEstimate[]): EstimateFeeResponse { const val = res[0]; return { overall_fee: toBigInt(val.overall_fee), @@ -78,7 +59,7 @@ export class RPCResponseParser }; } - public parseFeeEstimateBulkResponse(res: FeeEstimate[]): EstimateFeeResponseBulk { + public parseFeeEstimateBulkResponse(res: RPC.FeeEstimate[]): EstimateFeeResponseBulk { return res.map((val) => ({ overall_fee: toBigInt(val.overall_fee), gas_consumed: toBigInt(val.gas_consumed), @@ -89,24 +70,19 @@ export class RPCResponseParser })); } - public parseCallContractResponse(res: string[]): CallContractResponse { - return { - result: res, - }; - } - public parseSimulateTransactionResponse( - res: RPCSimulateTransactionResponse + res: RPC.SimulateTransactionResponse ): SimulateTransactionResponse { return res.map((it) => { return { ...it, suggestedMaxFee: estimatedFeeToMaxFee(BigInt(it.fee_estimation.overall_fee)), + resourceBounds: estimateFeeToBounds(it.fee_estimation), }; }); } - public parseContractClassResponse(res: ContractClass): ContractClassResponse { + public parseContractClassResponse(res: RPC.ContractClass): ContractClassResponse { return { ...res, abi: typeof res.abi === 'string' ? JSON.parse(res.abi) : res.abi,