Skip to content

Commit

Permalink
fix(grpc): add example json-rpc in generated doc (#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ja7ad authored Aug 7, 2024
1 parent e0fb832 commit 98b228e
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 13 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ devtools:
go install mvdan.cc/gofumpt@latest
go install github.com/rakyll/[email protected]
go install github.com/pacviewer/jrpc-gateway/[email protected]
go install github.com/pacviewer/jrpc-gateway/protoc-gen-jrpc-doc/cmd/[email protected]

########################################
### Building
Expand Down
52 changes: 51 additions & 1 deletion www/grpc/buf/json-rpc-md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,57 @@ All the amounts and values in gRPC endpoints are in NanoPAC units,
which are atomic and the smallest unit in the Pactus blockchain.
Each PAC is equivalent to 1,000,000,000 or 10<sup>9</sup> NanoPACs.

<h2>JSON-RPC Services</h2>
## Example

To call JSON-RPC methods, you need to create the JSON-RPC request:

```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "pactus.network.get_node_info",
"params": {}
}
```

> Make sure you always add the `params` field, even if no parameters are needed, and ensure you use curly braces.

Then you use the `curl` command to send the request to the node:

```bash
curl --location 'http://localhost:8545/' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"id": 1,
"method": "pactus.network.get_node_info",
"params": {}
}'
```

> Before sending the request, you need to enable the JSON-RPC service inside the
> [configuration](/get-started/configuration/).

### Using Basic Auth

If you have enabled the [gRPC Basic Authentication](/tutorials/grpc-sign-transactions/),
then you need to set the `Authorization` header.

```bash
curl --location 'http://localhost:8545/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <BASIC-AUTH-TOKEN>' \
--data '{
"jsonrpc": "2.0",
"id": 1,
"method": "pactus.blockchain.get_account",
"params": {
"address": "pc1z2r0fmu8sg2ffa0tgrr08gnefcxl2kq7wvquf8z"
}
}'
```

<h2>JSON-RPC Methods</h2>

<div id="toc-container">
<ul class="">
Expand Down
2 changes: 1 addition & 1 deletion www/grpc/gen/docs/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ Message has no fields.
<td class="fw-bold">last_block_time</td>
<td> int64</td>
<td>
The last block time as timestamp
Timestamp of the last block in Unix format
</td>
</tr>
</tbody>
Expand Down
54 changes: 52 additions & 2 deletions www/grpc/gen/docs/json-rpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,57 @@ All the amounts and values in gRPC endpoints are in NanoPAC units,
which are atomic and the smallest unit in the Pactus blockchain.
Each PAC is equivalent to 1,000,000,000 or 10<sup>9</sup> NanoPACs.

<h2>JSON-RPC Services</h2>
## Example

To call JSON-RPC methods, you need to create the JSON-RPC request:

```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "pactus.network.get_node_info",
"params": {}
}
```

> Make sure you always add the `params` field, even if no parameters are needed, and ensure you use curly braces.
Then you use the `curl` command to send the request to the node:

```bash
curl --location 'http://localhost:8545/' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"id": 1,
"method": "pactus.network.get_node_info",
"params": {}
}'
```

> Before sending the request, you need to enable the JSON-RPC service inside the
> [configuration](/get-started/configuration/).
### Using Basic Auth

If you have enabled the [gRPC Basic Authentication](/tutorials/grpc-sign-transactions/),
then you need to set the `Authorization` header.

```bash
curl --location 'http://localhost:8545/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <BASIC-AUTH-TOKEN>' \
--data '{
"jsonrpc": "2.0",
"id": 1,
"method": "pactus.blockchain.get_account",
"params": {
"address": "pc1z2r0fmu8sg2ffa0tgrr08gnefcxl2kq7wvquf8z"
}
}'
```

<h2>JSON-RPC Methods</h2>

<div id="toc-container">
<ul class="">
Expand Down Expand Up @@ -1403,7 +1453,7 @@ Parameters has no fields.
<td class="fw-bold">last_block_time</td>
<td> numeric</td>
<td>
The last block time as timestamp
Timestamp of the last block in Unix format
</td>
</tr>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion www/grpc/gen/go/blockchain.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions www/grpc/gen/java/pactus/blockchain/BlockchainOuterClass.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion www/grpc/gen/rust/pactus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ pub struct GetBlockchainInfoResponse {
/// Lowest-height block stored (only present if pruning is enabled)
#[prost(uint32, tag="9")]
pub pruning_height: u32,
/// The last block time as timestamp
/// Timestamp of the last block in Unix format
#[prost(int64, tag="10")]
pub last_block_time: i64,
}
Expand Down
2 changes: 1 addition & 1 deletion www/grpc/swagger-ui/pactus.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@
"lastBlockTime": {
"type": "string",
"format": "int64",
"title": "The last block time as timestamp"
"title": "Timestamp of the last block in Unix format"
}
},
"description": "Message containing the response with general blockchain information."
Expand Down

0 comments on commit 98b228e

Please sign in to comment.