WIP: Resolve json rpc #57
|
@ -25,6 +25,7 @@ type Args struct {
|
||||||
EsPort string
|
EsPort string
|
||||||
PrometheusPort string
|
PrometheusPort string
|
||||||
NotifierPort string
|
NotifierPort string
|
||||||
|
JSONRPCPort string
|
||||||
EsIndex string
|
EsIndex string
|
||||||
RefreshDelta int
|
RefreshDelta int
|
||||||
CacheTTL int
|
CacheTTL int
|
||||||
|
@ -55,6 +56,7 @@ const (
|
||||||
DefaultEsPort = "9200"
|
DefaultEsPort = "9200"
|
||||||
DefaultPrometheusPort = "2112"
|
DefaultPrometheusPort = "2112"
|
||||||
DefaultNotifierPort = "18080"
|
DefaultNotifierPort = "18080"
|
||||||
|
DefaultJSONRPCPort = "8080"
|
||||||
DefaultRefreshDelta = 5
|
DefaultRefreshDelta = 5
|
||||||
DefaultCacheTTL = 5
|
DefaultCacheTTL = 5
|
||||||
DefaultPeerFile = "peers.txt"
|
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})
|
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})
|
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})
|
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})
|
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})
|
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})
|
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,
|
EsPort: *esPort,
|
||||||
PrometheusPort: *prometheusPort,
|
PrometheusPort: *prometheusPort,
|
||||||
NotifierPort: *notifierPort,
|
NotifierPort: *notifierPort,
|
||||||
|
JSONRPCPort: *jsonRPCPort,
|
||||||
EsIndex: *esIndex,
|
EsIndex: *esIndex,
|
||||||
RefreshDelta: *refreshDelta,
|
RefreshDelta: *refreshDelta,
|
||||||
CacheTTL: *cacheTTL,
|
CacheTTL: *cacheTTL,
|
||||||
|
|
|
@ -55,6 +55,7 @@ func makeDefaultArgs() *server.Args {
|
||||||
EsPort: server.DefaultEsPort,
|
EsPort: server.DefaultEsPort,
|
||||||
PrometheusPort: server.DefaultPrometheusPort,
|
PrometheusPort: server.DefaultPrometheusPort,
|
||||||
NotifierPort: server.DefaultNotifierPort,
|
NotifierPort: server.DefaultNotifierPort,
|
||||||
|
JSONRPCPort: server.DefaultJSONRPCPort,
|
||||||
EsIndex: server.DefaultEsIndex,
|
EsIndex: server.DefaultEsIndex,
|
||||||
RefreshDelta: server.DefaultRefreshDelta,
|
RefreshDelta: server.DefaultRefreshDelta,
|
||||||
CacheTTL: server.DefaultCacheTTL,
|
CacheTTL: server.DefaultCacheTTL,
|
||||||
|
|
|
@ -23,19 +23,20 @@ type Result struct {
|
||||||
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
JSON port number should be a new thing in args.go, defaulting to 50001. Then pass the args struct (or json parts of it) into StartJsonRPC111(). JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
|
|||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (t *JSONServer) Resolve2(r *http.Request, args *ResolveData, result *Result) error {
|
// Resolve is the json rpc endpoint for resolve
|
||||||
JSON port number should be a new thing in args.go, defaulting to 50001. Then pass the args struct (or json parts of it) into StartJsonRPC111(). JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
JSON port number should be a new thing in args.go, defaulting to 50001. Then pass the args struct (or json parts of it) into StartJsonRPC111(). JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
|
|||||||
func (t *JSONServer) Resolve2(r *http.Request, args *ResolveData, result **pb.Outputs) error {
|
func (t *JSONServer) Resolve(r *http.Request, args *ResolveData, result **pb.Outputs) error {
|
||||||
JSON port number should be a new thing in args.go, defaulting to 50001. Then pass the args struct (or json parts of it) into StartJsonRPC111(). JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
JSON port number should be a new thing in args.go, defaulting to 50001. Then pass the args struct (or json parts of it) into StartJsonRPC111(). JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
|
|||||||
log.Println("Resolve2")
|
log.Println("Resolve")
|
||||||
JSON port number should be a new thing in args.go, defaulting to 50001. Then pass the args struct (or json parts of it) into StartJsonRPC111(). JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
JSON port number should be a new thing in args.go, defaulting to 50001. Then pass the args struct (or json parts of it) into StartJsonRPC111(). JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
|
|||||||
res, err := InternalResolve(args.Data, t.DB)
|
res, err := InternalResolve(args.Data, t.DB)
|
||||||
*result = res
|
*result = res
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) StartJsonRPC111() error {
|
// StartJsonRPC starts the json rpc server and registers the endpoints.
|
||||||
JSON port number should be a new thing in args.go, defaulting to 50001. Then pass the args struct (or json parts of it) into StartJsonRPC111(). JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
JSON port number should be a new thing in args.go, defaulting to 50001. Then pass the args struct (or json parts of it) into StartJsonRPC111(). JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
|
|||||||
|
func (s *Server) StartJsonRPC() error {
|
||||||
JSON port number should be a new thing in args.go, defaulting to 50001. Then pass the args struct (or json parts of it) into StartJsonRPC111(). JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
|
|||||||
server := new(JSONServer)
|
server := new(JSONServer)
|
||||||
server.DB = s.DB
|
server.DB = s.DB
|
||||||
|
|
||||||
port := ":8080"
|
port := ":" + s.Args.JSONRPCPort
|
||||||
JSON port number should be a new thing in args.go, defaulting to 50001. Then pass the args struct (or json parts of it) into StartJsonRPC111(). JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
JSON port number should be a new thing in args.go, defaulting to 50001. Then pass the args struct (or json parts of it) into StartJsonRPC111(). JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
|
|||||||
|
|
||||||
s1 := rpc.NewServer() // Create a new RPC server
|
s1 := rpc.NewServer() // Create a new RPC server
|
||||||
s1.RegisterCodec(json.NewCodec(), "application/json") // Register the type of data requested as JSON
|
s1.RegisterCodec(json.NewCodec(), "application/json") // Register the type of data requested as JSON
|
||||||
|
|
||||||
JSON port number should be a new thing in args.go, defaulting to 50001. Then pass the args struct (or json parts of it) into StartJsonRPC111(). JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
JSON port number should be a new thing in args.go, defaulting to 50001. Then pass the args struct (or json parts of it) into StartJsonRPC111(). JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().
Yup, I just added that. It's already carried in through the Server struct. Yup, I just added that. It's already carried in through the Server struct.
|
|
@ -310,7 +310,7 @@ func MakeHubServer(ctx context.Context, args *Args) *Server {
|
||||||
}
|
}
|
||||||
if !args.DisableStartJSONRPC {
|
if !args.DisableStartJSONRPC {
|
||||||
go func() {
|
go func() {
|
||||||
err := s.StartJsonRPC111()
|
err := s.StartJsonRPC()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("JSONRPC Server failed!", err)
|
log.Println("JSONRPC Server failed!", err)
|
||||||
}
|
}
|
||||||
|
@ -455,38 +455,12 @@ func (s *Server) HeightHashSubscribe() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolve is the gRPC endpoint for resolve.
|
||||||
func (s *Server) Resolve(ctx context.Context, args *pb.StringArray) (*pb.Outputs, error) {
|
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)
|
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) {
|
func InternalResolve(urls []string, DB *db.ReadOnlyDBColumnFamily) (*pb.Outputs, error) {
|
||||||
if DB == nil {
|
if DB == nil {
|
||||||
return nil, errors.New("db is nil")
|
return nil, errors.New("db is nil")
|
||||||
|
|
JSON port number should be a new thing in args.go, defaulting to 50001.
Then pass the args struct (or json parts of it) into StartJsonRPC111().