Skip to content

Commit 848d011

Browse files
authored
Merge pull request #43 from algorandfoundation/refactor/import
refactor: export more functions under internal namespace for import replacement pattern
2 parents 4bb8380 + b5e3460 commit 848d011

File tree

6 files changed

+58
-22
lines changed

6 files changed

+58
-22
lines changed

examples/simple-voting/contract.algo.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import type { Account, bytes, uint64 } from '@algorandfoundation/algorand-typescript'
2-
import { assert, BaseContract, Bytes, GlobalState, LocalState, op, TransactionType, Uint64 } from '@algorandfoundation/algorand-typescript'
2+
import {
3+
assert,
4+
BaseContract,
5+
Bytes,
6+
GlobalState,
7+
gtxn,
8+
LocalState,
9+
op,
10+
TransactionType,
11+
Uint64,
12+
} from '@algorandfoundation/algorand-typescript'
313

414
const VOTE_PRICE = Uint64(10_000)
515
export default class SimpleVotingContract extends BaseContract {
@@ -34,6 +44,7 @@ export default class SimpleVotingContract extends BaseContract {
3444

3545
private vote(voter: Account): boolean {
3646
assert(op.Global.groupSize === Uint64(2))
47+
assert(gtxn.PaymentTxn(1).amount === VOTE_PRICE)
3748
assert(op.GTxn.amount(1) === VOTE_PRICE)
3849
assert(op.GTxn.typeEnum(1) === TransactionType.Payment)
3950

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"tslib": "^2.6.2"
6565
},
6666
"dependencies": {
67-
"@algorandfoundation/algorand-typescript": "^1.0.0-beta.10",
67+
"@algorandfoundation/algorand-typescript": "^1.0.0-beta.11",
6868
"@algorandfoundation/puya-ts": "^1.0.0-beta.13",
6969
"elliptic": "^6.5.7",
7070
"js-sha256": "^0.11.0",

src/impl/gtxn.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,11 @@ export const GTxn: typeof op.GTxn = {
210210
return lazyContext.activeGroup.getApplicationTransaction(t).numClearStateProgramPages
211211
},
212212
}
213+
214+
export const Transaction = (index: uint64) => lazyContext.txn.activeGroup.getTransaction(index)
215+
export const PaymentTxn = (index: uint64) => lazyContext.txn.activeGroup.getPaymentTransaction(index)
216+
export const KeyRegistrationTxn = (index: uint64) => lazyContext.txn.activeGroup.getKeyRegistrationTransaction(index)
217+
export const AssetConfigTxn = (index: uint64) => lazyContext.txn.activeGroup.getAssetConfigTransaction(index)
218+
export const AssetTransferTxn = (index: uint64) => lazyContext.txn.activeGroup.getAssetTransferTransaction(index)
219+
export const AssetFreezeTxn = (index: uint64) => lazyContext.txn.activeGroup.getAssetFreezeTransaction(index)
220+
export const ApplicationTxn = (index: uint64) => lazyContext.txn.activeGroup.getApplicationTransaction(index)

src/internal.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,30 @@ export { Global } from './impl/global'
55
export { log } from './impl/log'
66
export { assertMatchImpl as assertMatch, matchImpl as match } from './impl/match'
77
export { Account, Application, Asset } from './impl/reference'
8+
export { Box, BoxMap, BoxRef, GlobalState, LocalState } from './impl/state'
89
export { TemplateVarImpl as TemplateVar } from './impl/template-var'
910
export { Txn } from './impl/txn'
1011
export { urangeImpl as urange } from './impl/urange'
1112
export * as arc4 from './internal-arc4'
1213
export * as op from './internal-op'
14+
import { ApplicationTxn, AssetConfigTxn, AssetFreezeTxn, AssetTransferTxn, KeyRegistrationTxn, PaymentTxn, Transaction } from './impl/gtxn'
15+
export const gtxn = {
16+
Transaction,
17+
PaymentTxn,
18+
KeyRegistrationTxn,
19+
AssetConfigTxn,
20+
AssetTransferTxn,
21+
AssetFreezeTxn,
22+
ApplicationTxn,
23+
}
24+
25+
import { applicationCall, assetConfig, assetFreeze, assetTransfer, keyRegistration, payment, submitGroup } from './impl/inner-transactions'
26+
export const itxn = {
27+
submitGroup,
28+
payment,
29+
keyRegistration,
30+
assetConfig,
31+
assetTransfer,
32+
assetFreeze,
33+
applicationCall,
34+
}

src/test-execution-context.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { internal } from '@algorandfoundation/algorand-typescript'
33
import { captureMethodConfig } from './abi-metadata'
44
import { DEFAULT_TEMPLATE_VAR_PREFIX } from './constants'
55
import type { DecodedLogs, LogDecoding } from './decode-logs'
6-
import * as ops from './impl'
6+
import { ApplicationTxn, AssetConfigTxn, AssetFreezeTxn, AssetTransferTxn, KeyRegistrationTxn, PaymentTxn, Transaction } from './impl/gtxn'
77
import {
88
applicationCall as itxnApplicationCall,
99
assetConfig as itxnAssetConfig,
@@ -47,11 +47,6 @@ export class TestExecutionContext implements internal.ExecutionContext {
4747
return this.txn.exportLogs(appId, ...decoding)
4848
}
4949

50-
/* @internal */
51-
get op() {
52-
return ops
53-
}
54-
5550
get contract() {
5651
return this.#contractContext
5752
}
@@ -82,13 +77,13 @@ export class TestExecutionContext implements internal.ExecutionContext {
8277
/* @internal */
8378
get gtxn() {
8479
return {
85-
Transaction: (index: uint64) => this.txn.activeGroup.getTransaction(index),
86-
PaymentTxn: (index: uint64) => this.txn.activeGroup.getPaymentTransaction(index),
87-
KeyRegistrationTxn: (index: uint64) => this.txn.activeGroup.getKeyRegistrationTransaction(index),
88-
AssetConfigTxn: (index: uint64) => this.txn.activeGroup.getAssetConfigTransaction(index),
89-
AssetTransferTxn: (index: uint64) => this.txn.activeGroup.getAssetTransferTransaction(index),
90-
AssetFreezeTxn: (index: uint64) => this.txn.activeGroup.getAssetFreezeTransaction(index),
91-
ApplicationTxn: (index: uint64) => this.txn.activeGroup.getApplicationTransaction(index),
80+
Transaction,
81+
PaymentTxn,
82+
KeyRegistrationTxn,
83+
AssetConfigTxn,
84+
AssetTransferTxn,
85+
AssetFreezeTxn,
86+
ApplicationTxn,
9287
}
9388
}
9489

0 commit comments

Comments
 (0)