import { LedgerAccount } from '../snarky.js'; import { Field } from './core.js'; import { UInt32, UInt64 } from './int.js'; import { PrivateKey, PublicKey } from './signature.js'; import { ZkappCommand, AccountUpdate, ZkappPublicInput } from './account_update.js'; import * as Fetch from './fetch.js'; import { NetworkValue } from './precondition.js'; import { Proof } from './proof_system.js'; import { Context } from './global-context.js'; export { createTransaction, BerkeleyQANet, LocalBlockchain, currentTransaction, CurrentTransaction, setActiveInstance, transaction, currentSlot, getAccount, hasAccount, getBalance, getNetworkState, accountCreationFee, sendTransaction, fetchEvents, getActions, FeePayerSpec, }; interface TransactionId { wait(): Promise; hash(): string; } interface Transaction { transaction: ZkappCommand; toJSON(): string; toPretty(): any; toGraphqlQuery(): string; sign(additionalKeys?: PrivateKey[]): Transaction; prove(): Promise<(Proof | undefined)[]>; send(): Promise; } declare type Account = Fetch.Account; declare type FetchMode = 'fetch' | 'cached' | 'test'; declare type CurrentTransaction = { sender?: PublicKey; accountUpdates: AccountUpdate[]; fetchMode: FetchMode; isFinalRunOutsideCircuit: boolean; }; declare let currentTransaction: Context.t; declare type FeePayerSpec = PrivateKey | { feePayerKey: PrivateKey; fee?: number | string | UInt64; memo?: string; nonce?: number; } | undefined; declare function createTransaction(feePayer: FeePayerSpec, f: () => unknown, { fetchMode, isFinalRunOutsideCircuit, proofsEnabled, }?: { fetchMode?: FetchMode | undefined; isFinalRunOutsideCircuit?: boolean | undefined; proofsEnabled?: boolean | undefined; }): Transaction; interface Mina { transaction(sender: FeePayerSpec, f: () => void): Promise; currentSlot(): UInt32; hasAccount(publicKey: PublicKey, tokenId?: Field): boolean; getAccount(publicKey: PublicKey, tokenId?: Field): Account; getNetworkState(): NetworkValue; accountCreationFee(): UInt64; sendTransaction(transaction: Transaction): Promise; fetchEvents: (publicKey: PublicKey, tokenId?: Field) => any; getActions: (publicKey: PublicKey, tokenId?: Field) => { hash: string; actions: string[][]; }[]; } /** * A mock Mina blockchain running locally and useful for testing. */ declare function LocalBlockchain({ accountCreationFee, proofsEnabled, }?: { accountCreationFee?: string | number | undefined; proofsEnabled?: boolean | undefined; }): { accountCreationFee: () => UInt64; currentSlot(): UInt32; hasAccount(publicKey: PublicKey, tokenId?: Field): boolean; getAccount(publicKey: PublicKey, tokenId?: Field): Account; getNetworkState(): { snarkedLedgerHash: Field; timestamp: UInt64; blockchainLength: UInt32; minWindowDensity: UInt32; totalCurrency: UInt64; globalSlotSinceHardFork: UInt32; globalSlotSinceGenesis: UInt32; stakingEpochData: { ledger: { hash: Field; totalCurrency: UInt64; }; seed: Field; startCheckpoint: Field; lockCheckpoint: Field; epochLength: UInt32; }; nextEpochData: { ledger: { hash: Field; totalCurrency: UInt64; }; seed: Field; startCheckpoint: Field; lockCheckpoint: Field; epochLength: UInt32; }; }; sendTransaction(txn: Transaction): Promise<{ wait: () => Promise; hash: () => string; }>; transaction(sender: FeePayerSpec, f: () => void): Promise; applyJsonTransaction(json: string): LedgerAccount[]; fetchEvents(publicKey: PublicKey, tokenId?: Field): Promise; getActions(publicKey: PublicKey, tokenId?: Field): { hash: string; actions: string[][]; }[]; addAccount: (pk: PublicKey, balance: string) => void; /** * An array of 10 test accounts that have been pre-filled with * 30000000000 units of currency. */ testAccounts: { publicKey: PublicKey; privateKey: PrivateKey; }[]; setTimestamp(ms: UInt64): void; setGlobalSlot(slot: UInt32 | number): void; incrementGlobalSlot(increment: UInt32 | number): void; setBlockchainLength(height: UInt32): void; setTotalCurrency(currency: UInt64): void; setProofsEnabled(newProofsEnabled: boolean): void; }; declare function BerkeleyQANet(graphqlEndpoint: string): Mina; /** * Set the currently used Mina instance. */ declare function setActiveInstance(m: Mina): void; /** * Construct a smart contract transaction. Within the callback passed to this function, * you can call into the methods of smart contracts. * * ```typescript * transaction(() => { * myZkapp.update(); * someOtherZkapp.someOtherMethod(); * }) * ``` * * @return A transaction that can subsequently be submitted to the chain. */ declare function transaction(f: () => void): Promise; declare function transaction(sender: FeePayerSpec, f: () => void): Promise; /** * @return The current slot number, according to the active Mina instance. */ declare function currentSlot(): UInt32; /** * @return The account data associated to the given public key. */ declare function getAccount(publicKey: PublicKey, tokenId?: Field): Account; declare function hasAccount(publicKey: PublicKey, tokenId?: Field): boolean; /** * @return Data associated with the current state of the Mina network. */ declare function getNetworkState(): { snarkedLedgerHash: Field; timestamp: UInt64; blockchainLength: UInt32; minWindowDensity: UInt32; totalCurrency: UInt64; globalSlotSinceHardFork: UInt32; globalSlotSinceGenesis: UInt32; stakingEpochData: { ledger: { hash: Field; totalCurrency: UInt64; }; seed: Field; startCheckpoint: Field; lockCheckpoint: Field; epochLength: UInt32; }; nextEpochData: { ledger: { hash: Field; totalCurrency: UInt64; }; seed: Field; startCheckpoint: Field; lockCheckpoint: Field; epochLength: UInt32; }; }; /** * @return The balance associated to the given public key. */ declare function getBalance(publicKey: PublicKey, tokenId?: Field): UInt64; declare function accountCreationFee(): UInt64; declare function sendTransaction(txn: Transaction): Promise; /** * @return A list of emitted events associated to the given public key. */ declare function fetchEvents(publicKey: PublicKey, tokenId: Field): Promise; /** * @return A list of emitted sequencing actions associated to the given public key. */ declare function getActions(publicKey: PublicKey, tokenId: Field): { hash: string; actions: string[][]; }[];