diff --git a/packages/algo-ts/src/box.ts b/packages/algo-ts/src/box.ts index 2c97bb3e..9ef87f3b 100644 --- a/packages/algo-ts/src/box.ts +++ b/packages/algo-ts/src/box.ts @@ -1,3 +1,4 @@ +import { ctxMgr } from './execution-context' import { bytes, uint64 } from './primitives' export type Box = { @@ -24,12 +25,11 @@ export type BoxMap = { export type BoxRef = { readonly key: bytes - readonly exists: boolean value: bytes get(options: { default: bytes }): bytes - put(value: bytes): bytes - splice(start: uint64, end: uint64, value: bytes): void + put(value: bytes): void + splice(start: uint64, length: uint64, value: bytes): void replace(start: uint64, value: bytes): void extract(start: uint64, length: uint64): bytes delete(): boolean @@ -40,13 +40,13 @@ export type BoxRef = { } export function Box(options: { key: bytes | string }): Box { - throw new Error('Not implemented') + return ctxMgr.instance.state.Box(options) } export function BoxMap(options: { keyPrefix: bytes | string }): BoxMap { - throw new Error('Not implemented') + return ctxMgr.instance.state.BoxMap(options) } export function BoxRef(options: { key: bytes | string }): BoxRef { - throw new Error('Not implemented') + return ctxMgr.instance.state.BoxRef(options) } diff --git a/packages/algo-ts/src/execution-context.ts b/packages/algo-ts/src/execution-context.ts index dd02bf02..c862d721 100644 --- a/packages/algo-ts/src/execution-context.ts +++ b/packages/algo-ts/src/execution-context.ts @@ -1,4 +1,4 @@ -import { Contract, GlobalState, gtxn, itxn, LocalState } from '.' +import { Box, BoxMap, BoxRef, Contract, GlobalState, gtxn, itxn, LocalState } from '.' import { AbiMethodConfig, BareMethodConfig } from './arc4' import { OpsNamespace } from './op-types' import { bytes, uint64 } from './primitives' @@ -32,8 +32,11 @@ export type ExecutionContext = { applicationCall: typeof itxn.applicationCall } state: { - createGlobalState: typeof GlobalState - createLocalState: typeof LocalState + GlobalState: typeof GlobalState + LocalState: typeof LocalState + Box: typeof Box + BoxMap: typeof BoxMap + BoxRef: typeof BoxRef } } diff --git a/packages/algo-ts/src/op.ts b/packages/algo-ts/src/op.ts index bb1d1c36..4a5ba18d 100644 --- a/packages/algo-ts/src/op.ts +++ b/packages/algo-ts/src/op.ts @@ -138,5 +138,6 @@ export const AppParams = createObjectProxy('AppParams') export const AssetHolding = createObjectProxy('AssetHolding') export const AssetParams = createObjectProxy('AssetParams') export const Block = createObjectProxy('Block') +export const Box = createObjectProxy('Box') export { VrfVerify } from './op-types' diff --git a/packages/algo-ts/src/state.ts b/packages/algo-ts/src/state.ts index 6e27a5cc..cd169813 100644 --- a/packages/algo-ts/src/state.ts +++ b/packages/algo-ts/src/state.ts @@ -13,7 +13,7 @@ export type GlobalStateOptions = { key?: bytes | string; initialValue /** A single key in global state */ export function GlobalState(options?: GlobalStateOptions): GlobalState { - return ctxMgr.instance.state.createGlobalState(options) + return ctxMgr.instance.state.GlobalState(options) } /** A value saved in local state */ @@ -29,5 +29,5 @@ export type LocalState = { /** A single key in local state */ export function LocalState(options?: { key?: bytes | string }): LocalState { - return ctxMgr.instance.state.createLocalState(options) + return ctxMgr.instance.state.LocalState(options) }