Skip to content

Commit

Permalink
fix leaking rpc condition parmeters to time condition schema
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jun 14, 2023
1 parent 662b5f5 commit 96a92d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/conditions/base/time.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import Joi from 'joi';

import { omit } from '../../utils';

import { RpcCondition, rpcConditionSchema } from './rpc';

const BLOCKTIME_METHOD = 'blocktime';

const timeConditionSchema = {
...rpcConditionSchema,
// TimeCondition is an RpcCondition with the method set to 'blocktime' and no parameters
...omit(rpcConditionSchema, ['parameters']),
method: Joi.string().valid(BLOCKTIME_METHOD).required(),
parameters: undefined, // TimeCondition does not accept parameters
};

export class TimeCondition extends RpcCondition {
Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ export const bytesEquals = (first: Uint8Array, second: Uint8Array): boolean =>

export const objectEquals = (a: unknown, b: unknown, strict = true): boolean =>
deepEqual(a, b, { strict });

export const omit = (obj: Record<string, unknown>, keys: string[]) => {
const copy = { ...obj };
keys.forEach((key) => delete copy[key]);
return copy;
};

0 comments on commit 96a92d5

Please sign in to comment.