Skip to content

Commit

Permalink
Add currentHeightHex keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastijankuzner committed Feb 6, 2025
1 parent 8df52ce commit c29f5ba
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/api-evm/source/service-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ import {
} from "./actions/index.js";
import Handlers from "./handlers.js";
import { Server } from "./server.js";
import { schemas } from "./validation/index.js";
import { makeKeywords, schemas } from "./validation/index.js";

export class ServiceProvider extends AbstractServiceProvider<Server> {
public async register(): Promise<void> {
for (const keyword of Object.values(
makeKeywords(this.app.get<Contracts.State.Store>(Identifiers.State.Store)),
)) {
this.app.get<Contracts.Crypto.Validator>(Identifiers.Cryptography.Validator).addKeyword(keyword);
}

for (const schema of Object.values(schemas)) {
this.app.get<Contracts.Crypto.Validator>(Identifiers.Cryptography.Validator).addSchema(schema);
}
Expand Down
1 change: 1 addition & 0 deletions packages/api-evm/source/validation/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./keywords.js";
export * from "./schemas.js";
15 changes: 15 additions & 0 deletions packages/api-evm/source/validation/keywords.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Contracts } from "@mainsail/contracts";
import { FuncKeywordDefinition } from "ajv";

export const makeKeywords = (stateStore: Contracts.State.Store) => {
const currentHeight: FuncKeywordDefinition = {
compile: (schema) => (data) => Number(data) === stateStore.getHeight(),
errors: false,
keyword: "currentHeightHex",
metaSchema: {
type: "boolean",
},
};

return { currentHeight };
};
1 change: 1 addition & 0 deletions packages/api-evm/source/validation/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const schemas: Record<"blockTag", AnySchemaObject> = {
},
{
$ref: "prefixedHex",
currentHeightHex: true,
},
],
},
Expand Down

0 comments on commit c29f5ba

Please sign in to comment.