Skip to content

Commit

Permalink
refactor: use impl pattern for Account, Application, Asset, and log f…
Browse files Browse the repository at this point in the history
…unctions
  • Loading branch information
boblat committed Jan 3, 2025
1 parent 9490b44 commit 8832e7a
Show file tree
Hide file tree
Showing 32 changed files with 402 additions and 392 deletions.
4 changes: 1 addition & 3 deletions src/context-helpers/internal-context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Account, BaseContract, internal } from '@algorandfoundation/algorand-typescript'
import { AccountData } from '../impl/account'
import { ApplicationData } from '../impl/application'
import { AssetData } from '../impl/asset'
import { AccountData, ApplicationData, AssetData } from '../impl/reference'
import { TransactionGroup } from '../subcontexts/transaction-context'
import { TestExecutionContext } from '../test-execution-context'

Expand Down
4 changes: 1 addition & 3 deletions src/encoders.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { biguint, BigUint, bytes, internal, TransactionType, uint64, Uint64 } from '@algorandfoundation/algorand-typescript'
import { ARC4Encoded, OnCompleteAction } from '@algorandfoundation/algorand-typescript/arc4'
import { AccountCls } from './impl/account'
import { ApplicationCls } from './impl/application'
import { AssetCls } from './impl/asset'
import { BytesBackedCls, Uint64BackedCls } from './impl/base'
import { arc4Encoders, encodeArc4Impl, getArc4Encoder } from './impl/encoded-types'
import { AccountCls, ApplicationCls, AssetCls } from './impl/reference'
import { DeliberateAny } from './typescript-helpers'
import { asBytes, asMaybeBigUintCls, asMaybeBytesCls, asMaybeUint64Cls, asUint64Cls, asUint8Array, nameOfType } from './util'

Expand Down
102 changes: 0 additions & 102 deletions src/impl/account.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/impl/app-params.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Account, Application, Bytes, bytes, gtxn, internal, Uint64, uint64 } from '@algorandfoundation/algorand-typescript'
import { lazyContext } from '../context-helpers/internal-context'
import { asMaybeUint64Cls, asUint64 } from '../util'
import { AccountImpl } from './reference'

const resolveAppIndex = (appIdOrIndex: internal.primitives.StubUint64Compat): uint64 => {
const input = asUint64(appIdOrIndex)
Expand Down Expand Up @@ -54,10 +55,10 @@ export const AppParams: internal.opTypes.AppParamsType = {
},
appCreator(a: Application | internal.primitives.StubUint64Compat): readonly [Account, boolean] {
const app = getApp(a)
return app === undefined ? [Account(), false] : [app.creator, true]
return app === undefined ? [AccountImpl(), false] : [app.creator, true]
},
appAddress(a: Application | internal.primitives.StubUint64Compat): readonly [Account, boolean] {
const app = getApp(a)
return app === undefined ? [Account(), false] : [app.address, true]
return app === undefined ? [AccountImpl(), false] : [app.address, true]
},
}
80 changes: 0 additions & 80 deletions src/impl/application.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/impl/asset-holding.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Account, Asset, internal, Uint64, uint64 } from '@algorandfoundation/algorand-typescript'
import { lazyContext } from '../context-helpers/internal-context'
import { AssetHolding as AssetHoldingData } from './account'
import { getAccount } from './acct-params'
import { getAsset } from './asset-params'
import { AssetHolding as AssetHoldingData } from './reference'

const getAssetHolding = (
acctOrIndex: Account | internal.primitives.StubUint64Compat,
Expand Down
11 changes: 6 additions & 5 deletions src/impl/asset-params.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Account, Asset, Bytes, bytes, gtxn, internal, Uint64, uint64 } from '@algorandfoundation/algorand-typescript'
import { lazyContext } from '../context-helpers/internal-context'
import { asMaybeUint64Cls, asUint64 } from '../util'
import { AccountImpl } from './reference'

const resolveAssetIndex = (assetIdOrIndex: internal.primitives.StubUint64Compat): uint64 => {
const input = asUint64(assetIdOrIndex)
Expand Down Expand Up @@ -54,22 +55,22 @@ export const AssetParams: internal.opTypes.AssetParamsType = {
},
assetManager(a: Asset | internal.primitives.StubUint64Compat): readonly [Account, boolean] {
const asset = getAsset(a)
return asset === undefined ? [Account(), false] : [asset.manager, true]
return asset === undefined ? [AccountImpl(), false] : [asset.manager, true]
},
assetReserve(a: Asset | internal.primitives.StubUint64Compat): readonly [Account, boolean] {
const asset = getAsset(a)
return asset === undefined ? [Account(), false] : [asset.reserve, true]
return asset === undefined ? [AccountImpl(), false] : [asset.reserve, true]
},
assetFreeze(a: Asset | internal.primitives.StubUint64Compat): readonly [Account, boolean] {
const asset = getAsset(a)
return asset === undefined ? [Account(), false] : [asset.freeze, true]
return asset === undefined ? [AccountImpl(), false] : [asset.freeze, true]
},
assetClawback(a: Asset | internal.primitives.StubUint64Compat): readonly [Account, boolean] {
const asset = getAsset(a)
return asset === undefined ? [Account(), false] : [asset.clawback, true]
return asset === undefined ? [AccountImpl(), false] : [asset.clawback, true]
},
assetCreator(a: Asset | internal.primitives.StubUint64Compat): readonly [Account, boolean] {
const asset = getAsset(a)
return asset === undefined ? [Account(), false] : [asset.creator, true]
return asset === undefined ? [AccountImpl(), false] : [asset.creator, true]
},
}
76 changes: 0 additions & 76 deletions src/impl/asset.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/impl/compiled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@algorandfoundation/algorand-typescript'
import { lazyContext } from '../context-helpers/internal-context'
import { ConstructorFor } from '../typescript-helpers'
import { ApplicationData } from './application'
import { ApplicationData } from './reference'

export function compileImpl(
artefact: ConstructorFor<BaseContract> | ConstructorFor<LogicSig>,
Expand Down
4 changes: 2 additions & 2 deletions src/impl/emit.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { internal } from '@algorandfoundation/algorand-typescript'
import { lazyContext } from '../context-helpers/internal-context'
import { DeliberateAny } from '../typescript-helpers'
import { sha512_256 } from './crypto'
import { getArc4Encoded, getArc4TypeName } from './encoded-types'
import { logImpl } from './log'

export function emitImpl<T>(typeInfoString: string, event: T | string, ...eventProps: unknown[]) {
let eventData
Expand All @@ -24,5 +24,5 @@ export function emitImpl<T>(typeInfoString: string, event: T | string, ...eventP
}

const eventHash = sha512_256(eventName)
lazyContext.value.log(eventHash.slice(0, 4).concat(eventData.bytes))
logImpl(eventHash.slice(0, 4).concat(eventData.bytes))
}
6 changes: 2 additions & 4 deletions src/impl/encoded-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ import { lazyContext } from '../context-helpers/internal-context'
import { fromBytes, TypeInfo } from '../encoders'
import { DeliberateAny } from '../typescript-helpers'
import { asBigInt, asBigUint, asBigUintCls, asBytesCls, asUint64, asUint8Array, conactUint8Arrays, uint8ArrayToNumber } from '../util'
import { AccountCls } from './account'
import { ApplicationCls } from './application'
import { AssetCls } from './asset'
import { AccountCls, AccountImpl, ApplicationCls, AssetCls } from './reference'
import { ApplicationTransaction } from './transactions'

const ABI_LENGTH_SIZE = 2
Expand Down Expand Up @@ -479,7 +477,7 @@ export class AddressImpl extends Address {
}

get native(): Account {
return Account(this.value.bytes)
return AccountImpl(this.value.bytes)
}

get items(): ByteImpl[] {
Expand Down
Loading

0 comments on commit 8832e7a

Please sign in to comment.