Skip to content

Commit

Permalink
feat(validation util): simplify validation util
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Nov 6, 2024
1 parent 251695e commit cd57929
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 446 deletions.
26 changes: 8 additions & 18 deletions src/types/ant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,14 @@ export const AntStateSchema = z.object({
export type AoANTState = z.infer<typeof AntStateSchema>;

export const AntReadHandlers = [
'getState',
'getInfo',
'getRecord',
'getRecords',
'getOwner',
'getControllers',
'getTicker',
'getName',
'getBalance',
'getBalances',
'balance',
'balances',
'totalSupply',
'info',
'controllers',
'record',
'records',
'state',
] as const;

export type AoANTReadHandler = (typeof AntReadHandlers)[number];
Expand All @@ -121,23 +119,15 @@ export const AntWriteHandlers = [
'_eval',
'_default',
'transfer',
'balance',
'balances',
'totalSupply',
'info',
'addController',
'removeController',
'controllers',
'setRecord',
'removeRecord',
'record',
'records',
'setName',
'setTicker',
'setDescription',
'setKeywords',
'initializeState',
'state',
'releaseName',
'reassignName',
] as const;
Expand Down
23 changes: 22 additions & 1 deletion src/utils/ao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Arweave from 'arweave';
import { z } from 'zod';

import { defaultArweave } from '../common/arweave.js';
import { ANTRegistry, AOProcess, Logger } from '../common/index.js';
import { ANT, ANTRegistry, AOProcess, Logger } from '../common/index.js';
import {
ANT_LUA_ID,
ANT_REGISTRY_ID,
Expand Down Expand Up @@ -253,3 +253,24 @@ export function createAoSigner(signer: ContractSigner): AoSigner {

return aoSigner;
}

export async function getAntHandlers({
processId,
ao = connect(),
}: {
processId: string;
ao?: AoClient;
}): Promise<string[]> {
const ant = ANT.init({
process: new AOProcess({
processId,
ao,
}),
});
const info = await ant.getInfo();
const handlers = info?.Handlers || info?.HandlerNames;

if (!Array.isArray(handlers)) throw new Error('Failed to get handlers');

return handlers;
}
Loading

0 comments on commit cd57929

Please sign in to comment.