Skip to content

Commit

Permalink
fix: provider rpc 0.5-0.6 getTransactionReceipt response standardization
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Dec 12, 2023
1 parent ab50471 commit 76b6ab4
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 233 deletions.
4 changes: 3 additions & 1 deletion __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ describe('deploy and test Wallet', () => {
});

expect(result).toMatchSchemaRef('EstimateFee');
expect(innerInvokeEstFeeSpy.mock.calls[0][1].version).toBe(constants.TRANSACTION_VERSION.F1);
expect([constants.TRANSACTION_VERSION.F1, constants.TRANSACTION_VERSION.F3]).toContain(
innerInvokeEstFeeSpy.mock.calls[0][1].version
);
innerInvokeEstFeeSpy.mockClear();
});

Expand Down
11 changes: 10 additions & 1 deletion __tests__/schemas/provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,16 @@
]
},
"actual_fee": {
"type": "string"
"type": "object",
"properties": {
"amount": {
"type": "string"
},
"unit": {
"type": "string",
"enum": ["WEI", "FRI"]
}
}
},
"status_data": {
"type": "string"
Expand Down
4 changes: 3 additions & 1 deletion src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ export class RpcProvider implements ProviderInterface {
}

public async getTransactionReceipt(txHash: BigNumberish) {
return this.channel.getTransactionReceipt(txHash);
return this.channel
.getTransactionReceipt(txHash)
.then(this.responseParser.parseTransactionReceipt);
}

public async getTransactionTrace(txHash: BigNumberish) {
Expand Down
4 changes: 4 additions & 0 deletions src/types/api/rpcspec_0_6/nonspec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import {
EVENTS_CHUNK,
EVENT_FILTER,
FEE_ESTIMATE,
FEE_PAYMENT,
FELT,
MSG_FROM_L1,
NONCE_UPDATE,
PENDING_BLOCK_WITH_TXS,
PENDING_BLOCK_WITH_TX_HASHES,
PENDING_STATE_UPDATE,
PENDING_TXN_RECEIPT,
PRICE_UNIT,
REPLACED_CLASS,
RESOURCE_BOUNDS_MAPPING,
RESULT_PAGE_REQUEST,
Expand Down Expand Up @@ -88,6 +90,8 @@ export type TransactionStatus = {
execution_status?: TXN_EXECUTION_STATUS;
};
export type ResourceBounds = RESOURCE_BOUNDS_MAPPING;
export type FeePayment = FEE_PAYMENT;
export type PriceUnit = PRICE_UNIT;

// Diff Than Seq
export type StorageDiffs = Array<CONTRACT_STORAGE_DIFF_ITEM>;
Expand Down
17 changes: 0 additions & 17 deletions src/types/provider/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,3 @@ export type RpcProviderOptions = {
default?: boolean;
waitMode?: boolean;
};

export type SequencerHttpMethod = 'POST' | 'GET';

export type SequencerProviderOptions = {
headers?: Record<string, string>;
blockIdentifier?: BlockIdentifier;
chainId?: StarknetChainId;
} & (
| {
network: NetworkName | StarknetChainId;
}
| {
baseUrl: string;
feederGatewayUrl?: string;
gatewayUrl?: string;
}
);
6 changes: 3 additions & 3 deletions src/types/provider/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export interface InvokeTransactionReceiptResponse {
execution_status: TransactionExecutionStatus;
finality_status: TransactionFinalityStatus;
status?: `${TransactionStatus}`; // SEQ only
actual_fee: string | RPC.SPEC.FEE_ESTIMATE;
actual_fee: RPC.FeePayment;
block_hash: RPC.BlockHash;
block_number: BlockNumber;
transaction_hash: string;
Expand All @@ -127,7 +127,7 @@ export type DeclareTransactionReceiptResponse = {
execution_status: TransactionExecutionStatus;
finality_status: TransactionFinalityStatus;
status?: `${TransactionStatus}`; // SEQ only
actual_fee: string;
actual_fee: RPC.FeePayment;
block_hash: RPC.BlockHash;
block_number: BlockNumber;
transaction_hash: string;
Expand Down Expand Up @@ -157,7 +157,7 @@ export type RevertedTransactionReceiptResponse = {
execution_status: TransactionExecutionStatus.REVERTED | any; // any due to RPC Spec issue
finality_status: TransactionFinalityStatus | any;
status?: TransactionStatus; // SEQ only
actual_fee: string | RPC.SPEC.FEE_PAYMENT;
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;
Expand Down
17 changes: 17 additions & 0 deletions src/utils/responseParser/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
EstimateFeeResponse,
EstimateFeeResponseBulk,
GetBlockResponse,
GetTransactionReceiptResponse,
GetTransactionResponse,
RPC,
SimulateTransactionResponse,
} from '../../types';
import {
Expand Down Expand Up @@ -45,6 +47,21 @@ export class RPCResponseParser
};
}

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
return {
...res,
actual_fee: {
amount: res.actual_fee,
unit: 'FRI' as RPC.PriceUnit,
},
};
}

return res;
}

public parseGetTransactionResponse(res: TransactionWithHash): GetTransactionResponse {
return {
calldata: 'calldata' in res ? res.calldata : [],
Expand Down
210 changes: 0 additions & 210 deletions src/utils/responseParser/sequencer.ts

This file was deleted.

0 comments on commit 76b6ab4

Please sign in to comment.