Skip to content

Commit

Permalink
cleaned up some references
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Jun 12, 2024
1 parent 083f996 commit 8ad0ce1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
6 changes: 5 additions & 1 deletion src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export type Config = {
host: string
apiKey?: string
}
// Map some arbitary string to a list of code IDs.

/**
* Map some arbitary string to a list of code IDs.
* @deprecated Use WasmCodeService to access code IDs.
*/
codeIds?: Partial<Record<string, number[]>>

// If present, sets up Sentry error reporting.
Expand Down
6 changes: 3 additions & 3 deletions src/db/models/Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export class Contract extends Model {
* from the config.
*/
matchesCodeIdKeys(...keys: string[]): boolean {
const codeIds =
WasmCodeService.getInstance().findWasmCodeIdsByKeys(...keys) ?? []
return codeIds.includes(this.codeId)
return WasmCodeService.getInstance()
.findWasmCodeIdsByKeys(...keys)
.includes(this.codeId)
}
}
4 changes: 2 additions & 2 deletions src/scripts/preCompute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export const main = async () => {
} else if (options.ids?.length || options.codeIdsKeys?.length) {
const codeIds = [
...(options.ids || []),
...(WasmCodeService.getInstance().findWasmCodeIdsByKeys(
...WasmCodeService.getInstance().findWasmCodeIdsByKeys(
options.codeIdsKeys || []
) ?? []),
),
]
addresses = (
await Contract.findAll({
Expand Down
14 changes: 10 additions & 4 deletions src/scripts/revalidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ const main = async () => {
let replaced = 0
const formulasReplaced = new Set<string>()

const codeIds =
WasmCodeService.getInstance().findWasmCodeIdsByKeys(
...WasmCodeService.extractWasmCodeKeys(codeIdsKeys)
) ?? []
const extractedCodeIdsKeys = WasmCodeService.extractWasmCodeKeys(codeIdsKeys)
const codeIds = WasmCodeService.getInstance().findWasmCodeIdsByKeys(
...extractedCodeIdsKeys
)

if (extractedCodeIdsKeys.length > 0 && codeIds.length === 0) {
throw new Error(
'No code IDs found matching keys: ' + extractedCodeIdsKeys.join(', ')
)
}

const contracts =
codeIds.length > 0
Expand Down
14 changes: 8 additions & 6 deletions src/scripts/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ const main = async () => {
}
: {}

const codeIds =
WasmCodeService.getInstance().findWasmCodeIdsByKeys(
...WasmCodeService.extractWasmCodeKeys(codeIdsKeys)
) ?? []
const extractedCodeIdsKeys = WasmCodeService.extractWasmCodeKeys(codeIdsKeys)
const codeIds = WasmCodeService.getInstance().findWasmCodeIdsByKeys(
...extractedCodeIdsKeys
)

if (typeof codeIdsKeys === 'string' && codeIds.length === 0) {
throw new Error('No code IDs found in config')
if (extractedCodeIdsKeys.length > 0 && codeIds.length === 0) {
throw new Error(
'No code IDs found matching keys: ' + extractedCodeIdsKeys.join(', ')
)
}

const includeContract = {
Expand Down
7 changes: 4 additions & 3 deletions src/server/routes/indexer/computer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,10 @@ export const computer: Router.Middleware = async (ctx) => {

if (typedFormula.formula.filter.codeIdsKeys?.length) {
const codeIdKeys = typedFormula.formula.filter.codeIdsKeys
const allCodeIds =
WasmCodeService.getInstance().findWasmCodeIdsByKeys(...codeIdKeys)
allowed &&= allCodeIds.includes(contract.codeId)

allowed &&= WasmCodeService.getInstance()
.findWasmCodeIdsByKeys(...codeIdKeys)
.includes(contract.codeId)
}

if (!allowed) {
Expand Down

0 comments on commit 8ad0ce1

Please sign in to comment.