-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cli,world): resolve table by just name #2850
Changes from 6 commits
49e1bc5
4730aa2
d1a140c
ca20384
c27a365
d5c693d
b998ccb
77d9e82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
export enum DynamicResolutionType { | ||
TABLE_ID, | ||
SYSTEM_ADDRESS, | ||
} | ||
import { World } from "./output"; | ||
|
||
export type DynamicResolution = { | ||
type: DynamicResolutionType; | ||
// TODO: add systemAddress support | ||
type: "tableId"; | ||
input: string; | ||
}; | ||
|
||
|
@@ -18,9 +16,9 @@ export type ValueWithType = { | |
*/ | ||
export function resolveTableId(tableName: string) { | ||
return { | ||
type: DynamicResolutionType.TABLE_ID, | ||
type: "tableId", | ||
input: tableName, | ||
}; | ||
} as const; | ||
} | ||
|
||
/** Type guard for DynamicResolution */ | ||
|
@@ -38,20 +36,29 @@ export function isValueWithType(value: unknown): value is ValueWithType { | |
*/ | ||
export function resolveWithContext( | ||
input: unknown, | ||
context: { systemAddresses?: Record<string, Promise<string>>; tableIds?: Record<string, Uint8Array> }, | ||
context: { config: World; systemAddresses?: Record<string, Promise<string>> }, | ||
): ValueWithType { | ||
if (isValueWithType(input)) return input; | ||
|
||
if (isDynamicResolution(input)) { | ||
let resolved: ValueWithType | undefined = undefined; | ||
if (input.type === "tableId") { | ||
const tableEntries = Object.entries(context.config.tables).filter( | ||
([tableName, table]) => tableName === input.input || table.name === input.input, | ||
); | ||
|
||
if (input.type === DynamicResolutionType.TABLE_ID) { | ||
const tableId = context.tableIds?.[input.input]; | ||
resolved = tableId && { value: tableId, type: "bytes32" }; | ||
} | ||
if (tableEntries.length > 1) { | ||
throw new Error( | ||
`Found more than one table with name "${input.input}". Try using one of the following table names instead: ${tableEntries.map(([tableName]) => tableName).join(", ")}`, | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! |
||
} | ||
|
||
if (resolved) return resolved; | ||
if (tableEntries.length === 1) { | ||
const [entry] = tableEntries; | ||
const [, table] = entry; | ||
return { type: "bytes32", value: table.tableId }; | ||
} | ||
} | ||
} | ||
|
||
throw new Error(`Could not resolve dynamic resolution: \n${JSON.stringify(input, null, 2)}`); | ||
throw new Error(`Could not resolve dynamic resolution:\n${JSON.stringify(input, null, 2)}`); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ export * from "../encodeSystemCallsFrom"; | |
export * from "../actions/callFrom"; | ||
|
||
export * from "../callWithSignatureTypes"; | ||
|
||
export { resolveTableId, resolveWithContext } from "../config/v2/dynamicResolution"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am intentionally exporting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is an internal thing and changing this to strings instead of enums leads to better errors in the
resolveWithContext
function