Skip to content

Commit 623c57a

Browse files
authored
Merge pull request #1 from simsonraj/error_groups
Error groups - Extended open-rpc spec sample implementation
2 parents 4008859 + 46a9906 commit 623c57a

9 files changed

+22834
-29551
lines changed

package-lock.json

Lines changed: 22667 additions & 29547 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626
"homepage": "https://github.com/ethereum/execution-apis#readme",
2727
"devDependencies": {
2828
"@graphql-inspector/core": "~3.3.0",
29-
"@open-rpc/generator": "1.18.6",
30-
"@open-rpc/schema-utils-js": "1.15.0",
31-
"gatsby": "~4.16.0",
29+
"@open-rpc/extensions": "^0.0.2",
30+
"@open-rpc/generator": "^2.0.0",
31+
"@open-rpc/meta-schema": "^1.14.2",
32+
"@open-rpc/schema-utils-js": "2.1.0",
33+
"@open-rpc/specification-extension-spec": "^1.0.2",
34+
"gatsby": "^5.0.0",
3235
"gh-pages": "~4.0.0",
3336
"graphql": "~16.3.0",
3437
"graphql-request": "~4.1.0",

scripts/build.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from "fs";
22
import yaml from "js-yaml";
33
import mergeAllOf from "json-schema-merge-allof";
44
import { dereferenceDocument } from "@open-rpc/schema-utils-js";
5+
import {XErrorGroupsJSON} from "@open-rpc/extensions";
56

67
function sortByMethodName(methods) {
78
return methods.slice().sort((a, b) => {
@@ -79,6 +80,45 @@ schemaFiles.forEach(file => {
7980
};
8081
});
8182

83+
let extensionSpecs = [];
84+
let extensionSpecsBase = "src/extensions/"
85+
let extensionsSpecsFiles = fs.readdirSync(extensionSpecsBase);
86+
extensionsSpecsFiles.forEach(file => {
87+
console.log(file);
88+
// skip if directory
89+
if (fs.lstatSync(extensionSpecsBase + file).isDirectory()) {
90+
return;
91+
}
92+
let raw = fs.readFileSync(extensionSpecsBase + file);
93+
let parsed = yaml.load(raw);
94+
extensionSpecs.push(parsed);
95+
});
96+
97+
extensionSpecs.push(XErrorGroupsJSON);
98+
99+
let extensions = [];
100+
let extensionsBase = "src/extensions/components/"
101+
let extensionsFiles = fs.readdirSync(extensionsBase);
102+
extensionsFiles.forEach(file => {
103+
console.log(file);
104+
let raw = fs.readFileSync(extensionsBase + file);
105+
let parsed = yaml.load(raw);
106+
extensions.push(parsed);
107+
});
108+
109+
// if extensions key matches with extensionSpecs name, then add it to an array of extensionSpec name
110+
let extensionsDef = {};
111+
extensionSpecs.forEach((extensionSpec) => {
112+
extensions.forEach((extension) => {
113+
if (extension.hasOwnProperty(extensionSpec.name)) {
114+
extensionsDef[extensionSpec.name] ={
115+
...extensionsDef[extensionSpec.name],
116+
...extension[extensionSpec.name]
117+
}
118+
}
119+
});
120+
});
121+
82122
const doc = {
83123
openrpc: "1.2.4",
84124
info: {
@@ -91,7 +131,9 @@ const doc = {
91131
version: "0.0.0"
92132
},
93133
methods: sortByMethodName(methods),
134+
"x-extensions": extensionSpecs,
94135
components: {
136+
...extensionsDef,
95137
schemas: schemas
96138
}
97139
}

scripts/validate.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import fs from "fs";
22
import {
33
parseOpenRPCDocument,
4+
dereferenceDocument,
45
validateOpenRPCDocument
56
} from "@open-rpc/schema-utils-js";
7+
import OpenrpcDocument from "@open-rpc/meta-schema";
68

79
let rawdata = fs.readFileSync("openrpc.json");
810
let openrpc = JSON.parse(rawdata);
911

10-
const error = validateOpenRPCDocument(openrpc);
12+
/** @type {OpenrpcDocument} */
13+
const document = openrpc;
14+
const dereffed = await dereferenceDocument(document);
15+
16+
const error = validateOpenRPCDocument(dereffed);
1117
if (error != true) {
1218
console.log(error.name);
1319
console.log(error.message);

src/eth/submit.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
required: true
66
schema:
77
$ref: '#/components/schemas/GenericTransaction'
8+
x-error-group:
9+
- $ref: '#/components/x-error-group/JSONRPCNonStandardErrors'
10+
- $ref: '#/components/x-error-group/JSONRPCStandardErrors'
11+
- $ref: '#/components/x-error-group/GasErrors'
12+
- $ref: '#/components/x-error-group/ExecutionErrors'
13+
# Inline additional errors specific to this method
14+
-
15+
- code: -31000
16+
message: "Already known transaction"
17+
data: "Transaction is already known to the transaction pool"
18+
- code: -31001
19+
message: "Invalid sender"
20+
data: "Transaction sender is invalid."
821
result:
922
name: Transaction hash
1023
schema:
@@ -35,6 +48,19 @@
3548
required: true
3649
schema:
3750
$ref: '#/components/schemas/bytes'
51+
x-error-group:
52+
- $ref: '#/components/x-error-group/JSONRPCNonStandardErrors'
53+
- $ref: '#/components/x-error-group/JSONRPCStandardErrors'
54+
- $ref: '#/components/x-error-group/GasErrors'
55+
- $ref: '#/components/x-error-group/ExecutionErrors'
56+
# Inline additional errors specific to this method
57+
-
58+
- code: -31000
59+
message: "Already known transaction"
60+
data: "Transaction is already known to the transaction pool"
61+
- code: -31001
62+
message: "Invalid sender"
63+
data: "Transaction sender is invalid."
3864
result:
3965
name: Transaction hash
4066
schema:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
x-error-group:
2+
ExecutionErrors:
3+
- code: -31800
4+
message: "Nonce too low"
5+
data: "Transaction nonce is lower than the sender account's current nonce"
6+
- code: -31801
7+
message: "Nonce too high"
8+
data: "Transaction nonce is higher than the sender account's current nonce"
9+
- code: -31802
10+
message: "Execution reverted"
11+
data: "Execution is reverted by REVERT Opcode"
12+
- code: -31803
13+
message: "Invalid opcode"
14+
data: "An invalid opcode was encountered during execution"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
x-error-group:
2+
GasErrors:
3+
- code: -31800
4+
message: "Gas too low"
5+
data: "Transaction gas is too low / intrinsic gas too low"
6+
- code: -31801
7+
message: "Out of gas"
8+
data: "The transaction ran out of gas"
9+
- code: -31802
10+
message: "Gas Price too low"
11+
data: "Gas price too low / gas price below configured minimum gas price"
12+
- code: -31803
13+
message: "Exceeded Block gas limit"
14+
data: "Tx gas limit exceeds max block gas limit / intrinsic gas exceeds gas limit"
15+
- code: -31804
16+
message: "Exceeded Fee cap"
17+
data: "Tx fee exceeds cap / max priority fee per gas higher than max fee per gas"
18+
- code: -31805
19+
message: "Gas overflow"
20+
data: "Gas overflow error"
21+
- code: -31806
22+
message: "Price lower than the base fee"
23+
data: "Transaction price must be greater than base fee / max fee per gas less than block base fee"
24+
- code: -31807
25+
message: "Max priority fee overflow"
26+
data: "Max priority fee per gas higher than 2^256-1"
27+
- code: -31808
28+
message: "Max fee overflow"
29+
data: "Max fee per gas higher than 2^256-1"
30+
- code: -31809
31+
message: "Insufficient funds"
32+
data: "Insufficient funds for gas * price + value"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
x-error-group:
2+
JSONRPCNonStandardErrors:
3+
- code: -32000
4+
message: "Invalid input"
5+
data: "Missing or invalid parameters"
6+
- code: -32001
7+
message: "Resource not found"
8+
data: "Requested resource not found"
9+
- code: -32002
10+
message: "Resource unavailable"
11+
data: "Requested resource not available"
12+
- code: -32003
13+
message: "Transaction rejected"
14+
data: "Transaction creation failed"
15+
- code: -32004
16+
message: "Method not supported"
17+
data: "Method is not implemented"
18+
- code: -32005
19+
message: "Limit exceeded"
20+
data: "Request exceeds defined limit"
21+
- code: -32006
22+
message: "JSON-RPC version not supported"
23+
data: "Version of JSON-RPC protocol is not supported"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
x-error-group:
2+
JSONRPCStandardErrors:
3+
- code: -32700
4+
message: "Parse error"
5+
data: "An error occurred on the server while parsing the JSON text"
6+
- code: -32600
7+
message: "Invalid request"
8+
data: "The JSON sent is not a valid request object"
9+
- code: -32601
10+
message: "Method not found"
11+
data: "The method does not exist / is not available"
12+
- code: -32602
13+
message: "Invalid params"
14+
data: "Invalid method parameter(s)"
15+
- code: -32603
16+
message: "Internal error"
17+
data: "Internal JSON-RPC error"

0 commit comments

Comments
 (0)