Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Schema compliance with execution-apis schema #372

Merged
merged 8 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions docs/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@
"items": {
"title": "rewardPercentile",
"description": "Floating point value between 0 and 100.",
"type": "number"
"type": "number",
"pattern": "^[0-9][0-9]?$|^100$"
}
}
}
Expand Down Expand Up @@ -159,7 +160,9 @@
"description": "An array of gas used ratio.",
"type": "array",
"items": {
"$ref": "#/components/schemas/uint"
"title": "hex encoded unsigned integer",
"type": "string",
"pattern": "^0x([1-9a-f]+[0-9a-f]*|0|0.8)$"
}
},
"baseFeePerGas": {
Expand Down Expand Up @@ -358,11 +361,7 @@
"result": {
"name": "Log objects",
"schema": {
"title": "Filter results",
"type": "array",
"items": {
"$ref": "#/components/schemas/FilterResults"
}
"$ref": "#/components/schemas/FilterResults"
}
}
},
Expand Down Expand Up @@ -460,10 +459,7 @@
"name": "Transaction count",
"schema": {
"title": "Transaction count",
"type": "array",
"items": {
"$ref": "#/components/schemas/uint"
}
"$ref": "#/components/schemas/uint"
}
}
},
Expand Down Expand Up @@ -683,7 +679,7 @@
"name": "The current client version.",
"schema": {
"type": "string",
"pattern": "relay/<semanticVersion>"
"pattern": "relay\/[0-9]\\.[0-9]\\.[0-9]"
}
}
}
Expand Down Expand Up @@ -1378,6 +1374,11 @@
"title": "Error message",
"type": "string",
"pattern": "Unsupported JSON-RPC method"
},
"name": {
"title": "Error name",
"type": "string",
"pattern": "Method not found"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"start": "npx lerna exec --scope @hashgraph/json-rpc-server -- npm run start",
"start:docker": "docker run --name hedera-relay -d -p 7546:7546 ${npm_package_name}:latest",
"test": "npx lerna run test",
"openrpctest": "ts-mocha packages/server/tests/integration/openrpc.spec.ts",
"openrpctest": "ts-mocha packages/relay/tests/lib/openrpc.spec.ts --exit",
"integration:prerequisite": "ts-node packages/server/tests/helpers/prerequisite.ts"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/relay/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export interface Eth {

getBlockByNumber(blockNum: string, showDetails: boolean): Promise<Block | null>;

getBlockTransactionCountByHash(hash: string): Promise<number | null>;
getBlockTransactionCountByHash(hash: string): Promise<string | null>;

getBlockTransactionCountByNumber(blockNum: string): Promise<number | null>
getBlockTransactionCountByNumber(blockNum: string): Promise<string | null>

getCode(address: string, blockNumber: string | null): Promise<string>;

Expand Down
18 changes: 9 additions & 9 deletions packages/relay/src/lib/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ export class EthImpl implements Eth {
*
* @param hash
*/
async getBlockTransactionCountByHash(hash: string): Promise<number | null> {
async getBlockTransactionCountByHash(hash: string): Promise<string | null> {
this.logger.trace('getBlockTransactionCountByHash(hash=%s, showDetails=%o)', hash);
return this.mirrorNodeClient
.getBlock(hash)
Expand All @@ -555,7 +555,7 @@ export class EthImpl implements Eth {
* Gets the number of transaction in a block by its block number.
* @param blockNumOrTag
*/
async getBlockTransactionCountByNumber(blockNumOrTag: string): Promise<number | null> {
async getBlockTransactionCountByNumber(blockNumOrTag: string): Promise<string | null> {
this.logger.trace('getBlockTransactionCountByNumber(blockNum=%s, showDetails=%o)', blockNumOrTag);
const blockNum = await this.translateBlockTag(blockNumOrTag);
return this.mirrorNodeClient
Expand Down Expand Up @@ -778,13 +778,13 @@ export class EthImpl implements Eth {
input: contractResult.function_parameters,
maxPriorityFeePerGas: maxPriorityFee,
maxFeePerGas: maxFee,
nonce: contractResult.nonce,
nonce: contractResult.nonce === null ? null : EthImpl.numberTo0x(contractResult.nonce),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Add a nullable param to EthImpl.numberTo0x().
With default true and use this logic here and a few places.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to create a new static function eg. EthImpl.nullableNumberTo0x. If we modify numberTo0x we will need to refactor/touch a lot of rpc methods because they rely on the returned type of numberTo0x to be a string

r: rSig,
s: sSig,
to: contractResult.to?.substring(0, 42),
transactionIndex: EthImpl.numberTo0x(contractResult.transaction_index),
type: contractResult.type,
v: contractResult.v,
type: contractResult.type === null ? null : EthImpl.numberTo0x(contractResult.type),
v: contractResult.v === null ? null : EthImpl.numberTo0x(contractResult.v),
value: EthImpl.numberTo0x(contractResult.amount),
});
}
Expand Down Expand Up @@ -997,7 +997,7 @@ export class EthImpl implements Eth {
return null;
}

return block.count;
return EthImpl.numberTo0x(block.count);
}

private getTransactionFromContractResults(contractResults: any) {
Expand Down Expand Up @@ -1033,13 +1033,13 @@ export class EthImpl implements Eth {
input: contractResultDetails.function_parameters,
maxPriorityFeePerGas: EthImpl.toNullIfEmptyHex(contractResultDetails.max_priority_fee_per_gas),
maxFeePerGas: EthImpl.toNullIfEmptyHex(contractResultDetails.max_fee_per_gas),
nonce: contractResultDetails.nonce,
nonce: contractResultDetails.nonce === null ? null : EthImpl.numberTo0x(contractResultDetails.nonce),
r: rSig,
s: sSig,
to: contractResultDetails.to.substring(0, 42),
transactionIndex: EthImpl.numberTo0x(contractResultDetails.transaction_index),
type: contractResultDetails.type,
v: contractResultDetails.v,
type: contractResultDetails.type === null ? null : EthImpl.numberTo0x(contractResultDetails.type),
v: contractResultDetails.v === null ? null : EthImpl.numberTo0x(contractResultDetails.v),
value: EthImpl.numberTo0x(contractResultDetails.amount),
});
})
Expand Down
Loading