import { ProvablePure } from '../snarky.js'; import { SmartContract } from './zkapp.js'; export { State, state, declareState }; export { assertStatePrecondition, cleanStatePrecondition }; /** * Gettable and settable state that can be checked for equality. */ declare type State = { get(): A; set(a: A): void; fetch(): Promise; assertEquals(a: A): void; assertNothing(): void; }; declare function State(): State; /** * A decorator to use within a zkapp to indicate what will be stored on-chain. * For example, if you want to store a field element `some_state` in a zkapp, * you can use the following in the declaration of your zkapp: * * ``` * @state(Field) some_state = State(); * ``` * */ declare function state(stateType: ProvablePure): (target: SmartContract & { constructor: any; }, key: string, _descriptor?: PropertyDescriptor) => void; /** * `declareState` can be used in place of the `@state` decorator to declare on-chain state on a SmartContract. * It should be placed _after_ the class declaration. * Here is an example of declaring a state property `x` of type `Field`. * ```ts * class MyContract extends SmartContract { * x = State(); * // ... * } * declareState(MyContract, { x: Field }); * ``` * * If you're using pure JS, it's _not_ possible to use the built-in class field syntax, * i.e. the following will _not_ work: * * ```js * // THIS IS WRONG IN JS! * class MyContract extends SmartContract { * x = State(); * } * declareState(MyContract, { x: Field }); * ``` * * Instead, add a constructor where you assign the property: * ```js * class MyContract extends SmartContract { * constructor(x) { * super(); * this.x = State(); * } * } * declareState(MyContract, { x: Field }); * ``` */ declare function declareState(SmartContract: T, states: Record>): void; declare function assertStatePrecondition(sc: SmartContract): void; declare function cleanStatePrecondition(sc: SmartContract): void;