Esempio n. 1
0
func Routes(network *TendermintNetwork) map[string]*rpc.RPCFunc {
	return map[string]*rpc.RPCFunc{
		// subscribe/unsubscribe are reserved for websocket events.
		//	"subscribe":   rpc.NewWSRPCFunc(Subscribe, []string{"event"}),
		//	"unsubscribe": rpc.NewWSRPCFunc(Unsubscribe, []string{"event"}),

		"status":                 rpc.NewRPCFunc(StatusResult(network), ""),
		"get_chain":              rpc.NewRPCFunc(GetChainResult(network), "chainID"),
		"register_chain":         rpc.NewRPCFunc(RegisterChainResult(network), "chainConfig"),
		"validator_set":          rpc.NewRPCFunc(GetValidatorSetResult(network), "valsetID"),
		"register_validator_set": rpc.NewRPCFunc(RegisterValidatorSetResult(network), "valSetID"),
		"validator":              rpc.NewRPCFunc(GetValidatorResult(network), "valSetID,valID"),
		"update_validator":       rpc.NewRPCFunc(UpdateValidatorResult(network), "chainID,valID,rpcAddr"),

		"start_meter": rpc.NewRPCFunc(network.StartMeter, "chainID,valID,event"),
		"stop_meter":  rpc.NewRPCFunc(network.StopMeter, "chainID,valID,event"),
		"meter":       rpc.NewRPCFunc(GetMeterResult(network), "chainID,valID,event"),
	}
}
Esempio n. 2
0
package core

import (
	rpc "github.com/tendermint/go-rpc/server"
	"github.com/tendermint/go-rpc/types"
	ctypes "github.com/tendermint/tendermint/rpc/core/types"
)

// TODO: eliminate redundancy between here and reading code from core/
var Routes = map[string]*rpc.RPCFunc{
	"subscribe":            rpc.NewWSRPCFunc(SubscribeResult, "event"),
	"unsubscribe":          rpc.NewWSRPCFunc(UnsubscribeResult, "event"),
	"status":               rpc.NewRPCFunc(StatusResult, ""),
	"net_info":             rpc.NewRPCFunc(NetInfoResult, ""),
	"dial_seeds":           rpc.NewRPCFunc(DialSeedsResult, "seeds"),
	"blockchain":           rpc.NewRPCFunc(BlockchainInfoResult, "minHeight,maxHeight"),
	"genesis":              rpc.NewRPCFunc(GenesisResult, ""),
	"block":                rpc.NewRPCFunc(BlockResult, "height"),
	"validators":           rpc.NewRPCFunc(ValidatorsResult, ""),
	"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusStateResult, ""),
	"broadcast_tx_sync":    rpc.NewRPCFunc(BroadcastTxSyncResult, "tx"),
	"broadcast_tx_async":   rpc.NewRPCFunc(BroadcastTxAsyncResult, "tx"),
	"unconfirmed_txs":      rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
	// subscribe/unsubscribe are reserved for websocket events.
}

func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
	if r, err := Subscribe(wsCtx, event); err != nil {
		return nil, err
	} else {
		return r, nil
Esempio n. 3
0
package core

import (
	rpc "github.com/tendermint/go-rpc/server"
	"github.com/tendermint/go-rpc/types"
	ctypes "github.com/tendermint/tendermint/rpc/core/types"
)

var Routes = map[string]*rpc.RPCFunc{
	// subscribe/unsubscribe are reserved for websocket events.
	"subscribe":   rpc.NewWSRPCFunc(SubscribeResult, "event"),
	"unsubscribe": rpc.NewWSRPCFunc(UnsubscribeResult, "event"),

	"status":               rpc.NewRPCFunc(StatusResult, ""),
	"net_info":             rpc.NewRPCFunc(NetInfoResult, ""),
	"dial_seeds":           rpc.NewRPCFunc(DialSeedsResult, "seeds"),
	"blockchain":           rpc.NewRPCFunc(BlockchainInfoResult, "minHeight,maxHeight"),
	"genesis":              rpc.NewRPCFunc(GenesisResult, ""),
	"block":                rpc.NewRPCFunc(BlockResult, "height"),
	"validators":           rpc.NewRPCFunc(ValidatorsResult, ""),
	"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusStateResult, ""),
	"broadcast_tx_sync":    rpc.NewRPCFunc(BroadcastTxSyncResult, "tx"),
	"broadcast_tx_async":   rpc.NewRPCFunc(BroadcastTxAsyncResult, "tx"),
	"unconfirmed_txs":      rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
	"num_unconfirmed_txs":  rpc.NewRPCFunc(NumUnconfirmedTxsResult, ""),

	"unsafe_set_config":         rpc.NewRPCFunc(UnsafeSetConfigResult, "type,key,value"),
	"unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfilerResult, "filename"),
	"unsafe_stop_cpu_profiler":  rpc.NewRPCFunc(UnsafeStopCPUProfilerResult, ""),
	"unsafe_write_heap_profile": rpc.NewRPCFunc(UnsafeWriteHeapProfileResult, "filename"),
}
Esempio n. 4
0
package core

import (
	rpc "github.com/tendermint/go-rpc/server"
	"github.com/tendermint/go-rpc/types"
	ctypes "github.com/tendermint/tendermint/rpc/core/types"
)

// TODO: eliminate redundancy between here and reading code from core/
var Routes = map[string]*rpc.RPCFunc{
	"subscribe":            rpc.NewWSRPCFunc(SubscribeResult, "event"),
	"unsubscribe":          rpc.NewWSRPCFunc(UnsubscribeResult, "event"),
	"status":               rpc.NewRPCFunc(StatusResult, ""),
	"net_info":             rpc.NewRPCFunc(NetInfoResult, ""),
	"blockchain":           rpc.NewRPCFunc(BlockchainInfoResult, "minHeight,maxHeight"),
	"genesis":              rpc.NewRPCFunc(GenesisResult, ""),
	"get_block":            rpc.NewRPCFunc(GetBlockResult, "height"),
	"list_validators":      rpc.NewRPCFunc(ListValidatorsResult, ""),
	"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusStateResult, ""),
	"broadcast_tx":         rpc.NewRPCFunc(BroadcastTxResult, "tx"),
	"list_unconfirmed_txs": rpc.NewRPCFunc(ListUnconfirmedTxsResult, ""),
	// subscribe/unsubscribe are reserved for websocket events.
}

func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
	if r, err := Subscribe(wsCtx, event); err != nil {
		return nil, err
	} else {
		return r, nil
	}
}
Esempio n. 5
0
package main

import (
	"fmt"
	"net/http"

	. "github.com/tendermint/go-common"
	rpcserver "github.com/tendermint/go-rpc/server"
)

var routes = map[string]*rpcserver.RPCFunc{
	"hello_world": rpcserver.NewRPCFunc(HelloWorld, "name,num"),
}

func HelloWorld(name string, num int) (Result, error) {
	return Result{fmt.Sprintf("hi %s %d", name, num)}, nil
}

type Result struct {
	Result string
}

func main() {
	mux := http.NewServeMux()
	rpcserver.RegisterRPCFuncs(mux, routes)
	_, err := rpcserver.StartHTTPServer("0.0.0.0:8008", mux)
	if err != nil {
		Exit(err.Error())
	}

	// Wait forever