Skip to content

Commit 95551f8

Browse files
committed
feat: add v11 onlineStake function
1 parent 181a10e commit 95551f8

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

src/impl/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export { Global } from './global'
1111
export { GTxn } from './gtxn'
1212
export { GITxn, ITxn, ITxnCreate } from './itxn'
1313
export { arg } from './logicSigArg'
14+
export { onlineStake } from './online-stake'
1415
export * from './pure'
1516
export { gloadBytes, gloadUint64, Scratch } from './scratch'
1617
export { gaid, Txn } from './txn'

src/impl/online-stake.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { internal } from '@algorandfoundation/algorand-typescript'
2+
import { lazyContext } from '../context-helpers/internal-context'
3+
4+
export const onlineStake: internal.opTypes.OnlineStakeType = () => {
5+
return lazyContext.ledger.onlineStake
6+
}

src/subcontexts/ledger-context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class LedgerContext {
2020
voterDataMap = new AccountMap<VoterData>()
2121
blocks = new Uint64Map<BlockData>()
2222
globalData = new GlobalData()
23+
onlineStake = 0
2324

2425
/* @internal */
2526
addAppIdContractMap(appId: internal.primitives.StubUint64Compat, contract: BaseContract): void {

tests/state-op-codes.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { DynamicBytes, UintN64 } from '@algorandfoundation/algorand-typescript/a
66
import { afterEach, describe, expect, it, test } from 'vitest'
77
import { TestExecutionContext } from '../src'
88
import { ABI_RETURN_VALUE_LOG_PREFIX, MIN_TXN_FEE, OnApplicationComplete, ZERO_ADDRESS } from '../src/constants'
9+
import { lazyContext } from '../src/context-helpers/internal-context'
910
import { testInvariant } from '../src/errors'
1011
import { Block, gloadBytes, gloadUint64 } from '../src/impl'
1112
import { AccountCls } from '../src/impl/account'
@@ -298,6 +299,14 @@ describe('State op codes', async () => {
298299
})
299300
})
300301

302+
describe('onlineStake', async () => {
303+
it('should return the configured online stake', async () => {
304+
lazyContext.ledger.onlineStake = Uint64(42)
305+
const result = op.onlineStake()
306+
expect(result).toEqual(42)
307+
})
308+
})
309+
301310
describe('Global', async () => {
302311
it('should return the correct global field value', async () => {
303312
const creator = ctx.any.account()

0 commit comments

Comments
 (0)