Skip to content

Commit

Permalink
Merge pull request #24 from algorandfoundation/feat-app-global
Browse files Browse the repository at this point in the history
feat: implement AppGlobal via context manager
  • Loading branch information
boblat authored Oct 29, 2024
2 parents 2649e5b + 759d18c commit e8f7bd8
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 84 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/algo-ts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@algorandfoundation/algorand-typescript",
"version": "0.0.1-alpha.11",
"version": "0.0.1-alpha.12",
"description": "This package contains definitions for the types which comprise Algorand TypeScript which can be compiled to run on the Algorand Virtual Machine using the Puya compiler.",
"private": false,
"main": "index.js",
Expand Down
6 changes: 5 additions & 1 deletion packages/algo-ts/src/execution-context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract, gtxn, itxn } from '.'
import { Contract, GlobalState, gtxn, itxn, LocalState } from '.'
import { AbiMethodConfig, BareMethodConfig } from './arc4'
import { OpsNamespace } from './op-types'
import { bytes, uint64 } from './primitives'
Expand Down Expand Up @@ -31,6 +31,10 @@ export type ExecutionContext = {
assetFreeze: typeof itxn.assetFreeze
applicationCall: typeof itxn.applicationCall
}
state: {
createGlobalState: typeof GlobalState
createLocalState: typeof LocalState
}
}

declare global {
Expand Down
71 changes: 0 additions & 71 deletions packages/algo-ts/src/impl/state.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/algo-ts/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export { ExecutionContext, ctxMgr } from './execution-context'
export * as encodingUtil from './impl/encoding-util'
export * as errors from './impl/errors'
export * as primitives from './impl/primitives'
export * as state from './impl/state'
export * as opTypes from './op-types'
1 change: 1 addition & 0 deletions packages/algo-ts/src/op.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const ITxnCreate: ITxnCreateType = createObjectProxy('ITxnCreate')
export const Scratch: ScratchType = createObjectProxy('Scratch')

export const AcctParams = createObjectProxy('AcctParams')
export const AppGlobal = createObjectProxy('AppGlobal')
export const AppParams = createObjectProxy('AppParams')
export const AssetHolding = createObjectProxy('AssetHolding')
export const AssetParams = createObjectProxy('AssetParams')
Expand Down
13 changes: 4 additions & 9 deletions packages/algo-ts/src/state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GlobalStateCls, LocalStateMapCls } from './impl/state'
import { ctxMgr } from './execution-context'
import { bytes } from './primitives'
import { Account } from './reference'

Expand All @@ -9,11 +9,11 @@ export type GlobalState<ValueType> = {
hasValue: boolean
}

type GlobalStateOptions<ValueType> = { key?: bytes | string; initialValue?: ValueType }
export type GlobalStateOptions<ValueType> = { key?: bytes | string; initialValue?: ValueType }

/** A single key in global state */
export function GlobalState<ValueType>(options?: GlobalStateOptions<ValueType>): GlobalState<ValueType> {
return new GlobalStateCls(options?.key, options?.initialValue)
return ctxMgr.instance.state.createGlobalState(options)
}

/** A value saved in local state */
Expand All @@ -29,10 +29,5 @@ export type LocalState<ValueType> = {

/** A single key in local state */
export function LocalState<ValueType>(options?: { key?: bytes | string }): LocalState<ValueType> {
function localStateInternal(account: Account): LocalStateForAccount<ValueType> {
return localStateInternal.map.getValue(account)
}
localStateInternal.key = options?.key
localStateInternal.map = new LocalStateMapCls<ValueType>()
return localStateInternal
return ctxMgr.instance.state.createLocalState(options)
}

0 comments on commit e8f7bd8

Please sign in to comment.