-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
114 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Joi from 'joi'; | ||
|
||
import { ETH_ADDRESS_REGEXP } from '../const'; | ||
|
||
import { RpcCondition, rpcConditionSchema } from './rpc'; | ||
|
||
export const STANDARD_CONTRACT_TYPES = ['ERC20', 'ERC721']; | ||
|
||
const contractMethodSchemas: Record<string, Joi.Schema> = { | ||
...rpcConditionSchema, | ||
contractAddress: Joi.string().pattern(ETH_ADDRESS_REGEXP).required(), | ||
standardContractType: Joi.string() | ||
.valid(...STANDARD_CONTRACT_TYPES) | ||
.optional(), | ||
method: Joi.string().required(), | ||
functionAbi: Joi.object().optional(), | ||
parameters: Joi.array().required(), | ||
}; | ||
|
||
export class ContractCondition extends RpcCondition { | ||
public readonly schema = Joi.object(contractMethodSchemas) | ||
// At most one of these keys needs to be present | ||
.xor('standardContractType', 'functionAbi'); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { Condition } from './condition'; | ||
export { EvmCondition } from './evm'; | ||
export { ContractCondition } from './contract'; | ||
export { RpcCondition } from './rpc'; | ||
export { TimeCondition } from './time'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,21 @@ | ||
import Joi from 'joi'; | ||
|
||
import { SUPPORTED_CHAINS } from '../const'; | ||
import { omit } from '../../utils'; | ||
|
||
import { Condition } from './condition'; | ||
import { returnValueTestSchema } from './schema'; | ||
import { RpcCondition, rpcConditionSchema } from './rpc'; | ||
|
||
export class TimeCondition extends Condition { | ||
// TODO: This is the only condition that uses defaults, and also the only condition that uses `method` in order | ||
// to determine the schema. I.e. the only method that used `METHOD = 'blocktime'` in `nucypher/nucypher`. | ||
// TODO: Consider introducing a different field for this, e.g. `conditionType` or `type`. Use this field in a | ||
// condition factory. | ||
const BLOCKTIME_METHOD = 'blocktime'; | ||
|
||
const timeConditionSchema = { | ||
// TimeCondition is an RpcCondition with the method set to 'blocktime' and no parameters | ||
...omit(rpcConditionSchema, ['parameters']), | ||
method: Joi.string().valid(BLOCKTIME_METHOD).required(), | ||
}; | ||
|
||
export class TimeCondition extends RpcCondition { | ||
public readonly defaults: Record<string, unknown> = { | ||
method: 'blocktime', | ||
method: BLOCKTIME_METHOD, | ||
}; | ||
|
||
public readonly schema = Joi.object({ | ||
method: Joi.string().valid(this.defaults.method).required(), | ||
returnValueTest: returnValueTestSchema.required(), | ||
chain: Joi.number() | ||
.valid(...SUPPORTED_CHAINS) | ||
.required(), | ||
}); | ||
public readonly schema = Joi.object(timeConditionSchema); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
aad7ebe
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.
Bundled size for the package is listed below:
build/module/types/ethers-contracts/factories: 82.03 KB
build/module/types/ethers-contracts: 156.25 KB
build/module/types: 160.16 KB
build/module/src/agents: 31.25 KB
build/module/src/policies: 19.53 KB
build/module/src/conditions/base: 50.78 KB
build/module/src/conditions/predefined: 19.53 KB
build/module/src/conditions/context: 39.06 KB
build/module/src/conditions: 148.44 KB
build/module/src/sdk/strategy: 42.97 KB
build/module/src/sdk: 58.59 KB
build/module/src/characters: 89.84 KB
build/module/src/kits: 19.53 KB
build/module/src: 433.59 KB
build/module: 644.53 KB
build/main/types/ethers-contracts/factories: 82.03 KB
build/main/types/ethers-contracts: 156.25 KB
build/main/types: 160.16 KB
build/main/src/agents: 31.25 KB
build/main/src/policies: 19.53 KB
build/main/src/conditions/base: 50.78 KB
build/main/src/conditions/predefined: 19.53 KB
build/main/src/conditions/context: 39.06 KB
build/main/src/conditions: 148.44 KB
build/main/src/sdk/strategy: 42.97 KB
build/main/src/sdk: 58.59 KB
build/main/src/characters: 89.84 KB
build/main/src/kits: 19.53 KB
build/main/src: 437.50 KB
build/main: 648.44 KB
build: 1.27 MB