starknet 3.18.2 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -0
- package/README.md +1 -2
- package/__tests__/account.test.ts +11 -56
- package/__tests__/contract.test.ts +11 -49
- package/__tests__/defaultProvider.test.ts +321 -0
- package/__tests__/fixtures.ts +32 -11
- package/__tests__/jest.setup.ts +2 -3
- package/__tests__/rpcProvider.test.ts +17 -0
- package/__tests__/sequencerProvider.test.ts +45 -0
- package/account/default.d.ts +54 -77
- package/account/default.js +271 -596
- package/account/index.js +18 -31
- package/account/interface.d.ts +66 -95
- package/account/interface.js +20 -30
- package/constants.d.ts +17 -19
- package/constants.js +2038 -2059
- package/contract/contractFactory.d.ts +25 -29
- package/contract/contractFactory.js +94 -210
- package/contract/default.d.ts +117 -146
- package/contract/default.js +582 -776
- package/contract/index.js +19 -32
- package/contract/interface.d.ts +72 -92
- package/contract/interface.js +6 -5
- package/dist/account/default.d.ts +5 -9
- package/dist/account/default.js +35 -169
- package/dist/account/interface.d.ts +3 -15
- package/dist/contract/contractFactory.js +4 -4
- package/dist/contract/default.d.ts +3 -3
- package/dist/contract/default.js +3 -2
- package/dist/contract/interface.d.ts +2 -2
- package/dist/provider/default.d.ts +18 -134
- package/dist/provider/default.js +47 -411
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +2 -0
- package/dist/provider/interface.d.ts +45 -50
- package/dist/provider/rpc.d.ts +57 -0
- package/dist/provider/rpc.js +364 -0
- package/dist/provider/sequencer.d.ts +66 -0
- package/dist/provider/sequencer.js +444 -0
- package/dist/types/account.d.ts +2 -3
- package/dist/types/api/index.d.ts +16 -0
- package/dist/types/api/index.js +18 -0
- package/dist/types/api/rpc.d.ts +221 -0
- package/dist/types/{api.js → api/rpc.js} +0 -0
- package/dist/types/api/sequencer.d.ts +289 -0
- package/dist/types/api/sequencer.js +2 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.js +15 -1
- package/dist/types/lib.d.ts +3 -1
- package/dist/types/provider.d.ts +86 -0
- package/dist/types/provider.js +2 -0
- package/dist/utils/fetchPonyfill.d.ts +2 -0
- package/dist/utils/fetchPonyfill.js +6 -0
- package/dist/utils/provider.d.ts +4 -0
- package/dist/utils/provider.js +38 -0
- package/dist/utils/responseParser/index.d.ts +11 -0
- package/dist/utils/responseParser/index.js +9 -0
- package/dist/utils/responseParser/rpc.d.ts +13 -0
- package/dist/utils/responseParser/rpc.js +96 -0
- package/dist/utils/responseParser/sequencer.d.ts +13 -0
- package/dist/utils/responseParser/sequencer.js +124 -0
- package/index.js +42 -75
- package/package.json +2 -3
- package/provider/default.d.ts +21 -175
- package/provider/default.js +139 -704
- package/provider/errors.d.ts +4 -4
- package/provider/errors.js +30 -40
- package/provider/index.d.ts +2 -0
- package/provider/index.js +22 -33
- package/provider/interface.d.ts +104 -131
- package/provider/interface.js +6 -5
- package/provider/rpc.d.ts +57 -0
- package/provider/rpc.js +364 -0
- package/provider/sequencer.d.ts +66 -0
- package/provider/sequencer.js +444 -0
- package/provider/utils.d.ts +7 -9
- package/provider/utils.js +39 -44
- package/signer/default.d.ts +5 -9
- package/signer/default.js +72 -177
- package/signer/index.js +18 -31
- package/signer/interface.d.ts +29 -33
- package/signer/interface.js +6 -5
- package/src/account/default.ts +26 -146
- package/src/account/interface.ts +5 -20
- package/src/contract/contractFactory.ts +3 -6
- package/src/contract/default.ts +6 -4
- package/src/contract/interface.ts +2 -2
- package/src/provider/default.ts +63 -395
- package/src/provider/index.ts +2 -0
- package/src/provider/interface.ts +68 -63
- package/src/provider/rpc.ts +299 -0
- package/src/provider/sequencer.ts +385 -0
- package/src/types/account.ts +2 -3
- package/src/types/api/index.ts +17 -0
- package/src/types/api/rpc.ts +247 -0
- package/src/types/api/sequencer.ts +331 -0
- package/src/types/index.ts +3 -1
- package/src/types/lib.ts +3 -1
- package/src/types/provider.ts +108 -0
- package/src/utils/fetchPonyfill.ts +4 -0
- package/src/utils/provider.ts +28 -0
- package/src/utils/responseParser/index.ts +28 -0
- package/src/utils/responseParser/rpc.ts +93 -0
- package/src/utils/responseParser/sequencer.ts +127 -0
- package/types/account.d.ts +5 -7
- package/types/account.js +2 -2
- package/types/api/index.d.ts +16 -0
- package/types/api/index.js +18 -0
- package/types/api/rpc.d.ts +221 -0
- package/types/api/rpc.js +2 -0
- package/types/api/sequencer.d.ts +289 -0
- package/types/api/sequencer.js +2 -0
- package/types/contract.d.ts +1 -1
- package/types/contract.js +2 -2
- package/types/index.d.ts +3 -1
- package/types/index.js +35 -34
- package/types/lib.d.ts +36 -41
- package/types/lib.js +2 -2
- package/types/provider.d.ts +86 -0
- package/types/provider.js +2 -0
- package/types/signer.d.ts +2 -2
- package/types/signer.js +2 -2
- package/utils/address.js +26 -37
- package/utils/ellipticCurve.d.ts +1 -6
- package/utils/ellipticCurve.js +73 -137
- package/utils/encode.js +49 -85
- package/utils/fetchPonyfill.d.ts +2 -0
- package/utils/fetchPonyfill.js +6 -0
- package/utils/hash.d.ts +4 -31
- package/utils/hash.js +76 -141
- package/utils/json.d.ts +13 -45
- package/utils/json.js +15 -22
- package/utils/number.d.ts +2 -9
- package/utils/number.js +47 -81
- package/utils/provider.d.ts +4 -0
- package/utils/provider.js +38 -0
- package/utils/responseParser/index.d.ts +11 -0
- package/utils/responseParser/index.js +9 -0
- package/utils/responseParser/rpc.d.ts +13 -0
- package/utils/responseParser/rpc.js +96 -0
- package/utils/responseParser/sequencer.d.ts +13 -0
- package/utils/responseParser/sequencer.js +124 -0
- package/utils/shortString.js +13 -21
- package/utils/stark.d.ts +0 -1
- package/utils/stark.js +59 -93
- package/utils/transaction.d.ts +3 -6
- package/utils/transaction.js +50 -81
- package/utils/typedData/index.d.ts +3 -15
- package/utils/typedData/index.js +109 -175
- package/utils/typedData/types.d.ts +9 -9
- package/utils/typedData/types.js +2 -2
- package/utils/typedData/utils.js +6 -6
- package/utils/uint256.d.ts +5 -5
- package/utils/uint256.js +16 -26
- package/www/docs/API/account.md +3 -4
- package/www/docs/API/contract.md +2 -2
- package/www/docs/API/contractFactory.md +2 -2
- package/www/docs/API/provider.md +185 -74
- package/www/guides/account.md +1 -8
- package/www/guides/erc20.md +3 -0
- package/__tests__/provider.test.ts +0 -168
- package/dist/types/api.d.ts +0 -261
- package/src/types/api.ts +0 -303
- package/types/api.d.ts +0 -287
- package/types/api.js +0 -2
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import BN from 'bn.js';
|
|
2
|
+
|
|
3
|
+
import { BlockIdentifier } from '../../provider/utils';
|
|
4
|
+
import { BigNumberish } from '../../utils/number';
|
|
5
|
+
import {
|
|
6
|
+
Abi,
|
|
7
|
+
BlockNumber,
|
|
8
|
+
EntryPointType,
|
|
9
|
+
RawCalldata,
|
|
10
|
+
Signature,
|
|
11
|
+
Status,
|
|
12
|
+
TransactionStatus,
|
|
13
|
+
} from '../lib';
|
|
14
|
+
import { ContractClass } from '../provider';
|
|
15
|
+
|
|
16
|
+
export type GetTransactionStatusResponse = {
|
|
17
|
+
tx_status: Status;
|
|
18
|
+
block_hash?: string;
|
|
19
|
+
tx_failure_reason?: {
|
|
20
|
+
code: string;
|
|
21
|
+
error_message: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type GetContractAddressesResponse = {
|
|
26
|
+
Starknet: string;
|
|
27
|
+
GpsStatementVerifier: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type InvokeFunctionTrace = {
|
|
31
|
+
caller_address: string;
|
|
32
|
+
contract_address: string;
|
|
33
|
+
code_address: string;
|
|
34
|
+
selector: string;
|
|
35
|
+
calldata: RawCalldata;
|
|
36
|
+
result: Array<any>;
|
|
37
|
+
execution_resources: ExecutionResources;
|
|
38
|
+
internal_call: Array<InvokeFunctionTrace>;
|
|
39
|
+
events: Array<any>;
|
|
40
|
+
messages: Array<any>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type ExecutionResources = {
|
|
44
|
+
n_steps: number;
|
|
45
|
+
builtin_instance_counter: {
|
|
46
|
+
pedersen_builtin: number;
|
|
47
|
+
range_check_builtin: number;
|
|
48
|
+
bitwise_builtin: number;
|
|
49
|
+
output_builtin: number;
|
|
50
|
+
ecdsa_builtin: number;
|
|
51
|
+
ec_op_builtin?: number;
|
|
52
|
+
};
|
|
53
|
+
n_memory_holes: number;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type GetCodeResponse = {
|
|
57
|
+
bytecode: string[];
|
|
58
|
+
abi: Abi;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type GetTransactionTraceResponse = {
|
|
62
|
+
function_invocation: {
|
|
63
|
+
caller_address: string;
|
|
64
|
+
contract_address: string;
|
|
65
|
+
code_address: string;
|
|
66
|
+
selector: string;
|
|
67
|
+
calldata: RawArgs;
|
|
68
|
+
result: Array<any>;
|
|
69
|
+
execution_resources: ExecutionResources;
|
|
70
|
+
internal_call: Array<any>;
|
|
71
|
+
events: Array<any>;
|
|
72
|
+
messages: Array<any>;
|
|
73
|
+
};
|
|
74
|
+
signature: Signature;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type RawArgs = {
|
|
78
|
+
[inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish };
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export namespace Sequencer {
|
|
82
|
+
export type DeclareTransaction = {
|
|
83
|
+
type: 'DECLARE';
|
|
84
|
+
contract_class: ContractClass;
|
|
85
|
+
nonce: BigNumberish;
|
|
86
|
+
sender_address: BigNumberish;
|
|
87
|
+
signature: Signature;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export type DeployTransaction = {
|
|
91
|
+
type: 'DEPLOY';
|
|
92
|
+
contract_definition: ContractClass;
|
|
93
|
+
contract_address_salt: BigNumberish;
|
|
94
|
+
constructor_calldata: string[];
|
|
95
|
+
nonce?: BigNumberish;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export type InvokeFunctionTransaction = {
|
|
99
|
+
type: 'INVOKE_FUNCTION';
|
|
100
|
+
contract_address: string;
|
|
101
|
+
signature?: Signature;
|
|
102
|
+
entry_point_type?: EntryPointType;
|
|
103
|
+
entry_point_selector: string;
|
|
104
|
+
calldata?: RawCalldata;
|
|
105
|
+
nonce?: BigNumberish;
|
|
106
|
+
max_fee?: BigNumberish;
|
|
107
|
+
version?: BigNumberish;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export type Transaction = DeclareTransaction | DeployTransaction | InvokeFunctionTransaction;
|
|
111
|
+
|
|
112
|
+
export type AddTransactionResponse = {
|
|
113
|
+
transaction_hash: string;
|
|
114
|
+
code?: TransactionStatus;
|
|
115
|
+
address?: string;
|
|
116
|
+
class_hash?: string;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export interface InvokeFunctionTransactionResponse extends InvokeFunctionTransaction {
|
|
120
|
+
transaction_hash: string;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export type TransactionResponse =
|
|
124
|
+
| DeclareTransaction
|
|
125
|
+
| DeployTransaction
|
|
126
|
+
| InvokeFunctionTransactionResponse;
|
|
127
|
+
|
|
128
|
+
export type SuccessfulTransactionResponse = {
|
|
129
|
+
status: Status;
|
|
130
|
+
transaction: TransactionResponse;
|
|
131
|
+
block_hash: string;
|
|
132
|
+
block_number: BlockNumber;
|
|
133
|
+
transaction_index: number;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export type FailedTransactionResponse = {
|
|
137
|
+
status: 'REJECTED';
|
|
138
|
+
transaction_failure_reason: {
|
|
139
|
+
code: string;
|
|
140
|
+
error_message: string;
|
|
141
|
+
};
|
|
142
|
+
transaction: TransactionResponse;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export type GetTransactionResponse = SuccessfulTransactionResponse | FailedTransactionResponse;
|
|
146
|
+
|
|
147
|
+
export type TransactionReceiptResponse =
|
|
148
|
+
| SuccessfulTransactionReceiptResponse
|
|
149
|
+
| FailedTransactionReceiptResponse;
|
|
150
|
+
|
|
151
|
+
export type SuccessfulTransactionReceiptResponse = {
|
|
152
|
+
status: Status;
|
|
153
|
+
transaction_hash: string;
|
|
154
|
+
transaction_index: number;
|
|
155
|
+
block_hash: string;
|
|
156
|
+
block_number: BlockNumber;
|
|
157
|
+
l2_to_l1_messages: string[];
|
|
158
|
+
events: string[];
|
|
159
|
+
actual_fee: string;
|
|
160
|
+
execution_resources: ExecutionResources;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export type FailedTransactionReceiptResponse = {
|
|
164
|
+
status: 'REJECTED';
|
|
165
|
+
transaction_failure_reason: {
|
|
166
|
+
code: string;
|
|
167
|
+
error_message: string;
|
|
168
|
+
};
|
|
169
|
+
transaction_hash: string;
|
|
170
|
+
l2_to_l1_messages: string[];
|
|
171
|
+
events: string[];
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export type GetBlockResponse = {
|
|
175
|
+
block_number: number;
|
|
176
|
+
state_root: string;
|
|
177
|
+
block_hash: string;
|
|
178
|
+
transactions: {
|
|
179
|
+
[txHash: string]: TransactionResponse;
|
|
180
|
+
};
|
|
181
|
+
timestamp: number;
|
|
182
|
+
transaction_receipts: {
|
|
183
|
+
[txHash: string]: {
|
|
184
|
+
block_hash: string;
|
|
185
|
+
transaction_hash: string;
|
|
186
|
+
l2_to_l1_messages: {
|
|
187
|
+
to_address: string;
|
|
188
|
+
payload: string[];
|
|
189
|
+
from_address: string;
|
|
190
|
+
}[];
|
|
191
|
+
block_number: BlockNumber;
|
|
192
|
+
status: Status;
|
|
193
|
+
transaction_index: number;
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
parent_block_hash: string;
|
|
197
|
+
status: Status;
|
|
198
|
+
gas_price: string;
|
|
199
|
+
sequencer_address: string;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
export type CallContractTransaction = Omit<
|
|
203
|
+
InvokeFunctionTransaction,
|
|
204
|
+
'type' | 'entry_point_type' | 'nonce'
|
|
205
|
+
>;
|
|
206
|
+
|
|
207
|
+
export type CallContractResponse = {
|
|
208
|
+
result: string[];
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
// Support 0.9.1 changes in a backward-compatible way
|
|
212
|
+
export type EstimateFeeResponse =
|
|
213
|
+
| {
|
|
214
|
+
overall_fee: number;
|
|
215
|
+
gas_price: number;
|
|
216
|
+
gas_usage: number;
|
|
217
|
+
}
|
|
218
|
+
| {
|
|
219
|
+
amount: BN;
|
|
220
|
+
unit: string;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export type Endpoints = {
|
|
224
|
+
get_contract_addresses: {
|
|
225
|
+
QUERY: never;
|
|
226
|
+
REQUEST: never;
|
|
227
|
+
RESPONSE: GetContractAddressesResponse;
|
|
228
|
+
};
|
|
229
|
+
add_transaction: {
|
|
230
|
+
QUERY: never;
|
|
231
|
+
REQUEST: Transaction;
|
|
232
|
+
RESPONSE: AddTransactionResponse;
|
|
233
|
+
};
|
|
234
|
+
get_transaction: {
|
|
235
|
+
QUERY: {
|
|
236
|
+
transactionHash: string;
|
|
237
|
+
};
|
|
238
|
+
REQUEST: never;
|
|
239
|
+
RESPONSE: GetTransactionResponse;
|
|
240
|
+
};
|
|
241
|
+
get_transaction_status: {
|
|
242
|
+
QUERY: {
|
|
243
|
+
transactionHash: string;
|
|
244
|
+
};
|
|
245
|
+
REQUEST: never;
|
|
246
|
+
RESPONSE: GetTransactionStatusResponse;
|
|
247
|
+
};
|
|
248
|
+
get_transaction_trace: {
|
|
249
|
+
QUERY: {
|
|
250
|
+
transactionHash: string;
|
|
251
|
+
};
|
|
252
|
+
REQUEST: never;
|
|
253
|
+
RESPONSE: GetTransactionTraceResponse;
|
|
254
|
+
};
|
|
255
|
+
get_transaction_receipt: {
|
|
256
|
+
QUERY: {
|
|
257
|
+
transactionHash: string;
|
|
258
|
+
};
|
|
259
|
+
REQUEST: never;
|
|
260
|
+
RESPONSE: TransactionReceiptResponse;
|
|
261
|
+
};
|
|
262
|
+
get_storage_at: {
|
|
263
|
+
QUERY: {
|
|
264
|
+
contractAddress: string;
|
|
265
|
+
key: BigNumberish;
|
|
266
|
+
blockIdentifier: BlockIdentifier;
|
|
267
|
+
};
|
|
268
|
+
REQUEST: never;
|
|
269
|
+
RESPONSE: string;
|
|
270
|
+
};
|
|
271
|
+
get_code: {
|
|
272
|
+
QUERY: {
|
|
273
|
+
contractAddress: string;
|
|
274
|
+
blockIdentifier: BlockIdentifier;
|
|
275
|
+
};
|
|
276
|
+
REQUEST: never;
|
|
277
|
+
RESPONSE: GetCodeResponse;
|
|
278
|
+
};
|
|
279
|
+
get_block: {
|
|
280
|
+
QUERY: {
|
|
281
|
+
blockIdentifier: BlockIdentifier;
|
|
282
|
+
};
|
|
283
|
+
REQUEST: never;
|
|
284
|
+
RESPONSE: GetBlockResponse;
|
|
285
|
+
};
|
|
286
|
+
call_contract: {
|
|
287
|
+
QUERY: {
|
|
288
|
+
blockIdentifier: BlockIdentifier;
|
|
289
|
+
};
|
|
290
|
+
REQUEST: CallContractTransaction;
|
|
291
|
+
RESPONSE: CallContractResponse;
|
|
292
|
+
};
|
|
293
|
+
estimate_fee: {
|
|
294
|
+
QUERY: {
|
|
295
|
+
blockIdentifier: BlockIdentifier;
|
|
296
|
+
};
|
|
297
|
+
REQUEST: CallContractTransaction;
|
|
298
|
+
RESPONSE: EstimateFeeResponse;
|
|
299
|
+
};
|
|
300
|
+
get_class_by_hash: {
|
|
301
|
+
QUERY: {
|
|
302
|
+
classHash: string;
|
|
303
|
+
};
|
|
304
|
+
REQUEST: never;
|
|
305
|
+
RESPONSE: any;
|
|
306
|
+
};
|
|
307
|
+
get_class_hash_at: {
|
|
308
|
+
QUERY: {
|
|
309
|
+
contractAddress: string;
|
|
310
|
+
blockIdentifier?: BlockIdentifier;
|
|
311
|
+
};
|
|
312
|
+
REQUEST: never;
|
|
313
|
+
RESPONSE: string;
|
|
314
|
+
};
|
|
315
|
+
get_state_update: {
|
|
316
|
+
QUERY: {
|
|
317
|
+
blockHash: string;
|
|
318
|
+
};
|
|
319
|
+
REQUEST: never;
|
|
320
|
+
RESPONSE: any;
|
|
321
|
+
};
|
|
322
|
+
get_full_contract: {
|
|
323
|
+
QUERY: {
|
|
324
|
+
contractAddress: string;
|
|
325
|
+
blockIdentifier?: BlockIdentifier;
|
|
326
|
+
};
|
|
327
|
+
REQUEST: never;
|
|
328
|
+
RESPONSE: any;
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
}
|
package/src/types/index.ts
CHANGED
package/src/types/lib.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type DeployContractPayload = {
|
|
|
14
14
|
|
|
15
15
|
export type DeclareContractPayload = {
|
|
16
16
|
contract: CompiledContract | string;
|
|
17
|
+
version?: BigNumberish;
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
export type Invocation = {
|
|
@@ -64,7 +65,8 @@ export type Abi = Array<FunctionAbi | StructAbi>;
|
|
|
64
65
|
|
|
65
66
|
export type EntryPointsByType = object;
|
|
66
67
|
export type Program = Record<any, any>;
|
|
67
|
-
export type
|
|
68
|
+
export type BlockTag = 'pending' | 'latest';
|
|
69
|
+
export type BlockNumber = BlockTag | null | number;
|
|
68
70
|
|
|
69
71
|
export type CompiledContract = {
|
|
70
72
|
abi: Abi;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import BN from 'bn.js';
|
|
2
|
+
|
|
3
|
+
import { Abi, CompressedProgram, EntryPointsByType, RawCalldata, Signature, Status } from './lib';
|
|
4
|
+
|
|
5
|
+
export interface GetBlockResponse {
|
|
6
|
+
accepted_time: number;
|
|
7
|
+
block_hash: string;
|
|
8
|
+
block_number: number;
|
|
9
|
+
gas_price: string;
|
|
10
|
+
new_root: string;
|
|
11
|
+
old_root?: string;
|
|
12
|
+
parent_hash: string;
|
|
13
|
+
sequencer: string;
|
|
14
|
+
status: Status;
|
|
15
|
+
transactions: Array<string>;
|
|
16
|
+
starknet_version?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type GetTransactionResponse = InvokeTransactionResponse & DeclareTransactionResponse;
|
|
20
|
+
|
|
21
|
+
export interface CommonTransactionResponse {
|
|
22
|
+
transaction_hash?: string;
|
|
23
|
+
version?: string;
|
|
24
|
+
signature?: Signature;
|
|
25
|
+
max_fee?: string;
|
|
26
|
+
nonce?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface InvokeTransactionResponse extends CommonTransactionResponse {
|
|
30
|
+
contract_address?: string;
|
|
31
|
+
entry_point_selector?: string;
|
|
32
|
+
calldata: RawCalldata;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ContractEntryPoint {
|
|
36
|
+
offset: string;
|
|
37
|
+
selector: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ContractClass {
|
|
41
|
+
program: CompressedProgram;
|
|
42
|
+
entry_points_by_type: EntryPointsByType;
|
|
43
|
+
abi?: Abi;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface DeclareTransactionResponse extends CommonTransactionResponse {
|
|
47
|
+
contract_class?: any;
|
|
48
|
+
sender_address?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type GetTransactionReceiptResponse =
|
|
52
|
+
| InvokeTransactionReceiptResponse
|
|
53
|
+
| DeclareTransactionReceiptResponse;
|
|
54
|
+
|
|
55
|
+
export interface CommonTransactionReceiptResponse {
|
|
56
|
+
transaction_hash: string;
|
|
57
|
+
status: Status;
|
|
58
|
+
actual_fee?: string;
|
|
59
|
+
status_data?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface MessageToL1 {
|
|
63
|
+
to_address: string;
|
|
64
|
+
payload: Array<string>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface Event {
|
|
68
|
+
from_address: string;
|
|
69
|
+
keys: Array<string>;
|
|
70
|
+
data: Array<string>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface MessageToL2 {
|
|
74
|
+
from_address: string;
|
|
75
|
+
payload: Array<string>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface InvokeTransactionReceiptResponse extends CommonTransactionReceiptResponse {
|
|
79
|
+
messages_sent: Array<MessageToL1>;
|
|
80
|
+
events: Array<Event>;
|
|
81
|
+
l1_origin_message?: MessageToL2;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export type DeclareTransactionReceiptResponse = CommonTransactionReceiptResponse;
|
|
85
|
+
|
|
86
|
+
export interface EstimateFeeResponse {
|
|
87
|
+
overall_fee: BN;
|
|
88
|
+
gas_consumed?: BN;
|
|
89
|
+
gas_price?: BN;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface InvokeFunctionResponse {
|
|
93
|
+
transaction_hash: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface DeployContractResponse {
|
|
97
|
+
contract_address: string;
|
|
98
|
+
transaction_hash: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface DeclareContractResponse {
|
|
102
|
+
transaction_hash: string;
|
|
103
|
+
class_hash: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type CallContractResponse = {
|
|
107
|
+
result: Array<string>;
|
|
108
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export default (typeof window !== 'undefined' && window.fetch) || // use buildin fetch in browser if available
|
|
2
|
+
(typeof global !== 'undefined' && global.fetch) || // use buildin fetch in node, react-native and service worker if available
|
|
3
|
+
// eslint-disable-next-line global-require
|
|
4
|
+
require('isomorphic-fetch'); // ponyfill fetch in node and browsers that don't have it
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CompiledContract, ContractClass, RawCalldata } from '../types';
|
|
2
|
+
import { parse } from './json';
|
|
3
|
+
import { isHex, toBN, toHex } from './number';
|
|
4
|
+
import { compressProgram } from './stark';
|
|
5
|
+
|
|
6
|
+
export function wait(delay: number) {
|
|
7
|
+
return new Promise((res) => {
|
|
8
|
+
setTimeout(res, delay);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function parseCalldata(calldata: RawCalldata = []) {
|
|
13
|
+
return calldata.map((data) => {
|
|
14
|
+
if (typeof data === 'string' && isHex(data as string)) {
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
return toHex(toBN(data));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function parseContract(contract: CompiledContract | string) {
|
|
22
|
+
const parsedContract =
|
|
23
|
+
typeof contract === 'string' ? (parse(contract) as CompiledContract) : contract;
|
|
24
|
+
return {
|
|
25
|
+
...parsedContract,
|
|
26
|
+
program: compressProgram(parsedContract.program),
|
|
27
|
+
} as ContractClass;
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CallContractResponse,
|
|
3
|
+
DeclareContractResponse,
|
|
4
|
+
DeployContractResponse,
|
|
5
|
+
EstimateFeeResponse,
|
|
6
|
+
GetBlockResponse,
|
|
7
|
+
GetTransactionReceiptResponse,
|
|
8
|
+
GetTransactionResponse,
|
|
9
|
+
InvokeFunctionResponse,
|
|
10
|
+
} from '../../types';
|
|
11
|
+
|
|
12
|
+
export abstract class ResponseParser {
|
|
13
|
+
abstract parseGetBlockResponse(res: any): GetBlockResponse;
|
|
14
|
+
|
|
15
|
+
abstract parseGetTransactionResponse(res: any): GetTransactionResponse;
|
|
16
|
+
|
|
17
|
+
abstract parseGetTransactionReceiptResponse(res: any): GetTransactionReceiptResponse;
|
|
18
|
+
|
|
19
|
+
abstract parseFeeEstimateResponse(res: any): EstimateFeeResponse;
|
|
20
|
+
|
|
21
|
+
abstract parseCallContractResponse(res: any): CallContractResponse;
|
|
22
|
+
|
|
23
|
+
abstract parseInvokeFunctionResponse(res: any): InvokeFunctionResponse;
|
|
24
|
+
|
|
25
|
+
abstract parseDeployContractResponse(res: any): DeployContractResponse;
|
|
26
|
+
|
|
27
|
+
abstract parseDeclareContractResponse(res: any): DeclareContractResponse;
|
|
28
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CallContractResponse,
|
|
3
|
+
DeclareContractResponse,
|
|
4
|
+
DeployContractResponse,
|
|
5
|
+
EstimateFeeResponse,
|
|
6
|
+
GetBlockResponse,
|
|
7
|
+
GetTransactionReceiptResponse,
|
|
8
|
+
GetTransactionResponse,
|
|
9
|
+
InvokeFunctionResponse,
|
|
10
|
+
} from '../../types';
|
|
11
|
+
import { RPC } from '../../types/api';
|
|
12
|
+
import { toBN } from '../number';
|
|
13
|
+
import { ResponseParser } from '.';
|
|
14
|
+
|
|
15
|
+
export class RPCResponseParser extends ResponseParser {
|
|
16
|
+
public parseGetBlockResponse(res: RPC.GetBlockResponse): GetBlockResponse {
|
|
17
|
+
return {
|
|
18
|
+
accepted_time: res.accepted_time,
|
|
19
|
+
block_hash: res.block_hash,
|
|
20
|
+
block_number: res.block_number,
|
|
21
|
+
gas_price: res.gas_price,
|
|
22
|
+
new_root: res.new_root,
|
|
23
|
+
old_root: res.old_root,
|
|
24
|
+
parent_hash: res.parent_hash,
|
|
25
|
+
sequencer: res.sequencer,
|
|
26
|
+
status: res.status,
|
|
27
|
+
transactions: res.transactions,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public parseGetTransactionResponse(res: RPC.GetTransactionResponse): GetTransactionResponse {
|
|
32
|
+
return {
|
|
33
|
+
calldata: res.calldata || [],
|
|
34
|
+
contract_address: res.contract_address,
|
|
35
|
+
contract_class: res.contract_class,
|
|
36
|
+
entry_point_selector: res.entry_point_selector,
|
|
37
|
+
max_fee: res.max_fee,
|
|
38
|
+
nonce: res.nonce,
|
|
39
|
+
sender_address: res.sender_address,
|
|
40
|
+
signature: res.signature || [],
|
|
41
|
+
transaction_hash: res.txn_hash,
|
|
42
|
+
version: res.version,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public parseGetTransactionReceiptResponse(
|
|
47
|
+
res: RPC.GetTransactionReceiptResponse
|
|
48
|
+
): GetTransactionReceiptResponse {
|
|
49
|
+
return {
|
|
50
|
+
transaction_hash: res.txn_hash,
|
|
51
|
+
actual_fee: res.actual_fee,
|
|
52
|
+
status: res.status,
|
|
53
|
+
status_data: res.status_data,
|
|
54
|
+
messages_sent: res.messages_sent,
|
|
55
|
+
l1_origin_message: res.l1_origin_message,
|
|
56
|
+
events: res.events,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public parseFeeEstimateResponse(res: RPC.EstimateFeeResponse): EstimateFeeResponse {
|
|
61
|
+
return {
|
|
62
|
+
overall_fee: toBN(res.overall_fee),
|
|
63
|
+
gas_consumed: toBN(res.gas_consumed),
|
|
64
|
+
gas_price: toBN(res.gas_price),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public parseCallContractResponse(res: Array<string>): CallContractResponse {
|
|
69
|
+
return {
|
|
70
|
+
result: res,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public parseInvokeFunctionResponse(res: RPC.AddTransactionResponse): InvokeFunctionResponse {
|
|
75
|
+
return {
|
|
76
|
+
transaction_hash: res.transaction_hash,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public parseDeployContractResponse(res: RPC.DeployContractResponse): DeployContractResponse {
|
|
81
|
+
return {
|
|
82
|
+
transaction_hash: res.transaction_hash,
|
|
83
|
+
contract_address: res.contract_address,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public parseDeclareContractResponse(res: RPC.DeclareResponse): DeclareContractResponse {
|
|
88
|
+
return {
|
|
89
|
+
transaction_hash: res.transaction_hash,
|
|
90
|
+
class_hash: res.class_hash,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|