Skip to content

Commit 52f8e61

Browse files
committed
fix: restore GetCode to common interface for backward compatibility
1 parent 67d87fc commit 52f8e61

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

__tests__/defaultProvider.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe('defaultProvider', () => {
4646
test(`getBlock(blockHash=${exampleBlockHash}, blockNumber=undefined)`, () => {
4747
return expect(testProvider.getBlock(exampleBlockHash)).resolves.not.toThrow();
4848
});
49+
4950
test('getBlock(blockIdentifier=latest)', async () => {
5051
expect(exampleBlock).not.toBeNull();
5152

@@ -250,13 +251,11 @@ describe('defaultProvider', () => {
250251
});
251252

252253
describe('Contract methods', () => {
253-
// let contractAddress: string;
254254
let deployResponse: DeployContractResponse;
255255
let declareResponse: DeclareContractResponse;
256256

257257
beforeAll(async () => {
258258
deployResponse = await provider.deployContract({ contract: compiledErc20 });
259-
// contractAddress = deployResponse.contract_address;
260259
declareResponse = await provider.declareContract({ contract: compiledErc20 });
261260
await Promise.all([
262261
provider.waitForTransaction(deployResponse.transaction_hash),

__tests__/sequencerProvider.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
getTestProvider,
88
} from './fixtures';
99

10-
// This run only if Devnet Sequencer ?
10+
// Run only if Devnet Sequencer
1111
describeIfSequencer('SequencerProvider', () => {
1212
let provider: SequencerProvider;
1313
let customSequencerProvider: Provider;

src/provider/default.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
DeployContractResponse,
1010
EstimateFeeResponse,
1111
GetBlockResponse,
12+
GetCodeResponse,
1213
GetTransactionReceiptResponse,
1314
GetTransactionResponse,
1415
Invocation,
@@ -102,6 +103,13 @@ export class Provider implements ProviderInterface {
102103
return this.provider.declareContract(payload);
103104
}
104105

106+
public async getCode(
107+
contractAddress: string,
108+
blockIdentifier?: BlockIdentifier
109+
): Promise<GetCodeResponse> {
110+
return this.provider.getCode(contractAddress, blockIdentifier);
111+
}
112+
105113
public async waitForTransaction(txHash: BigNumberish, retryInterval?: number): Promise<void> {
106114
return this.provider.waitForTransaction(txHash, retryInterval);
107115
}

src/provider/interface.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
DeployContractResponse,
1010
EstimateFeeResponse,
1111
GetBlockResponse,
12+
GetCodeResponse,
1213
GetTransactionReceiptResponse,
1314
GetTransactionResponse,
1415
Invocation,
@@ -41,6 +42,14 @@ export abstract class ProviderInterface {
4142
*/
4243
public abstract getBlock(blockIdentifier: BlockIdentifier): Promise<GetBlockResponse>;
4344

45+
/**
46+
* @deprecated The method should not be used
47+
*/
48+
public abstract getCode(
49+
contractAddress: string,
50+
blockIdentifier?: BlockIdentifier
51+
): Promise<GetCodeResponse>;
52+
4453
/**
4554
* Gets the contract class of the deployed contract.
4655
*

src/provider/rpc.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
DeployContractResponse,
99
EstimateFeeResponse,
1010
GetBlockResponse,
11+
GetCodeResponse,
1112
GetTransactionReceiptResponse,
1213
GetTransactionResponse,
1314
Invocation,
@@ -91,7 +92,7 @@ export class RpcProvider implements ProviderInterface {
9192

9293
public async getBlockWithTxHashes(
9394
blockIdentifier: BlockIdentifier = 'pending'
94-
): Promise<RPC.getBlockWithTxHashesResponse> {
95+
): Promise<RPC.GetBlockWithTxHashesResponse> {
9596
const blockIdentifierGetter = new BlockIdentifierClass(blockIdentifier);
9697
return this.fetchEndpoint('starknet_getBlockWithTxHashes', [
9798
blockIdentifierGetter.getIdentifier(),
@@ -100,7 +101,7 @@ export class RpcProvider implements ProviderInterface {
100101

101102
public async getBlockWithTxs(
102103
blockIdentifier: BlockIdentifier = 'pending'
103-
): Promise<RPC.getBlockWithTxs> {
104+
): Promise<RPC.GetBlockWithTxs> {
104105
const blockIdentifierGetter = new BlockIdentifierClass(blockIdentifier);
105106
return this.fetchEndpoint('starknet_getBlockWithTxs', [blockIdentifierGetter.getIdentifier()]);
106107
}
@@ -236,6 +237,13 @@ export class RpcProvider implements ProviderInterface {
236237
return this.responseParser.parseCallContractResponse(result);
237238
}
238239

240+
public async getCode(
241+
_contractAddress: string,
242+
_blockIdentifier?: BlockIdentifier
243+
): Promise<GetCodeResponse> {
244+
throw new Error('RPC 0.1.0 does not implement getCode function');
245+
}
246+
239247
public async waitForTransaction(txHash: BigNumberish, retryInterval: number = 8000) {
240248
let onchain = false;
241249
let retries = 100;

src/types/provider.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export interface GetBlockResponse {
1616
transactions: Array<string>;
1717
}
1818

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+
1924
export type GetTransactionResponse = InvokeTransactionResponse & DeclareTransactionResponse;
2025

2126
export interface CommonTransactionResponse {

0 commit comments

Comments
 (0)