starknet 4.3.0 → 4.3.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/__tests__/defaultProvider.test.ts +11 -24
  3. package/__tests__/rpcProvider.test.ts +3 -3
  4. package/__tests__/sequencerProvider.test.ts +9 -1
  5. package/dist/provider/default.d.ts +2 -2
  6. package/dist/provider/default.js +3 -3
  7. package/dist/provider/interface.d.ts +6 -3
  8. package/dist/provider/rpc.d.ts +9 -4
  9. package/dist/provider/rpc.js +67 -25
  10. package/dist/provider/sequencer.d.ts +2 -2
  11. package/dist/provider/sequencer.js +4 -4
  12. package/dist/provider/utils.d.ts +12 -0
  13. package/dist/provider/utils.js +17 -1
  14. package/dist/types/api/openrpc.d.ts +151 -0
  15. package/dist/types/api/openrpc.js +9 -0
  16. package/dist/types/api/rpc.d.ts +22 -43
  17. package/dist/types/provider.d.ts +5 -5
  18. package/dist/utils/ellipticCurve.d.ts +13 -0
  19. package/dist/utils/ellipticCurve.js +20 -16
  20. package/dist/utils/responseParser/rpc.d.ts +13 -3
  21. package/dist/utils/responseParser/rpc.js +2 -10
  22. package/dist/utils/responseParser/sequencer.d.ts +4 -1
  23. package/dist/utils/responseParser/sequencer.js +1 -7
  24. package/package.json +1 -1
  25. package/provider/default.d.ts +2 -2
  26. package/provider/default.js +3 -3
  27. package/provider/interface.d.ts +6 -3
  28. package/provider/rpc.d.ts +9 -4
  29. package/provider/rpc.js +67 -25
  30. package/provider/sequencer.d.ts +2 -2
  31. package/provider/sequencer.js +4 -4
  32. package/provider/utils.d.ts +12 -0
  33. package/provider/utils.js +17 -1
  34. package/src/provider/default.ts +2 -3
  35. package/src/provider/interface.ts +5 -3
  36. package/src/provider/rpc.ts +56 -34
  37. package/src/provider/sequencer.ts +3 -6
  38. package/src/provider/utils.ts +22 -1
  39. package/src/types/api/openrpc.ts +168 -0
  40. package/src/types/api/rpc.ts +22 -45
  41. package/src/types/provider.ts +5 -5
  42. package/src/utils/ellipticCurve.ts +20 -16
  43. package/src/utils/responseParser/rpc.ts +16 -13
  44. package/src/utils/responseParser/sequencer.ts +5 -8
  45. package/types/api/openrpc.d.ts +151 -0
  46. package/types/api/openrpc.js +9 -0
  47. package/types/api/rpc.d.ts +22 -43
  48. package/types/provider.d.ts +5 -5
  49. package/utils/ellipticCurve.d.ts +13 -0
  50. package/utils/ellipticCurve.js +20 -16
  51. package/utils/responseParser/rpc.d.ts +13 -3
  52. package/utils/responseParser/rpc.js +2 -10
  53. package/utils/responseParser/sequencer.d.ts +4 -1
  54. package/utils/responseParser/sequencer.js +1 -7
  55. package/www/docs/API/account.md +20 -18
  56. package/www/docs/API/contract.md +10 -10
  57. package/www/docs/API/contractFactory.md +14 -11
  58. package/www/docs/API/provider.md +29 -63
  59. package/www/docs/API/signer.md +8 -10
  60. package/www/docs/API/utils.md +151 -74
  61. package/www/guides/account.md +5 -5
  62. package/www/guides/erc20.md +20 -4
  63. package/www/guides/intro.md +3 -1
package/CHANGELOG.md CHANGED
@@ -1,8 +1,23 @@
1
+ ## [4.3.1](https://github.com/0xs34n/starknet.js/compare/v4.3.0...v4.3.1) (2022-08-31)
2
+
3
+ ### Bug Fixes
4
+
5
+ - getClassAt and Test Fixes ([548cf6e](https://github.com/0xs34n/starknet.js/commit/548cf6e69d16292b9c216493c77e1c7a14be2ae9))
6
+ - getCode removed from RPC 0.1.0 ([744a988](https://github.com/0xs34n/starknet.js/commit/744a9882c363331ff47f409971cacbfda977c4c2))
7
+ - merge ([67d87fc](https://github.com/0xs34n/starknet.js/commit/67d87fc834ea5b877029445f39782457584fb4ec))
8
+ - naming ([0c75f6f](https://github.com/0xs34n/starknet.js/commit/0c75f6f431c3828b1078d955123b2d13aef6b5d0))
9
+ - restore GetCode to common interface for backward compatibility ([52f8e61](https://github.com/0xs34n/starknet.js/commit/52f8e61797a3f2390577b3a6e977adae11346a23))
10
+ - rpc 0.1.0 getStorageAt ([c622913](https://github.com/0xs34n/starknet.js/commit/c6229138c57cd9a04b982c386c7278d63b931a1f))
11
+ - **RpcProvider:** update of RpcProvider getBlock method to work with v0.3.0 of pathfinder ([3b12421](https://github.com/0xs34n/starknet.js/commit/3b124219dd25ef5a0c81583fcfe67d6a3cc5a70e))
12
+ - test getBlock('latest') ([2c92f79](https://github.com/0xs34n/starknet.js/commit/2c92f79aefe3af68834aa9a9a16754c0ff4116cc))
13
+ - test getBlock(latest) ([0c5e31e](https://github.com/0xs34n/starknet.js/commit/0c5e31effb63bf7afb26c9f2049b66c93c6b1366))
14
+ - unoptimise getClassAt test to work with integration ([e98220b](https://github.com/0xs34n/starknet.js/commit/e98220bc6e6fff55bc439773bd1258844de312e2))
15
+
1
16
  # [4.3.0](https://github.com/0xs34n/starknet.js/compare/v4.2.0...v4.3.0) (2022-08-09)
2
17
 
3
18
  ### Bug Fixes
4
19
 
5
- - intendations in provider.md ([4a310c6](https://github.com/0xs34n/starknet.js/commit/4a310c6c992c77f9f6729a70c1af14481cd891f7))
20
+ - indentations in provider.md ([4a310c6](https://github.com/0xs34n/starknet.js/commit/4a310c6c992c77f9f6729a70c1af14481cd891f7))
6
21
  - **sequenceProvider:** feedergatewayUrl and gatewayUrl ([e236d23](https://github.com/0xs34n/starknet.js/commit/e236d2352e3fbb0f78965decac5893217347ceb7))
7
22
 
8
23
  ### Features
@@ -50,11 +50,11 @@ describe('defaultProvider', () => {
50
50
  test('getBlock(blockIdentifier=latest)', async () => {
51
51
  expect(exampleBlock).not.toBeNull();
52
52
 
53
- const { block_number, accepted_time } = exampleBlock;
53
+ const { block_number, timestamp } = exampleBlock;
54
54
 
55
55
  expect(typeof block_number).toEqual('number');
56
56
 
57
- return expect(typeof accepted_time).toEqual('number');
57
+ return expect(typeof timestamp).toEqual('number');
58
58
  });
59
59
 
60
60
  test('getBlock() -> { blockNumber }', async () => {
@@ -62,11 +62,6 @@ describe('defaultProvider', () => {
62
62
  return expect(block).toHaveProperty('block_number');
63
63
  });
64
64
 
65
- test('getCode() -> { bytecode }', async () => {
66
- const code = await testProvider.getCode(exampleContractAddress);
67
- return expect(Array.isArray(code.bytecode)).toBe(true);
68
- });
69
-
70
65
  describe('getStorageAt', () => {
71
66
  test('with "key" type of number', () => {
72
67
  return expect(testProvider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow();
@@ -144,7 +139,7 @@ describe('defaultProvider', () => {
144
139
 
145
140
  describeIfNotDevnet('Provider', () => {
146
141
  const provider = getTestProvider();
147
- describe(`Provider methods`, () => {
142
+ describe(`Provider methods if not devnet`, () => {
148
143
  describe('getBlock', () => {
149
144
  test('pending', async () => {
150
145
  const latestBlock = await provider.getBlock();
@@ -152,11 +147,8 @@ describe('defaultProvider', () => {
152
147
  expect(latestBlock).toHaveProperty('parent_hash');
153
148
  expect(latestBlock).toHaveProperty('block_number');
154
149
  expect(latestBlock).toHaveProperty('status');
155
- expect(latestBlock).toHaveProperty('sequencer');
156
150
  expect(latestBlock).toHaveProperty('new_root');
157
- expect(latestBlock).toHaveProperty('old_root');
158
- expect(latestBlock).toHaveProperty('accepted_time');
159
- expect(latestBlock).toHaveProperty('gas_price');
151
+ expect(latestBlock).toHaveProperty('timestamp');
160
152
  expect(latestBlock).toHaveProperty('transactions');
161
153
  expect(Array.isArray(latestBlock.transactions)).toBe(true);
162
154
  });
@@ -170,11 +162,8 @@ describe('defaultProvider', () => {
170
162
  expect(block).toHaveProperty('parent_hash');
171
163
  expect(block).toHaveProperty('block_number');
172
164
  expect(block).toHaveProperty('status');
173
- expect(block).toHaveProperty('sequencer');
174
165
  expect(block).toHaveProperty('new_root');
175
- expect(block).toHaveProperty('old_root');
176
- expect(block).toHaveProperty('accepted_time');
177
- expect(block).toHaveProperty('gas_price');
166
+ expect(block).toHaveProperty('timestamp');
178
167
  expect(block).toHaveProperty('transactions');
179
168
  expect(Array.isArray(block.transactions)).toBe(true);
180
169
  });
@@ -185,11 +174,8 @@ describe('defaultProvider', () => {
185
174
  expect(block).toHaveProperty('parent_hash');
186
175
  expect(block).toHaveProperty('block_number');
187
176
  expect(block).toHaveProperty('status');
188
- expect(block).toHaveProperty('sequencer');
189
177
  expect(block).toHaveProperty('new_root');
190
- expect(block).toHaveProperty('old_root');
191
- expect(block).toHaveProperty('accepted_time');
192
- expect(block).toHaveProperty('gas_price');
178
+ expect(block).toHaveProperty('timestamp');
193
179
  expect(block).toHaveProperty('transactions');
194
180
  expect(Array.isArray(block.transactions)).toBe(true);
195
181
  });
@@ -199,7 +185,7 @@ describe('defaultProvider', () => {
199
185
  test('pending', async () => {
200
186
  const storage = await provider.getStorageAt(
201
187
  '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
202
- 0
188
+ '0'
203
189
  );
204
190
  expect(typeof storage).toBe('string');
205
191
  });
@@ -207,7 +193,7 @@ describe('defaultProvider', () => {
207
193
  test('Block Hash 0x7104702055c2a5773a870ceada9552ec659d69c18053b14078983f07527dea8', async () => {
208
194
  const storage = await provider.getStorageAt(
209
195
  '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166',
210
- 0,
196
+ '0',
211
197
  '0x7225762c7ff5e7e5f0867f0a8e73594df4f44f05a65375339a76398e8ae3e64'
212
198
  );
213
199
  expect(typeof storage).toBe('string');
@@ -245,7 +231,6 @@ describe('defaultProvider', () => {
245
231
  expect(transaction.max_fee).toBeTruthy();
246
232
  expect(transaction.transaction_hash).toBeTruthy();
247
233
  expect(transaction).toHaveProperty('nonce');
248
- expect(transaction).toHaveProperty('sender_address');
249
234
  expect(transaction).toHaveProperty('version');
250
235
  });
251
236
  });
@@ -269,6 +254,7 @@ describe('defaultProvider', () => {
269
254
  let contractAddress: string;
270
255
  let deployResponse: DeployContractResponse;
271
256
  let declareResponse: DeclareContractResponse;
257
+ let blockNumber: BlockNumber;
272
258
 
273
259
  beforeAll(async () => {
274
260
  deployResponse = await provider.deployContract({ contract: compiledErc20 });
@@ -278,6 +264,7 @@ describe('defaultProvider', () => {
278
264
  provider.waitForTransaction(deployResponse.transaction_hash),
279
265
  provider.waitForTransaction(declareResponse.transaction_hash),
280
266
  ]);
267
+ ({ block_number: blockNumber } = await provider.getBlock('latest'));
281
268
  });
282
269
 
283
270
  describe('deployContract', () => {
@@ -296,7 +283,7 @@ describe('defaultProvider', () => {
296
283
 
297
284
  describe('getClassAt', () => {
298
285
  test('response', async () => {
299
- const classResponse = await provider.getClassAt(contractAddress);
286
+ const classResponse = await provider.getClassAt(contractAddress, blockNumber);
300
287
 
301
288
  expect(classResponse).toHaveProperty('program');
302
289
  expect(classResponse).toHaveProperty('entry_points_by_type');
@@ -2,15 +2,15 @@ import { RpcProvider } from '../src';
2
2
  import { describeIfRpc, getTestProvider } from './fixtures';
3
3
 
4
4
  describeIfRpc('RPCProvider', () => {
5
- let provider: RpcProvider;
5
+ let rpcProvider: RpcProvider;
6
6
 
7
7
  beforeAll(async () => {
8
- provider = getTestProvider() as RpcProvider;
8
+ rpcProvider = getTestProvider() as RpcProvider;
9
9
  });
10
10
 
11
11
  describe('RPC methods', () => {
12
12
  test('getChainId', async () => {
13
- const chainId = await provider.getChainId();
13
+ const chainId = await rpcProvider.getChainId();
14
14
  expect(chainId).toBe('0x534e5f474f45524c49');
15
15
  });
16
16
  });
@@ -7,9 +7,11 @@ import {
7
7
  getTestProvider,
8
8
  } from './fixtures';
9
9
 
10
+ // Run only if Devnet Sequencer
10
11
  describeIfSequencer('SequencerProvider', () => {
11
12
  let provider: SequencerProvider;
12
13
  let customSequencerProvider: Provider;
14
+ let exampleContractAddress: string;
13
15
 
14
16
  beforeAll(async () => {
15
17
  provider = getTestProvider() as SequencerProvider;
@@ -26,11 +28,12 @@ describeIfSequencer('SequencerProvider', () => {
26
28
  let exampleTransactionHash: string;
27
29
 
28
30
  beforeAll(async () => {
29
- const { transaction_hash } = await provider.deployContract({
31
+ const { transaction_hash, contract_address } = await provider.deployContract({
30
32
  contract: compiledErc20,
31
33
  });
32
34
  await provider.waitForTransaction(transaction_hash);
33
35
  exampleTransactionHash = transaction_hash;
36
+ exampleContractAddress = contract_address;
34
37
  });
35
38
 
36
39
  test('getTransactionStatus()', async () => {
@@ -43,6 +46,11 @@ describeIfSequencer('SequencerProvider', () => {
43
46
  expect(transactionTrace).toHaveProperty('signature');
44
47
  });
45
48
 
49
+ test('getCode() -> { bytecode }', async () => {
50
+ const code = await provider.getCode(exampleContractAddress);
51
+ return expect(Array.isArray(code.bytecode)).toBe(true);
52
+ });
53
+
46
54
  describeIfNotDevnet('which are not available on devnet', () => {
47
55
  test('getContractAddresses()', async () => {
48
56
  const { GpsStatementVerifier, Starknet } = await provider.getContractAddresses();
@@ -1,5 +1,5 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { BlockTag, Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
2
+ import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
3
3
  import { BigNumberish } from '../utils/number';
4
4
  import { ProviderInterface } from './interface';
5
5
  import { RpcProviderOptions } from './rpc';
@@ -16,7 +16,7 @@ export declare class Provider implements ProviderInterface {
16
16
  getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
17
17
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
18
18
  getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
19
- getStorageAt(contractAddress: string, key: BigNumberish, blockTagOrHash?: BlockTag | BigNumberish): Promise<BigNumberish>;
19
+ getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
20
20
  getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
21
21
  getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
22
22
  callContract(request: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
@@ -86,11 +86,11 @@ var Provider = /** @class */ (function () {
86
86
  });
87
87
  });
88
88
  };
89
- Provider.prototype.getStorageAt = function (contractAddress, key, blockTagOrHash) {
90
- if (blockTagOrHash === void 0) { blockTagOrHash = 'pending'; }
89
+ Provider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
90
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
91
91
  return __awaiter(this, void 0, void 0, function () {
92
92
  return __generator(this, function (_a) {
93
- return [2 /*return*/, this.provider.getStorageAt(contractAddress, key, blockTagOrHash)];
93
+ return [2 /*return*/, this.provider.getStorageAt(contractAddress, key, blockIdentifier)];
94
94
  });
95
95
  });
96
96
  };
@@ -1,5 +1,5 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import type { BlockTag, Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
2
+ import type { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
3
3
  import type { BigNumberish } from '../utils/number';
4
4
  import { BlockIdentifier } from './utils';
5
5
  export declare abstract class ProviderInterface {
@@ -19,6 +19,9 @@ export declare abstract class ProviderInterface {
19
19
  * @returns the block object
20
20
  */
21
21
  abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
22
+ /**
23
+ * @deprecated The method should not be used
24
+ */
22
25
  abstract getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
23
26
  /**
24
27
  * Gets the contract class of the deployed contract.
@@ -33,10 +36,10 @@ export declare abstract class ProviderInterface {
33
36
  *
34
37
  * @param contractAddress
35
38
  * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
36
- * @param blockHashOrTag - block hash or tag (pending, latest)
39
+ * @param blockIdentifier - block identifier
37
40
  * @returns the value of the storage variable
38
41
  */
39
- abstract getStorageAt(contractAddress: string, key: BigNumberish, blockHashOrTag?: BlockTag | BigNumberish): Promise<BigNumberish>;
42
+ abstract getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier: BlockIdentifier): Promise<BigNumberish>;
40
43
  /**
41
44
  * Gets the transaction information from a tx id.
42
45
  *
@@ -1,5 +1,5 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { BlockTag, Call, CallContractResponse, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
2
+ import { Call, CallContractResponse, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetCodeResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
3
3
  import { RPC } from '../types/api';
4
4
  import { BigNumberish } from '../utils/number';
5
5
  import { ProviderInterface } from './interface';
@@ -15,16 +15,21 @@ export declare class RpcProvider implements ProviderInterface {
15
15
  protected fetchEndpoint<T extends keyof RPC.Methods>(method: T, request?: RPC.Methods[T]['REQUEST']): Promise<RPC.Methods[T]['RESPONSE']>;
16
16
  getChainId(): Promise<StarknetChainId>;
17
17
  getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
18
- getStorageAt(contractAddress: string, key: BigNumberish, blockHashOrTag?: BlockTag | BigNumberish): Promise<BigNumberish>;
18
+ getBlockWithTxHashes(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxHashesResponse>;
19
+ getBlockWithTxs(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxs>;
20
+ getNonce(contractAddress: string): Promise<any>;
21
+ getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
19
22
  getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
23
+ getTransactionByHash(txHash: BigNumberish): Promise<RPC.GetTransactionByHashResponse>;
24
+ getTransactionByBlockIdAndIndex(blockIdentifier: BlockIdentifier, index: number): Promise<RPC.GetTransactionByBlockIdAndIndex>;
20
25
  getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
21
- getClassAt(contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<any>;
26
+ getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<any>;
22
27
  getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
23
28
  declareContract({ contract, version, }: DeclareContractPayload): Promise<DeclareContractResponse>;
24
29
  deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
25
30
  invokeFunction(functionInvocation: Invocation, details: InvocationsDetails): Promise<InvokeFunctionResponse>;
26
31
  callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
27
- getCode(contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<RPC.GetCodeResponse>;
32
+ getCode(_contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
28
33
  waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
29
34
  /**
30
35
  * Gets the transaction count from a block.
@@ -47,6 +47,7 @@ var number_1 = require("../utils/number");
47
47
  var provider_1 = require("../utils/provider");
48
48
  var rpc_1 = require("../utils/responseParser/rpc");
49
49
  var stark_1 = require("../utils/stark");
50
+ var utils_1 = require("./utils");
50
51
  var RpcProvider = /** @class */ (function () {
51
52
  function RpcProvider(optionsOrProvider) {
52
53
  var _this = this;
@@ -112,36 +113,78 @@ var RpcProvider = /** @class */ (function () {
112
113
  });
113
114
  });
114
115
  };
116
+ // Common Interface
115
117
  RpcProvider.prototype.getBlock = function (blockIdentifier) {
116
118
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
117
119
  return __awaiter(this, void 0, void 0, function () {
118
- var method;
119
120
  return __generator(this, function (_a) {
120
- method = typeof blockIdentifier === 'string' && (0, number_1.isHex)(blockIdentifier)
121
- ? 'starknet_getBlockByHash'
122
- : 'starknet_getBlockByNumber';
123
- return [2 /*return*/, this.fetchEndpoint(method, [blockIdentifier]).then(this.responseParser.parseGetBlockResponse)];
121
+ return [2 /*return*/, this.getBlockWithTxHashes(blockIdentifier).then(this.responseParser.parseGetBlockResponse)];
124
122
  });
125
123
  });
126
124
  };
127
- RpcProvider.prototype.getStorageAt = function (contractAddress, key, blockHashOrTag) {
128
- if (blockHashOrTag === void 0) { blockHashOrTag = 'pending'; }
125
+ RpcProvider.prototype.getBlockWithTxHashes = function (blockIdentifier) {
126
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
127
+ return __awaiter(this, void 0, void 0, function () {
128
+ var blockIdentifierGetter;
129
+ return __generator(this, function (_a) {
130
+ blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
131
+ return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxHashes', [
132
+ blockIdentifierGetter.getIdentifier(),
133
+ ])];
134
+ });
135
+ });
136
+ };
137
+ RpcProvider.prototype.getBlockWithTxs = function (blockIdentifier) {
138
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
139
+ return __awaiter(this, void 0, void 0, function () {
140
+ var blockIdentifierGetter;
141
+ return __generator(this, function (_a) {
142
+ blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
143
+ return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxs', [blockIdentifierGetter.getIdentifier()])];
144
+ });
145
+ });
146
+ };
147
+ RpcProvider.prototype.getNonce = function (contractAddress) {
148
+ return __awaiter(this, void 0, void 0, function () {
149
+ return __generator(this, function (_a) {
150
+ return [2 /*return*/, this.fetchEndpoint('starknet_getNonce', [contractAddress])];
151
+ });
152
+ });
153
+ };
154
+ RpcProvider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
155
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
129
156
  return __awaiter(this, void 0, void 0, function () {
130
- var parsedKey;
157
+ var parsedKey, blockIdentifierGetter;
131
158
  return __generator(this, function (_a) {
132
159
  parsedKey = (0, number_1.toHex)((0, number_1.toBN)(key));
160
+ blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
133
161
  return [2 /*return*/, this.fetchEndpoint('starknet_getStorageAt', [
134
162
  contractAddress,
135
163
  parsedKey,
136
- blockHashOrTag,
164
+ blockIdentifierGetter.getIdentifier(),
137
165
  ])];
138
166
  });
139
167
  });
140
168
  };
169
+ // common interface
141
170
  RpcProvider.prototype.getTransaction = function (txHash) {
142
171
  return __awaiter(this, void 0, void 0, function () {
143
172
  return __generator(this, function (_a) {
144
- return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByHash', [txHash]).then(this.responseParser.parseGetTransactionResponse)];
173
+ return [2 /*return*/, this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse)];
174
+ });
175
+ });
176
+ };
177
+ RpcProvider.prototype.getTransactionByHash = function (txHash) {
178
+ return __awaiter(this, void 0, void 0, function () {
179
+ return __generator(this, function (_a) {
180
+ return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByHash', [txHash])];
181
+ });
182
+ });
183
+ };
184
+ RpcProvider.prototype.getTransactionByBlockIdAndIndex = function (blockIdentifier, index) {
185
+ return __awaiter(this, void 0, void 0, function () {
186
+ return __generator(this, function (_a) {
187
+ return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByHash', [blockIdentifier, index])];
145
188
  });
146
189
  });
147
190
  };
@@ -152,11 +195,15 @@ var RpcProvider = /** @class */ (function () {
152
195
  });
153
196
  });
154
197
  };
155
- RpcProvider.prototype.getClassAt = function (contractAddress, _blockIdentifier) {
156
- if (_blockIdentifier === void 0) { _blockIdentifier = 'pending'; }
198
+ RpcProvider.prototype.getClassAt = function (contractAddress, blockIdentifier) {
157
199
  return __awaiter(this, void 0, void 0, function () {
200
+ var blockIdentifierGetter;
158
201
  return __generator(this, function (_a) {
159
- return [2 /*return*/, this.fetchEndpoint('starknet_getClassAt', [contractAddress])];
202
+ blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
203
+ return [2 /*return*/, this.fetchEndpoint('starknet_getClassAt', [
204
+ blockIdentifierGetter.getIdentifier(),
205
+ contractAddress,
206
+ ])];
160
207
  });
161
208
  });
162
209
  };
@@ -248,16 +295,10 @@ var RpcProvider = /** @class */ (function () {
248
295
  });
249
296
  });
250
297
  };
251
- RpcProvider.prototype.getCode = function (contractAddress, _blockIdentifier) {
298
+ RpcProvider.prototype.getCode = function (_contractAddress, _blockIdentifier) {
252
299
  return __awaiter(this, void 0, void 0, function () {
253
- var result;
254
300
  return __generator(this, function (_a) {
255
- switch (_a.label) {
256
- case 0: return [4 /*yield*/, this.fetchEndpoint('starknet_getCode', [contractAddress])];
257
- case 1:
258
- result = _a.sent();
259
- return [2 /*return*/, this.responseParser.parseGetCodeResponse(result)];
260
- }
301
+ throw new Error('RPC 0.1.0 does not implement getCode function');
261
302
  });
262
303
  });
263
304
  };
@@ -325,11 +366,12 @@ var RpcProvider = /** @class */ (function () {
325
366
  */
326
367
  RpcProvider.prototype.getTransactionCount = function (blockIdentifier) {
327
368
  return __awaiter(this, void 0, void 0, function () {
369
+ var blockIdentifierGetter;
328
370
  return __generator(this, function (_a) {
329
- if (typeof blockIdentifier === 'number') {
330
- return [2 /*return*/, this.fetchEndpoint('starknet_getBlockTransactionCountByNumber', [blockIdentifier])];
331
- }
332
- return [2 /*return*/, this.fetchEndpoint('starknet_getBlockTransactionCountByHash', [blockIdentifier])];
371
+ blockIdentifierGetter = new utils_1.BlockIdentifierClass(blockIdentifier);
372
+ return [2 /*return*/, this.fetchEndpoint('starknet_getBlockTransactionCount', [
373
+ blockIdentifierGetter.getIdentifier(),
374
+ ])];
333
375
  });
334
376
  });
335
377
  };
@@ -1,5 +1,5 @@
1
1
  import { StarknetChainId } from '../constants';
2
- import { BlockTag, Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
2
+ import { Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
3
3
  import { GetContractAddressesResponse, GetTransactionStatusResponse, GetTransactionTraceResponse, Sequencer } from '../types/api';
4
4
  import { BigNumberish } from '../utils/number';
5
5
  import { ProviderInterface } from './interface';
@@ -29,7 +29,7 @@ export declare class SequencerProvider implements ProviderInterface {
29
29
  protected fetchEndpoint<T extends keyof Sequencer.Endpoints>(endpoint: T, ...[query, request]: Sequencer.Endpoints[T]['QUERY'] extends never ? Sequencer.Endpoints[T]['REQUEST'] extends never ? [] : [undefined, Sequencer.Endpoints[T]['REQUEST']] : Sequencer.Endpoints[T]['REQUEST'] extends never ? [Sequencer.Endpoints[T]['QUERY']] : [Sequencer.Endpoints[T]['QUERY'], Sequencer.Endpoints[T]['REQUEST']]): Promise<Sequencer.Endpoints[T]['RESPONSE']>;
30
30
  callContract({ contractAddress, entrypoint: entryPointSelector, calldata }: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
31
31
  getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
32
- getStorageAt(contractAddress: string, key: BigNumberish, blockHashOrTag?: BlockTag | BigNumberish): Promise<BigNumberish>;
32
+ getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
33
33
  getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
34
34
  getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
35
35
  getClassAt(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<ContractClass>;
@@ -249,14 +249,14 @@ var SequencerProvider = /** @class */ (function () {
249
249
  });
250
250
  });
251
251
  };
252
- SequencerProvider.prototype.getStorageAt = function (contractAddress, key, blockHashOrTag) {
253
- if (blockHashOrTag === void 0) { blockHashOrTag = 'pending'; }
252
+ SequencerProvider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
253
+ if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
254
254
  return __awaiter(this, void 0, void 0, function () {
255
255
  var parsedKey;
256
256
  return __generator(this, function (_a) {
257
257
  parsedKey = (0, number_1.toBN)(key).toString(10);
258
258
  return [2 /*return*/, this.fetchEndpoint('get_storage_at', {
259
- blockIdentifier: blockHashOrTag,
259
+ blockIdentifier: blockIdentifier,
260
260
  contractAddress: contractAddress,
261
261
  key: parsedKey,
262
262
  })];
@@ -359,7 +359,7 @@ var SequencerProvider = /** @class */ (function () {
359
359
  if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
360
360
  return __awaiter(this, void 0, void 0, function () {
361
361
  return __generator(this, function (_a) {
362
- return [2 /*return*/, this.fetchEndpoint('get_code', { contractAddress: contractAddress, blockIdentifier: blockIdentifier }).then(this.responseParser.parseGetCodeResponse)];
362
+ return [2 /*return*/, this.fetchEndpoint('get_code', { contractAddress: contractAddress, blockIdentifier: blockIdentifier })];
363
363
  });
364
364
  });
365
365
  };
@@ -1,3 +1,4 @@
1
+ /// <reference types="bn.js" />
1
2
  import type { BlockNumber } from '../types';
2
3
  import { BigNumberish } from '../utils/number';
3
4
  /**
@@ -23,6 +24,17 @@ declare type BlockIdentifierObject = {
23
24
  type: 'BLOCK_HASH';
24
25
  data: BigNumberish;
25
26
  };
27
+ export declare class BlockIdentifierClass {
28
+ blockIdentifier: BlockIdentifier;
29
+ constructor(blockIdentifier: BlockIdentifier);
30
+ getIdentifier(): string | import("bn.js") | {
31
+ block_hash: string;
32
+ block_number?: undefined;
33
+ } | {
34
+ block_number: number;
35
+ block_hash?: undefined;
36
+ } | null;
37
+ }
26
38
  /**
27
39
  * Identifies the block to be queried.
28
40
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFormattedBlockIdentifier = exports.getBlockIdentifier = exports.txIdentifier = exports.formatHash = void 0;
3
+ exports.getFormattedBlockIdentifier = exports.getBlockIdentifier = exports.BlockIdentifierClass = exports.txIdentifier = exports.formatHash = void 0;
4
4
  var number_1 = require("../utils/number");
5
5
  /**
6
6
  *
@@ -29,6 +29,22 @@ function txIdentifier(txHash, txId) {
29
29
  return "transactionHash=".concat(hashString);
30
30
  }
31
31
  exports.txIdentifier = txIdentifier;
32
+ var BlockIdentifierClass = /** @class */ (function () {
33
+ function BlockIdentifierClass(blockIdentifier) {
34
+ this.blockIdentifier = blockIdentifier;
35
+ }
36
+ BlockIdentifierClass.prototype.getIdentifier = function () {
37
+ if (typeof this.blockIdentifier === 'string' && (0, number_1.isHex)(this.blockIdentifier)) {
38
+ return { block_hash: this.blockIdentifier };
39
+ }
40
+ if (typeof this.blockIdentifier === 'number') {
41
+ return { block_number: this.blockIdentifier };
42
+ }
43
+ return this.blockIdentifier;
44
+ };
45
+ return BlockIdentifierClass;
46
+ }());
47
+ exports.BlockIdentifierClass = BlockIdentifierClass;
32
48
  /**
33
49
  * Identifies the block to be queried.
34
50
  *