From a97b28758e1067a221aaaae2fa5eae2a76977cee Mon Sep 17 00:00:00 2001 From: Javad Date: Wed, 7 Aug 2024 18:11:02 +0330 Subject: [PATCH] fix: add example json-rpc in generated docs --- Makefile | 1 - www/grpc/buf/json-rpc-md.tmpl | 52 +++++++++++++++++- www/grpc/gen/docs/grpc.md | 2 +- www/grpc/gen/docs/json-rpc.md | 54 ++++++++++++++++++- www/grpc/gen/go/blockchain.pb.go | 2 +- .../blockchain/BlockchainOuterClass.java | 10 ++-- www/grpc/gen/rust/pactus.rs | 2 +- www/grpc/swagger-ui/pactus.swagger.json | 2 +- 8 files changed, 112 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 28d1f8642..e0d85b568 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,6 @@ devtools: go install mvdan.cc/gofumpt@latest go install github.com/rakyll/statik@v0.1.7 go install github.com/pacviewer/jrpc-gateway/protoc-gen-jrpc-gateway@v0.3.2 - go install github.com/pacviewer/jrpc-gateway/protoc-gen-jrpc-doc/cmd/protoc-gen-jrpc-doc@v0.1.7 ######################################## ### Building diff --git a/www/grpc/buf/json-rpc-md.tmpl b/www/grpc/buf/json-rpc-md.tmpl index aef588647..bf2f37433 100644 --- a/www/grpc/buf/json-rpc-md.tmpl +++ b/www/grpc/buf/json-rpc-md.tmpl @@ -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 109 NanoPACs. -

JSON-RPC Services

+## 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 ' \ +--data '{ + "jsonrpc": "2.0", + "id": 1, + "method": "pactus.blockchain.get_account", + "params": { + "address": "pc1z2r0fmu8sg2ffa0tgrr08gnefcxl2kq7wvquf8z" + } +}' +``` + +

JSON-RPC Methods

    diff --git a/www/grpc/gen/docs/grpc.md b/www/grpc/gen/docs/grpc.md index f0250feec..4a5202701 100644 --- a/www/grpc/gen/docs/grpc.md +++ b/www/grpc/gen/docs/grpc.md @@ -1402,7 +1402,7 @@ Message has no fields. last_block_time int64 - The last block time as timestamp + Timestamp of the last block in Unix format diff --git a/www/grpc/gen/docs/json-rpc.md b/www/grpc/gen/docs/json-rpc.md index dd4ce6fec..af07bb94d 100644 --- a/www/grpc/gen/docs/json-rpc.md +++ b/www/grpc/gen/docs/json-rpc.md @@ -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 109 NanoPACs. -

    JSON-RPC Services

    +## 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 ' \ +--data '{ + "jsonrpc": "2.0", + "id": 1, + "method": "pactus.blockchain.get_account", + "params": { + "address": "pc1z2r0fmu8sg2ffa0tgrr08gnefcxl2kq7wvquf8z" + } +}' +``` + +

    JSON-RPC Methods

      @@ -1403,7 +1453,7 @@ Parameters has no fields. last_block_time numeric - The last block time as timestamp + Timestamp of the last block in Unix format diff --git a/www/grpc/gen/go/blockchain.pb.go b/www/grpc/gen/go/blockchain.pb.go index a13c249ca..54adbf252 100644 --- a/www/grpc/gen/go/blockchain.pb.go +++ b/www/grpc/gen/go/blockchain.pb.go @@ -982,7 +982,7 @@ type GetBlockchainInfoResponse struct { IsPruned bool `protobuf:"varint,8,opt,name=is_pruned,json=isPruned,proto3" json:"is_pruned,omitempty"` // Lowest-height block stored (only present if pruning is enabled) PruningHeight uint32 `protobuf:"varint,9,opt,name=pruning_height,json=pruningHeight,proto3" json:"pruning_height,omitempty"` - // The last block time as timestamp + // Timestamp of the last block in Unix format LastBlockTime int64 `protobuf:"varint,10,opt,name=last_block_time,json=lastBlockTime,proto3" json:"last_block_time,omitempty"` } diff --git a/www/grpc/gen/java/pactus/blockchain/BlockchainOuterClass.java b/www/grpc/gen/java/pactus/blockchain/BlockchainOuterClass.java index d8e174538..efb543008 100644 --- a/www/grpc/gen/java/pactus/blockchain/BlockchainOuterClass.java +++ b/www/grpc/gen/java/pactus/blockchain/BlockchainOuterClass.java @@ -10975,7 +10975,7 @@ pactus.blockchain.BlockchainOuterClass.ValidatorInfoOrBuilder getCommitteeValida /** *
      -     * The last block time as timestamp
      +     * Timestamp of the last block in Unix format
            * 
      * * int64 last_block_time = 10 [json_name = "lastBlockTime"]; @@ -11244,7 +11244,7 @@ public int getPruningHeight() { private long lastBlockTime_; /** *
      -     * The last block time as timestamp
      +     * Timestamp of the last block in Unix format
            * 
      * * int64 last_block_time = 10 [json_name = "lastBlockTime"]; @@ -12536,7 +12536,7 @@ public Builder clearPruningHeight() { private long lastBlockTime_ ; /** *
      -       * The last block time as timestamp
      +       * Timestamp of the last block in Unix format
              * 
      * * int64 last_block_time = 10 [json_name = "lastBlockTime"]; @@ -12548,7 +12548,7 @@ public long getLastBlockTime() { } /** *
      -       * The last block time as timestamp
      +       * Timestamp of the last block in Unix format
              * 
      * * int64 last_block_time = 10 [json_name = "lastBlockTime"]; @@ -12563,7 +12563,7 @@ public Builder setLastBlockTime(long value) { } /** *
      -       * The last block time as timestamp
      +       * Timestamp of the last block in Unix format
              * 
      * * int64 last_block_time = 10 [json_name = "lastBlockTime"]; diff --git a/www/grpc/gen/rust/pactus.rs b/www/grpc/gen/rust/pactus.rs index 36ce81831..897e4a1b0 100644 --- a/www/grpc/gen/rust/pactus.rs +++ b/www/grpc/gen/rust/pactus.rs @@ -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, } diff --git a/www/grpc/swagger-ui/pactus.swagger.json b/www/grpc/swagger-ui/pactus.swagger.json index a5f84b7c6..c7a3d6e1e 100644 --- a/www/grpc/swagger-ui/pactus.swagger.json +++ b/www/grpc/swagger-ui/pactus.swagger.json @@ -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."