github.com/adoriasoft/tendermint@v0.34.0-dev1.0.20200722151356-96d84601a75a/light/proxy/routes.go (about)

     1  package proxy
     2  
     3  import (
     4  	"github.com/tendermint/tendermint/libs/bytes"
     5  	lrpc "github.com/tendermint/tendermint/light/rpc"
     6  	ctypes "github.com/tendermint/tendermint/rpc/core/types"
     7  	rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server"
     8  	rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
     9  	"github.com/tendermint/tendermint/types"
    10  )
    11  
    12  func RPCRoutes(c *lrpc.Client) map[string]*rpcserver.RPCFunc {
    13  	return map[string]*rpcserver.RPCFunc{
    14  		// Subscribe/unsubscribe are reserved for websocket events.
    15  		"subscribe":       rpcserver.NewWSRPCFunc(c.SubscribeWS, "query"),
    16  		"unsubscribe":     rpcserver.NewWSRPCFunc(c.UnsubscribeWS, "query"),
    17  		"unsubscribe_all": rpcserver.NewWSRPCFunc(c.UnsubscribeAllWS, ""),
    18  
    19  		// info API
    20  		"health":               rpcserver.NewRPCFunc(makeHealthFunc(c), ""),
    21  		"status":               rpcserver.NewRPCFunc(makeStatusFunc(c), ""),
    22  		"net_info":             rpcserver.NewRPCFunc(makeNetInfoFunc(c), ""),
    23  		"blockchain":           rpcserver.NewRPCFunc(makeBlockchainInfoFunc(c), "minHeight,maxHeight"),
    24  		"genesis":              rpcserver.NewRPCFunc(makeGenesisFunc(c), ""),
    25  		"block":                rpcserver.NewRPCFunc(makeBlockFunc(c), "height"),
    26  		"block_by_hash":        rpcserver.NewRPCFunc(makeBlockByHashFunc(c), "hash"),
    27  		"block_results":        rpcserver.NewRPCFunc(makeBlockResultsFunc(c), "height"),
    28  		"commit":               rpcserver.NewRPCFunc(makeCommitFunc(c), "height"),
    29  		"tx":                   rpcserver.NewRPCFunc(makeTxFunc(c), "hash,prove"),
    30  		"tx_search":            rpcserver.NewRPCFunc(makeTxSearchFunc(c), "query,prove,page,per_page,order_by"),
    31  		"validators":           rpcserver.NewRPCFunc(makeValidatorsFunc(c), "height,page,per_page"),
    32  		"dump_consensus_state": rpcserver.NewRPCFunc(makeDumpConsensusStateFunc(c), ""),
    33  		"consensus_state":      rpcserver.NewRPCFunc(makeConsensusStateFunc(c), ""),
    34  		"consensus_params":     rpcserver.NewRPCFunc(makeConsensusParamsFunc(c), "height"),
    35  		"unconfirmed_txs":      rpcserver.NewRPCFunc(makeUnconfirmedTxsFunc(c), "limit"),
    36  		"num_unconfirmed_txs":  rpcserver.NewRPCFunc(makeNumUnconfirmedTxsFunc(c), ""),
    37  
    38  		// tx broadcast API
    39  		"broadcast_tx_commit": rpcserver.NewRPCFunc(makeBroadcastTxCommitFunc(c), "tx"),
    40  		"broadcast_tx_sync":   rpcserver.NewRPCFunc(makeBroadcastTxSyncFunc(c), "tx"),
    41  		"broadcast_tx_async":  rpcserver.NewRPCFunc(makeBroadcastTxAsyncFunc(c), "tx"),
    42  
    43  		// abci API
    44  		"abci_query": rpcserver.NewRPCFunc(makeABCIQueryFunc(c), "path,data,height,prove"),
    45  		"abci_info":  rpcserver.NewRPCFunc(makeABCIInfoFunc(c), ""),
    46  
    47  		// evidence API
    48  		"broadcast_evidence": rpcserver.NewRPCFunc(makeBroadcastEvidenceFunc(c), "evidence"),
    49  	}
    50  }
    51  
    52  type rpcHealthFunc func(ctx *rpctypes.Context) (*ctypes.ResultHealth, error)
    53  
    54  func makeHealthFunc(c *lrpc.Client) rpcHealthFunc {
    55  	return func(ctx *rpctypes.Context) (*ctypes.ResultHealth, error) {
    56  		return c.Health()
    57  	}
    58  }
    59  
    60  type rpcStatusFunc func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error)
    61  
    62  // nolint: interfacer
    63  func makeStatusFunc(c *lrpc.Client) rpcStatusFunc {
    64  	return func(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) {
    65  		return c.Status()
    66  	}
    67  }
    68  
    69  type rpcNetInfoFunc func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultNetInfo, error)
    70  
    71  func makeNetInfoFunc(c *lrpc.Client) rpcNetInfoFunc {
    72  	return func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultNetInfo, error) {
    73  		return c.NetInfo()
    74  	}
    75  }
    76  
    77  type rpcBlockchainInfoFunc func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error)
    78  
    79  func makeBlockchainInfoFunc(c *lrpc.Client) rpcBlockchainInfoFunc {
    80  	return func(ctx *rpctypes.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) {
    81  		return c.BlockchainInfo(minHeight, maxHeight)
    82  	}
    83  }
    84  
    85  type rpcGenesisFunc func(ctx *rpctypes.Context) (*ctypes.ResultGenesis, error)
    86  
    87  func makeGenesisFunc(c *lrpc.Client) rpcGenesisFunc {
    88  	return func(ctx *rpctypes.Context) (*ctypes.ResultGenesis, error) {
    89  		return c.Genesis()
    90  	}
    91  }
    92  
    93  type rpcBlockFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlock, error)
    94  
    95  func makeBlockFunc(c *lrpc.Client) rpcBlockFunc {
    96  	return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlock, error) {
    97  		return c.Block(height)
    98  	}
    99  }
   100  
   101  type rpcBlockByHashFunc func(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error)
   102  
   103  func makeBlockByHashFunc(c *lrpc.Client) rpcBlockByHashFunc {
   104  	return func(ctx *rpctypes.Context, hash []byte) (*ctypes.ResultBlock, error) {
   105  		return c.BlockByHash(hash)
   106  	}
   107  }
   108  
   109  type rpcBlockResultsFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlockResults, error)
   110  
   111  func makeBlockResultsFunc(c *lrpc.Client) rpcBlockResultsFunc {
   112  	return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultBlockResults, error) {
   113  		return c.BlockResults(height)
   114  	}
   115  }
   116  
   117  type rpcCommitFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultCommit, error)
   118  
   119  func makeCommitFunc(c *lrpc.Client) rpcCommitFunc {
   120  	return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultCommit, error) {
   121  		return c.Commit(height)
   122  	}
   123  }
   124  
   125  type rpcTxFunc func(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error)
   126  
   127  func makeTxFunc(c *lrpc.Client) rpcTxFunc {
   128  	return func(ctx *rpctypes.Context, hash []byte, prove bool) (*ctypes.ResultTx, error) {
   129  		return c.Tx(hash, prove)
   130  	}
   131  }
   132  
   133  type rpcTxSearchFunc func(ctx *rpctypes.Context, query string, prove bool,
   134  	page, perPage *int, orderBy string) (*ctypes.ResultTxSearch, error)
   135  
   136  func makeTxSearchFunc(c *lrpc.Client) rpcTxSearchFunc {
   137  	return func(ctx *rpctypes.Context, query string, prove bool, page, perPage *int, orderBy string) (
   138  		*ctypes.ResultTxSearch, error) {
   139  		return c.TxSearch(query, prove, page, perPage, orderBy)
   140  	}
   141  }
   142  
   143  type rpcValidatorsFunc func(ctx *rpctypes.Context, height *int64,
   144  	page, perPage *int) (*ctypes.ResultValidators, error)
   145  
   146  func makeValidatorsFunc(c *lrpc.Client) rpcValidatorsFunc {
   147  	return func(ctx *rpctypes.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error) {
   148  		return c.Validators(height, page, perPage)
   149  	}
   150  }
   151  
   152  type rpcDumpConsensusStateFunc func(ctx *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error)
   153  
   154  func makeDumpConsensusStateFunc(c *lrpc.Client) rpcDumpConsensusStateFunc {
   155  	return func(ctx *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error) {
   156  		return c.DumpConsensusState()
   157  	}
   158  }
   159  
   160  type rpcConsensusStateFunc func(ctx *rpctypes.Context) (*ctypes.ResultConsensusState, error)
   161  
   162  func makeConsensusStateFunc(c *lrpc.Client) rpcConsensusStateFunc {
   163  	return func(ctx *rpctypes.Context) (*ctypes.ResultConsensusState, error) {
   164  		return c.ConsensusState()
   165  	}
   166  }
   167  
   168  type rpcConsensusParamsFunc func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultConsensusParams, error)
   169  
   170  func makeConsensusParamsFunc(c *lrpc.Client) rpcConsensusParamsFunc {
   171  	return func(ctx *rpctypes.Context, height *int64) (*ctypes.ResultConsensusParams, error) {
   172  		return c.ConsensusParams(height)
   173  	}
   174  }
   175  
   176  type rpcUnconfirmedTxsFunc func(ctx *rpctypes.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error)
   177  
   178  func makeUnconfirmedTxsFunc(c *lrpc.Client) rpcUnconfirmedTxsFunc {
   179  	return func(ctx *rpctypes.Context, limit *int) (*ctypes.ResultUnconfirmedTxs, error) {
   180  		return c.UnconfirmedTxs(limit)
   181  	}
   182  }
   183  
   184  type rpcNumUnconfirmedTxsFunc func(ctx *rpctypes.Context) (*ctypes.ResultUnconfirmedTxs, error)
   185  
   186  func makeNumUnconfirmedTxsFunc(c *lrpc.Client) rpcNumUnconfirmedTxsFunc {
   187  	return func(ctx *rpctypes.Context) (*ctypes.ResultUnconfirmedTxs, error) {
   188  		return c.NumUnconfirmedTxs()
   189  	}
   190  }
   191  
   192  type rpcBroadcastTxCommitFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error)
   193  
   194  func makeBroadcastTxCommitFunc(c *lrpc.Client) rpcBroadcastTxCommitFunc {
   195  	return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
   196  		return c.BroadcastTxCommit(tx)
   197  	}
   198  }
   199  
   200  type rpcBroadcastTxSyncFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error)
   201  
   202  func makeBroadcastTxSyncFunc(c *lrpc.Client) rpcBroadcastTxSyncFunc {
   203  	return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
   204  		return c.BroadcastTxSync(tx)
   205  	}
   206  }
   207  
   208  type rpcBroadcastTxAsyncFunc func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error)
   209  
   210  func makeBroadcastTxAsyncFunc(c *lrpc.Client) rpcBroadcastTxAsyncFunc {
   211  	return func(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
   212  		return c.BroadcastTxAsync(tx)
   213  	}
   214  }
   215  
   216  type rpcABCIQueryFunc func(ctx *rpctypes.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error)
   217  
   218  func makeABCIQueryFunc(c *lrpc.Client) rpcABCIQueryFunc {
   219  	return func(ctx *rpctypes.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
   220  		return c.ABCIQuery(path, data)
   221  	}
   222  }
   223  
   224  type rpcABCIInfoFunc func(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error)
   225  
   226  func makeABCIInfoFunc(c *lrpc.Client) rpcABCIInfoFunc {
   227  	return func(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) {
   228  		return c.ABCIInfo()
   229  	}
   230  }
   231  
   232  type rpcBroadcastEvidenceFunc func(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error)
   233  
   234  // nolint: interfacer
   235  func makeBroadcastEvidenceFunc(c *lrpc.Client) rpcBroadcastEvidenceFunc {
   236  	return func(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) {
   237  		return c.BroadcastEvidence(ev)
   238  	}
   239  }