WIP: Resolve json rpc #57
|
@ -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 {
|
|||
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"`
|
||||
}
|
||||
|
||||
//func (t *JSONServer) Resolve2(r *http.Request, args *ResolveData, result *Result) 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.
|
||||
func (t *JSONServer) Resolve2(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.
|
||||
log.Println("Resolve2")
|
||||
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.
|
||||
// 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.
|
||||
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.
|
||||
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.
|
||||
res, err := InternalResolve(args.Data, t.DB)
|
||||
*result = res
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Server) StartJsonRPC111() 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.
|
||||
// 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.
|
||||
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.DB = s.DB
|
||||
|
||||
port := ":8080"
|
||||
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.
|
||||
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.
|
||||
|
||||
s1 := rpc.NewServer() // Create a new RPC server
|
||||
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 {
|
||||
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")
|
||||
|
|
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().