Skip to content

Commit

Permalink
fix: Add readonly and events to contract schema
Browse files Browse the repository at this point in the history
Merge pull request #53 from joe-p/readonly_schema
  • Loading branch information
robdmoore committed Jan 2, 2024
2 parents 607287a + d285bc5 commit 63b4cfe
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 41 deletions.
31 changes: 31 additions & 0 deletions src/schema/application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type DefaultArgument =
*/
source: "abi-method";
data: ContractMethod;
[k: string]: unknown;
}
| {
/**
Expand All @@ -31,6 +32,7 @@ export type DefaultArgument =
* The key of the state variable
*/
data: string;
[k: string]: unknown;
}
| {
/**
Expand All @@ -41,6 +43,7 @@ export type DefaultArgument =
* The key of the state variable
*/
data: string;
[k: string]: unknown;
}
| {
/**
Expand All @@ -51,6 +54,7 @@ export type DefaultArgument =
* The static default value to use.
*/
data: string | number;
[k: string]: unknown;
};
export type CallConfigValue = "NEVER" | "CALL" | "CREATE" | "ALL";

Expand All @@ -63,6 +67,7 @@ export interface AlgoAppSpec {
schema: SchemaSpec;
state: StateSchemaSpec;
bare_call_config?: CallConfig;
[k: string]: unknown;
}
export interface Hint {
read_only?: boolean;
Expand All @@ -74,10 +79,12 @@ export interface Hint {
[k: string]: DefaultArgument;
};
call_config?: CallConfig;
[k: string]: unknown;
}
export interface Struct {
name: string;
elements: StructElement[];
[k: string]: unknown;
}
/**
* The contract of the ABI method to invoke.
Expand All @@ -92,7 +99,11 @@ export interface ContractMethod {
* Catch all for fixed length arrays and tuples
*/
type: string;
[k: string]: unknown;
};
readonly?: boolean;
events?: Event[];
[k: string]: unknown;
}
export interface ContractMethodArg {
desc?: string;
Expand All @@ -101,6 +112,13 @@ export interface ContractMethodArg {
*/
type: string;
name: string;
[k: string]: unknown;
}
export interface Event {
name: string;
args: ContractMethodArg[];
desc?: string;
[k: string]: unknown;
}
export interface CallConfig {
no_op?: CallConfigValue;
Expand All @@ -112,16 +130,20 @@ export interface CallConfig {
export interface AppSources {
approval?: string;
clear?: string;
[k: string]: unknown;
}
export interface AbiContract {
name: string;
desc?: string;
methods: ContractMethod1[];
events?: Event[];
networks?: {
[k: string]: {
appID: number;
[k: string]: unknown;
};
};
[k: string]: unknown;
}
export interface ContractMethod1 {
name: string;
Expand All @@ -133,14 +155,19 @@ export interface ContractMethod1 {
* Catch all for fixed length arrays and tuples
*/
type: string;
[k: string]: unknown;
};
readonly?: boolean;
events?: Event[];
[k: string]: unknown;
}
/**
* The schema for global and local storage
*/
export interface SchemaSpec {
global?: Schema;
local?: Schema;
[k: string]: unknown;
}
export interface Schema {
declared?: {
Expand All @@ -149,6 +176,7 @@ export interface Schema {
reserved?: {
[k: string]: ReservedSchemaValueSpec;
};
[k: string]: unknown;
}
export interface DeclaredSchemaValueSpec {
/**
Expand All @@ -167,6 +195,7 @@ export interface DeclaredSchemaValueSpec {
* Whether the value is set statically (at create time only) or dynamically
*/
static?: boolean;
[k: string]: unknown;
}
export interface ReservedSchemaValueSpec {
/**
Expand All @@ -186,8 +215,10 @@ export interface ReservedSchemaValueSpec {
export interface StateSchemaSpec {
global: StateSchema;
local: StateSchema;
[k: string]: unknown;
}
export interface StateSchema {
num_uints: number;
num_byte_slices: number;
[k: string]: unknown;
}
107 changes: 77 additions & 30 deletions src/schema/application.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
"$schema": "http://json-schema.org/draft-07/schema",
"title": "AlgoAppSpec",
"type": "object",
"required": ["contract", "schema", "source", "state"],
"additionalProperties": false,
"required": [
"contract",
"schema",
"source",
"state"
],
"additionalProperties": true,
"properties": {
"hints": {
"type": "object",
Expand All @@ -30,12 +35,18 @@
"definitions": {
"AVMType": {
"description": "AVM data type",
"enum": ["uint64", "bytes"]
"enum": [
"uint64",
"bytes"
]
},
"DeclaredSchemaValueSpec": {
"type": "object",
"required": ["type", "key"],
"additionalProperties": false,
"required": [
"type",
"key"
],
"additionalProperties": true,
"properties": {
"type": {
"description": "The type of the value",
Expand All @@ -57,7 +68,9 @@
},
"ReservedSchemaValueSpec": {
"type": "object",
"required": ["type"],
"required": [
"type"
],
"properties": {
"type": {
"description": "The type of the value",
Expand All @@ -75,8 +88,11 @@
},
"StateSchemaSpec": {
"type": "object",
"additionalProperties": false,
"required": ["global", "local"],
"additionalProperties": true,
"required": [
"global",
"local"
],
"properties": {
"global": {
"$ref": "#/definitions/StateSchema"
Expand All @@ -88,8 +104,11 @@
},
"StateSchema": {
"type": "object",
"additionalProperties": false,
"required": ["num_byte_slices", "num_uints"],
"additionalProperties": true,
"required": [
"num_byte_slices",
"num_uints"
],
"properties": {
"num_uints": {
"type": "integer"
Expand All @@ -102,7 +121,7 @@
"SchemaSpec": {
"description": "The schema for global and local storage",
"type": "object",
"additionalProperties": false,
"additionalProperties": true,
"properties": {
"global": {
"$ref": "#/definitions/Schema"
Expand All @@ -114,7 +133,7 @@
},
"Schema": {
"type": "object",
"additionalProperties": false,
"additionalProperties": true,
"properties": {
"declared": {
"type": "object",
Expand All @@ -132,7 +151,7 @@
},
"AppSources": {
"type": "object",
"additionalProperties": false,
"additionalProperties": true,
"properties": {
"approval": {
"type": "string"
Expand All @@ -144,7 +163,7 @@
},
"Hint": {
"type": "object",
"additionalProperties": false,
"additionalProperties": true,
"properties": {
"read_only": {
"type": "boolean"
Expand Down Expand Up @@ -192,12 +211,20 @@
}
},
"CallConfigValue": {
"enum": ["NEVER", "CALL", "CREATE", "ALL"]
"enum": [
"NEVER",
"CALL",
"CREATE",
"ALL"
]
},
"Struct": {
"type": "object",
"additionalProperties": false,
"required": ["name", "elements"],
"additionalProperties": true,
"required": [
"name",
"elements"
],
"properties": {
"name": {
"type": "string"
Expand Down Expand Up @@ -233,12 +260,17 @@
"oneOf": [
{
"type": "object",
"required": ["source", "data"],
"additionalProperties": false,
"required": [
"source",
"data"
],
"additionalProperties": true,
"properties": {
"source": {
"description": "The default value should be fetched by invoking an ABI method",
"enum": ["abi-method"]
"enum": [
"abi-method"
]
},
"data": {
"description": "The contract of the ABI method to invoke.",
Expand All @@ -248,12 +280,17 @@
},
{
"type": "object",
"required": ["source", "data"],
"additionalProperties": false,
"required": [
"source",
"data"
],
"additionalProperties": true,
"properties": {
"source": {
"description": "The default value should be fetched from global state",
"enum": ["global-state"]
"enum": [
"global-state"
]
},
"data": {
"description": "The key of the state variable",
Expand All @@ -263,12 +300,17 @@
},
{
"type": "object",
"required": ["source", "data"],
"additionalProperties": false,
"required": [
"source",
"data"
],
"additionalProperties": true,
"properties": {
"source": {
"description": "The default value should be fetched from the local state of the sender user",
"enum": ["local-state"]
"enum": [
"local-state"
]
},
"data": {
"description": "The key of the state variable",
Expand All @@ -278,12 +320,17 @@
},
{
"type": "object",
"required": ["source", "data"],
"additionalProperties": false,
"required": [
"source",
"data"
],
"additionalProperties": true,
"properties": {
"source": {
"description": "The default value is a constant.",
"enum": ["constant"]
"enum": [
"constant"
]
},
"data": {
"description": "The static default value to use.",
Expand All @@ -304,4 +351,4 @@
]
}
}
}
}
Loading

0 comments on commit 63b4cfe

Please sign in to comment.