starknet 4.5.0 → 4.6.0
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 +15 -0
- package/README.md +3 -1
- package/__tests__/defaultProvider.test.ts +7 -9
- package/__tests__/rpcProvider.test.ts +107 -12
- package/__tests__/utils/utils.test.ts +17 -0
- package/dist/provider/rpc.d.ts +12 -2
- package/dist/provider/rpc.js +124 -70
- package/dist/provider/sequencer.js +2 -1
- package/dist/provider/utils.d.ts +11 -35
- package/dist/provider/utils.js +52 -63
- package/dist/types/api/openrpc.d.ts +392 -32
- package/dist/types/api/openrpc.js +21 -3
- package/dist/types/api/rpc.d.ts +74 -107
- package/dist/utils/responseParser/rpc.d.ts +7 -4
- package/dist/utils/responseParser/rpc.js +1 -1
- package/package.json +1 -1
- package/provider/rpc.d.ts +12 -2
- package/provider/rpc.js +124 -70
- package/provider/sequencer.js +2 -1
- package/provider/utils.d.ts +11 -35
- package/provider/utils.js +52 -63
- package/src/provider/rpc.ts +88 -54
- package/src/provider/sequencer.ts +3 -2
- package/src/provider/utils.ts +43 -56
- package/src/types/api/openrpc.ts +371 -41
- package/src/types/api/rpc.ts +71 -125
- package/src/utils/responseParser/rpc.ts +9 -5
- package/types/api/openrpc.d.ts +392 -32
- package/types/api/openrpc.js +21 -3
- package/types/api/rpc.d.ts +74 -107
- package/utils/responseParser/rpc.d.ts +7 -4
- package/utils/responseParser/rpc.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# [4.6.0](https://github.com/0xs34n/starknet.js/compare/v4.5.0...v4.6.0) (2022-09-15)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- add test getTransactionCount [skip ci] ([342755a](https://github.com/0xs34n/starknet.js/commit/342755aa99dda016d7aa394a0023b3f2e5d5e963))
|
|
6
|
+
- estimateFee and call block id ([ef1645f](https://github.com/0xs34n/starknet.js/commit/ef1645f740e7c29edea6b091bec9949ec713953f))
|
|
7
|
+
- rpc test update, comepleted rpc to openrpc mapping, rpc provider methods ([8b41e0f](https://github.com/0xs34n/starknet.js/commit/8b41e0fcf36b34b20dfaba356cfc0131f02d7d69))
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
- new Block utility object, rpc fetch clenup, open rpc fetch api ([0d381c8](https://github.com/0xs34n/starknet.js/commit/0d381c89fe655b2628f02e67095ef03cb1721398))
|
|
12
|
+
- read, write and trace api ([d488ab2](https://github.com/0xs34n/starknet.js/commit/d488ab2513b88fdeb4e27b6ec2b7226ffd359445))
|
|
13
|
+
- retry rpc wait for transaction 200 times instead of 100 ([3bc9118](https://github.com/0xs34n/starknet.js/commit/3bc9118cae86fba21e1c85667079079662ba0b7b))
|
|
14
|
+
- updated rpc tests with new methods ([e369d95](https://github.com/0xs34n/starknet.js/commit/e369d95d72f3b39b3e8b8baa99867b94c1d5d1c1))
|
|
15
|
+
|
|
1
16
|
# [4.5.0](https://github.com/0xs34n/starknet.js/compare/v4.4.2...v4.5.0) (2022-09-09)
|
|
2
17
|
|
|
3
18
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -139,10 +139,11 @@ describe('defaultProvider', () => {
|
|
|
139
139
|
|
|
140
140
|
describeIfNotDevnet('Provider', () => {
|
|
141
141
|
const provider = getTestProvider();
|
|
142
|
+
let latestBlock;
|
|
142
143
|
describe(`Provider methods if not devnet`, () => {
|
|
143
144
|
describe('getBlock', () => {
|
|
144
|
-
test('pending', async () => {
|
|
145
|
-
|
|
145
|
+
test('getBlock by tag pending', async () => {
|
|
146
|
+
latestBlock = await provider.getBlock();
|
|
146
147
|
expect(latestBlock).toHaveProperty('block_hash');
|
|
147
148
|
expect(latestBlock).toHaveProperty('parent_hash');
|
|
148
149
|
expect(latestBlock).toHaveProperty('block_number');
|
|
@@ -153,11 +154,8 @@ describe('defaultProvider', () => {
|
|
|
153
154
|
expect(Array.isArray(latestBlock.transactions)).toBe(true);
|
|
154
155
|
});
|
|
155
156
|
|
|
156
|
-
test('
|
|
157
|
-
const block = await provider.getBlock(
|
|
158
|
-
'0x8a30a1212d142cb0053fe9921e1dbf64f651d328565bd2e7ac24059c270f43'
|
|
159
|
-
);
|
|
160
|
-
|
|
157
|
+
test('getBlock by Hash', async () => {
|
|
158
|
+
const block = await provider.getBlock(latestBlock.block_hash);
|
|
161
159
|
expect(block).toHaveProperty('block_hash');
|
|
162
160
|
expect(block).toHaveProperty('parent_hash');
|
|
163
161
|
expect(block).toHaveProperty('block_number');
|
|
@@ -168,8 +166,8 @@ describe('defaultProvider', () => {
|
|
|
168
166
|
expect(Array.isArray(block.transactions)).toBe(true);
|
|
169
167
|
});
|
|
170
168
|
|
|
171
|
-
test('
|
|
172
|
-
const block = await provider.getBlock(
|
|
169
|
+
test('getBlock by Number', async () => {
|
|
170
|
+
const block = await provider.getBlock(latestBlock.block_number);
|
|
173
171
|
expect(block).toHaveProperty('block_hash');
|
|
174
172
|
expect(block).toHaveProperty('parent_hash');
|
|
175
173
|
expect(block).toHaveProperty('block_number');
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Account, RpcProvider, ec } from '../src';
|
|
1
|
+
import { Account, GetBlockResponse, RpcProvider, ec } from '../src';
|
|
2
2
|
import {
|
|
3
|
+
compiledErc20,
|
|
3
4
|
compiledOpenZeppelinAccount,
|
|
4
5
|
describeIfRpc,
|
|
5
6
|
getTestAccount,
|
|
@@ -20,21 +21,115 @@ describeIfRpc('RPCProvider', () => {
|
|
|
20
21
|
accountPublicKey = ec.getStarkKey(accountKeyPair);
|
|
21
22
|
});
|
|
22
23
|
|
|
24
|
+
test('getChainId', async () => {
|
|
25
|
+
const chainId = await rpcProvider.getChainId();
|
|
26
|
+
expect(chainId).toBe('0x534e5f474f45524c49');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('getPendingTransactions', async () => {
|
|
30
|
+
const transactions = await rpcProvider.getPendingTransactions();
|
|
31
|
+
expect(Array.isArray(transactions)).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('getTransactionCount', async () => {
|
|
35
|
+
const count = await rpcProvider.getTransactionCount('latest');
|
|
36
|
+
expect(typeof count).toBe('number');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('getBlockHashAndNumber', async () => {
|
|
40
|
+
const blockHashAndNumber = await rpcProvider.getBlockHashAndNumber();
|
|
41
|
+
expect(blockHashAndNumber).toHaveProperty('block_hash');
|
|
42
|
+
expect(blockHashAndNumber).toHaveProperty('block_number');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('getStateUpdate', async () => {
|
|
46
|
+
const stateUpdate = await rpcProvider.getStateUpdate('latest');
|
|
47
|
+
expect(stateUpdate).toHaveProperty('block_hash');
|
|
48
|
+
expect(stateUpdate).toHaveProperty('new_root');
|
|
49
|
+
expect(stateUpdate).toHaveProperty('old_root');
|
|
50
|
+
expect(stateUpdate).toHaveProperty('state_diff');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
xtest('getProtocolVersion', async () => {
|
|
54
|
+
await rpcProvider.getProtocolVersion();
|
|
55
|
+
});
|
|
56
|
+
|
|
23
57
|
describe('RPC methods', () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
58
|
+
let latestBlock: GetBlockResponse;
|
|
59
|
+
|
|
60
|
+
beforeAll(async () => {
|
|
61
|
+
latestBlock = await rpcProvider.getBlock('latest');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('getBlockWithTxHashes', async () => {
|
|
65
|
+
const blockResponse = await rpcProvider.getBlockWithTxHashes(latestBlock.block_number);
|
|
66
|
+
expect(blockResponse).toHaveProperty('transactions');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('getBlockWithTxs', async () => {
|
|
70
|
+
const blockResponse = await rpcProvider.getBlockWithTxs(latestBlock.block_number);
|
|
71
|
+
expect(blockResponse).toHaveProperty('transactions');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('getTransactionByBlockIdAndIndex', async () => {
|
|
75
|
+
const transaction = await rpcProvider.getTransactionByBlockIdAndIndex(
|
|
76
|
+
latestBlock.block_number,
|
|
77
|
+
0
|
|
78
|
+
);
|
|
79
|
+
expect(transaction).toHaveProperty('transaction_hash');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
xtest('traceBlockTransactions', async () => {
|
|
83
|
+
await rpcProvider.traceBlockTransactions(latestBlock.block_hash);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('deploy contract related tests', () => {
|
|
87
|
+
let contract_address;
|
|
88
|
+
let transaction_hash;
|
|
89
|
+
|
|
90
|
+
beforeAll(async () => {
|
|
91
|
+
({ contract_address, transaction_hash } = await rpcProvider.deployContract({
|
|
92
|
+
contract: compiledOpenZeppelinAccount,
|
|
93
|
+
constructorCalldata: [accountPublicKey],
|
|
94
|
+
addressSalt: accountPublicKey,
|
|
95
|
+
}));
|
|
96
|
+
await rpcProvider.waitForTransaction(transaction_hash);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('deployContract result', () => {
|
|
100
|
+
expect(contract_address).toBeTruthy();
|
|
101
|
+
expect(transaction_hash).toBeTruthy();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('getTransactionByHash', async () => {
|
|
105
|
+
const transaction = await rpcProvider.getTransactionByHash(transaction_hash);
|
|
106
|
+
expect(transaction).toHaveProperty('transaction_hash');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('getClassHashAt', async () => {
|
|
110
|
+
const classHash = await rpcProvider.getClassHashAt('latest', contract_address);
|
|
111
|
+
expect(typeof classHash).toBe('string');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
xtest('traceTransaction', async () => {
|
|
115
|
+
await rpcProvider.traceTransaction(transaction_hash);
|
|
116
|
+
});
|
|
27
117
|
});
|
|
28
118
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
119
|
+
describe('declare contract related tests', () => {
|
|
120
|
+
let class_hash;
|
|
121
|
+
|
|
122
|
+
beforeAll(async () => {
|
|
123
|
+
({ class_hash } = await rpcProvider.declareContract({
|
|
124
|
+
contract: compiledErc20,
|
|
125
|
+
}));
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('getClass', async () => {
|
|
129
|
+
const contractClass = await rpcProvider.getClass(class_hash);
|
|
130
|
+
expect(contractClass).toHaveProperty('program');
|
|
131
|
+
expect(contractClass).toHaveProperty('entry_points_by_type');
|
|
34
132
|
});
|
|
35
|
-
await rpcProvider.waitForTransaction(transaction_hash);
|
|
36
|
-
expect(contract_address).toBeTruthy();
|
|
37
|
-
expect(transaction_hash).toBeTruthy();
|
|
38
133
|
});
|
|
39
134
|
|
|
40
135
|
test.todo('getEstimateFee');
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
|
|
3
3
|
import { constants, hash, json, number, stark } from '../../src';
|
|
4
|
+
import { Block } from '../../src/provider/utils';
|
|
4
5
|
import { pedersen } from '../../src/utils/hash';
|
|
5
6
|
|
|
6
7
|
const { IS_BROWSER } = constants;
|
|
@@ -112,3 +113,19 @@ describe('calculateContractAddressFromHash()', () => {
|
|
|
112
113
|
);
|
|
113
114
|
});
|
|
114
115
|
});
|
|
116
|
+
|
|
117
|
+
describe('new Block()', () => {
|
|
118
|
+
test('Block identifier and queryIdentifier', () => {
|
|
119
|
+
const blockA = new Block(0);
|
|
120
|
+
expect(blockA.identifier).toMatchObject({ block_number: 0 });
|
|
121
|
+
expect(blockA.queryIdentifier).toBe('blockNumber=0');
|
|
122
|
+
|
|
123
|
+
const blockB = new Block('latest');
|
|
124
|
+
expect(blockB.identifier).toBe('latest');
|
|
125
|
+
expect(blockB.queryIdentifier).toBe('blockNumber=latest');
|
|
126
|
+
|
|
127
|
+
const blockC = new Block('0x01');
|
|
128
|
+
expect(blockC.identifier).toMatchObject({ block_hash: '0x01' });
|
|
129
|
+
expect(blockC.queryIdentifier).toBe('blockHash=0x01');
|
|
130
|
+
});
|
|
131
|
+
});
|
package/dist/provider/rpc.d.ts
CHANGED
|
@@ -12,24 +12,34 @@ export declare class RpcProvider implements ProviderInterface {
|
|
|
12
12
|
chainId: StarknetChainId;
|
|
13
13
|
private responseParser;
|
|
14
14
|
constructor(optionsOrProvider: RpcProviderOptions);
|
|
15
|
+
fetch(method: any, params: any): Promise<any>;
|
|
16
|
+
protected errorHandler(error: any): void;
|
|
15
17
|
protected fetchEndpoint<T extends keyof RPC.Methods>(method: T, request?: RPC.Methods[T]['REQUEST']): Promise<RPC.Methods[T]['RESPONSE']>;
|
|
16
|
-
getChainId(): Promise<
|
|
18
|
+
getChainId(): Promise<any>;
|
|
17
19
|
getBlock(blockIdentifier?: BlockIdentifier): Promise<GetBlockResponse>;
|
|
20
|
+
getBlockHashAndNumber(): Promise<RPC.BlockHashAndNumber>;
|
|
18
21
|
getBlockWithTxHashes(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxHashesResponse>;
|
|
19
22
|
getBlockWithTxs(blockIdentifier?: BlockIdentifier): Promise<RPC.GetBlockWithTxs>;
|
|
23
|
+
getClassHashAt(blockIdentifier: BlockIdentifier, contractAddress: RPC.ContractAddress): Promise<RPC.Felt>;
|
|
20
24
|
getNonce(contractAddress: string): Promise<any>;
|
|
25
|
+
getPendingTransactions(): Promise<RPC.PendingTransactions>;
|
|
26
|
+
getProtocolVersion(): Promise<Error>;
|
|
27
|
+
getStateUpdate(blockIdentifier: BlockIdentifier): Promise<RPC.StateUpdate>;
|
|
21
28
|
getStorageAt(contractAddress: string, key: BigNumberish, blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
|
|
22
29
|
getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse>;
|
|
23
30
|
getTransactionByHash(txHash: BigNumberish): Promise<RPC.GetTransactionByHashResponse>;
|
|
24
31
|
getTransactionByBlockIdAndIndex(blockIdentifier: BlockIdentifier, index: number): Promise<RPC.GetTransactionByBlockIdAndIndex>;
|
|
25
32
|
getTransactionReceipt(txHash: BigNumberish): Promise<GetTransactionReceiptResponse>;
|
|
33
|
+
getClass(classHash: RPC.Felt): Promise<RPC.ContractClass>;
|
|
26
34
|
getClassAt(contractAddress: string, blockIdentifier: BlockIdentifier): Promise<any>;
|
|
35
|
+
getCode(_contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
27
36
|
getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
|
|
28
37
|
declareContract({ contract, version, }: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
29
38
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
30
39
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
31
40
|
callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
32
|
-
|
|
41
|
+
traceTransaction(transactionHash: RPC.TransactionHash): Promise<RPC.Trace>;
|
|
42
|
+
traceBlockTransactions(blockHash: RPC.BlockHash): Promise<RPC.Traces>;
|
|
33
43
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
34
44
|
/**
|
|
35
45
|
* Gets the transaction count from a block.
|
package/dist/provider/rpc.js
CHANGED
|
@@ -58,54 +58,45 @@ var RpcProvider = /** @class */ (function () {
|
|
|
58
58
|
_this.chainId = chainId;
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
+
RpcProvider.prototype.fetch = function (method, params) {
|
|
62
|
+
return (0, fetchPonyfill_1.default)(this.nodeUrl, {
|
|
63
|
+
method: 'POST',
|
|
64
|
+
body: (0, json_1.stringify)({ method: method, jsonrpc: '2.0', params: params, id: 0 }),
|
|
65
|
+
headers: { 'Content-Type': 'application/json' },
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
RpcProvider.prototype.errorHandler = function (error) {
|
|
69
|
+
if (error) {
|
|
70
|
+
var code = error.code, message = error.message;
|
|
71
|
+
throw new Error("".concat(code, ": ").concat(message));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
61
74
|
RpcProvider.prototype.fetchEndpoint = function (method, request) {
|
|
62
75
|
var _a;
|
|
63
76
|
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
-
var
|
|
77
|
+
var rawResult, _b, error, result, error_1;
|
|
65
78
|
return __generator(this, function (_c) {
|
|
66
79
|
switch (_c.label) {
|
|
67
80
|
case 0:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
jsonrpc: '2.0',
|
|
71
|
-
params: request,
|
|
72
|
-
id: 0,
|
|
73
|
-
};
|
|
74
|
-
_c.label = 1;
|
|
81
|
+
_c.trys.push([0, 3, , 4]);
|
|
82
|
+
return [4 /*yield*/, this.fetch(method, request)];
|
|
75
83
|
case 1:
|
|
76
|
-
_c.trys.push([1, 4, , 5]);
|
|
77
|
-
return [4 /*yield*/, (0, fetchPonyfill_1.default)(this.nodeUrl, {
|
|
78
|
-
method: 'POST',
|
|
79
|
-
body: (0, json_1.stringify)(requestData),
|
|
80
|
-
headers: {
|
|
81
|
-
'Content-Type': 'application/json',
|
|
82
|
-
},
|
|
83
|
-
})];
|
|
84
|
-
case 2:
|
|
85
84
|
rawResult = _c.sent();
|
|
86
85
|
return [4 /*yield*/, rawResult.json()];
|
|
87
|
-
case
|
|
86
|
+
case 2:
|
|
88
87
|
_b = _c.sent(), error = _b.error, result = _b.result;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
return [2 /*return*/, result];
|
|
95
|
-
}
|
|
96
|
-
return [3 /*break*/, 5];
|
|
97
|
-
case 4:
|
|
88
|
+
this.errorHandler(error);
|
|
89
|
+
return [2 /*return*/, result];
|
|
90
|
+
case 3:
|
|
98
91
|
error_1 = _c.sent();
|
|
99
|
-
|
|
100
|
-
if (data === null || data === void 0 ? void 0 : data.message) {
|
|
101
|
-
throw new Error("".concat(data.code, ": ").concat(data.message));
|
|
102
|
-
}
|
|
92
|
+
this.errorHandler((_a = error_1 === null || error_1 === void 0 ? void 0 : error_1.response) === null || _a === void 0 ? void 0 : _a.data);
|
|
103
93
|
throw error_1;
|
|
104
|
-
case
|
|
94
|
+
case 4: return [2 /*return*/];
|
|
105
95
|
}
|
|
106
96
|
});
|
|
107
97
|
});
|
|
108
98
|
};
|
|
99
|
+
// Methods from Interface
|
|
109
100
|
RpcProvider.prototype.getChainId = function () {
|
|
110
101
|
return __awaiter(this, void 0, void 0, function () {
|
|
111
102
|
return __generator(this, function (_a) {
|
|
@@ -113,7 +104,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
113
104
|
});
|
|
114
105
|
});
|
|
115
106
|
};
|
|
116
|
-
//
|
|
107
|
+
// Methods from Interface
|
|
117
108
|
RpcProvider.prototype.getBlock = function (blockIdentifier) {
|
|
118
109
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
119
110
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -122,25 +113,39 @@ var RpcProvider = /** @class */ (function () {
|
|
|
122
113
|
});
|
|
123
114
|
});
|
|
124
115
|
};
|
|
116
|
+
RpcProvider.prototype.getBlockHashAndNumber = function () {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
+
return __generator(this, function (_a) {
|
|
119
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_blockHashAndNumber')];
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
};
|
|
125
123
|
RpcProvider.prototype.getBlockWithTxHashes = function (blockIdentifier) {
|
|
126
124
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
127
125
|
return __awaiter(this, void 0, void 0, function () {
|
|
128
|
-
var
|
|
126
|
+
var block;
|
|
129
127
|
return __generator(this, function (_a) {
|
|
130
|
-
|
|
131
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxHashes', [
|
|
132
|
-
blockIdentifierGetter.getIdentifier(),
|
|
133
|
-
])];
|
|
128
|
+
block = new utils_1.Block(blockIdentifier);
|
|
129
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxHashes', [block.identifier])];
|
|
134
130
|
});
|
|
135
131
|
});
|
|
136
132
|
};
|
|
137
133
|
RpcProvider.prototype.getBlockWithTxs = function (blockIdentifier) {
|
|
138
134
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
139
135
|
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
-
var
|
|
136
|
+
var block;
|
|
137
|
+
return __generator(this, function (_a) {
|
|
138
|
+
block = new utils_1.Block(blockIdentifier);
|
|
139
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockWithTxs', [block.identifier])];
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
RpcProvider.prototype.getClassHashAt = function (blockIdentifier, contractAddress) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
+
var block;
|
|
141
146
|
return __generator(this, function (_a) {
|
|
142
|
-
|
|
143
|
-
return [2 /*return*/, this.fetchEndpoint('
|
|
147
|
+
block = new utils_1.Block(blockIdentifier);
|
|
148
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getClassHashAt', [block.identifier, contractAddress])];
|
|
144
149
|
});
|
|
145
150
|
});
|
|
146
151
|
};
|
|
@@ -151,22 +156,45 @@ var RpcProvider = /** @class */ (function () {
|
|
|
151
156
|
});
|
|
152
157
|
});
|
|
153
158
|
};
|
|
159
|
+
RpcProvider.prototype.getPendingTransactions = function () {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
161
|
+
return __generator(this, function (_a) {
|
|
162
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_pendingTransactions')];
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
RpcProvider.prototype.getProtocolVersion = function () {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
168
|
+
return __generator(this, function (_a) {
|
|
169
|
+
throw new Error('Pathfinder does not implement this rpc 0.1.0 method');
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
RpcProvider.prototype.getStateUpdate = function (blockIdentifier) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
+
var block;
|
|
176
|
+
return __generator(this, function (_a) {
|
|
177
|
+
block = new utils_1.Block(blockIdentifier);
|
|
178
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getStateUpdate', [block.identifier])];
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
};
|
|
154
182
|
RpcProvider.prototype.getStorageAt = function (contractAddress, key, blockIdentifier) {
|
|
155
183
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
156
184
|
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
-
var parsedKey,
|
|
185
|
+
var parsedKey, block;
|
|
158
186
|
return __generator(this, function (_a) {
|
|
159
187
|
parsedKey = (0, number_1.toHex)((0, number_1.toBN)(key));
|
|
160
|
-
|
|
188
|
+
block = new utils_1.Block(blockIdentifier);
|
|
161
189
|
return [2 /*return*/, this.fetchEndpoint('starknet_getStorageAt', [
|
|
162
190
|
contractAddress,
|
|
163
191
|
parsedKey,
|
|
164
|
-
|
|
192
|
+
block.identifier,
|
|
165
193
|
])];
|
|
166
194
|
});
|
|
167
195
|
});
|
|
168
196
|
};
|
|
169
|
-
//
|
|
197
|
+
// Methods from Interface
|
|
170
198
|
RpcProvider.prototype.getTransaction = function (txHash) {
|
|
171
199
|
return __awaiter(this, void 0, void 0, function () {
|
|
172
200
|
return __generator(this, function (_a) {
|
|
@@ -183,8 +211,13 @@ var RpcProvider = /** @class */ (function () {
|
|
|
183
211
|
};
|
|
184
212
|
RpcProvider.prototype.getTransactionByBlockIdAndIndex = function (blockIdentifier, index) {
|
|
185
213
|
return __awaiter(this, void 0, void 0, function () {
|
|
214
|
+
var block;
|
|
186
215
|
return __generator(this, function (_a) {
|
|
187
|
-
|
|
216
|
+
block = new utils_1.Block(blockIdentifier);
|
|
217
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getTransactionByBlockIdAndIndex', [
|
|
218
|
+
block.identifier,
|
|
219
|
+
index,
|
|
220
|
+
])];
|
|
188
221
|
});
|
|
189
222
|
});
|
|
190
223
|
};
|
|
@@ -195,15 +228,26 @@ var RpcProvider = /** @class */ (function () {
|
|
|
195
228
|
});
|
|
196
229
|
});
|
|
197
230
|
};
|
|
231
|
+
RpcProvider.prototype.getClass = function (classHash) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
233
|
+
return __generator(this, function (_a) {
|
|
234
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getClass', [classHash])];
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
};
|
|
198
238
|
RpcProvider.prototype.getClassAt = function (contractAddress, blockIdentifier) {
|
|
199
239
|
return __awaiter(this, void 0, void 0, function () {
|
|
200
|
-
var
|
|
240
|
+
var block;
|
|
201
241
|
return __generator(this, function (_a) {
|
|
202
|
-
|
|
203
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_getClassAt', [
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
242
|
+
block = new utils_1.Block(blockIdentifier);
|
|
243
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getClassAt', [block.identifier, contractAddress])];
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
RpcProvider.prototype.getCode = function (_contractAddress, _blockIdentifier) {
|
|
248
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
249
|
+
return __generator(this, function (_a) {
|
|
250
|
+
throw new Error('RPC 0.1.0 does not implement getCode function');
|
|
207
251
|
});
|
|
208
252
|
});
|
|
209
253
|
};
|
|
@@ -211,7 +255,9 @@ var RpcProvider = /** @class */ (function () {
|
|
|
211
255
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
212
256
|
if (invocationDetails === void 0) { invocationDetails = {}; }
|
|
213
257
|
return __awaiter(this, void 0, void 0, function () {
|
|
258
|
+
var block_id;
|
|
214
259
|
return __generator(this, function (_a) {
|
|
260
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
215
261
|
return [2 /*return*/, this.fetchEndpoint('starknet_estimateFee', [
|
|
216
262
|
{
|
|
217
263
|
contract_address: invocation.contractAddress,
|
|
@@ -220,7 +266,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
220
266
|
signature: (0, number_1.bigNumberishArrayToHexadecimalStringArray)(invocation.signature || []),
|
|
221
267
|
version: (0, number_1.toHex)((0, number_1.toBN)((invocationDetails === null || invocationDetails === void 0 ? void 0 : invocationDetails.version) || 0)),
|
|
222
268
|
},
|
|
223
|
-
|
|
269
|
+
block_id,
|
|
224
270
|
]).then(this.responseParser.parseFeeEstimateResponse)];
|
|
225
271
|
});
|
|
226
272
|
});
|
|
@@ -276,20 +322,23 @@ var RpcProvider = /** @class */ (function () {
|
|
|
276
322
|
});
|
|
277
323
|
});
|
|
278
324
|
};
|
|
325
|
+
// Methods from Interface
|
|
279
326
|
RpcProvider.prototype.callContract = function (call, blockIdentifier) {
|
|
280
327
|
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
281
328
|
return __awaiter(this, void 0, void 0, function () {
|
|
282
|
-
var result;
|
|
329
|
+
var block_id, result;
|
|
283
330
|
return __generator(this, function (_a) {
|
|
284
331
|
switch (_a.label) {
|
|
285
|
-
case 0:
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
332
|
+
case 0:
|
|
333
|
+
block_id = new utils_1.Block(blockIdentifier).identifier;
|
|
334
|
+
return [4 /*yield*/, this.fetchEndpoint('starknet_call', [
|
|
335
|
+
{
|
|
336
|
+
contract_address: call.contractAddress,
|
|
337
|
+
entry_point_selector: (0, hash_1.getSelectorFromName)(call.entrypoint),
|
|
338
|
+
calldata: (0, provider_1.parseCalldata)(call.calldata),
|
|
339
|
+
},
|
|
340
|
+
block_id,
|
|
341
|
+
])];
|
|
293
342
|
case 1:
|
|
294
343
|
result = _a.sent();
|
|
295
344
|
return [2 /*return*/, this.responseParser.parseCallContractResponse(result)];
|
|
@@ -297,10 +346,17 @@ var RpcProvider = /** @class */ (function () {
|
|
|
297
346
|
});
|
|
298
347
|
});
|
|
299
348
|
};
|
|
300
|
-
RpcProvider.prototype.
|
|
349
|
+
RpcProvider.prototype.traceTransaction = function (transactionHash) {
|
|
301
350
|
return __awaiter(this, void 0, void 0, function () {
|
|
302
351
|
return __generator(this, function (_a) {
|
|
303
|
-
|
|
352
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_traceTransaction', [transactionHash])];
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
RpcProvider.prototype.traceBlockTransactions = function (blockHash) {
|
|
357
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
358
|
+
return __generator(this, function (_a) {
|
|
359
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_traceBlockTransactions', [blockHash])];
|
|
304
360
|
});
|
|
305
361
|
});
|
|
306
362
|
};
|
|
@@ -312,7 +368,7 @@ var RpcProvider = /** @class */ (function () {
|
|
|
312
368
|
switch (_a.label) {
|
|
313
369
|
case 0:
|
|
314
370
|
onchain = false;
|
|
315
|
-
retries =
|
|
371
|
+
retries = 200;
|
|
316
372
|
_a.label = 1;
|
|
317
373
|
case 1:
|
|
318
374
|
if (!!onchain) return [3 /*break*/, 7];
|
|
@@ -368,12 +424,10 @@ var RpcProvider = /** @class */ (function () {
|
|
|
368
424
|
*/
|
|
369
425
|
RpcProvider.prototype.getTransactionCount = function (blockIdentifier) {
|
|
370
426
|
return __awaiter(this, void 0, void 0, function () {
|
|
371
|
-
var
|
|
427
|
+
var block;
|
|
372
428
|
return __generator(this, function (_a) {
|
|
373
|
-
|
|
374
|
-
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockTransactionCount', [
|
|
375
|
-
blockIdentifierGetter.getIdentifier(),
|
|
376
|
-
])];
|
|
429
|
+
block = new utils_1.Block(blockIdentifier);
|
|
430
|
+
return [2 /*return*/, this.fetchEndpoint('starknet_getBlockTransactionCount', [block.identifier])];
|
|
377
431
|
});
|
|
378
432
|
});
|
|
379
433
|
};
|
|
@@ -134,7 +134,8 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
134
134
|
.map(function (_a) {
|
|
135
135
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
136
136
|
if (key === 'blockIdentifier') {
|
|
137
|
-
|
|
137
|
+
var block = new utils_1.Block(value);
|
|
138
|
+
return "".concat(block.queryIdentifier);
|
|
138
139
|
}
|
|
139
140
|
return "".concat(key, "=").concat(value);
|
|
140
141
|
})
|