In this section we will use an Akash deployments query as an example of:
- General use of the Akash API repository within custom code
- Explore Akash API Go code generated thru protoc
- Using the Protobuf generated gateway for blockchain queries
- Sending receipt of Protobuf messages with HTTP API requests to Akash RPC nodes
Sections Within This Guide
gRPC Gateway Use
The Protobuf generated gRPC gateway creates a HTTP handler for upstream gRPC queries. The gRPC gateway provides an interface for clients incapable of using gRPC calls directly. In this guide we use the gRPC source code for blockchain queries to remove friction and ease of development.
The gRPC gateway definitions used on our example query of Akash deployments are located here.
Example gRPC Gateway Use and Deep Dive Explanations
Subsections within Code Exploration
Complete Code Example - Query Deployments with Owner Filter
NOTE - prior to execution of this code ensure package dependencies mirror those found in the source code repo
go.mod
file here
Deep Code Exploration Using Query Deployments Example
Protoc Generated Go Code Overview
- Within the example Deployments blockchain query we make use of:
NOTE - the protoc generated Go files used in our custom code examples are the same type definitions used throughout Akash source code. For example - the Akash CLI source code and specifically Deployment/Deployments queries are defined here. Within the referenced file and CLI client definitions the types located in
github.com/akash-network/akash-api/go/node/deployment/v1beta3
are utilized. These are the same definitions and types we we use in this custom client code example.
Protoc Generated File Deepdive
- The example Deployments Query code uses the protoc generated gRPC gateway
- The gRPC gateway registers the DeploymentsQuery endpoint
- For DeploymentsQuery the HTTP GET request requires the following attributes in the payload with associated values for our use case:
-
"path":"/akash.deployment.v1beta3.Query/Deployments"
-
"data"
- protobuf encoded message
-
Custom/Relevant Code
- Utilize the protoc generated Go type of
QueryDeploymentsRequest
- Embed protobuf encoded payload in HTTP request to gRPC gateway
QueryDeploymentsRequest Type
- Source code for this type is located here