|
| 1 | +import { Account, Application, Bytes, bytes, internal, Uint64, uint64 } from '@algorandfoundation/algorand-typescript' |
| 2 | +import { lazyContext } from '../context-helpers/internal-context' |
| 3 | +import { asBytes } from '../util' |
| 4 | +import { getAccount } from './acct-params' |
| 5 | +import { getApp } from './app-params' |
| 6 | + |
| 7 | +export const AppLocal: internal.opTypes.AppLocalType = { |
| 8 | + delete: function (a: Account | internal.primitives.StubUint64Compat, b: internal.primitives.StubBytesCompat): void { |
| 9 | + const app = lazyContext.activeApplication |
| 10 | + const account = getAccount(a) |
| 11 | + lazyContext.ledger.setLocalState(app, account, b, undefined) |
| 12 | + }, |
| 13 | + getBytes: function (a: Account | internal.primitives.StubUint64Compat, b: internal.primitives.StubBytesCompat): bytes { |
| 14 | + const account = getAccount(a) |
| 15 | + return this.getExBytes(account, 0, asBytes(b))[0] |
| 16 | + }, |
| 17 | + getUint64: function (a: Account | internal.primitives.StubUint64Compat, b: internal.primitives.StubBytesCompat): uint64 { |
| 18 | + const account = getAccount(a) |
| 19 | + return this.getExUint64(account, 0, asBytes(b))[0] |
| 20 | + }, |
| 21 | + getExBytes: function ( |
| 22 | + a: Account | internal.primitives.StubUint64Compat, |
| 23 | + b: Application | internal.primitives.StubUint64Compat, |
| 24 | + c: internal.primitives.StubBytesCompat, |
| 25 | + ): readonly [bytes, boolean] { |
| 26 | + const app = getApp(b) |
| 27 | + const account = getAccount(a) |
| 28 | + if (app === undefined || account === undefined) { |
| 29 | + return [Bytes(), false] |
| 30 | + } |
| 31 | + const [state, exists] = lazyContext.ledger.getLocalState(app, account, c) |
| 32 | + if (!exists) { |
| 33 | + return [Bytes(), false] |
| 34 | + } |
| 35 | + return [state!.value as bytes, exists] |
| 36 | + }, |
| 37 | + getExUint64: function ( |
| 38 | + a: Account | internal.primitives.StubUint64Compat, |
| 39 | + b: Application | internal.primitives.StubUint64Compat, |
| 40 | + c: internal.primitives.StubBytesCompat, |
| 41 | + ): readonly [uint64, boolean] { |
| 42 | + const app = getApp(b) |
| 43 | + const account = getAccount(a) |
| 44 | + if (app === undefined || account === undefined) { |
| 45 | + return [Uint64(0), false] |
| 46 | + } |
| 47 | + const [state, exists] = lazyContext.ledger.getLocalState(app, account, c) |
| 48 | + if (!exists) { |
| 49 | + return [Uint64(0), false] |
| 50 | + } |
| 51 | + return [state!.value as uint64, exists] |
| 52 | + }, |
| 53 | + put: function (a: Account | internal.primitives.StubUint64Compat, b: internal.primitives.StubBytesCompat, c: uint64 | bytes): void { |
| 54 | + const app = lazyContext.activeApplication |
| 55 | + const account = getAccount(a) |
| 56 | + lazyContext.ledger.setLocalState(app, account, b, c) |
| 57 | + }, |
| 58 | +} |
0 commit comments