Skip to content

Commit

Permalink
feat: rpc v0.2 endpoint, default identifiers, getClassHashAt flip par…
Browse files Browse the repository at this point in the history
…ameters
  • Loading branch information
tabaktoni committed Nov 11, 2022
1 parent 0a9f84f commit f0a0d6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion __tests__/rpcProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describeIfRpc('RPCProvider', () => {
});

test('getClassHashAt', async () => {
const classHash = await rpcProvider.getClassHashAt('latest', contract_address);
const classHash = await rpcProvider.getClassHashAt(contract_address);
expect(typeof classHash).toBe('string');
});

Expand Down
23 changes: 14 additions & 9 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class RpcProvider implements ProviderInterface {
}

public fetch(method: any, params: any): Promise<any> {
return fetch(this.nodeUrl, {
return fetch(`${this.nodeUrl}/rpc/v0.2`, {

This comment has been minimized.

Copy link
@0xSidius

0xSidius Nov 21, 2022

@tabaktoni can we not hard-code /rpc/v0.2?

This comment has been minimized.

Copy link
@ivpavici

ivpavici Nov 21, 2022

Collaborator
method: 'POST',
body: stringify({ method, jsonrpc: '2.0', params, id: 0 }),
headers: this.headers,
Expand Down Expand Up @@ -124,8 +124,8 @@ export class RpcProvider implements ProviderInterface {
}

public async getClassHashAt(
blockIdentifier: BlockIdentifier,
contractAddress: RPC.ContractAddress
contractAddress: RPC.ContractAddress,
blockIdentifier: BlockIdentifier = 'pending'
): Promise<RPC.Felt> {
const block_id = new Block(blockIdentifier).identifier;
return this.fetchEndpoint('starknet_getClassHashAt', {
Expand Down Expand Up @@ -153,7 +153,9 @@ export class RpcProvider implements ProviderInterface {
throw new Error('Pathfinder does not implement this rpc 0.1.0 method');
}

public async getStateUpdate(blockIdentifier: BlockIdentifier): Promise<RPC.StateUpdate> {
public async getStateUpdate(
blockIdentifier: BlockIdentifier = 'pending'
): Promise<RPC.StateUpdate> {
const block_id = new Block(blockIdentifier).identifier;
return this.fetchEndpoint('starknet_getStateUpdate', { block_id });
}
Expand Down Expand Up @@ -195,7 +197,7 @@ export class RpcProvider implements ProviderInterface {

public async getClass(
classHash: RPC.Felt,
blockIdentifier: BlockIdentifier
blockIdentifier: BlockIdentifier = 'pending'
): Promise<RPC.ContractClass> {
const block_id = new Block(blockIdentifier).identifier;
return this.fetchEndpoint('starknet_getClass', { class_hash: classHash, block_id });
Expand All @@ -216,7 +218,7 @@ export class RpcProvider implements ProviderInterface {
_contractAddress: string,
_blockIdentifier?: BlockIdentifier
): Promise<GetCodeResponse> {
throw new Error('RPC 0.1.0 does not implement getCode function');
throw new Error('RPC does not implement getCode function');
}

public async getEstimateFee(
Expand Down Expand Up @@ -316,9 +318,12 @@ export class RpcProvider implements ProviderInterface {
});
}

/**
* @deprecated This method wont be supported soon, use Account.deploy instead
*/
public async deployContract(
{ contract, constructorCalldata, addressSalt }: DeployContractPayload,
details: InvocationsDetails
details?: InvocationsDetails
): Promise<DeployContractResponse> {
const contractDefinition = parseContract(contract);
return this.fetchEndpoint('starknet_addDeployTransaction', {
Expand All @@ -331,7 +336,7 @@ export class RpcProvider implements ProviderInterface {
abi: contractDefinition.abi,
},
type: 'DEPLOY',
version: toHex(toBN(details.version || 0)),
version: toHex(toBN(details?.version || 0)),
},
});
}
Expand Down Expand Up @@ -446,7 +451,7 @@ export class RpcProvider implements ProviderInterface {
* @returns Number of transactions
*/
public async getTransactionCount(
blockIdentifier: BlockIdentifier
blockIdentifier: BlockIdentifier = 'pending'
): Promise<RPC.GetTransactionCountResponse> {
const block_id = new Block(blockIdentifier).identifier;
return this.fetchEndpoint('starknet_getBlockTransactionCount', { block_id });
Expand Down

0 comments on commit f0a0d6c

Please sign in to comment.