cleanup and add args for json rpc
This commit is contained in:
parent
41d6f5ee38
commit
0e5ab2711f
4 changed files with 14 additions and 34 deletions
|
@ -25,6 +25,7 @@ type Args struct {
|
|||
EsPort string
|
||||
PrometheusPort string
|
||||
NotifierPort string
|
||||
JSONRPCPort string
|
||||
EsIndex string
|
||||
RefreshDelta int
|
||||
CacheTTL int
|
||||
|
@ -55,6 +56,7 @@ const (
|
|||
DefaultEsPort = "9200"
|
||||
DefaultPrometheusPort = "2112"
|
||||
DefaultNotifierPort = "18080"
|
||||
DefaultJSONRPCPort = "8080"
|
||||
DefaultRefreshDelta = 5
|
||||
DefaultCacheTTL = 5
|
||||
DefaultPeerFile = "peers.txt"
|
||||
|
@ -114,6 +116,7 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
|
|||
esPort := parser.String("", "esport", &argparse.Options{Required: false, Help: "elasticsearch port", Default: DefaultEsPort})
|
||||
prometheusPort := parser.String("", "prometheus-port", &argparse.Options{Required: false, Help: "prometheus port", Default: DefaultPrometheusPort})
|
||||
notifierPort := parser.String("", "notifier-port", &argparse.Options{Required: false, Help: "notifier port", Default: DefaultNotifierPort})
|
||||
jsonRPCPort := parser.String("", "json-rpc-port", &argparse.Options{Required: false, Help: "JSON RPC port", Default: DefaultJSONRPCPort})
|
||||
esIndex := parser.String("", "esindex", &argparse.Options{Required: false, Help: "elasticsearch index name", Default: DefaultEsIndex})
|
||||
refreshDelta := parser.Int("", "refresh-delta", &argparse.Options{Required: false, Help: "elasticsearch index refresh delta in seconds", Default: DefaultRefreshDelta})
|
||||
cacheTTL := parser.Int("", "cachettl", &argparse.Options{Required: false, Help: "Cache TTL in minutes", Default: DefaultCacheTTL})
|
||||
|
@ -160,6 +163,7 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
|
|||
EsPort: *esPort,
|
||||
PrometheusPort: *prometheusPort,
|
||||
NotifierPort: *notifierPort,
|
||||
JSONRPCPort: *jsonRPCPort,
|
||||
EsIndex: *esIndex,
|
||||
RefreshDelta: *refreshDelta,
|
||||
CacheTTL: *cacheTTL,
|
||||
|
|
|
@ -55,6 +55,7 @@ func makeDefaultArgs() *server.Args {
|
|||
EsPort: server.DefaultEsPort,
|
||||
PrometheusPort: server.DefaultPrometheusPort,
|
||||
NotifierPort: server.DefaultNotifierPort,
|
||||
JSONRPCPort: server.DefaultJSONRPCPort,
|
||||
EsIndex: server.DefaultEsIndex,
|
||||
RefreshDelta: server.DefaultRefreshDelta,
|
||||
CacheTTL: server.DefaultCacheTTL,
|
||||
|
|
|
@ -23,19 +23,20 @@ type Result struct {
|
|||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
//func (t *JSONServer) Resolve2(r *http.Request, args *ResolveData, result *Result) error {
|
||||
func (t *JSONServer) Resolve2(r *http.Request, args *ResolveData, result **pb.Outputs) error {
|
||||
log.Println("Resolve2")
|
||||
// Resolve is the json rpc endpoint for resolve
|
||||
func (t *JSONServer) Resolve(r *http.Request, args *ResolveData, result **pb.Outputs) error {
|
||||
log.Println("Resolve")
|
||||
res, err := InternalResolve(args.Data, t.DB)
|
||||
*result = res
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Server) StartJsonRPC111() error {
|
||||
// StartJsonRPC starts the json rpc server and registers the endpoints.
|
||||
func (s *Server) StartJsonRPC() error {
|
||||
server := new(JSONServer)
|
||||
server.DB = s.DB
|
||||
|
||||
port := ":8080"
|
||||
port := ":" + s.Args.JSONRPCPort
|
||||
|
||||
s1 := rpc.NewServer() // Create a new RPC server
|
||||
s1.RegisterCodec(json.NewCodec(), "application/json") // Register the type of data requested as JSON
|
||||
|
|
|
@ -310,7 +310,7 @@ func MakeHubServer(ctx context.Context, args *Args) *Server {
|
|||
}
|
||||
if !args.DisableStartJSONRPC {
|
||||
go func() {
|
||||
err := s.StartJsonRPC111()
|
||||
err := s.StartJsonRPC()
|
||||
if err != nil {
|
||||
log.Println("JSONRPC Server failed!", err)
|
||||
}
|
||||
|
@ -455,38 +455,12 @@ func (s *Server) HeightHashSubscribe() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Resolve is the gRPC endpoint for resolve.
|
||||
func (s *Server) Resolve(ctx context.Context, args *pb.StringArray) (*pb.Outputs, error) {
|
||||
// metrics.RequestsCount.With(prometheus.Labels{"method": "resolve"}).Inc()
|
||||
|
||||
// allTxos := make([]*pb.Output, 0)
|
||||
// allExtraTxos := make([]*pb.Output, 0)
|
||||
|
||||
// for _, url := range args.Value {
|
||||
// res := s.DB.Resolve(url)
|
||||
// txos, extraTxos, err := res.ToOutputs()
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// // TODO: there may be a more efficient way to do this.
|
||||
// allTxos = append(allTxos, txos...)
|
||||
// allExtraTxos = append(allExtraTxos, extraTxos...)
|
||||
// }
|
||||
|
||||
// res := &pb.Outputs{
|
||||
// Txos: allTxos,
|
||||
// ExtraTxos: allExtraTxos,
|
||||
// Total: uint32(len(allTxos) + len(allExtraTxos)),
|
||||
// Offset: 0, //TODO
|
||||
// Blocked: nil, //TODO
|
||||
// BlockedTotal: 0, //TODO
|
||||
// }
|
||||
|
||||
// logrus.Warn(res)
|
||||
|
||||
// return res, nil
|
||||
return InternalResolve(args.Value, s.DB)
|
||||
}
|
||||
|
||||
// InternalResolve takes an array of urls and resolves them to their transactions.
|
||||
func InternalResolve(urls []string, DB *db.ReadOnlyDBColumnFamily) (*pb.Outputs, error) {
|
||||
if DB == nil {
|
||||
return nil, errors.New("db is nil")
|
||||
|
|
Loading…
Reference in a new issue