mirror of
https://github.com/LBRYFoundation/herald.go.git
synced 2025-09-30 15:10:33 +00:00
Started porting blockchain.block.get_header
This commit is contained in:
parent
228fc6f54b
commit
e5225a5b58
10 changed files with 693 additions and 52 deletions
1
go.mod
1
go.mod
|
@ -8,6 +8,7 @@ require (
|
|||
github.com/golang/protobuf v1.5.2
|
||||
github.com/lbryio/lbry.go/v2 v2.7.2-0.20210625145058-2b155597bf57
|
||||
github.com/olivere/elastic/v7 v7.0.24
|
||||
github.com/ybbus/jsonrpc/v2 v2.1.6 // indirect
|
||||
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
|
||||
golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea // indirect
|
||||
golang.org/x/text v0.3.6
|
||||
|
|
4
go.sum
4
go.sum
|
@ -103,6 +103,7 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
|
|||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
|
@ -132,7 +133,10 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
|
|||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/ybbus/jsonrpc v0.0.0-20180411222309-2a548b7d822d h1:tQo6hjclyv3RHUgZOl6iWb2Y44A/sN9bf9LAYfuioEg=
|
||||
github.com/ybbus/jsonrpc v0.0.0-20180411222309-2a548b7d822d/go.mod h1:XJrh1eMSzdIYFbM08flv0wp5G35eRniyeGut1z+LSiE=
|
||||
github.com/ybbus/jsonrpc/v2 v2.1.6 h1:++pboiaaD6TZ9FJ1JOBBRB/tPtR1njYzqz1iSZGv+3Y=
|
||||
github.com/ybbus/jsonrpc/v2 v2.1.6/go.mod h1:rIuG1+ORoiqocf9xs/v+ecaAVeo3zcZHQgInyKFMeg0=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
|
|
72
main.go
72
main.go
|
@ -43,12 +43,29 @@ func GetEnvironmentStandard() map[string]string {
|
|||
})
|
||||
}
|
||||
|
||||
func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
|
||||
/*
|
||||
func makeServeCmd(parser *argparse.Parser) *argparse.Command {
|
||||
serveCmd := parser.NewCommand("serve", "start the hub server")
|
||||
|
||||
host := serveCmd.String("", "rpchost", &argparse.Options{Required: false, Help: "host", Default: defaultHost})
|
||||
port := serveCmd.String("", "rpcport", &argparse.Options{Required: false, Help: "port", Default: defaultPort})
|
||||
esHost := serveCmd.String("", "eshost", &argparse.Options{Required: false, Help: "host", Default: defaultEsHost})
|
||||
esPort := serveCmd.String("", "esport", &argparse.Options{Required: false, Help: "port", Default: defaultEsPort})
|
||||
dev := serveCmd.Flag("", "dev", &argparse.Options{Required: false, Help: "port", Default: false})
|
||||
|
||||
return serveCmd
|
||||
}
|
||||
*/
|
||||
|
||||
func parseArgs(searchRequest *pb.SearchRequest, blockReq *pb.BlockRequest) *server.Args {
|
||||
|
||||
environment := GetEnvironmentStandard()
|
||||
parser := argparse.NewParser("hub", "hub server and client")
|
||||
|
||||
serveCmd := parser.NewCommand("serve", "start the hub server")
|
||||
searchCmd := parser.NewCommand("search", "claim search")
|
||||
getblockCmd := parser.NewCommand("getblock", "get block")
|
||||
getblockHeaderCmd := parser.NewCommand("getblockheader", "get block header")
|
||||
|
||||
host := parser.String("", "rpchost", &argparse.Options{Required: false, Help: "host", Default: defaultHost})
|
||||
port := parser.String("", "rpcport", &argparse.Options{Required: false, Help: "port", Default: defaultPort})
|
||||
|
@ -66,6 +83,8 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
|
|||
channelId := parser.String("", "channel_id", &argparse.Options{Required: false, Help: "channel id"})
|
||||
channelIds := parser.StringList("", "channel_ids", &argparse.Options{Required: false, Help: "channel ids"})
|
||||
|
||||
hash := parser.String("", "hash", &argparse.Options{Required: false, Help: "block hash"})
|
||||
|
||||
// Now parse the arguments
|
||||
err := parser.Parse(os.Args)
|
||||
if err != nil {
|
||||
|
@ -74,7 +93,7 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
|
|||
|
||||
|
||||
args := &server.Args{
|
||||
Serve: false,
|
||||
CmdType: server.SearchCmd,
|
||||
Host: *host,
|
||||
Port: ":" + *port,
|
||||
EsHost: *esHost,
|
||||
|
@ -102,7 +121,15 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
|
|||
}
|
||||
|
||||
if serveCmd.Happened() {
|
||||
args.Serve = true
|
||||
args.CmdType = server.ServeCmd
|
||||
} else if searchCmd.Happened() {
|
||||
args.CmdType = server.SearchCmd
|
||||
} else if getblockCmd.Happened() {
|
||||
args.CmdType = server.GetblockCmd
|
||||
blockReq.Verbose = true
|
||||
} else if getblockHeaderCmd.Happened() {
|
||||
args.CmdType = server.GetblockHeaderCmd
|
||||
blockReq.Verbose = true
|
||||
}
|
||||
|
||||
if *text != "" {
|
||||
|
@ -133,15 +160,20 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
|
|||
searchRequest.ChannelId = &pb.InvertibleField{Invert: false, Value: *channelIds}
|
||||
}
|
||||
|
||||
if *hash != "" {
|
||||
blockReq.Blockhash = *hash
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
func main() {
|
||||
searchRequest := &pb.SearchRequest{}
|
||||
blockReq := &pb.BlockRequest{}
|
||||
|
||||
args := parseArgs(searchRequest)
|
||||
args := parseArgs(searchRequest, blockReq)
|
||||
|
||||
if args.Serve {
|
||||
if args.CmdType == server.ServeCmd {
|
||||
|
||||
l, err := net.Listen("tcp", args.Port)
|
||||
if err != nil {
|
||||
|
@ -174,15 +206,29 @@ func main() {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
|
||||
log.Println(args)
|
||||
if args.CmdType == server.SearchCmd {
|
||||
r, err := c.Search(ctx, searchRequest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
r, err := c.Search(ctx, searchRequest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("found %d results\n", r.GetTotal())
|
||||
|
||||
log.Printf("found %d results\n", r.GetTotal())
|
||||
|
||||
for _, t := range r.Txos {
|
||||
fmt.Printf("%s:%d\n", util.TxHashToTxId(t.TxHash), t.Nout)
|
||||
for _, t := range r.Txos {
|
||||
fmt.Printf("%s:%d\n", util.TxHashToTxId(t.TxHash), t.Nout)
|
||||
}
|
||||
} else if args.CmdType == server.GetblockCmd {
|
||||
r, err := c.GetBlock(ctx, blockReq)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println(r)
|
||||
} else if args.CmdType == server.GetblockHeaderCmd {
|
||||
r, err := c.GetBlockHeader(ctx, blockReq)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println(r)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ package pb;
|
|||
|
||||
service Hub {
|
||||
rpc Search (SearchRequest) returns (Outputs) {}
|
||||
rpc GetBlock (BlockRequest) returns (BlockOutput) {}
|
||||
rpc GetBlockHeader (BlockRequest) returns (BlockHeaderOutput) {}
|
||||
}
|
||||
|
||||
message InvertibleField {
|
||||
|
@ -93,4 +95,9 @@ message SearchRequest {
|
|||
.google.protobuf.BoolValue remove_duplicates = 76;
|
||||
.google.protobuf.BoolValue no_totals = 77;
|
||||
repeated string search_indices = 78;
|
||||
}
|
||||
|
||||
message BlockRequest {
|
||||
string blockhash = 1;
|
||||
bool verbose = 2;
|
||||
}
|
|
@ -60,3 +60,44 @@ message Blocked {
|
|||
uint32 count = 1;
|
||||
Output channel = 2;
|
||||
}
|
||||
|
||||
message BlockOutput {
|
||||
string hash = 1;
|
||||
int32 confirmations = 2;
|
||||
}
|
||||
/*
|
||||
{ (json object)
|
||||
"hash" : "hex", (string) the block hash (same as provided)
|
||||
"confirmations" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain
|
||||
"height" : n, (numeric) The block height or index
|
||||
"version" : n, (numeric) The block version
|
||||
"versionHex" : "hex", (string) The block version formatted in hexadecimal
|
||||
"merkleroot" : "hex", (string) The merkle root
|
||||
"time" : xxx, (numeric) The block time expressed in UNIX epoch time
|
||||
"mediantime" : xxx, (numeric) The median block time expressed in UNIX epoch time
|
||||
"nonce" : n, (numeric) The nonce
|
||||
"bits" : "hex", (string) The bits
|
||||
"difficulty" : n, (numeric) The difficulty
|
||||
"chainwork" : "hex", (string) Expected number of hashes required to produce the current chain
|
||||
"nTx" : n, (numeric) The number of transactions in the block
|
||||
"previousblockhash" : "hex", (string) The hash of the previous block
|
||||
"nextblockhash" : "hex" (string) The hash of the next block
|
||||
}
|
||||
*/
|
||||
message BlockHeaderOutput {
|
||||
string hash = 1;
|
||||
int64 confirmations = 2;
|
||||
int64 height = 3;
|
||||
int64 version = 4;
|
||||
string versionHex = 5;
|
||||
string merkleroot = 6;
|
||||
int64 time = 7;
|
||||
int64 mediantime = 8;
|
||||
int64 nonce = 9;
|
||||
string bits = 10;
|
||||
double difficulty = 11;
|
||||
string chainwork = 12;
|
||||
int64 nTx = 13;
|
||||
string previousblockhash = 14;
|
||||
string nextblockhash = 15;
|
||||
}
|
|
@ -745,6 +745,61 @@ func (x *SearchRequest) GetSearchIndices() []string {
|
|||
return nil
|
||||
}
|
||||
|
||||
type BlockRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Blockhash string `protobuf:"bytes,1,opt,name=blockhash,proto3" json:"blockhash"`
|
||||
Verbose bool `protobuf:"varint,2,opt,name=verbose,proto3" json:"verbose"`
|
||||
}
|
||||
|
||||
func (x *BlockRequest) Reset() {
|
||||
*x = BlockRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_hub_proto_msgTypes[3]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *BlockRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*BlockRequest) ProtoMessage() {}
|
||||
|
||||
func (x *BlockRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_hub_proto_msgTypes[3]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use BlockRequest.ProtoReflect.Descriptor instead.
|
||||
func (*BlockRequest) Descriptor() ([]byte, []int) {
|
||||
return file_hub_proto_rawDescGZIP(), []int{3}
|
||||
}
|
||||
|
||||
func (x *BlockRequest) GetBlockhash() string {
|
||||
if x != nil {
|
||||
return x.Blockhash
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *BlockRequest) GetVerbose() bool {
|
||||
if x != nil {
|
||||
return x.Verbose
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var File_hub_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_hub_proto_rawDesc = []byte{
|
||||
|
@ -947,13 +1002,24 @@ var file_hub_proto_rawDesc = []byte{
|
|||
0x52, 0x08, 0x6e, 0x6f, 0x54, 0x6f, 0x74, 0x61, 0x6c, 0x73, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x65,
|
||||
0x61, 0x72, 0x63, 0x68, 0x5f, 0x69, 0x6e, 0x64, 0x69, 0x63, 0x65, 0x73, 0x18, 0x4e, 0x20, 0x03,
|
||||
0x28, 0x09, 0x52, 0x0d, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x49, 0x6e, 0x64, 0x69, 0x63, 0x65,
|
||||
0x73, 0x32, 0x31, 0x0a, 0x03, 0x48, 0x75, 0x62, 0x12, 0x2a, 0x0a, 0x06, 0x53, 0x65, 0x61, 0x72,
|
||||
0x63, 0x68, 0x12, 0x11, 0x2e, 0x70, 0x62, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65,
|
||||
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0b, 0x2e, 0x70, 0x62, 0x2e, 0x4f, 0x75, 0x74, 0x70, 0x75,
|
||||
0x74, 0x73, 0x22, 0x00, 0x42, 0x26, 0x5a, 0x24, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63,
|
||||
0x6f, 0x6d, 0x2f, 0x6c, 0x62, 0x72, 0x79, 0x69, 0x6f, 0x2f, 0x68, 0x75, 0x62, 0x2f, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x67, 0x6f, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x33,
|
||||
0x73, 0x22, 0x46, 0x0a, 0x0c, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
|
||||
0x74, 0x12, 0x1c, 0x0a, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x68, 0x61, 0x73, 0x68, 0x12,
|
||||
0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x62, 0x6f, 0x73, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08,
|
||||
0x52, 0x07, 0x76, 0x65, 0x72, 0x62, 0x6f, 0x73, 0x65, 0x32, 0x9f, 0x01, 0x0a, 0x03, 0x48, 0x75,
|
||||
0x62, 0x12, 0x2a, 0x0a, 0x06, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x12, 0x11, 0x2e, 0x70, 0x62,
|
||||
0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0b,
|
||||
0x2e, 0x70, 0x62, 0x2e, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x73, 0x22, 0x00, 0x12, 0x2f, 0x0a,
|
||||
0x08, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x10, 0x2e, 0x70, 0x62, 0x2e, 0x42,
|
||||
0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0f, 0x2e, 0x70, 0x62,
|
||||
0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x22, 0x00, 0x12, 0x3b,
|
||||
0x0a, 0x0e, 0x47, 0x65, 0x74, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72,
|
||||
0x12, 0x10, 0x2e, 0x70, 0x62, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65,
|
||||
0x73, 0x74, 0x1a, 0x15, 0x2e, 0x70, 0x62, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x61,
|
||||
0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x22, 0x00, 0x42, 0x26, 0x5a, 0x24, 0x67,
|
||||
0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x62, 0x72, 0x79, 0x69, 0x6f,
|
||||
0x2f, 0x68, 0x75, 0x62, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x67, 0x6f,
|
||||
0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -969,22 +1035,25 @@ func file_hub_proto_rawDescGZIP() []byte {
|
|||
}
|
||||
|
||||
var file_hub_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||
var file_hub_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
|
||||
var file_hub_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
|
||||
var file_hub_proto_goTypes = []interface{}{
|
||||
(RangeField_Op)(0), // 0: pb.RangeField.Op
|
||||
(*InvertibleField)(nil), // 1: pb.InvertibleField
|
||||
(*RangeField)(nil), // 2: pb.RangeField
|
||||
(*SearchRequest)(nil), // 3: pb.SearchRequest
|
||||
(*wrapperspb.Int32Value)(nil), // 4: google.protobuf.Int32Value
|
||||
(*wrapperspb.BoolValue)(nil), // 5: google.protobuf.BoolValue
|
||||
(*Outputs)(nil), // 6: pb.Outputs
|
||||
(*BlockRequest)(nil), // 4: pb.BlockRequest
|
||||
(*wrapperspb.Int32Value)(nil), // 5: google.protobuf.Int32Value
|
||||
(*wrapperspb.BoolValue)(nil), // 6: google.protobuf.BoolValue
|
||||
(*Outputs)(nil), // 7: pb.Outputs
|
||||
(*BlockOutput)(nil), // 8: pb.BlockOutput
|
||||
(*BlockHeaderOutput)(nil), // 9: pb.BlockHeaderOutput
|
||||
}
|
||||
var file_hub_proto_depIdxs = []int32{
|
||||
0, // 0: pb.RangeField.op:type_name -> pb.RangeField.Op
|
||||
4, // 1: pb.SearchRequest.amount_order:type_name -> google.protobuf.Int32Value
|
||||
4, // 2: pb.SearchRequest.limit:type_name -> google.protobuf.Int32Value
|
||||
4, // 3: pb.SearchRequest.offset:type_name -> google.protobuf.Int32Value
|
||||
5, // 4: pb.SearchRequest.is_controlling:type_name -> google.protobuf.BoolValue
|
||||
5, // 1: pb.SearchRequest.amount_order:type_name -> google.protobuf.Int32Value
|
||||
5, // 2: pb.SearchRequest.limit:type_name -> google.protobuf.Int32Value
|
||||
5, // 3: pb.SearchRequest.offset:type_name -> google.protobuf.Int32Value
|
||||
6, // 4: pb.SearchRequest.is_controlling:type_name -> google.protobuf.BoolValue
|
||||
1, // 5: pb.SearchRequest.claim_id:type_name -> pb.InvertibleField
|
||||
2, // 6: pb.SearchRequest.tx_position:type_name -> pb.RangeField
|
||||
2, // 7: pb.SearchRequest.amount:type_name -> pb.RangeField
|
||||
|
@ -1000,7 +1069,7 @@ var file_hub_proto_depIdxs = []int32{
|
|||
2, // 17: pb.SearchRequest.duration:type_name -> pb.RangeField
|
||||
2, // 18: pb.SearchRequest.censor_type:type_name -> pb.RangeField
|
||||
2, // 19: pb.SearchRequest.channel_join:type_name -> pb.RangeField
|
||||
5, // 20: pb.SearchRequest.signature_valid:type_name -> google.protobuf.BoolValue
|
||||
6, // 20: pb.SearchRequest.signature_valid:type_name -> google.protobuf.BoolValue
|
||||
2, // 21: pb.SearchRequest.effective_amount:type_name -> pb.RangeField
|
||||
2, // 22: pb.SearchRequest.support_amount:type_name -> pb.RangeField
|
||||
2, // 23: pb.SearchRequest.trending_group:type_name -> pb.RangeField
|
||||
|
@ -1009,16 +1078,20 @@ var file_hub_proto_depIdxs = []int32{
|
|||
2, // 26: pb.SearchRequest.trending_global:type_name -> pb.RangeField
|
||||
1, // 27: pb.SearchRequest.channel_id:type_name -> pb.InvertibleField
|
||||
1, // 28: pb.SearchRequest.channel_ids:type_name -> pb.InvertibleField
|
||||
4, // 29: pb.SearchRequest.tx_nout:type_name -> google.protobuf.Int32Value
|
||||
5, // 30: pb.SearchRequest.has_channel_signature:type_name -> google.protobuf.BoolValue
|
||||
5, // 31: pb.SearchRequest.has_source:type_name -> google.protobuf.BoolValue
|
||||
4, // 32: pb.SearchRequest.limit_claims_per_channel:type_name -> google.protobuf.Int32Value
|
||||
5, // 33: pb.SearchRequest.remove_duplicates:type_name -> google.protobuf.BoolValue
|
||||
5, // 34: pb.SearchRequest.no_totals:type_name -> google.protobuf.BoolValue
|
||||
5, // 29: pb.SearchRequest.tx_nout:type_name -> google.protobuf.Int32Value
|
||||
6, // 30: pb.SearchRequest.has_channel_signature:type_name -> google.protobuf.BoolValue
|
||||
6, // 31: pb.SearchRequest.has_source:type_name -> google.protobuf.BoolValue
|
||||
5, // 32: pb.SearchRequest.limit_claims_per_channel:type_name -> google.protobuf.Int32Value
|
||||
6, // 33: pb.SearchRequest.remove_duplicates:type_name -> google.protobuf.BoolValue
|
||||
6, // 34: pb.SearchRequest.no_totals:type_name -> google.protobuf.BoolValue
|
||||
3, // 35: pb.Hub.Search:input_type -> pb.SearchRequest
|
||||
6, // 36: pb.Hub.Search:output_type -> pb.Outputs
|
||||
36, // [36:37] is the sub-list for method output_type
|
||||
35, // [35:36] is the sub-list for method input_type
|
||||
4, // 36: pb.Hub.GetBlock:input_type -> pb.BlockRequest
|
||||
4, // 37: pb.Hub.GetBlockHeader:input_type -> pb.BlockRequest
|
||||
7, // 38: pb.Hub.Search:output_type -> pb.Outputs
|
||||
8, // 39: pb.Hub.GetBlock:output_type -> pb.BlockOutput
|
||||
9, // 40: pb.Hub.GetBlockHeader:output_type -> pb.BlockHeaderOutput
|
||||
38, // [38:41] is the sub-list for method output_type
|
||||
35, // [35:38] is the sub-list for method input_type
|
||||
35, // [35:35] is the sub-list for extension type_name
|
||||
35, // [35:35] is the sub-list for extension extendee
|
||||
0, // [0:35] is the sub-list for field type_name
|
||||
|
@ -1067,6 +1140,18 @@ func file_hub_proto_init() {
|
|||
return nil
|
||||
}
|
||||
}
|
||||
file_hub_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*BlockRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
|
@ -1074,7 +1159,7 @@ func file_hub_proto_init() {
|
|||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_hub_proto_rawDesc,
|
||||
NumEnums: 1,
|
||||
NumMessages: 3,
|
||||
NumMessages: 4,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
|
|
|
@ -19,6 +19,8 @@ const _ = grpc.SupportPackageIsVersion7
|
|||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type HubClient interface {
|
||||
Search(ctx context.Context, in *SearchRequest, opts ...grpc.CallOption) (*Outputs, error)
|
||||
GetBlock(ctx context.Context, in *BlockRequest, opts ...grpc.CallOption) (*BlockOutput, error)
|
||||
GetBlockHeader(ctx context.Context, in *BlockRequest, opts ...grpc.CallOption) (*BlockHeaderOutput, error)
|
||||
}
|
||||
|
||||
type hubClient struct {
|
||||
|
@ -38,11 +40,31 @@ func (c *hubClient) Search(ctx context.Context, in *SearchRequest, opts ...grpc.
|
|||
return out, nil
|
||||
}
|
||||
|
||||
func (c *hubClient) GetBlock(ctx context.Context, in *BlockRequest, opts ...grpc.CallOption) (*BlockOutput, error) {
|
||||
out := new(BlockOutput)
|
||||
err := c.cc.Invoke(ctx, "/pb.Hub/GetBlock", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *hubClient) GetBlockHeader(ctx context.Context, in *BlockRequest, opts ...grpc.CallOption) (*BlockHeaderOutput, error) {
|
||||
out := new(BlockHeaderOutput)
|
||||
err := c.cc.Invoke(ctx, "/pb.Hub/GetBlockHeader", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// HubServer is the server API for Hub service.
|
||||
// All implementations must embed UnimplementedHubServer
|
||||
// for forward compatibility
|
||||
type HubServer interface {
|
||||
Search(context.Context, *SearchRequest) (*Outputs, error)
|
||||
GetBlock(context.Context, *BlockRequest) (*BlockOutput, error)
|
||||
GetBlockHeader(context.Context, *BlockRequest) (*BlockHeaderOutput, error)
|
||||
mustEmbedUnimplementedHubServer()
|
||||
}
|
||||
|
||||
|
@ -53,6 +75,12 @@ type UnimplementedHubServer struct {
|
|||
func (UnimplementedHubServer) Search(context.Context, *SearchRequest) (*Outputs, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Search not implemented")
|
||||
}
|
||||
func (UnimplementedHubServer) GetBlock(context.Context, *BlockRequest) (*BlockOutput, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetBlock not implemented")
|
||||
}
|
||||
func (UnimplementedHubServer) GetBlockHeader(context.Context, *BlockRequest) (*BlockHeaderOutput, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetBlockHeader not implemented")
|
||||
}
|
||||
func (UnimplementedHubServer) mustEmbedUnimplementedHubServer() {}
|
||||
|
||||
// UnsafeHubServer may be embedded to opt out of forward compatibility for this service.
|
||||
|
@ -84,6 +112,42 @@ func _Hub_Search_Handler(srv interface{}, ctx context.Context, dec func(interfac
|
|||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Hub_GetBlock_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(BlockRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(HubServer).GetBlock(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/pb.Hub/GetBlock",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(HubServer).GetBlock(ctx, req.(*BlockRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Hub_GetBlockHeader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(BlockRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(HubServer).GetBlockHeader(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/pb.Hub/GetBlockHeader",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(HubServer).GetBlockHeader(ctx, req.(*BlockRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// Hub_ServiceDesc is the grpc.ServiceDesc for Hub service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
|
@ -95,6 +159,14 @@ var Hub_ServiceDesc = grpc.ServiceDesc{
|
|||
MethodName: "Search",
|
||||
Handler: _Hub_Search_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetBlock",
|
||||
Handler: _Hub_GetBlock_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetBlockHeader",
|
||||
Handler: _Hub_GetBlockHeader_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "hub.proto",
|
||||
|
|
|
@ -556,6 +556,238 @@ func (x *Blocked) GetChannel() *Output {
|
|||
return nil
|
||||
}
|
||||
|
||||
type BlockOutput struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash"`
|
||||
Confirmations int32 `protobuf:"varint,2,opt,name=confirmations,proto3" json:"confirmations"`
|
||||
}
|
||||
|
||||
func (x *BlockOutput) Reset() {
|
||||
*x = BlockOutput{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_result_proto_msgTypes[5]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *BlockOutput) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*BlockOutput) ProtoMessage() {}
|
||||
|
||||
func (x *BlockOutput) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_result_proto_msgTypes[5]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use BlockOutput.ProtoReflect.Descriptor instead.
|
||||
func (*BlockOutput) Descriptor() ([]byte, []int) {
|
||||
return file_result_proto_rawDescGZIP(), []int{5}
|
||||
}
|
||||
|
||||
func (x *BlockOutput) GetHash() string {
|
||||
if x != nil {
|
||||
return x.Hash
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *BlockOutput) GetConfirmations() int32 {
|
||||
if x != nil {
|
||||
return x.Confirmations
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
//
|
||||
//{ (json object)
|
||||
//"hash" : "hex", (string) the block hash (same as provided)
|
||||
//"confirmations" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain
|
||||
//"height" : n, (numeric) The block height or index
|
||||
//"version" : n, (numeric) The block version
|
||||
//"versionHex" : "hex", (string) The block version formatted in hexadecimal
|
||||
//"merkleroot" : "hex", (string) The merkle root
|
||||
//"time" : xxx, (numeric) The block time expressed in UNIX epoch time
|
||||
//"mediantime" : xxx, (numeric) The median block time expressed in UNIX epoch time
|
||||
//"nonce" : n, (numeric) The nonce
|
||||
//"bits" : "hex", (string) The bits
|
||||
//"difficulty" : n, (numeric) The difficulty
|
||||
//"chainwork" : "hex", (string) Expected number of hashes required to produce the current chain
|
||||
//"nTx" : n, (numeric) The number of transactions in the block
|
||||
//"previousblockhash" : "hex", (string) The hash of the previous block
|
||||
//"nextblockhash" : "hex" (string) The hash of the next block
|
||||
//}
|
||||
type BlockHeaderOutput struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash"`
|
||||
Confirmations int64 `protobuf:"varint,2,opt,name=confirmations,proto3" json:"confirmations"`
|
||||
Height int64 `protobuf:"varint,3,opt,name=height,proto3" json:"height"`
|
||||
Version int64 `protobuf:"varint,4,opt,name=version,proto3" json:"version"`
|
||||
VersionHex string `protobuf:"bytes,5,opt,name=versionHex,proto3" json:"versionHex"`
|
||||
Merkleroot string `protobuf:"bytes,6,opt,name=merkleroot,proto3" json:"merkleroot"`
|
||||
Time int64 `protobuf:"varint,7,opt,name=time,proto3" json:"time"`
|
||||
Mediantime int64 `protobuf:"varint,8,opt,name=mediantime,proto3" json:"mediantime"`
|
||||
Nonce int64 `protobuf:"varint,9,opt,name=nonce,proto3" json:"nonce"`
|
||||
Bits string `protobuf:"bytes,10,opt,name=bits,proto3" json:"bits"`
|
||||
Difficulty float64 `protobuf:"fixed64,11,opt,name=difficulty,proto3" json:"difficulty"`
|
||||
Chainwork string `protobuf:"bytes,12,opt,name=chainwork,proto3" json:"chainwork"`
|
||||
NTx int64 `protobuf:"varint,13,opt,name=nTx,proto3" json:"nTx"`
|
||||
Previousblockhash string `protobuf:"bytes,14,opt,name=previousblockhash,proto3" json:"previousblockhash"`
|
||||
Nextblockhash string `protobuf:"bytes,15,opt,name=nextblockhash,proto3" json:"nextblockhash"`
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) Reset() {
|
||||
*x = BlockHeaderOutput{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_result_proto_msgTypes[6]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*BlockHeaderOutput) ProtoMessage() {}
|
||||
|
||||
func (x *BlockHeaderOutput) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_result_proto_msgTypes[6]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use BlockHeaderOutput.ProtoReflect.Descriptor instead.
|
||||
func (*BlockHeaderOutput) Descriptor() ([]byte, []int) {
|
||||
return file_result_proto_rawDescGZIP(), []int{6}
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetHash() string {
|
||||
if x != nil {
|
||||
return x.Hash
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetConfirmations() int64 {
|
||||
if x != nil {
|
||||
return x.Confirmations
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetHeight() int64 {
|
||||
if x != nil {
|
||||
return x.Height
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetVersion() int64 {
|
||||
if x != nil {
|
||||
return x.Version
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetVersionHex() string {
|
||||
if x != nil {
|
||||
return x.VersionHex
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetMerkleroot() string {
|
||||
if x != nil {
|
||||
return x.Merkleroot
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetTime() int64 {
|
||||
if x != nil {
|
||||
return x.Time
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetMediantime() int64 {
|
||||
if x != nil {
|
||||
return x.Mediantime
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetNonce() int64 {
|
||||
if x != nil {
|
||||
return x.Nonce
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetBits() string {
|
||||
if x != nil {
|
||||
return x.Bits
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetDifficulty() float64 {
|
||||
if x != nil {
|
||||
return x.Difficulty
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetChainwork() string {
|
||||
if x != nil {
|
||||
return x.Chainwork
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetNTx() int64 {
|
||||
if x != nil {
|
||||
return x.NTx
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetPreviousblockhash() string {
|
||||
if x != nil {
|
||||
return x.Previousblockhash
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *BlockHeaderOutput) GetNextblockhash() string {
|
||||
if x != nil {
|
||||
return x.Nextblockhash
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var File_result_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_result_proto_rawDesc = []byte{
|
||||
|
@ -640,10 +872,43 @@ var file_result_proto_rawDesc = []byte{
|
|||
0x65, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x0d, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x24, 0x0a, 0x07, 0x63, 0x68, 0x61, 0x6e,
|
||||
0x6e, 0x65, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x70, 0x62, 0x2e, 0x4f,
|
||||
0x75, 0x74, 0x70, 0x75, 0x74, 0x52, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x42, 0x26,
|
||||
0x5a, 0x24, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x62, 0x72,
|
||||
0x79, 0x69, 0x6f, 0x2f, 0x68, 0x75, 0x62, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66,
|
||||
0x2f, 0x67, 0x6f, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x75, 0x74, 0x70, 0x75, 0x74, 0x52, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x22, 0x47,
|
||||
0x0a, 0x0b, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x12, 0x12, 0x0a,
|
||||
0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x61, 0x73,
|
||||
0x68, 0x12, 0x24, 0x0a, 0x0d, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0d, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72,
|
||||
0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0xc1, 0x03, 0x0a, 0x11, 0x42, 0x6c, 0x6f, 0x63,
|
||||
0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x12, 0x12, 0x0a,
|
||||
0x04, 0x68, 0x61, 0x73, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x61, 0x73,
|
||||
0x68, 0x12, 0x24, 0x0a, 0x0d, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72,
|
||||
0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68,
|
||||
0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x12,
|
||||
0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03,
|
||||
0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1e, 0x0a, 0x0a, 0x76, 0x65, 0x72,
|
||||
0x73, 0x69, 0x6f, 0x6e, 0x48, 0x65, 0x78, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x76,
|
||||
0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x48, 0x65, 0x78, 0x12, 0x1e, 0x0a, 0x0a, 0x6d, 0x65, 0x72,
|
||||
0x6b, 0x6c, 0x65, 0x72, 0x6f, 0x6f, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6d,
|
||||
0x65, 0x72, 0x6b, 0x6c, 0x65, 0x72, 0x6f, 0x6f, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x69, 0x6d,
|
||||
0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x1e, 0x0a,
|
||||
0x0a, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28,
|
||||
0x03, 0x52, 0x0a, 0x6d, 0x65, 0x64, 0x69, 0x61, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x14, 0x0a,
|
||||
0x05, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x6e, 0x6f,
|
||||
0x6e, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x69, 0x74, 0x73, 0x18, 0x0a, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x04, 0x62, 0x69, 0x74, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x69, 0x66, 0x66, 0x69,
|
||||
0x63, 0x75, 0x6c, 0x74, 0x79, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x01, 0x52, 0x0a, 0x64, 0x69, 0x66,
|
||||
0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x68, 0x61, 0x69, 0x6e,
|
||||
0x77, 0x6f, 0x72, 0x6b, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x68, 0x61, 0x69,
|
||||
0x6e, 0x77, 0x6f, 0x72, 0x6b, 0x12, 0x10, 0x0a, 0x03, 0x6e, 0x54, 0x78, 0x18, 0x0d, 0x20, 0x01,
|
||||
0x28, 0x03, 0x52, 0x03, 0x6e, 0x54, 0x78, 0x12, 0x2c, 0x0a, 0x11, 0x70, 0x72, 0x65, 0x76, 0x69,
|
||||
0x6f, 0x75, 0x73, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x68, 0x61, 0x73, 0x68, 0x18, 0x0e, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x11, 0x70, 0x72, 0x65, 0x76, 0x69, 0x6f, 0x75, 0x73, 0x62, 0x6c, 0x6f, 0x63,
|
||||
0x6b, 0x68, 0x61, 0x73, 0x68, 0x12, 0x24, 0x0a, 0x0d, 0x6e, 0x65, 0x78, 0x74, 0x62, 0x6c, 0x6f,
|
||||
0x63, 0x6b, 0x68, 0x61, 0x73, 0x68, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x6e, 0x65,
|
||||
0x78, 0x74, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x68, 0x61, 0x73, 0x68, 0x42, 0x26, 0x5a, 0x24, 0x67,
|
||||
0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6c, 0x62, 0x72, 0x79, 0x69, 0x6f,
|
||||
0x2f, 0x68, 0x75, 0x62, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x67, 0x6f,
|
||||
0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -659,14 +924,16 @@ func file_result_proto_rawDescGZIP() []byte {
|
|||
}
|
||||
|
||||
var file_result_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||
var file_result_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
|
||||
var file_result_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
|
||||
var file_result_proto_goTypes = []interface{}{
|
||||
(Error_Code)(0), // 0: pb.Error.Code
|
||||
(*Outputs)(nil), // 1: pb.Outputs
|
||||
(*Output)(nil), // 2: pb.Output
|
||||
(*ClaimMeta)(nil), // 3: pb.ClaimMeta
|
||||
(*Error)(nil), // 4: pb.Error
|
||||
(*Blocked)(nil), // 5: pb.Blocked
|
||||
(Error_Code)(0), // 0: pb.Error.Code
|
||||
(*Outputs)(nil), // 1: pb.Outputs
|
||||
(*Output)(nil), // 2: pb.Output
|
||||
(*ClaimMeta)(nil), // 3: pb.ClaimMeta
|
||||
(*Error)(nil), // 4: pb.Error
|
||||
(*Blocked)(nil), // 5: pb.Blocked
|
||||
(*BlockOutput)(nil), // 6: pb.BlockOutput
|
||||
(*BlockHeaderOutput)(nil), // 7: pb.BlockHeaderOutput
|
||||
}
|
||||
var file_result_proto_depIdxs = []int32{
|
||||
2, // 0: pb.Outputs.txos:type_name -> pb.Output
|
||||
|
@ -752,6 +1019,30 @@ func file_result_proto_init() {
|
|||
return nil
|
||||
}
|
||||
}
|
||||
file_result_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*BlockOutput); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_result_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*BlockHeaderOutput); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
file_result_proto_msgTypes[1].OneofWrappers = []interface{}{
|
||||
(*Output_Claim)(nil),
|
||||
|
@ -763,7 +1054,7 @@ func file_result_proto_init() {
|
|||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_result_proto_rawDesc,
|
||||
NumEnums: 1,
|
||||
NumMessages: 5,
|
||||
NumMessages: 7,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
|
|
86
server/block.go
Normal file
86
server/block.go
Normal file
|
@ -0,0 +1,86 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
pb "github.com/lbryio/hub/protobuf/go"
|
||||
"log"
|
||||
|
||||
//"net/rpc/jsonrpc"
|
||||
"github.com/ybbus/jsonrpc/v2"
|
||||
)
|
||||
|
||||
func (s *Server) GetBlock(ctx context.Context, blockReq *pb.BlockRequest) (*pb.BlockOutput, error) {
|
||||
|
||||
log.Println("In GetBlock")
|
||||
rpcClient := jsonrpc.NewClientWithOpts("http://localhost"+":29245", &jsonrpc.RPCClientOpts{
|
||||
CustomHeaders: map[string]string{
|
||||
"Authorization": "Basic " + base64.StdEncoding.EncodeToString([]byte("lbry"+":"+"lbry")),
|
||||
},
|
||||
})
|
||||
|
||||
log.Println("Making call ...")
|
||||
var r pb.BlockOutput
|
||||
res, err := rpcClient.Call("getblock", blockReq.Blockhash)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return &pb.BlockOutput{Hash: "", Confirmations: 0}, err
|
||||
}
|
||||
log.Println(res)
|
||||
err = res.GetObject(&r)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return &pb.BlockOutput{Hash: "", Confirmations: 0}, err
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (s *Server) GetBlockHeader(ctx context.Context, blockReq *pb.BlockRequest) (*pb.BlockHeaderOutput, error) {
|
||||
|
||||
log.Println("In GetBlock")
|
||||
rpcClient := jsonrpc.NewClientWithOpts("http://localhost"+":29245", &jsonrpc.RPCClientOpts{
|
||||
CustomHeaders: map[string]string{
|
||||
"Authorization": "Basic " + base64.StdEncoding.EncodeToString([]byte("lbry"+":"+"lbry")),
|
||||
},
|
||||
})
|
||||
|
||||
log.Println("Making call ...")
|
||||
var r pb.BlockHeaderOutput
|
||||
res, err := rpcClient.Call("getblock", blockReq.Blockhash)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return &pb.BlockHeaderOutput{Hash: "", Confirmations: 0}, err
|
||||
}
|
||||
log.Println(res)
|
||||
err = res.GetObject(&r)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return &pb.BlockHeaderOutput{Hash: "", Confirmations: 0}, err
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
}
|
||||
/*
|
||||
func (s *Server) GetBlock(ctx context.Context, blockReq *pb.BlockRequest) (*pb.BlockOutput, error) {
|
||||
|
||||
log.Println("In GetBlock")
|
||||
conn, err := jsonrpc.Dial("tcp", "localhost"+":19245")
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
log.Println("Making call ...")
|
||||
var r pb.BlockOutput
|
||||
//var rr json.RawMessage
|
||||
err = conn.Call("getblock", blockReq.Blockhash, nil)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return &pb.BlockOutput{Hash: "", Confirmations: 0}, err
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
*/
|
|
@ -18,8 +18,16 @@ type Server struct {
|
|||
pb.UnimplementedHubServer
|
||||
}
|
||||
|
||||
const (
|
||||
ServeCmd = iota
|
||||
SearchCmd = iota
|
||||
GetblockCmd = iota
|
||||
GetblockHeaderCmd = iota
|
||||
)
|
||||
|
||||
type Args struct {
|
||||
Serve bool
|
||||
// TODO Make command types an enum
|
||||
CmdType int
|
||||
Host string
|
||||
Port string
|
||||
EsHost string
|
||||
|
|
Loading…
Add table
Reference in a new issue