Skip to content

Commit 76b6ab4

Browse files
committed
fix: provider rpc 0.5-0.6 getTransactionReceipt response standardization
1 parent ab50471 commit 76b6ab4

File tree

8 files changed

+40
-233
lines changed

8 files changed

+40
-233
lines changed

__tests__/account.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ describe('deploy and test Wallet', () => {
9696
});
9797

9898
expect(result).toMatchSchemaRef('EstimateFee');
99-
expect(innerInvokeEstFeeSpy.mock.calls[0][1].version).toBe(constants.TRANSACTION_VERSION.F1);
99+
expect([constants.TRANSACTION_VERSION.F1, constants.TRANSACTION_VERSION.F3]).toContain(
100+
innerInvokeEstFeeSpy.mock.calls[0][1].version
101+
);
100102
innerInvokeEstFeeSpy.mockClear();
101103
});
102104

__tests__/schemas/provider.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,16 @@
203203
]
204204
},
205205
"actual_fee": {
206-
"type": "string"
206+
"type": "object",
207+
"properties": {
208+
"amount": {
209+
"type": "string"
210+
},
211+
"unit": {
212+
"type": "string",
213+
"enum": ["WEI", "FRI"]
214+
}
215+
}
207216
},
208217
"status_data": {
209218
"type": "string"

src/provider/rpc.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ export class RpcProvider implements ProviderInterface {
127127
}
128128

129129
public async getTransactionReceipt(txHash: BigNumberish) {
130-
return this.channel.getTransactionReceipt(txHash);
130+
return this.channel
131+
.getTransactionReceipt(txHash)
132+
.then(this.responseParser.parseTransactionReceipt);
131133
}
132134

133135
public async getTransactionTrace(txHash: BigNumberish) {

src/types/api/rpcspec_0_6/nonspec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import {
1515
EVENTS_CHUNK,
1616
EVENT_FILTER,
1717
FEE_ESTIMATE,
18+
FEE_PAYMENT,
1819
FELT,
1920
MSG_FROM_L1,
2021
NONCE_UPDATE,
2122
PENDING_BLOCK_WITH_TXS,
2223
PENDING_BLOCK_WITH_TX_HASHES,
2324
PENDING_STATE_UPDATE,
2425
PENDING_TXN_RECEIPT,
26+
PRICE_UNIT,
2527
REPLACED_CLASS,
2628
RESOURCE_BOUNDS_MAPPING,
2729
RESULT_PAGE_REQUEST,
@@ -88,6 +90,8 @@ export type TransactionStatus = {
8890
execution_status?: TXN_EXECUTION_STATUS;
8991
};
9092
export type ResourceBounds = RESOURCE_BOUNDS_MAPPING;
93+
export type FeePayment = FEE_PAYMENT;
94+
export type PriceUnit = PRICE_UNIT;
9195

9296
// Diff Than Seq
9397
export type StorageDiffs = Array<CONTRACT_STORAGE_DIFF_ITEM>;

src/types/provider/configuration.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,3 @@ export type RpcProviderOptions = {
1212
default?: boolean;
1313
waitMode?: boolean;
1414
};
15-
16-
export type SequencerHttpMethod = 'POST' | 'GET';
17-
18-
export type SequencerProviderOptions = {
19-
headers?: Record<string, string>;
20-
blockIdentifier?: BlockIdentifier;
21-
chainId?: StarknetChainId;
22-
} & (
23-
| {
24-
network: NetworkName | StarknetChainId;
25-
}
26-
| {
27-
baseUrl: string;
28-
feederGatewayUrl?: string;
29-
gatewayUrl?: string;
30-
}
31-
);

src/types/provider/response.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export interface InvokeTransactionReceiptResponse {
112112
execution_status: TransactionExecutionStatus;
113113
finality_status: TransactionFinalityStatus;
114114
status?: `${TransactionStatus}`; // SEQ only
115-
actual_fee: string | RPC.SPEC.FEE_ESTIMATE;
115+
actual_fee: RPC.FeePayment;
116116
block_hash: RPC.BlockHash;
117117
block_number: BlockNumber;
118118
transaction_hash: string;
@@ -127,7 +127,7 @@ export type DeclareTransactionReceiptResponse = {
127127
execution_status: TransactionExecutionStatus;
128128
finality_status: TransactionFinalityStatus;
129129
status?: `${TransactionStatus}`; // SEQ only
130-
actual_fee: string;
130+
actual_fee: RPC.FeePayment;
131131
block_hash: RPC.BlockHash;
132132
block_number: BlockNumber;
133133
transaction_hash: string;
@@ -157,7 +157,7 @@ export type RevertedTransactionReceiptResponse = {
157157
execution_status: TransactionExecutionStatus.REVERTED | any; // any due to RPC Spec issue
158158
finality_status: TransactionFinalityStatus | any;
159159
status?: TransactionStatus; // SEQ only
160-
actual_fee: string | RPC.SPEC.FEE_PAYMENT;
160+
actual_fee: RPC.FeePayment;
161161
block_hash?: string; // ?~ optional due to RPC spec issue
162162
block_number?: BlockNumber; // ?~ optional due to RCP spec issue
163163
transaction_hash: string;

src/utils/responseParser/rpc.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import {
99
EstimateFeeResponse,
1010
EstimateFeeResponseBulk,
1111
GetBlockResponse,
12+
GetTransactionReceiptResponse,
1213
GetTransactionResponse,
14+
RPC,
1315
SimulateTransactionResponse,
1416
} from '../../types';
1517
import {
@@ -45,6 +47,21 @@ export class RPCResponseParser
4547
};
4648
}
4749

50+
public parseTransactionReceipt(res: RPC.TransactionReceipt): GetTransactionReceiptResponse {
51+
if (typeof res.actual_fee === 'string') {
52+
// This case is RPC 0.5. It can be only v2 thx with FRI units
53+
return {
54+
...res,
55+
actual_fee: {
56+
amount: res.actual_fee,
57+
unit: 'FRI' as RPC.PriceUnit,
58+
},
59+
};
60+
}
61+
62+
return res;
63+
}
64+
4865
public parseGetTransactionResponse(res: TransactionWithHash): GetTransactionResponse {
4966
return {
5067
calldata: 'calldata' in res ? res.calldata : [],

src/utils/responseParser/sequencer.ts

Lines changed: 0 additions & 210 deletions
This file was deleted.

0 commit comments

Comments
 (0)