diff --git a/lib/account.d.ts b/lib/account.d.ts index c0e3f3f481..50de238fff 100644 --- a/lib/account.d.ts +++ b/lib/account.d.ts @@ -1,9 +1,9 @@ import BN from 'bn.js'; import { AccessKey, Action, SignedTransaction } from './transaction'; import { FinalExecutionOutcome } from './providers'; +import { Finality, BlockId } from './providers/provider'; import { Connection } from './connection'; import { PublicKey } from './utils/key_pair'; -import { Finality } from './providers/provider'; export interface AccountState { amount: string; code_hash: string; @@ -119,7 +119,11 @@ export declare class Account { viewFunction(contractId: string, methodName: string, args: any, { parse }?: { parse?: typeof parseJsonFromRawResponse; }): Promise; - viewState(prefix: string | Uint8Array, finality?: Finality): Promise; + viewState(prefix: string | Uint8Array, blockQuery: { + blockId: BlockId; + } | { + finality: Finality; + }): Promise; /** * @returns array of {access_key: AccessKey, public_key: PublicKey} items. */ diff --git a/lib/account.js b/lib/account.js index 65bff6026c..429e7f8387 100644 --- a/lib/account.js +++ b/lib/account.js @@ -288,10 +288,12 @@ class Account { } return result.result && result.result.length > 0 && parse(Buffer.from(result.result)); } - async viewState(prefix, finality = 'optimistic') { + async viewState(prefix, blockQuery) { + const { blockId, finality } = blockQuery || {}; const { values } = await this.connection.provider.query({ request_type: 'view_state', - finality, + block_id: blockId, + finality: blockId ? undefined : finality || 'optimistic', account_id: this.accountId, prefix_base64: Buffer.from(prefix).toString('base64') }); diff --git a/src/account.ts b/src/account.ts index c28779bdfb..9c60121946 100644 --- a/src/account.ts +++ b/src/account.ts @@ -18,6 +18,7 @@ import { SignedTransaction } from './transaction'; import { FinalExecutionOutcome, TypedError, ErrorContext } from './providers'; +import { Finality, BlockId } from './providers/provider'; import { Connection } from './connection'; import {base_decode, base_encode} from './utils/serialize'; import { PublicKey } from './utils/key_pair'; @@ -26,7 +27,6 @@ import { parseRpcError } from './utils/rpc_errors'; import { ServerError } from './generated/rpc_error_types'; import exponentialBackoff from './utils/exponential-backoff'; -import { Finality } from './providers/provider'; // Default amount of gas to be sent with the function calls. Used to pay for the fees // incurred while running the contract execution. The unused amount will be refunded back to @@ -374,10 +374,12 @@ export class Account { return result.result && result.result.length > 0 && parse(Buffer.from(result.result)); } - async viewState(prefix: string | Uint8Array, finality: Finality = 'optimistic') { + async viewState(prefix: string | Uint8Array, blockQuery: { blockId: BlockId } | { finality: Finality } ) { + const { blockId, finality } = blockQuery as any || {}; const { values } = await this.connection.provider.query({ request_type: 'view_state', - finality, + block_id: blockId, + finality: blockId ? undefined : finality || 'optimistic', account_id: this.accountId, prefix_base64: Buffer.from(prefix,).toString('base64') });