@@ -19,6 +19,7 @@ import { parse, stringify } from '../utils/json';
1919import { BigNumberish , toBN , toHex } from '../utils/number' ;
2020import { compressProgram , formatSignature , randomAddress } from '../utils/stark' ;
2121import { ProviderInterface } from './interface' ;
22+ import { getFormattedBlockIdentifier } from './utils' ;
2223
2324type NetworkName = 'mainnet-alpha' | 'goerli-alpha' ;
2425
@@ -86,15 +87,19 @@ export class Provider implements ProviderInterface {
8687 * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L17-L25)
8788 *
8889 * @param invokeTransaction - transaction to be invoked
90+ * @param blockHash
8991 * @param blockNumber
9092 * @returns the result of the function on the smart contract.
9193 */
9294 public async callContract (
9395 invokeTransaction : CallContractTransaction ,
96+ blockHash ?: BigNumberish ,
9497 blockNumber : BlockNumber = null
9598 ) : Promise < CallContractResponse > {
99+ const formattedBlockIdentifier = getFormattedBlockIdentifier ( blockHash , blockNumber ) ;
100+
96101 const { data } = await axios . post < CallContractResponse > (
97- urljoin ( this . feederGatewayUrl , 'call_contract' , `?blockNumber= ${ blockNumber } ` ) ,
102+ urljoin ( this . feederGatewayUrl , 'call_contract' , formattedBlockIdentifier ) ,
98103 {
99104 signature : [ ] ,
100105 calldata : [ ] ,
@@ -105,16 +110,22 @@ export class Provider implements ProviderInterface {
105110 }
106111
107112 /**
108- * Gets the block information from a block ID .
113+ * Gets the block information from a block hash or block number .
109114 *
110- * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285 /src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
115+ * [Reference](https://github.com/starkware-libs/cairo-lang/blob/fc97bdd8322a7df043c87c371634b26c15ed6cee /src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L27-L31)
111116 *
117+ * @param blockHash
112118 * @param blockNumber
113119 * @returns the block object { block_number, previous_block_number, state_root, status, timestamp, transaction_receipts, transactions }
114120 */
115- public async getBlock ( blockNumber : BlockNumber = null ) : Promise < GetBlockResponse > {
121+ public async getBlock (
122+ blockHash ?: BigNumberish ,
123+ blockNumber : BlockNumber = null
124+ ) : Promise < GetBlockResponse > {
125+ const formattedBlockIdentifier = getFormattedBlockIdentifier ( blockHash , blockNumber ) ;
126+
116127 const { data } = await axios . get < GetBlockResponse > (
117- urljoin ( this . feederGatewayUrl , 'get_block' , `?blockNumber= ${ blockNumber } ` )
128+ urljoin ( this . feederGatewayUrl , 'get_block' , formattedBlockIdentifier )
118129 ) ;
119130 return data ;
120131 }
@@ -125,18 +136,22 @@ export class Provider implements ProviderInterface {
125136 * [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L33-L36)
126137 *
127138 * @param contractAddress
139+ * @param blockHash
128140 * @param blockNumber
129141 * @returns Bytecode and ABI of compiled contract
130142 */
131143 public async getCode (
132144 contractAddress : string ,
145+ blockHash ?: BigNumberish ,
133146 blockNumber : BlockNumber = null
134147 ) : Promise < GetCodeResponse > {
148+ const formattedBlockIdentifier = getFormattedBlockIdentifier ( blockHash , blockNumber ) ;
149+
135150 const { data } = await axios . get < GetCodeResponse > (
136151 urljoin (
137152 this . feederGatewayUrl ,
138153 'get_code' ,
139- `?contractAddress=${ contractAddress } &blockNumber= ${ blockNumber } `
154+ `?contractAddress=${ contractAddress } &${ formattedBlockIdentifier } `
140155 )
141156 ) ;
142157 return data ;
@@ -150,19 +165,23 @@ export class Provider implements ProviderInterface {
150165 *
151166 * @param contractAddress
152167 * @param key - from getStorageVarAddress('<STORAGE_VARIABLE_NAME>') (WIP)
168+ * @param blockHash
153169 * @param blockNumber
154170 * @returns the value of the storage variable
155171 */
156172 public async getStorageAt (
157173 contractAddress : string ,
158174 key : number ,
175+ blockHash ?: BigNumberish ,
159176 blockNumber : BlockNumber = null
160177 ) : Promise < object > {
178+ const formattedBlockIdentifier = getFormattedBlockIdentifier ( blockHash , blockNumber ) ;
179+
161180 const { data } = await axios . get < object > (
162181 urljoin (
163182 this . feederGatewayUrl ,
164183 'get_storage_at' ,
165- `?contractAddress=${ contractAddress } &key=${ key } &blockNumber= ${ blockNumber } `
184+ `?contractAddress=${ contractAddress } &key=${ key } &${ formattedBlockIdentifier } `
166185 )
167186 ) ;
168187 return data ;
0 commit comments