herald.go/server/server.go

90 lines
1.9 KiB
Go
Raw Normal View History

2021-04-19 21:25:34 +02:00
package server
2021-03-18 22:14:56 +01:00
import (
2021-06-18 06:01:47 +02:00
"log"
"regexp"
2021-03-18 22:14:56 +01:00
pb "github.com/lbryio/hub/protobuf/go"
2021-06-04 07:56:50 +02:00
"github.com/olivere/elastic/v7"
"google.golang.org/grpc"
2021-03-18 22:14:56 +01:00
)
2021-04-19 21:25:34 +02:00
type Server struct {
2021-06-01 04:19:10 +02:00
GrpcServer *grpc.Server
Args *Args
MultiSpaceRe *regexp.Regexp
WeirdCharsRe *regexp.Regexp
2021-06-04 07:56:50 +02:00
EsClient *elastic.Client
2021-03-18 22:14:56 +01:00
pb.UnimplementedHubServer
}
type Args struct {
Serve bool
2021-06-10 02:04:06 +02:00
Host string
Port string
EsHost string
EsPort string
2021-06-10 02:04:06 +02:00
Dev bool
}
2021-03-18 22:14:56 +01:00
/*
'blockchain.block.get_chunk'
'blockchain.block.get_header'
'blockchain.estimatefee'
'blockchain.relayfee'
'blockchain.scripthash.get_balance'
'blockchain.scripthash.get_history'
'blockchain.scripthash.get_mempool'
'blockchain.scripthash.listunspent'
'blockchain.scripthash.subscribe'
'blockchain.transaction.broadcast'
'blockchain.transaction.get'
'blockchain.transaction.get_batch'
'blockchain.transaction.info'
'blockchain.transaction.get_merkle'
'server.add_peer'
'server.banner'
'server.payment_address'
'server.donation_address'
'server.features'
'server.peers.subscribe'
'server.version'
'blockchain.transaction.get_height'
'blockchain.claimtrie.search'
'blockchain.claimtrie.resolve'
'blockchain.claimtrie.getclaimsbyids'
'blockchain.block.get_server_height'
'mempool.get_fee_histogram'
'blockchain.block.headers'
'server.ping'
'blockchain.headers.subscribe'
'blockchain.address.get_balance'
'blockchain.address.get_history'
'blockchain.address.get_mempool'
'blockchain.address.listunspent'
'blockchain.address.subscribe'
'blockchain.address.unsubscribe'
*/
2021-06-01 04:19:10 +02:00
func MakeHubServer(args *Args) *Server {
grpcServer := grpc.NewServer()
multiSpaceRe, err := regexp.Compile("\\s{2,}")
if err != nil {
log.Fatal(err)
}
weirdCharsRe, err := regexp.Compile("[#!~]")
if err != nil {
log.Fatal(err)
}
s := &Server {
GrpcServer: grpcServer,
Args: args,
MultiSpaceRe: multiSpaceRe,
WeirdCharsRe: weirdCharsRe,
}
return s
2021-06-10 02:04:06 +02:00
}