starknet 4.0.1 → 4.1.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 +6 -0
- package/__tests__/defaultProvider.test.ts +5 -0
- package/dist/provider/default.d.ts +2 -1
- package/dist/provider/default.js +7 -0
- package/dist/provider/interface.d.ts +2 -1
- package/dist/provider/rpc.d.ts +1 -0
- package/dist/provider/rpc.js +13 -0
- package/dist/provider/sequencer.d.ts +1 -0
- package/dist/provider/sequencer.js +8 -0
- package/dist/types/api/sequencer.d.ts +4 -4
- package/dist/types/provider.d.ts +3 -0
- package/dist/utils/responseParser/rpc.d.ts +1 -0
- package/dist/utils/responseParser/rpc.js +3 -0
- package/dist/utils/responseParser/sequencer.d.ts +1 -0
- package/dist/utils/responseParser/sequencer.js +3 -0
- package/package.json +2 -4
- package/provider/default.d.ts +2 -1
- package/provider/default.js +7 -0
- package/provider/interface.d.ts +2 -1
- package/provider/rpc.d.ts +1 -0
- package/provider/rpc.js +13 -0
- package/provider/sequencer.d.ts +1 -0
- package/provider/sequencer.js +8 -0
- package/src/provider/default.ts +8 -0
- package/src/provider/interface.ts +6 -0
- package/src/provider/rpc.ts +9 -0
- package/src/provider/sequencer.ts +9 -0
- package/src/types/api/sequencer.ts +5 -5
- package/src/types/provider.ts +5 -0
- package/src/utils/responseParser/rpc.ts +4 -0
- package/src/utils/responseParser/sequencer.ts +4 -0
- package/types/api/sequencer.d.ts +4 -4
- package/types/provider.d.ts +3 -0
- package/utils/responseParser/rpc.d.ts +1 -0
- package/utils/responseParser/rpc.js +3 -0
- package/utils/responseParser/sequencer.d.ts +1 -0
- package/utils/responseParser/sequencer.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# [4.1.0](https://github.com/0xs34n/starknet.js/compare/v4.0.1...v4.1.0) (2022-08-03)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- get-code ([de6e597](https://github.com/0xs34n/starknet.js/commit/de6e5971de5155925defcf9249a8160dc3fdc9b7))
|
|
6
|
+
|
|
1
7
|
## [4.0.1](https://github.com/0xs34n/starknet.js/compare/v4.0.0...v4.0.1) (2022-08-03)
|
|
2
8
|
|
|
3
9
|
### Bug Fixes
|
|
@@ -62,6 +62,11 @@ 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
|
+
|
|
65
70
|
describe('getStorageAt', () => {
|
|
66
71
|
test('with "key" type of number', () => {
|
|
67
72
|
return expect(testProvider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow();
|
|
@@ -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 { BlockTag, 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';
|
|
@@ -23,5 +23,6 @@ export declare class Provider implements ProviderInterface {
|
|
|
23
23
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
24
24
|
deployContract(payload: DeployContractPayload): Promise<DeployContractResponse>;
|
|
25
25
|
declareContract(payload: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
26
|
+
getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
26
27
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
27
28
|
}
|
package/dist/provider/default.js
CHANGED
|
@@ -137,6 +137,13 @@ var Provider = /** @class */ (function () {
|
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
139
|
};
|
|
140
|
+
Provider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
142
|
+
return __generator(this, function (_a) {
|
|
143
|
+
return [2 /*return*/, this.provider.getCode(contractAddress, blockIdentifier)];
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
};
|
|
140
147
|
Provider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
141
148
|
return __awaiter(this, void 0, void 0, function () {
|
|
142
149
|
return __generator(this, function (_a) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import type { BlockTag, Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
|
|
2
|
+
import type { BlockTag, 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,7 @@ export declare abstract class ProviderInterface {
|
|
|
19
19
|
* @returns the block object
|
|
20
20
|
*/
|
|
21
21
|
abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
|
|
22
|
+
abstract getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
22
23
|
/**
|
|
23
24
|
* Gets the contract class of the deployed contract.
|
|
24
25
|
*
|
package/dist/provider/rpc.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare class RpcProvider implements ProviderInterface {
|
|
|
24
24
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
25
25
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
26
26
|
callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
27
|
+
getCode(contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<RPC.GetCodeResponse>;
|
|
27
28
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
28
29
|
/**
|
|
29
30
|
* Gets the transaction count from a block.
|
package/dist/provider/rpc.js
CHANGED
|
@@ -248,6 +248,19 @@ var RpcProvider = /** @class */ (function () {
|
|
|
248
248
|
});
|
|
249
249
|
});
|
|
250
250
|
};
|
|
251
|
+
RpcProvider.prototype.getCode = function (contractAddress, _blockIdentifier) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
+
var result;
|
|
254
|
+
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
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
};
|
|
251
264
|
RpcProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
252
265
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
253
266
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -37,6 +37,7 @@ export declare class SequencerProvider implements ProviderInterface {
|
|
|
37
37
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
38
38
|
declareContract({ contract, }: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
39
39
|
getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
|
|
40
|
+
getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<Sequencer.GetCodeResponse>;
|
|
40
41
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
41
42
|
/**
|
|
42
43
|
* Gets the status of a transaction.
|
|
@@ -355,6 +355,14 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
355
355
|
});
|
|
356
356
|
});
|
|
357
357
|
};
|
|
358
|
+
SequencerProvider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
359
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
360
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
361
|
+
return __generator(this, function (_a) {
|
|
362
|
+
return [2 /*return*/, this.fetchEndpoint('get_code', { contractAddress: contractAddress, blockIdentifier: blockIdentifier }).then(this.responseParser.parseGetCodeResponse)];
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
};
|
|
358
366
|
SequencerProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
359
367
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
360
368
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -39,10 +39,6 @@ export declare type ExecutionResources = {
|
|
|
39
39
|
};
|
|
40
40
|
n_memory_holes: number;
|
|
41
41
|
};
|
|
42
|
-
export declare type GetCodeResponse = {
|
|
43
|
-
bytecode: string[];
|
|
44
|
-
abi: Abi;
|
|
45
|
-
};
|
|
46
42
|
export declare type GetTransactionTraceResponse = {
|
|
47
43
|
function_invocation: {
|
|
48
44
|
caller_address: string;
|
|
@@ -97,6 +93,10 @@ export declare namespace Sequencer {
|
|
|
97
93
|
address?: string;
|
|
98
94
|
class_hash?: string;
|
|
99
95
|
};
|
|
96
|
+
type GetCodeResponse = {
|
|
97
|
+
bytecode: string[];
|
|
98
|
+
abi: Abi;
|
|
99
|
+
};
|
|
100
100
|
interface InvokeFunctionTransactionResponse extends InvokeFunctionTransaction {
|
|
101
101
|
transaction_hash: string;
|
|
102
102
|
}
|
package/dist/types/provider.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ export interface GetBlockResponse {
|
|
|
13
13
|
transactions: Array<string>;
|
|
14
14
|
starknet_version?: string;
|
|
15
15
|
}
|
|
16
|
+
export interface GetCodeResponse {
|
|
17
|
+
bytecode: string[];
|
|
18
|
+
}
|
|
16
19
|
export declare type GetTransactionResponse = InvokeTransactionResponse & DeclareTransactionResponse;
|
|
17
20
|
export interface CommonTransactionResponse {
|
|
18
21
|
transaction_hash?: string;
|
|
@@ -5,6 +5,7 @@ export declare class RPCResponseParser extends ResponseParser {
|
|
|
5
5
|
parseGetBlockResponse(res: RPC.GetBlockResponse): GetBlockResponse;
|
|
6
6
|
parseGetTransactionResponse(res: RPC.GetTransactionResponse): GetTransactionResponse;
|
|
7
7
|
parseGetTransactionReceiptResponse(res: RPC.GetTransactionReceiptResponse): GetTransactionReceiptResponse;
|
|
8
|
+
parseGetCodeResponse(res: RPC.GetCodeResponse): RPC.GetCodeResponse;
|
|
8
9
|
parseFeeEstimateResponse(res: RPC.EstimateFeeResponse): EstimateFeeResponse;
|
|
9
10
|
parseCallContractResponse(res: Array<string>): CallContractResponse;
|
|
10
11
|
parseInvokeFunctionResponse(res: RPC.AddTransactionResponse): InvokeFunctionResponse;
|
|
@@ -62,6 +62,9 @@ var RPCResponseParser = /** @class */ (function (_super) {
|
|
|
62
62
|
events: res.events,
|
|
63
63
|
};
|
|
64
64
|
};
|
|
65
|
+
RPCResponseParser.prototype.parseGetCodeResponse = function (res) {
|
|
66
|
+
return res;
|
|
67
|
+
};
|
|
65
68
|
RPCResponseParser.prototype.parseFeeEstimateResponse = function (res) {
|
|
66
69
|
return {
|
|
67
70
|
overall_fee: (0, number_1.toBN)(res.overall_fee),
|
|
@@ -5,6 +5,7 @@ export declare class SequencerAPIResponseParser extends ResponseParser {
|
|
|
5
5
|
parseGetBlockResponse(res: Sequencer.GetBlockResponse): GetBlockResponse;
|
|
6
6
|
parseGetTransactionResponse(res: Sequencer.GetTransactionResponse): GetTransactionResponse;
|
|
7
7
|
parseGetTransactionReceiptResponse(res: Sequencer.TransactionReceiptResponse): GetTransactionReceiptResponse;
|
|
8
|
+
parseGetCodeResponse(res: Sequencer.GetCodeResponse): Sequencer.GetCodeResponse;
|
|
8
9
|
parseFeeEstimateResponse(res: Sequencer.EstimateFeeResponse): EstimateFeeResponse;
|
|
9
10
|
parseCallContractResponse(res: Sequencer.CallContractResponse): CallContractResponse;
|
|
10
11
|
parseInvokeFunctionResponse(res: Sequencer.AddTransactionResponse): InvokeFunctionResponse;
|
|
@@ -79,6 +79,9 @@ var SequencerAPIResponseParser = /** @class */ (function (_super) {
|
|
|
79
79
|
l1_origin_message: undefined,
|
|
80
80
|
};
|
|
81
81
|
};
|
|
82
|
+
SequencerAPIResponseParser.prototype.parseGetCodeResponse = function (res) {
|
|
83
|
+
return res;
|
|
84
|
+
};
|
|
82
85
|
SequencerAPIResponseParser.prototype.parseFeeEstimateResponse = function (res) {
|
|
83
86
|
if ('overall_fee' in res) {
|
|
84
87
|
var gasInfo = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starknet",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "JavaScript library for StarkNet",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"@types/minimalistic-assert": "^1.0.1",
|
|
44
44
|
"@types/pako": "^2.0.0",
|
|
45
45
|
"@types/url-join": "^4.0.1",
|
|
46
|
-
"@types/whatwg-fetch": "^0.0.33",
|
|
47
46
|
"@typescript-eslint/eslint-plugin": "^5.28.0",
|
|
48
47
|
"@typescript-eslint/parser": "^5.28.0",
|
|
49
48
|
"eslint": "^8.17.0",
|
|
@@ -61,8 +60,7 @@
|
|
|
61
60
|
"prettier": "^2.7.0",
|
|
62
61
|
"prettier-plugin-import-sort": "^0.0.7",
|
|
63
62
|
"typedoc": "^0.22.17",
|
|
64
|
-
"typescript": "^4.7.3"
|
|
65
|
-
"whatwg-fetch": "^3.6.2"
|
|
63
|
+
"typescript": "^4.7.3"
|
|
66
64
|
},
|
|
67
65
|
"dependencies": {
|
|
68
66
|
"@ethersproject/bytes": "^5.6.1",
|
package/provider/default.d.ts
CHANGED
|
@@ -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 { BlockTag, 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';
|
|
@@ -23,5 +23,6 @@ export declare class Provider implements ProviderInterface {
|
|
|
23
23
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
24
24
|
deployContract(payload: DeployContractPayload): Promise<DeployContractResponse>;
|
|
25
25
|
declareContract(payload: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
26
|
+
getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
26
27
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
27
28
|
}
|
package/provider/default.js
CHANGED
|
@@ -137,6 +137,13 @@ var Provider = /** @class */ (function () {
|
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
139
|
};
|
|
140
|
+
Provider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
142
|
+
return __generator(this, function (_a) {
|
|
143
|
+
return [2 /*return*/, this.provider.getCode(contractAddress, blockIdentifier)];
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
};
|
|
140
147
|
Provider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
141
148
|
return __awaiter(this, void 0, void 0, function () {
|
|
142
149
|
return __generator(this, function (_a) {
|
package/provider/interface.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StarknetChainId } from '../constants';
|
|
2
|
-
import type { BlockTag, Call, CallContractResponse, ContractClass, DeclareContractPayload, DeclareContractResponse, DeployContractPayload, DeployContractResponse, EstimateFeeResponse, GetBlockResponse, GetTransactionReceiptResponse, GetTransactionResponse, Invocation, InvocationsDetails, InvokeFunctionResponse } from '../types';
|
|
2
|
+
import type { BlockTag, 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,7 @@ export declare abstract class ProviderInterface {
|
|
|
19
19
|
* @returns the block object
|
|
20
20
|
*/
|
|
21
21
|
abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
|
|
22
|
+
abstract getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<GetCodeResponse>;
|
|
22
23
|
/**
|
|
23
24
|
* Gets the contract class of the deployed contract.
|
|
24
25
|
*
|
package/provider/rpc.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare class RpcProvider implements ProviderInterface {
|
|
|
24
24
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
25
25
|
invokeFunction(functionInvocation: Invocation, details: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
26
26
|
callContract(call: Call, blockIdentifier?: BlockIdentifier): Promise<CallContractResponse>;
|
|
27
|
+
getCode(contractAddress: string, _blockIdentifier?: BlockIdentifier): Promise<RPC.GetCodeResponse>;
|
|
27
28
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
28
29
|
/**
|
|
29
30
|
* Gets the transaction count from a block.
|
package/provider/rpc.js
CHANGED
|
@@ -248,6 +248,19 @@ var RpcProvider = /** @class */ (function () {
|
|
|
248
248
|
});
|
|
249
249
|
});
|
|
250
250
|
};
|
|
251
|
+
RpcProvider.prototype.getCode = function (contractAddress, _blockIdentifier) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
+
var result;
|
|
254
|
+
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
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
};
|
|
251
264
|
RpcProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
252
265
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
253
266
|
return __awaiter(this, void 0, void 0, function () {
|
package/provider/sequencer.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export declare class SequencerProvider implements ProviderInterface {
|
|
|
37
37
|
deployContract({ contract, constructorCalldata, addressSalt, }: DeployContractPayload): Promise<DeployContractResponse>;
|
|
38
38
|
declareContract({ contract, }: DeclareContractPayload): Promise<DeclareContractResponse>;
|
|
39
39
|
getEstimateFee(invocation: Invocation, blockIdentifier?: BlockIdentifier, invocationDetails?: InvocationsDetails): Promise<EstimateFeeResponse>;
|
|
40
|
+
getCode(contractAddress: string, blockIdentifier?: BlockIdentifier): Promise<Sequencer.GetCodeResponse>;
|
|
40
41
|
waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void>;
|
|
41
42
|
/**
|
|
42
43
|
* Gets the status of a transaction.
|
package/provider/sequencer.js
CHANGED
|
@@ -355,6 +355,14 @@ var SequencerProvider = /** @class */ (function () {
|
|
|
355
355
|
});
|
|
356
356
|
});
|
|
357
357
|
};
|
|
358
|
+
SequencerProvider.prototype.getCode = function (contractAddress, blockIdentifier) {
|
|
359
|
+
if (blockIdentifier === void 0) { blockIdentifier = 'pending'; }
|
|
360
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
361
|
+
return __generator(this, function (_a) {
|
|
362
|
+
return [2 /*return*/, this.fetchEndpoint('get_code', { contractAddress: contractAddress, blockIdentifier: blockIdentifier }).then(this.responseParser.parseGetCodeResponse)];
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
};
|
|
358
366
|
SequencerProvider.prototype.waitForTransaction = function (txHash, retryInterval) {
|
|
359
367
|
if (retryInterval === void 0) { retryInterval = 8000; }
|
|
360
368
|
return __awaiter(this, void 0, void 0, function () {
|
package/src/provider/default.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
DeployContractResponse,
|
|
11
11
|
EstimateFeeResponse,
|
|
12
12
|
GetBlockResponse,
|
|
13
|
+
GetCodeResponse,
|
|
13
14
|
GetTransactionReceiptResponse,
|
|
14
15
|
GetTransactionResponse,
|
|
15
16
|
Invocation,
|
|
@@ -103,6 +104,13 @@ export class Provider implements ProviderInterface {
|
|
|
103
104
|
return this.provider.declareContract(payload);
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
public async getCode(
|
|
108
|
+
contractAddress: string,
|
|
109
|
+
blockIdentifier?: BlockIdentifier
|
|
110
|
+
): Promise<GetCodeResponse> {
|
|
111
|
+
return this.provider.getCode(contractAddress, blockIdentifier);
|
|
112
|
+
}
|
|
113
|
+
|
|
106
114
|
public async waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void> {
|
|
107
115
|
return this.provider.waitForTransaction(txHash, retryInterval);
|
|
108
116
|
}
|
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
DeployContractResponse,
|
|
11
11
|
EstimateFeeResponse,
|
|
12
12
|
GetBlockResponse,
|
|
13
|
+
GetCodeResponse,
|
|
13
14
|
GetTransactionReceiptResponse,
|
|
14
15
|
GetTransactionResponse,
|
|
15
16
|
Invocation,
|
|
@@ -42,6 +43,11 @@ export abstract class ProviderInterface {
|
|
|
42
43
|
*/
|
|
43
44
|
public abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
|
|
44
45
|
|
|
46
|
+
public abstract getCode(
|
|
47
|
+
contractAddress: string,
|
|
48
|
+
blockIdentifier?: BlockIdentifier
|
|
49
|
+
): Promise<GetCodeResponse>;
|
|
50
|
+
|
|
45
51
|
/**
|
|
46
52
|
* Gets the contract class of the deployed contract.
|
|
47
53
|
*
|
package/src/provider/rpc.ts
CHANGED
|
@@ -213,6 +213,15 @@ export class RpcProvider implements ProviderInterface {
|
|
|
213
213
|
return this.responseParser.parseCallContractResponse(result);
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
+
public async getCode(
|
|
217
|
+
contractAddress: string,
|
|
218
|
+
_blockIdentifier?: BlockIdentifier
|
|
219
|
+
): Promise<RPC.GetCodeResponse> {
|
|
220
|
+
const result = await this.fetchEndpoint('starknet_getCode', [contractAddress]);
|
|
221
|
+
|
|
222
|
+
return this.responseParser.parseGetCodeResponse(result);
|
|
223
|
+
}
|
|
224
|
+
|
|
216
225
|
public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
|
|
217
226
|
let onchain = false;
|
|
218
227
|
let retries = 100;
|
|
@@ -323,6 +323,15 @@ export class SequencerProvider implements ProviderInterface {
|
|
|
323
323
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
+
public async getCode(
|
|
327
|
+
contractAddress: string,
|
|
328
|
+
blockIdentifier: BlockIdentifier = 'pending'
|
|
329
|
+
): Promise<Sequencer.GetCodeResponse> {
|
|
330
|
+
return this.fetchEndpoint('get_code', { contractAddress, blockIdentifier }).then(
|
|
331
|
+
this.responseParser.parseGetCodeResponse
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
326
335
|
public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
|
|
327
336
|
let onchain = false;
|
|
328
337
|
|
|
@@ -53,11 +53,6 @@ export type ExecutionResources = {
|
|
|
53
53
|
n_memory_holes: number;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
export type GetCodeResponse = {
|
|
57
|
-
bytecode: string[];
|
|
58
|
-
abi: Abi;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
56
|
export type GetTransactionTraceResponse = {
|
|
62
57
|
function_invocation: {
|
|
63
58
|
caller_address: string;
|
|
@@ -116,6 +111,11 @@ export namespace Sequencer {
|
|
|
116
111
|
class_hash?: string;
|
|
117
112
|
};
|
|
118
113
|
|
|
114
|
+
export type GetCodeResponse = {
|
|
115
|
+
bytecode: string[];
|
|
116
|
+
abi: Abi;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
119
|
export interface InvokeFunctionTransactionResponse extends InvokeFunctionTransaction {
|
|
120
120
|
transaction_hash: string;
|
|
121
121
|
}
|
package/src/types/provider.ts
CHANGED
|
@@ -16,6 +16,11 @@ export interface GetBlockResponse {
|
|
|
16
16
|
starknet_version?: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export interface GetCodeResponse {
|
|
20
|
+
bytecode: string[];
|
|
21
|
+
// abi: string; // is not consistent between rpc and sequencer (is it?), therefore not included in the provider interface
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
export type GetTransactionResponse = InvokeTransactionResponse & DeclareTransactionResponse;
|
|
20
25
|
|
|
21
26
|
export interface CommonTransactionResponse {
|
|
@@ -57,6 +57,10 @@ export class RPCResponseParser extends ResponseParser {
|
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
public parseGetCodeResponse(res: RPC.GetCodeResponse): RPC.GetCodeResponse {
|
|
61
|
+
return res;
|
|
62
|
+
}
|
|
63
|
+
|
|
60
64
|
public parseFeeEstimateResponse(res: RPC.EstimateFeeResponse): EstimateFeeResponse {
|
|
61
65
|
return {
|
|
62
66
|
overall_fee: toBN(res.overall_fee),
|
|
@@ -70,6 +70,10 @@ export class SequencerAPIResponseParser extends ResponseParser {
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
public parseGetCodeResponse(res: Sequencer.GetCodeResponse): Sequencer.GetCodeResponse {
|
|
74
|
+
return res;
|
|
75
|
+
}
|
|
76
|
+
|
|
73
77
|
public parseFeeEstimateResponse(res: Sequencer.EstimateFeeResponse): EstimateFeeResponse {
|
|
74
78
|
if ('overall_fee' in res) {
|
|
75
79
|
let gasInfo = {};
|
package/types/api/sequencer.d.ts
CHANGED
|
@@ -39,10 +39,6 @@ export declare type ExecutionResources = {
|
|
|
39
39
|
};
|
|
40
40
|
n_memory_holes: number;
|
|
41
41
|
};
|
|
42
|
-
export declare type GetCodeResponse = {
|
|
43
|
-
bytecode: string[];
|
|
44
|
-
abi: Abi;
|
|
45
|
-
};
|
|
46
42
|
export declare type GetTransactionTraceResponse = {
|
|
47
43
|
function_invocation: {
|
|
48
44
|
caller_address: string;
|
|
@@ -97,6 +93,10 @@ export declare namespace Sequencer {
|
|
|
97
93
|
address?: string;
|
|
98
94
|
class_hash?: string;
|
|
99
95
|
};
|
|
96
|
+
type GetCodeResponse = {
|
|
97
|
+
bytecode: string[];
|
|
98
|
+
abi: Abi;
|
|
99
|
+
};
|
|
100
100
|
interface InvokeFunctionTransactionResponse extends InvokeFunctionTransaction {
|
|
101
101
|
transaction_hash: string;
|
|
102
102
|
}
|
package/types/provider.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ export interface GetBlockResponse {
|
|
|
13
13
|
transactions: Array<string>;
|
|
14
14
|
starknet_version?: string;
|
|
15
15
|
}
|
|
16
|
+
export interface GetCodeResponse {
|
|
17
|
+
bytecode: string[];
|
|
18
|
+
}
|
|
16
19
|
export declare type GetTransactionResponse = InvokeTransactionResponse & DeclareTransactionResponse;
|
|
17
20
|
export interface CommonTransactionResponse {
|
|
18
21
|
transaction_hash?: string;
|
|
@@ -5,6 +5,7 @@ export declare class RPCResponseParser extends ResponseParser {
|
|
|
5
5
|
parseGetBlockResponse(res: RPC.GetBlockResponse): GetBlockResponse;
|
|
6
6
|
parseGetTransactionResponse(res: RPC.GetTransactionResponse): GetTransactionResponse;
|
|
7
7
|
parseGetTransactionReceiptResponse(res: RPC.GetTransactionReceiptResponse): GetTransactionReceiptResponse;
|
|
8
|
+
parseGetCodeResponse(res: RPC.GetCodeResponse): RPC.GetCodeResponse;
|
|
8
9
|
parseFeeEstimateResponse(res: RPC.EstimateFeeResponse): EstimateFeeResponse;
|
|
9
10
|
parseCallContractResponse(res: Array<string>): CallContractResponse;
|
|
10
11
|
parseInvokeFunctionResponse(res: RPC.AddTransactionResponse): InvokeFunctionResponse;
|
|
@@ -62,6 +62,9 @@ var RPCResponseParser = /** @class */ (function (_super) {
|
|
|
62
62
|
events: res.events,
|
|
63
63
|
};
|
|
64
64
|
};
|
|
65
|
+
RPCResponseParser.prototype.parseGetCodeResponse = function (res) {
|
|
66
|
+
return res;
|
|
67
|
+
};
|
|
65
68
|
RPCResponseParser.prototype.parseFeeEstimateResponse = function (res) {
|
|
66
69
|
return {
|
|
67
70
|
overall_fee: (0, number_1.toBN)(res.overall_fee),
|
|
@@ -5,6 +5,7 @@ export declare class SequencerAPIResponseParser extends ResponseParser {
|
|
|
5
5
|
parseGetBlockResponse(res: Sequencer.GetBlockResponse): GetBlockResponse;
|
|
6
6
|
parseGetTransactionResponse(res: Sequencer.GetTransactionResponse): GetTransactionResponse;
|
|
7
7
|
parseGetTransactionReceiptResponse(res: Sequencer.TransactionReceiptResponse): GetTransactionReceiptResponse;
|
|
8
|
+
parseGetCodeResponse(res: Sequencer.GetCodeResponse): Sequencer.GetCodeResponse;
|
|
8
9
|
parseFeeEstimateResponse(res: Sequencer.EstimateFeeResponse): EstimateFeeResponse;
|
|
9
10
|
parseCallContractResponse(res: Sequencer.CallContractResponse): CallContractResponse;
|
|
10
11
|
parseInvokeFunctionResponse(res: Sequencer.AddTransactionResponse): InvokeFunctionResponse;
|
|
@@ -79,6 +79,9 @@ var SequencerAPIResponseParser = /** @class */ (function (_super) {
|
|
|
79
79
|
l1_origin_message: undefined,
|
|
80
80
|
};
|
|
81
81
|
};
|
|
82
|
+
SequencerAPIResponseParser.prototype.parseGetCodeResponse = function (res) {
|
|
83
|
+
return res;
|
|
84
|
+
};
|
|
82
85
|
SequencerAPIResponseParser.prototype.parseFeeEstimateResponse = function (res) {
|
|
83
86
|
if ('overall_fee' in res) {
|
|
84
87
|
var gasInfo = {};
|