2021-04-19 21:25:34 +02:00
|
|
|
package server
|
2021-03-18 22:14:56 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
pb "github.com/lbryio/hub/protobuf/go"
|
2021-06-04 07:56:50 +02:00
|
|
|
"github.com/olivere/elastic/v7"
|
2021-05-25 02:09:28 +02:00
|
|
|
"google.golang.org/grpc"
|
2021-05-31 03:34:57 +02:00
|
|
|
"log"
|
2021-06-01 04:19:10 +02:00
|
|
|
"regexp"
|
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
|
|
|
|
}
|
|
|
|
|
2021-05-25 02:09:28 +02:00
|
|
|
type Args struct {
|
2021-05-25 05:28:43 +02:00
|
|
|
Serve bool
|
2021-06-10 02:04:06 +02:00
|
|
|
Host string
|
2021-05-25 02:09:28 +02:00
|
|
|
Port string
|
2021-06-04 18:38:17 +02:00
|
|
|
EsHost string
|
|
|
|
EsPort string
|
2021-06-10 02:04:06 +02:00
|
|
|
Dev bool
|
2021-05-25 02:09:28 +02:00
|
|
|
}
|
|
|
|
|
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-05-25 02:09:28 +02:00
|
|
|
|
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
|
|
|
}
|