github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/bft/rpc/core/abci.go (about)

     1  package core
     2  
     3  import (
     4  	abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types"
     5  	ctypes "github.com/gnolang/gno/tm2/pkg/bft/rpc/core/types"
     6  	rpctypes "github.com/gnolang/gno/tm2/pkg/bft/rpc/lib/types"
     7  )
     8  
     9  // Query the application for some information.
    10  //
    11  // ```shell
    12  // curl 'localhost:26657/abci_query?path=""&data="abcd"&prove=false'
    13  // ```
    14  //
    15  // ```go
    16  // client := client.NewHTTP("tcp://0.0.0.0:26657", "/websocket")
    17  // err := client.Start()
    18  //
    19  //	if err != nil {
    20  //	  // handle error
    21  //	}
    22  //
    23  // defer client.Stop()
    24  // result, err := client.ABCIQuery("", "abcd", true)
    25  // ```
    26  //
    27  // > The above command returns JSON structured like this:
    28  //
    29  // ```json
    30  //
    31  //	{
    32  //		"error": "",
    33  //		"result": {
    34  //			"response": {
    35  //				"log": "exists",
    36  //				"height": "0",
    37  //				"proof": "010114FED0DAD959F36091AD761C922ABA3CBF1D8349990101020103011406AA2262E2F448242DF2C2607C3CDC705313EE3B0001149D16177BC71E445476174622EA559715C293740C",
    38  //				"value": "61626364",
    39  //				"key": "61626364",
    40  //				"index": "-1",
    41  //				"code": "0"
    42  //			}
    43  //		},
    44  //		"id": "",
    45  //		"jsonrpc": "2.0"
    46  //	}
    47  //
    48  // ```
    49  //
    50  // ### Query Parameters
    51  //
    52  // | Parameter | Type   | Default | Required | Description                                    |
    53  // |-----------+--------+---------+----------+------------------------------------------------|
    54  // | path      | string | false   | false    | Path to the data ("/a/b/c")                    |
    55  // | data      | []byte | false   | true     | Data                                           |
    56  // | height    | int64  | 0       | false    | Height (0 means latest)                        |
    57  // | prove     | bool   | false   | false    | Includes proof if true                         |
    58  func ABCIQuery(ctx *rpctypes.Context, path string, data []byte, height int64, prove bool) (*ctypes.ResultABCIQuery, error) {
    59  	resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{
    60  		Path:   path,
    61  		Data:   data,
    62  		Height: height,
    63  		Prove:  prove,
    64  	})
    65  	if err != nil {
    66  		return nil, err
    67  	}
    68  	logger.Info("ABCIQuery", "path", path, "data", data, "result", resQuery)
    69  	return &ctypes.ResultABCIQuery{Response: resQuery}, nil
    70  }
    71  
    72  // Get some info about the application.
    73  //
    74  // ```shell
    75  // curl 'localhost:26657/abci_info'
    76  // ```
    77  //
    78  // ```go
    79  // client := client.NewHTTP("tcp://0.0.0.0:26657", "/websocket")
    80  // err := client.Start()
    81  //
    82  //	if err != nil {
    83  //	  // handle error
    84  //	}
    85  //
    86  // defer client.Stop()
    87  // info, err := client.ABCIInfo()
    88  // ```
    89  //
    90  // > The above command returns JSON structured like this:
    91  //
    92  // ```json
    93  //
    94  //	{
    95  //		"error": "",
    96  //		"result": {
    97  //			"response": {
    98  //				"data": "{\"size\":3}"
    99  //			}
   100  //		},
   101  //		"id": "",
   102  //		"jsonrpc": "2.0"
   103  //	}
   104  //
   105  // ```
   106  func ABCIInfo(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) {
   107  	resInfo, err := proxyAppQuery.InfoSync(abci.RequestInfo{})
   108  	if err != nil {
   109  		return nil, err
   110  	}
   111  	return &ctypes.ResultABCIInfo{Response: resInfo}, nil
   112  }