Skip to content

Commit

Permalink
fix: rpc 0.1.0 getStorageAt
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Aug 29, 2022
1 parent 744a988 commit c622913
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion __tests__/defaultProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('defaultProvider', () => {

describeIfNotDevnet('Provider', () => {
const provider = getTestProvider();
describe(`Provider methods`, () => {
describe(`Provider methods if not devnet`, () => {
describe('getBlock', () => {
test('pending', async () => {
const latestBlock = await provider.getBlock();
Expand Down
5 changes: 2 additions & 3 deletions src/provider/default.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { StarknetChainId } from '../constants';
import {
BlockTag,
Call,
CallContractResponse,
ContractClass,
Expand Down Expand Up @@ -68,9 +67,9 @@ export class Provider implements ProviderInterface {
public async getStorageAt(
contractAddress: string,
key: BigNumberish,
blockTagOrHash: BlockTag | BigNumberish = 'pending'
blockIdentifier: BlockIdentifier = 'pending'
): Promise<BigNumberish> {
return this.provider.getStorageAt(contractAddress, key, blockTagOrHash);
return this.provider.getStorageAt(contractAddress, key, blockIdentifier);
}

public async getTransaction(txHash: BigNumberish): Promise<GetTransactionResponse> {
Expand Down
5 changes: 2 additions & 3 deletions src/provider/interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { StarknetChainId } from '../constants';
import type {
BlockTag,
Call,
CallContractResponse,
ContractClass,
Expand Down Expand Up @@ -59,13 +58,13 @@ export abstract class ProviderInterface {
*
* @param contractAddress
* @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
* @param blockHashOrTag - block hash or tag (pending, latest)
* @param blockIdentifier - block identifier
* @returns the value of the storage variable
*/
public abstract getStorageAt(
contractAddress: string,
key: BigNumberish,
blockHashOrTag?: BlockTag | BigNumberish
blockIdentifier: BlockIdentifier
): Promise<BigNumberish>;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/provider/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { StarknetChainId } from '../constants';
import {
BlockTag,
Call,
CallContractResponse,
DeclareContractPayload,
Expand Down Expand Up @@ -113,13 +112,14 @@ export class RpcProvider implements ProviderInterface {
public async getStorageAt(
contractAddress: string,
key: BigNumberish,
blockHashOrTag: BlockTag | BigNumberish = 'pending'
blockIdentifier: BlockIdentifier = 'pending'
): Promise<BigNumberish> {
const parsedKey = toHex(toBN(key));
const blockIdentifierGetter = new BlockIdentifierClass(blockIdentifier);
return this.fetchEndpoint('starknet_getStorageAt', [
contractAddress,
parsedKey,
blockHashOrTag,
blockIdentifierGetter.getIdentifier(),
]);
}

Expand Down
5 changes: 2 additions & 3 deletions src/provider/sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import urljoin from 'url-join';

import { ONE, StarknetChainId, ZERO } from '../constants';
import {
BlockTag,
Call,
CallContractResponse,
ContractClass,
Expand Down Expand Up @@ -233,11 +232,11 @@ export class SequencerProvider implements ProviderInterface {
public async getStorageAt(
contractAddress: string,
key: BigNumberish,
blockHashOrTag: BlockTag | BigNumberish = 'pending'
blockIdentifier: BlockIdentifier = 'pending'
): Promise<BigNumberish> {
const parsedKey = toBN(key).toString(10);
return this.fetchEndpoint('get_storage_at', {
blockIdentifier: blockHashOrTag,
blockIdentifier,
contractAddress,
key: parsedKey,
});
Expand Down
3 changes: 2 additions & 1 deletion src/types/api/openrpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Starknet RPC version 0.1.0
* starknet_api_openrpc version 0.31.0
*
* TypeScript Representation of OpenRpc protocol types
* TypeScript Representation of OpenRpc protocol types | responses
*/

/**
Expand Down Expand Up @@ -145,4 +145,5 @@ type PENDING_BLOCK_WITH_TXS = BLOCK_BODY_WITH_TXS & {
export namespace OPENRPC {
export type getBlockWithTxHashesResponse = BLOCK_WITH_TX_HASHES | PENDING_BLOCK_WITH_TX_HASHES;
export type getBlockWithTxs = BLOCK_WITH_TXS | PENDING_BLOCK_WITH_TXS;
export type GetStorageAtResponse = FELT;
}
2 changes: 1 addition & 1 deletion src/types/api/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export namespace RPC {
transactions: string[];
}; */

export type GetStorageAtResponse = string;
export type GetStorageAtResponse = OPENRPC.GetStorageAtResponse;

export type GetTransactionReceiptResponse = {
txn_hash: string;
Expand Down
6 changes: 3 additions & 3 deletions www/docs/API/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ const provider = new starknet.Provider({

These are also default options for the Provider constructor with `network: 'goerli-alpha'`.

> **Note**
>
> **Note**
>
> `network` arguement should work in most cases. If you want to use sequencer arguement with `baseUrl`, you will not be able to use `network` field in the object.
## Methods
Expand Down Expand Up @@ -117,7 +117,7 @@ Gets the contract class of the deployed contract.

<hr/>

provider.**getStorageAt**(contractAddress, key, blockHashOrTag) => _Promise < string >_
provider.**getStorageAt**(contractAddress, key, blockIdentifier) => _Promise < string >_

Gets the contract's storage variable at a specific key.

Expand Down

0 comments on commit c622913

Please sign in to comment.