Skip to content

Commit d536ada

Browse files
committed
fix: Remove circular dependency
1 parent 86673f0 commit d536ada

File tree

6 files changed

+17
-21
lines changed

6 files changed

+17
-21
lines changed

src/awst_build/eb/storage/box/box-map.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import { wtypes } from '../../../../awst/wtypes'
77
import { invariant } from '../../../../util'
88
import type { PType } from '../../../ptypes'
99
import { BoxMapPType, BoxPType, bytesPType, stringPType } from '../../../ptypes'
10-
import { assertCanBeUsedForStorage } from '../../../ptypes/util'
1110
import { FunctionBuilder, type NodeBuilder } from '../../index'
1211
import { parseFunctionArgs } from '../../util/arg-parsing'
13-
import { extractKey } from '../util'
12+
import { assertCanBeUsedForStorage, extractKey } from '../util'
1413
import { BoxProxyExpressionBuilder } from './base'
1514
import { BoxExpressionBuilder } from './box'
1615

src/awst_build/eb/storage/box/box.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import { wtypes } from '../../../../awst/wtypes'
66
import { invariant } from '../../../../util'
77
import type { PType } from '../../../ptypes'
88
import { boolPType, BoxPType, bytesPType, ReadonlyTuplePType, stringPType, uint64PType, voidPType } from '../../../ptypes'
9-
import { assertCanBeUsedForStorage } from '../../../ptypes/util'
109
import { instanceEb } from '../../../type-registry'
1110
import { FunctionBuilder, type NodeBuilder } from '../../index'
1211
import { parseFunctionArgs } from '../../util/arg-parsing'
13-
import { extractKey } from '../util'
12+
import { assertCanBeUsedForStorage, extractKey } from '../util'
1413
import { boxExists, boxLength, BoxProxyExpressionBuilder, boxValue, BoxValueExpressionBuilder } from './base'
1514

1615
export class BoxFunctionBuilder extends FunctionBuilder {

src/awst_build/eb/storage/global-state.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ import { codeInvariant, invariant } from '../../../util'
1010
import { AppStorageDeclaration } from '../../models/app-storage-declaration'
1111
import type { ContractClassPType, PType } from '../../ptypes'
1212
import { boolPType, bytesPType, GlobalStateGeneric, GlobalStateType, numberPType, stringPType } from '../../ptypes'
13-
import { assertCanBeUsedForStorage } from '../../ptypes/util'
1413
import { typeRegistry } from '../../type-registry'
1514
import { BooleanExpressionBuilder } from '../boolean-expression-builder'
1615
import type { NodeBuilder } from '../index'
1716
import { FunctionBuilder, InstanceExpressionBuilder } from '../index'
1817
import { parseFunctionArgs } from '../util/arg-parsing'
1918
import { VoidExpressionBuilder } from '../void-expression-builder'
20-
import { extractKey } from './util'
19+
import { assertCanBeUsedForStorage, extractKey } from './util'
2120

2221
export class GlobalStateFunctionBuilder extends FunctionBuilder {
2322
constructor(sourceLocation: SourceLocation) {

src/awst_build/eb/storage/local-state.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ import { AppStorageDeclaration } from '../../models/app-storage-declaration'
1010

1111
import type { ContractClassPType, PType } from '../../ptypes'
1212
import { accountPType, boolPType, bytesPType, LocalStateType, stringPType } from '../../ptypes'
13-
import { assertCanBeUsedForStorage } from '../../ptypes/util'
1413
import { instanceEb } from '../../type-registry'
1514
import { FunctionBuilder, InstanceBuilder, InstanceExpressionBuilder, NodeBuilder } from '../index'
1615
import { parseFunctionArgs } from '../util/arg-parsing'
1716
import { VoidExpressionBuilder } from '../void-expression-builder'
18-
import { extractKey } from './util'
17+
import { assertCanBeUsedForStorage, extractKey } from './util'
1918

2019
export class LocalStateFunctionBuilder extends FunctionBuilder {
2120
constructor(sourceLocation: SourceLocation) {

src/awst_build/eb/storage/util.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import type { Expression } from '../../../awst/nodes'
33
import { BytesConstant } from '../../../awst/nodes'
44
import type { SourceLocation } from '../../../awst/source-location'
55
import type { wtypes } from '../../../awst/wtypes'
6+
import { CodeError } from '../../../errors'
7+
import type { PType } from '../../ptypes'
8+
import { ImmutableObjectPType, MutableObjectPType, TransientType, UnsupportedType } from '../../ptypes'
69
import type { InstanceBuilder } from '../index'
710

811
export function extractKey(key: InstanceBuilder, keyWType: wtypes.WType, sourceLocation: SourceLocation): Expression
@@ -29,3 +32,13 @@ export function extractKey(
2932
})
3033
}
3134
}
35+
36+
export function assertCanBeUsedForStorage(ptype: PType, sourceLocation?: SourceLocation) {
37+
if (ptype instanceof UnsupportedType || ptype instanceof TransientType) {
38+
throw new CodeError(`Type ${ptype} cannot be used for storage`, { sourceLocation })
39+
}
40+
if ((ptype instanceof MutableObjectPType || ptype instanceof ImmutableObjectPType) && !ptype.abiSafe) {
41+
const ptypeName = ptype.alias?.fullName || ptype.toString()
42+
throw new CodeError(`Type ${ptypeName} cannot be used for storage`, { sourceLocation })
43+
}
44+
}

src/awst_build/ptypes/util.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import * as crypto from 'node:crypto'
2-
import { ImmutableObjectPType, MutableObjectPType, TransientType, UnsupportedType } from '.'
3-
import type { SourceLocation } from '../../awst/source-location'
4-
import { CodeError } from '../../errors'
52
import type { PType } from './base'
63

74
export const ptypeIn = (target: PType, ...ptypes: [PType, ...PType[]]): boolean => {
@@ -16,13 +13,3 @@ export function generateObjectHash(objectProperties: Record<string, PType>) {
1613
hash.update(signature, 'utf8')
1714
return hash.digest('hex').substring(0, 8).toUpperCase()
1815
}
19-
20-
export function assertCanBeUsedForStorage(ptype: PType, sourceLocation?: SourceLocation) {
21-
if (ptype instanceof UnsupportedType || ptype instanceof TransientType) {
22-
throw new CodeError(`Type ${ptype} cannot be used for storage`, { sourceLocation })
23-
}
24-
if ((ptype instanceof MutableObjectPType || ptype instanceof ImmutableObjectPType) && !ptype.abiSafe) {
25-
const ptypeName = ptype.alias?.fullName || ptype.toString()
26-
throw new CodeError(`Type ${ptypeName} cannot be used for storage`, { sourceLocation })
27-
}
28-
}

0 commit comments

Comments
 (0)