Skip to content

Commit

Permalink
fix: removed parseGetTransactionReceiptResponse rpc response parser f…
Browse files Browse the repository at this point in the history
…or TransactionReceipt
  • Loading branch information
tabaktoni committed Oct 13, 2022
1 parent 0f685ef commit 7fca26d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
8 changes: 3 additions & 5 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ export class RpcProvider implements ProviderInterface {
}

public async getTransactionReceipt(txHash: string): Promise<GetTransactionReceiptResponse> {
return this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash }).then(
this.responseParser.parseGetTransactionReceiptResponse
);
return this.fetchEndpoint('starknet_getTransactionReceipt', { transaction_hash: txHash });
}

public async getClass(classHash: RPC.Felt): Promise<RPC.ContractClass> {
Expand Down Expand Up @@ -356,9 +354,9 @@ export class RpcProvider implements ProviderInterface {
// eslint-disable-next-line no-await-in-loop
const res = await this.getTransactionReceipt(txHash);

if (successStates.includes(res.status)) {
if (res.status && successStates.includes(res.status)) {
onchain = true;
} else if (errorStates.includes(res.status)) {
} else if (res.status && errorStates.includes(res.status)) {
const message = res.status;
const error = new Error(message) as Error & { response: any };
error.response = res;
Expand Down
2 changes: 1 addition & 1 deletion src/types/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export type GetTransactionReceiptResponse =

export interface CommonTransactionReceiptResponse {
transaction_hash: string;
status: Status;
status?: Status;
actual_fee?: string;
status_data?: string;
}
Expand Down
24 changes: 4 additions & 20 deletions src/utils/responseParser/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
CallContractResponse,
EstimateFeeResponse,
GetBlockResponse,
GetTransactionReceiptResponse,
GetTransactionResponse,
} from '../../types';
import { RPC } from '../../types/api';
Expand All @@ -21,15 +20,14 @@ type GetTransactionByHashResponse = RPC.GetTransactionByHashResponse & {
[key: string]: any;
};

type TransactionReceipt = RPC.TransactionReceipt & {
[key: string]: any;
};

export class RPCResponseParser
implements
Omit<
ResponseParser,
'parseDeclareContractResponse' | 'parseDeployContractResponse' | 'parseInvokeFunctionResponse'
| 'parseDeclareContractResponse'
| 'parseDeployContractResponse'
| 'parseInvokeFunctionResponse'
| 'parseGetTransactionReceiptResponse'
>
{
public parseGetBlockResponse(res: RpcGetBlockResponse): GetBlockResponse {
Expand All @@ -56,20 +54,6 @@ export class RPCResponseParser
};
}

public parseGetTransactionReceiptResponse(
res: TransactionReceipt
): GetTransactionReceiptResponse {
return {
transaction_hash: res.transaction_hash,
actual_fee: res.actual_fee,
status: res.status,
status_data: res.status_data,
messages_sent: res.messages_sent,
l1_origin_message: res.l1_origin_message,
events: res.events,
};
}

public parseFeeEstimateResponse(res: RPC.EstimateFeeResponse): EstimateFeeResponse {
return {
overall_fee: toBN(res.overall_fee),
Expand Down

0 comments on commit 7fca26d

Please sign in to comment.