mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-18 21:35:24 +01:00
Merge pull request #5652 from ErikEk/neutrino-sub-server
Neutrino sub-server
This commit is contained in:
commit
12b82d0156
2
.github/workflows/release.yaml
vendored
2
.github/workflows/release.yaml
vendored
@ -94,7 +94,7 @@ jobs:
|
||||
|
||||
Our release binaries are fully reproducible. Third parties are able to verify that the release binaries were produced properly without having to trust the release manager(s). See our [reproducible builds guide](https://github.com/lightningnetwork/lnd/tree/master/build/release) for how this can be achieved.
|
||||
The release binaries are compiled with `go${{ env.GO_VERSION }}`, which is required by verifiers to arrive at the same ones.
|
||||
They include the following build tags: `autopilotrpc`, `signrpc`, `walletrpc`, `chainrpc`, `invoicesrpc`, `routerrpc`, `watchtowerrpc` and `monitoring`. Note that these are already included in the release script, so they do not need to be provided.
|
||||
They include the following build tags: `autopilotrpc`, `signrpc`, `walletrpc`, `chainrpc`, `invoicesrpc`, `neutrinorpc`, `routerrpc`, `watchtowerrpc` and `monitoring`. Note that these are already included in the release script, so they do not need to be provided.
|
||||
|
||||
The `make release` command can be used to ensure one rebuilds with all the same flags used for the release. If one wishes to build for only a single platform, then `make release sys=<OS-ARCH> tag=<tag>` can be used.
|
||||
|
||||
|
@ -17,6 +17,7 @@ run:
|
||||
- chainrpc
|
||||
- dev
|
||||
- invoicesrpc
|
||||
- neutrinorpc
|
||||
- peersrpc
|
||||
- signrpc
|
||||
- walletrpc
|
||||
|
4
Makefile
4
Makefile
@ -306,7 +306,7 @@ apple: vendor mobile-rpc
|
||||
ios: vendor mobile-rpc
|
||||
@$(call print, "Building iOS cxframework ($(IOS_BUILD)).")
|
||||
mkdir -p $(IOS_BUILD_DIR)
|
||||
$(GOMOBILE_BIN) bind -target=ios,iossimulator -tags="mobile $(DEV_TAGS) autopilotrpc" $(LDFLAGS) -v -o $(IOS_BUILD) $(MOBILE_PKG)
|
||||
$(GOMOBILE_BIN) bind -target=ios,iossimulator -tags="mobile $(DEV_TAGS) autopilotrpc neutrinorpc" $(LDFLAGS) -v -o $(IOS_BUILD) $(MOBILE_PKG)
|
||||
|
||||
macos: vendor mobile-rpc
|
||||
@$(call print, "Building macOS cxframework ($(IOS_BUILD)).")
|
||||
@ -316,7 +316,7 @@ macos: vendor mobile-rpc
|
||||
android: vendor mobile-rpc
|
||||
@$(call print, "Building Android library ($(ANDROID_BUILD)).")
|
||||
mkdir -p $(ANDROID_BUILD_DIR)
|
||||
$(GOMOBILE_BIN) bind -target=android -tags="mobile $(DEV_TAGS) autopilotrpc" $(LDFLAGS) -v -o $(ANDROID_BUILD) $(MOBILE_PKG)
|
||||
$(GOMOBILE_BIN) bind -target=android -tags="mobile $(DEV_TAGS) autopilotrpc neutrinorpc" $(LDFLAGS) -v -o $(ANDROID_BUILD) $(MOBILE_PKG)
|
||||
|
||||
mobile: ios android
|
||||
|
||||
|
@ -418,6 +418,7 @@ func main() {
|
||||
// Add any extra commands determined by build flags.
|
||||
app.Commands = append(app.Commands, autopilotCommands()...)
|
||||
app.Commands = append(app.Commands, invoicesCommands()...)
|
||||
app.Commands = append(app.Commands, neutrinoCommands()...)
|
||||
app.Commands = append(app.Commands, routerCommands()...)
|
||||
app.Commands = append(app.Commands, walletCommands()...)
|
||||
app.Commands = append(app.Commands, watchtowerCommands()...)
|
||||
|
284
cmd/lncli/neutrino_active.go
Normal file
284
cmd/lncli/neutrino_active.go
Normal file
@ -0,0 +1,284 @@
|
||||
//go:build neutrinorpc
|
||||
// +build neutrinorpc
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/lightningnetwork/lnd/lnrpc/neutrinorpc"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func getNeutrinoKitClient(ctx *cli.Context) (neutrinorpc.NeutrinoKitClient, func()) {
|
||||
conn := getClientConn(ctx, false)
|
||||
|
||||
cleanUp := func() {
|
||||
conn.Close()
|
||||
}
|
||||
|
||||
return neutrinorpc.NewNeutrinoKitClient(conn), cleanUp
|
||||
}
|
||||
|
||||
var getNeutrinoStatusCommand = cli.Command{
|
||||
Name: "status",
|
||||
Usage: "Returns the status of the running neutrino instance.",
|
||||
Category: "Neutrino",
|
||||
Description: "Returns the status of the light client neutrino " +
|
||||
"instance, along with height and hash of the best block, and " +
|
||||
"a list of connected peers.",
|
||||
Action: actionDecorator(getNeutrinoStatus),
|
||||
}
|
||||
|
||||
func getNeutrinoStatus(ctx *cli.Context) error {
|
||||
ctxc := getContext()
|
||||
client, cleanUp := getNeutrinoKitClient(ctx)
|
||||
defer cleanUp()
|
||||
|
||||
req := &neutrinorpc.StatusRequest{}
|
||||
|
||||
resp, err := client.Status(ctxc, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var addPeerCommand = cli.Command{
|
||||
Name: "addpeer",
|
||||
Usage: "Add a peer.",
|
||||
Category: "Neutrino",
|
||||
Description: "Adds a new peer that has already been connected to the " +
|
||||
"server.",
|
||||
ArgsUsage: "address",
|
||||
Action: actionDecorator(addNeutrinoPeer),
|
||||
}
|
||||
|
||||
func addNeutrinoPeer(ctx *cli.Context) error {
|
||||
ctxc := getContext()
|
||||
|
||||
// Display the command's help message if we do not have the expected
|
||||
// number of arguments/flags.
|
||||
if ctx.NArg() != 1 || ctx.NumFlags() > 0 {
|
||||
return cli.ShowCommandHelp(ctx, "addpeer")
|
||||
}
|
||||
|
||||
client, cleanUp := getNeutrinoKitClient(ctx)
|
||||
defer cleanUp()
|
||||
|
||||
req := &neutrinorpc.AddPeerRequest{
|
||||
PeerAddrs: ctx.Args().First(),
|
||||
}
|
||||
|
||||
// Add a peer to the neutrino server.
|
||||
resp, err := client.AddPeer(ctxc, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var disconnectPeerCommand = cli.Command{
|
||||
Name: "disconnectpeer",
|
||||
Usage: "Disconnect a peer.",
|
||||
Category: "Neutrino",
|
||||
Description: "Disconnects a peer by target address. Both outbound and" +
|
||||
"inbound nodes will be searched for the target node. An error " +
|
||||
"message will be returned if the peer was not found.",
|
||||
ArgsUsage: "address",
|
||||
Action: actionDecorator(disconnectNeutrinoPeer),
|
||||
}
|
||||
|
||||
func disconnectNeutrinoPeer(ctx *cli.Context) error {
|
||||
ctxc := getContext()
|
||||
|
||||
// Display the command's help message if we do not have the expected
|
||||
// number of arguments/flags.
|
||||
if ctx.NArg() != 1 || ctx.NumFlags() > 0 {
|
||||
return cli.ShowCommandHelp(ctx, "disconnectpeer")
|
||||
}
|
||||
|
||||
client, cleanUp := getNeutrinoKitClient(ctx)
|
||||
defer cleanUp()
|
||||
|
||||
req := &neutrinorpc.DisconnectPeerRequest{
|
||||
PeerAddrs: ctx.Args().First(),
|
||||
}
|
||||
|
||||
// Disconnect a peer to the neutrino server.
|
||||
resp, err := client.DisconnectPeer(ctxc, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var isBannedCommand = cli.Command{
|
||||
Name: "isbanned",
|
||||
Usage: "Get ban status.",
|
||||
Category: "Neutrino",
|
||||
Description: "Returns true if the peer is banned, otherwise false.",
|
||||
ArgsUsage: "address",
|
||||
Action: actionDecorator(isBanned),
|
||||
}
|
||||
|
||||
func isBanned(ctx *cli.Context) error {
|
||||
ctxc := getContext()
|
||||
|
||||
// Display the command's help message if we do not have the expected
|
||||
// number of arguments/flags.
|
||||
if ctx.NArg() != 1 {
|
||||
return cli.ShowCommandHelp(ctx, "isbanned")
|
||||
}
|
||||
client, cleanUp := getNeutrinoKitClient(ctx)
|
||||
defer cleanUp()
|
||||
|
||||
req := &neutrinorpc.IsBannedRequest{
|
||||
PeerAddrs: ctx.Args().First(),
|
||||
}
|
||||
|
||||
// Check if the peer is banned.
|
||||
resp, err := client.IsBanned(ctxc, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var getBlockHeaderCommand = cli.Command{
|
||||
Name: "getblockheader",
|
||||
Usage: "Get a block header.",
|
||||
Category: "Neutrino",
|
||||
Description: "Returns a block header with a particular block hash.",
|
||||
ArgsUsage: "hash",
|
||||
Action: actionDecorator(getBlockHeader),
|
||||
}
|
||||
|
||||
func getBlockHeader(ctx *cli.Context) error {
|
||||
ctxc := getContext()
|
||||
args := ctx.Args()
|
||||
|
||||
// Display the command's help message if we do not have the expected
|
||||
// number of arguments/flags.
|
||||
if !args.Present() {
|
||||
return cli.ShowCommandHelp(ctx, "getblockheader")
|
||||
}
|
||||
|
||||
client, cleanUp := getNeutrinoKitClient(ctx)
|
||||
defer cleanUp()
|
||||
|
||||
req := &neutrinorpc.GetBlockHeaderRequest{
|
||||
Hash: ctx.Args().First(),
|
||||
}
|
||||
|
||||
resp, err := client.GetBlockHeader(ctxc, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var getBlockCommand = cli.Command{
|
||||
Name: "getblock",
|
||||
Usage: "Get a block.",
|
||||
Category: "Neutrino",
|
||||
Description: "Returns a block with a particular block hash.",
|
||||
ArgsUsage: "hash",
|
||||
Action: actionDecorator(getBlock),
|
||||
}
|
||||
|
||||
func getBlock(ctx *cli.Context) error {
|
||||
ctxc := getContext()
|
||||
args := ctx.Args()
|
||||
|
||||
// Display the command's help message if we do not have the expected
|
||||
// number of arguments/flags.
|
||||
if !args.Present() {
|
||||
return cli.ShowCommandHelp(ctx, "getblock")
|
||||
}
|
||||
|
||||
client, cleanUp := getNeutrinoKitClient(ctx)
|
||||
defer cleanUp()
|
||||
|
||||
req := &neutrinorpc.GetBlockRequest{
|
||||
Hash: args.First(),
|
||||
}
|
||||
|
||||
resp, err := client.GetBlock(ctxc, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var getCFilterCommand = cli.Command{
|
||||
Name: "getcfilter",
|
||||
Usage: "Get a compact filter.",
|
||||
Category: "Neutrino",
|
||||
Description: "Returns a compact filter of a particular block.",
|
||||
ArgsUsage: "hash",
|
||||
Action: actionDecorator(getCFilter),
|
||||
}
|
||||
|
||||
func getCFilter(ctx *cli.Context) error {
|
||||
ctxc := getContext()
|
||||
args := ctx.Args()
|
||||
|
||||
// Display the command's help message if we do not have the expected
|
||||
// number of arguments/flags.
|
||||
if !args.Present() {
|
||||
return cli.ShowCommandHelp(ctx, "getcfilter")
|
||||
}
|
||||
|
||||
client, cleanUp := getNeutrinoKitClient(ctx)
|
||||
defer cleanUp()
|
||||
|
||||
req := &neutrinorpc.GetCFilterRequest{Hash: args.First()}
|
||||
|
||||
resp, err := client.GetCFilter(ctxc, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// neutrinoCommands will return the set of commands to enable for neutrinorpc
|
||||
// builds.
|
||||
func neutrinoCommands() []cli.Command {
|
||||
return []cli.Command{
|
||||
{
|
||||
Name: "neutrino",
|
||||
Category: "Neutrino",
|
||||
Usage: "Interact with a running neutrino instance.",
|
||||
Description: "",
|
||||
Subcommands: []cli.Command{
|
||||
getNeutrinoStatusCommand,
|
||||
addPeerCommand,
|
||||
disconnectPeerCommand,
|
||||
isBannedCommand,
|
||||
getBlockCommand,
|
||||
getBlockHeaderCommand,
|
||||
getCFilterCommand,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
10
cmd/lncli/neutrino_default.go
Normal file
10
cmd/lncli/neutrino_default.go
Normal file
@ -0,0 +1,10 @@
|
||||
// +build !neutrinorpc
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/urfave/cli"
|
||||
|
||||
// neutrinoCommands will return nil for non-neutrinorpc builds.
|
||||
func neutrinoCommands() []cli.Command {
|
||||
return nil
|
||||
}
|
@ -85,6 +85,12 @@ to Bitcoin nodes that advertise a Tor v3 onion service address.
|
||||
* [Fixed an edge case where the lnd might be stuck at starting due to channel
|
||||
arbitrator relying on htlcswitch to be started
|
||||
first](https://github.com/lightningnetwork/lnd/pull/6214).
|
||||
|
||||
## Neutrino
|
||||
|
||||
* [New neutrino sub-server](https://github.com/lightningnetwork/lnd/pull/5652)
|
||||
capable of status checks, adding, disconnecting and listing
|
||||
peers, fetching compact filters and block/block headers.
|
||||
|
||||
* [Added signature length
|
||||
validation](https://github.com/lightningnetwork/lnd/pull/6314) when calling
|
||||
|
@ -48,7 +48,7 @@ function generate() {
|
||||
--custom_opt="$opts" \
|
||||
lightning.proto stateservice.proto walletunlocker.proto
|
||||
|
||||
PACKAGES="autopilotrpc chainrpc invoicesrpc peersrpc routerrpc signrpc verrpc walletrpc watchtowerrpc wtclientrpc devrpc"
|
||||
PACKAGES="autopilotrpc chainrpc invoicesrpc neutrinorpc peersrpc routerrpc signrpc verrpc walletrpc watchtowerrpc wtclientrpc devrpc"
|
||||
for package in $PACKAGES; do
|
||||
# Special import for the wallet kit.
|
||||
manual_import=""
|
||||
|
18
lnrpc/neutrinorpc/config_active.go
Normal file
18
lnrpc/neutrinorpc/config_active.go
Normal file
@ -0,0 +1,18 @@
|
||||
//go:build neutrinorpc
|
||||
// +build neutrinorpc
|
||||
|
||||
package neutrinorpc
|
||||
|
||||
import (
|
||||
"github.com/lightninglabs/neutrino"
|
||||
)
|
||||
|
||||
// Config is the primary configuration struct for the neutrino RPC server. It
|
||||
// contains all the items required for the rpc server to carry out its
|
||||
// duties. The fields with struct tags are meant to be parsed as normal
|
||||
// configuration options, while if able to be populated, the latter fields MUST
|
||||
// also be specified.
|
||||
type Config struct {
|
||||
// ChainService is required to handle neutrino chain service requests.
|
||||
NeutrinoCS *neutrino.ChainService
|
||||
}
|
7
lnrpc/neutrinorpc/config_default.go
Normal file
7
lnrpc/neutrinorpc/config_default.go
Normal file
@ -0,0 +1,7 @@
|
||||
//go:build !neutrinorpc
|
||||
// +build !neutrinorpc
|
||||
|
||||
package neutrinorpc
|
||||
|
||||
// Config is empty for non-neutrinorpc builds.
|
||||
type Config struct{}
|
55
lnrpc/neutrinorpc/driver.go
Normal file
55
lnrpc/neutrinorpc/driver.go
Normal file
@ -0,0 +1,55 @@
|
||||
//go:build neutrinorpc
|
||||
// +build neutrinorpc
|
||||
|
||||
package neutrinorpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
)
|
||||
|
||||
// createNewSubServer is a helper method that will create the new sub server
|
||||
// given the main config dispatcher method. If we're unable to find the config
|
||||
// that is meant for us in the config dispatcher, then we'll exit with an
|
||||
// error.
|
||||
func createNewSubServer(configRegistry lnrpc.SubServerConfigDispatcher) (
|
||||
*Server, lnrpc.MacaroonPerms, error) {
|
||||
|
||||
// We'll attempt to look up the config that we expect, according to our
|
||||
// subServerName name. If we can't find this, then we'll exit with an
|
||||
// error, as we're unable to properly initialize ourselves without this
|
||||
// config.
|
||||
subServerConf, ok := configRegistry.FetchConfig(subServerName)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("unable to find config for "+
|
||||
"subserver type %s", subServerName)
|
||||
}
|
||||
|
||||
// Now that we've found an object mapping to our service name, we'll
|
||||
// ensure that it's the type we need.
|
||||
config, ok := subServerConf.(*Config)
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("wrong type of config for "+
|
||||
"subserver %s, expected %T got %T", subServerName,
|
||||
&Config{}, subServerConf)
|
||||
}
|
||||
|
||||
return New(config)
|
||||
}
|
||||
|
||||
func init() {
|
||||
subServer := &lnrpc.SubServerDriver{
|
||||
SubServerName: subServerName,
|
||||
NewGrpcHandler: func() lnrpc.GrpcHandler {
|
||||
return &ServerShell{}
|
||||
},
|
||||
}
|
||||
|
||||
// If the build tag is active, then we'll register ourselves as a
|
||||
// sub-RPC server within the global lnrpc package namespace.
|
||||
if err := lnrpc.RegisterSubServer(subServer); err != nil {
|
||||
panic(fmt.Sprintf("failed to register sub server driver "+
|
||||
"'%s': %v", subServerName, err))
|
||||
}
|
||||
}
|
32
lnrpc/neutrinorpc/log.go
Normal file
32
lnrpc/neutrinorpc/log.go
Normal file
@ -0,0 +1,32 @@
|
||||
package neutrinorpc
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btclog"
|
||||
"github.com/lightningnetwork/lnd/build"
|
||||
)
|
||||
|
||||
// log is a logger that is initialized with no output filters. This
|
||||
// means the package will not perform any logging by default until the caller
|
||||
// requests it.
|
||||
var log btclog.Logger
|
||||
|
||||
// Subsystem defines the logging code for this subsystem.
|
||||
const Subsystem = "NRPC"
|
||||
|
||||
// The default amount of logging is none.
|
||||
func init() {
|
||||
UseLogger(build.NewSubLogger(Subsystem, nil))
|
||||
}
|
||||
|
||||
// DisableLog disables all library log output. Logging output is disabled
|
||||
// by default until UseLogger is called.
|
||||
func DisableLog() {
|
||||
UseLogger(btclog.Disabled)
|
||||
}
|
||||
|
||||
// UseLogger uses a specified Logger to output package logging info.
|
||||
// This should be used in preference to SetLogWriter if the caller is also
|
||||
// using btclog.
|
||||
func UseLogger(logger btclog.Logger) {
|
||||
log = logger
|
||||
}
|
1343
lnrpc/neutrinorpc/neutrino.pb.go
Normal file
1343
lnrpc/neutrinorpc/neutrino.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
693
lnrpc/neutrinorpc/neutrino.pb.gw.go
Normal file
693
lnrpc/neutrinorpc/neutrino.pb.gw.go
Normal file
@ -0,0 +1,693 @@
|
||||
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
|
||||
// source: neutrinorpc/neutrino.proto
|
||||
|
||||
/*
|
||||
Package neutrinorpc is a reverse proxy.
|
||||
|
||||
It translates gRPC into RESTful JSON APIs.
|
||||
*/
|
||||
package neutrinorpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// Suppress "imported and not used" errors
|
||||
var _ codes.Code
|
||||
var _ io.Reader
|
||||
var _ status.Status
|
||||
var _ = runtime.String
|
||||
var _ = utilities.NewDoubleArray
|
||||
var _ = metadata.Join
|
||||
|
||||
func request_NeutrinoKit_Status_0(ctx context.Context, marshaler runtime.Marshaler, client NeutrinoKitClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq StatusRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.Status(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_NeutrinoKit_Status_0(ctx context.Context, marshaler runtime.Marshaler, server NeutrinoKitServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq StatusRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.Status(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_NeutrinoKit_AddPeer_0(ctx context.Context, marshaler runtime.Marshaler, client NeutrinoKitClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq AddPeerRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.AddPeer(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_NeutrinoKit_AddPeer_0(ctx context.Context, marshaler runtime.Marshaler, server NeutrinoKitServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq AddPeerRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.AddPeer(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_NeutrinoKit_DisconnectPeer_0(ctx context.Context, marshaler runtime.Marshaler, client NeutrinoKitClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq DisconnectPeerRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.DisconnectPeer(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_NeutrinoKit_DisconnectPeer_0(ctx context.Context, marshaler runtime.Marshaler, server NeutrinoKitServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq DisconnectPeerRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
newReader, berr := utilities.IOReaderFactory(req.Body)
|
||||
if berr != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
|
||||
}
|
||||
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.DisconnectPeer(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_NeutrinoKit_IsBanned_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_NeutrinoKit_IsBanned_0(ctx context.Context, marshaler runtime.Marshaler, client NeutrinoKitClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq IsBannedRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_NeutrinoKit_IsBanned_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.IsBanned(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_NeutrinoKit_IsBanned_0(ctx context.Context, marshaler runtime.Marshaler, server NeutrinoKitServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq IsBannedRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_NeutrinoKit_IsBanned_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.IsBanned(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_NeutrinoKit_GetBlockHeader_0(ctx context.Context, marshaler runtime.Marshaler, client NeutrinoKitClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq GetBlockHeaderRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["hash"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "hash")
|
||||
}
|
||||
|
||||
protoReq.Hash, err = runtime.String(val)
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "hash", err)
|
||||
}
|
||||
|
||||
msg, err := client.GetBlockHeader(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_NeutrinoKit_GetBlockHeader_0(ctx context.Context, marshaler runtime.Marshaler, server NeutrinoKitServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq GetBlockHeaderRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["hash"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "hash")
|
||||
}
|
||||
|
||||
protoReq.Hash, err = runtime.String(val)
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "hash", err)
|
||||
}
|
||||
|
||||
msg, err := server.GetBlockHeader(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_NeutrinoKit_GetBlock_0(ctx context.Context, marshaler runtime.Marshaler, client NeutrinoKitClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq GetBlockRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["hash"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "hash")
|
||||
}
|
||||
|
||||
protoReq.Hash, err = runtime.String(val)
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "hash", err)
|
||||
}
|
||||
|
||||
msg, err := client.GetBlock(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_NeutrinoKit_GetBlock_0(ctx context.Context, marshaler runtime.Marshaler, server NeutrinoKitServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq GetBlockRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["hash"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "hash")
|
||||
}
|
||||
|
||||
protoReq.Hash, err = runtime.String(val)
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "hash", err)
|
||||
}
|
||||
|
||||
msg, err := server.GetBlock(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_NeutrinoKit_GetCFilter_0(ctx context.Context, marshaler runtime.Marshaler, client NeutrinoKitClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq GetCFilterRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["hash"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "hash")
|
||||
}
|
||||
|
||||
protoReq.Hash, err = runtime.String(val)
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "hash", err)
|
||||
}
|
||||
|
||||
msg, err := client.GetCFilter(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_NeutrinoKit_GetCFilter_0(ctx context.Context, marshaler runtime.Marshaler, server NeutrinoKitServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq GetCFilterRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
var (
|
||||
val string
|
||||
ok bool
|
||||
err error
|
||||
_ = err
|
||||
)
|
||||
|
||||
val, ok = pathParams["hash"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "hash")
|
||||
}
|
||||
|
||||
protoReq.Hash, err = runtime.String(val)
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "hash", err)
|
||||
}
|
||||
|
||||
msg, err := server.GetCFilter(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterNeutrinoKitHandlerServer registers the http handlers for service NeutrinoKit to "mux".
|
||||
// UnaryRPC :call NeutrinoKitServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterNeutrinoKitHandlerFromEndpoint instead.
|
||||
func RegisterNeutrinoKitHandlerServer(ctx context.Context, mux *runtime.ServeMux, server NeutrinoKitServer) error {
|
||||
|
||||
mux.Handle("GET", pattern_NeutrinoKit_Status_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/neutrinorpc.NeutrinoKit/Status", runtime.WithHTTPPathPattern("/v2/neutrino/status"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_NeutrinoKit_Status_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_NeutrinoKit_Status_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_NeutrinoKit_AddPeer_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/neutrinorpc.NeutrinoKit/AddPeer", runtime.WithHTTPPathPattern("/v2/neutrino/addpeer"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_NeutrinoKit_AddPeer_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_NeutrinoKit_AddPeer_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_NeutrinoKit_DisconnectPeer_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/neutrinorpc.NeutrinoKit/DisconnectPeer", runtime.WithHTTPPathPattern("/v2/neutrino/disconnect"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_NeutrinoKit_DisconnectPeer_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_NeutrinoKit_DisconnectPeer_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_NeutrinoKit_IsBanned_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/neutrinorpc.NeutrinoKit/IsBanned", runtime.WithHTTPPathPattern("/v2/neutrino/isbanned"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_NeutrinoKit_IsBanned_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_NeutrinoKit_IsBanned_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_NeutrinoKit_GetBlockHeader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/neutrinorpc.NeutrinoKit/GetBlockHeader", runtime.WithHTTPPathPattern("/v2/neutrino/blockheader/{hash}"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_NeutrinoKit_GetBlockHeader_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_NeutrinoKit_GetBlockHeader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_NeutrinoKit_GetBlock_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/neutrinorpc.NeutrinoKit/GetBlock", runtime.WithHTTPPathPattern("/v2/neutrino/block/{hash}"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_NeutrinoKit_GetBlock_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_NeutrinoKit_GetBlock_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_NeutrinoKit_GetCFilter_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/neutrinorpc.NeutrinoKit/GetCFilter", runtime.WithHTTPPathPattern("/v2/neutrino/cfilter/{hash}"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_NeutrinoKit_GetCFilter_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_NeutrinoKit_GetCFilter_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterNeutrinoKitHandlerFromEndpoint is same as RegisterNeutrinoKitHandler but
|
||||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
||||
func RegisterNeutrinoKitHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
||||
conn, err := grpc.Dial(endpoint, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
}()
|
||||
}()
|
||||
|
||||
return RegisterNeutrinoKitHandler(ctx, mux, conn)
|
||||
}
|
||||
|
||||
// RegisterNeutrinoKitHandler registers the http handlers for service NeutrinoKit to "mux".
|
||||
// The handlers forward requests to the grpc endpoint over "conn".
|
||||
func RegisterNeutrinoKitHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
||||
return RegisterNeutrinoKitHandlerClient(ctx, mux, NewNeutrinoKitClient(conn))
|
||||
}
|
||||
|
||||
// RegisterNeutrinoKitHandlerClient registers the http handlers for service NeutrinoKit
|
||||
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "NeutrinoKitClient".
|
||||
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "NeutrinoKitClient"
|
||||
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
|
||||
// "NeutrinoKitClient" to call the correct interceptors.
|
||||
func RegisterNeutrinoKitHandlerClient(ctx context.Context, mux *runtime.ServeMux, client NeutrinoKitClient) error {
|
||||
|
||||
mux.Handle("GET", pattern_NeutrinoKit_Status_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req, "/neutrinorpc.NeutrinoKit/Status", runtime.WithHTTPPathPattern("/v2/neutrino/status"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_NeutrinoKit_Status_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_NeutrinoKit_Status_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_NeutrinoKit_AddPeer_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req, "/neutrinorpc.NeutrinoKit/AddPeer", runtime.WithHTTPPathPattern("/v2/neutrino/addpeer"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_NeutrinoKit_AddPeer_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_NeutrinoKit_AddPeer_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("POST", pattern_NeutrinoKit_DisconnectPeer_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req, "/neutrinorpc.NeutrinoKit/DisconnectPeer", runtime.WithHTTPPathPattern("/v2/neutrino/disconnect"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_NeutrinoKit_DisconnectPeer_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_NeutrinoKit_DisconnectPeer_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_NeutrinoKit_IsBanned_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req, "/neutrinorpc.NeutrinoKit/IsBanned", runtime.WithHTTPPathPattern("/v2/neutrino/isbanned"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_NeutrinoKit_IsBanned_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_NeutrinoKit_IsBanned_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_NeutrinoKit_GetBlockHeader_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req, "/neutrinorpc.NeutrinoKit/GetBlockHeader", runtime.WithHTTPPathPattern("/v2/neutrino/blockheader/{hash}"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_NeutrinoKit_GetBlockHeader_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_NeutrinoKit_GetBlockHeader_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_NeutrinoKit_GetBlock_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req, "/neutrinorpc.NeutrinoKit/GetBlock", runtime.WithHTTPPathPattern("/v2/neutrino/block/{hash}"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_NeutrinoKit_GetBlock_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_NeutrinoKit_GetBlock_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_NeutrinoKit_GetCFilter_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req, "/neutrinorpc.NeutrinoKit/GetCFilter", runtime.WithHTTPPathPattern("/v2/neutrino/cfilter/{hash}"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_NeutrinoKit_GetCFilter_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_NeutrinoKit_GetCFilter_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_NeutrinoKit_Status_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "neutrino", "status"}, ""))
|
||||
|
||||
pattern_NeutrinoKit_AddPeer_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "neutrino", "addpeer"}, ""))
|
||||
|
||||
pattern_NeutrinoKit_DisconnectPeer_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "neutrino", "disconnect"}, ""))
|
||||
|
||||
pattern_NeutrinoKit_IsBanned_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v2", "neutrino", "isbanned"}, ""))
|
||||
|
||||
pattern_NeutrinoKit_GetBlockHeader_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v2", "neutrino", "blockheader", "hash"}, ""))
|
||||
|
||||
pattern_NeutrinoKit_GetBlock_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v2", "neutrino", "block", "hash"}, ""))
|
||||
|
||||
pattern_NeutrinoKit_GetCFilter_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v2", "neutrino", "cfilter", "hash"}, ""))
|
||||
)
|
||||
|
||||
var (
|
||||
forward_NeutrinoKit_Status_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_NeutrinoKit_AddPeer_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_NeutrinoKit_DisconnectPeer_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_NeutrinoKit_IsBanned_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_NeutrinoKit_GetBlockHeader_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_NeutrinoKit_GetBlock_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_NeutrinoKit_GetCFilter_0 = runtime.ForwardResponseMessage
|
||||
)
|
210
lnrpc/neutrinorpc/neutrino.proto
Normal file
210
lnrpc/neutrinorpc/neutrino.proto
Normal file
@ -0,0 +1,210 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package neutrinorpc;
|
||||
|
||||
option go_package = "github.com/lightningnetwork/lnd/lnrpc/neutrinorpc";
|
||||
|
||||
// NeutrinoKit is a service that can be used to get information about the
|
||||
// current state of the neutrino instance, fetch blocks and add/remove peers.
|
||||
service NeutrinoKit {
|
||||
/*
|
||||
Status returns the status of the light client neutrino instance,
|
||||
along with height and hash of the best block, and a list of connected
|
||||
peers.
|
||||
*/
|
||||
rpc Status (StatusRequest) returns (StatusResponse);
|
||||
|
||||
/*
|
||||
AddPeer adds a new peer that has already been connected to the server.
|
||||
*/
|
||||
rpc AddPeer (AddPeerRequest) returns (AddPeerResponse);
|
||||
|
||||
/*
|
||||
DisconnectPeer disconnects a peer by target address. Both outbound and
|
||||
inbound nodes will be searched for the target node. An error message will
|
||||
be returned if the peer was not found.
|
||||
*/
|
||||
rpc DisconnectPeer (DisconnectPeerRequest) returns (DisconnectPeerResponse);
|
||||
|
||||
/*
|
||||
IsBanned returns true if the peer is banned, otherwise false.
|
||||
*/
|
||||
rpc IsBanned (IsBannedRequest) returns (IsBannedResponse);
|
||||
|
||||
/*
|
||||
GetBlockHeader returns a block header with a particular block hash.
|
||||
*/
|
||||
rpc GetBlockHeader (GetBlockHeaderRequest) returns (GetBlockHeaderResponse);
|
||||
|
||||
/*
|
||||
GetBlock returns a block with a particular block hash.
|
||||
*/
|
||||
rpc GetBlock (GetBlockRequest) returns (GetBlockResponse);
|
||||
|
||||
/*
|
||||
GetCFilter returns a compact filter from a block.
|
||||
*/
|
||||
rpc GetCFilter (GetCFilterRequest) returns (GetCFilterResponse);
|
||||
}
|
||||
|
||||
message StatusRequest {
|
||||
}
|
||||
|
||||
message StatusResponse {
|
||||
// Indicates whether the neutrino backend is active or not.
|
||||
bool active = 1;
|
||||
|
||||
// Is fully synced.
|
||||
bool synced = 2;
|
||||
|
||||
// Best block height.
|
||||
int32 block_height = 3;
|
||||
|
||||
// Best block hash.
|
||||
string block_hash = 4;
|
||||
|
||||
// Connected peers.
|
||||
repeated string peers = 5;
|
||||
}
|
||||
|
||||
message AddPeerRequest {
|
||||
// Peer to add.
|
||||
string peer_addrs = 1;
|
||||
}
|
||||
|
||||
message AddPeerResponse {
|
||||
}
|
||||
|
||||
message DisconnectPeerRequest {
|
||||
// Peer to disconnect.
|
||||
string peer_addrs = 1;
|
||||
}
|
||||
|
||||
message DisconnectPeerResponse {
|
||||
}
|
||||
|
||||
message IsBannedRequest {
|
||||
// Peer to lookup.
|
||||
string peer_addrs = 1;
|
||||
}
|
||||
|
||||
message IsBannedResponse {
|
||||
bool banned = 1;
|
||||
}
|
||||
|
||||
message GetBlockHeaderRequest {
|
||||
// Block hash in hex notation.
|
||||
string hash = 1;
|
||||
}
|
||||
|
||||
message GetBlockHeaderResponse {
|
||||
// The block hash (same as provided).
|
||||
string hash = 1;
|
||||
|
||||
// The number of confirmations.
|
||||
int64 confirmations = 2;
|
||||
|
||||
// The block size excluding witness data.
|
||||
int64 stripped_size = 3;
|
||||
|
||||
// The block size (bytes).
|
||||
int64 size = 4;
|
||||
|
||||
// The block weight as defined in BIP 141.
|
||||
int64 weight = 5;
|
||||
|
||||
// The block height or index.
|
||||
int32 height = 6;
|
||||
|
||||
// The block version.
|
||||
int32 version = 7;
|
||||
|
||||
// The block version.
|
||||
string version_hex = 8;
|
||||
|
||||
// The merkle root.
|
||||
string merkleroot = 9;
|
||||
|
||||
// The block time in seconds since epoch (Jan 1 1970 GMT).
|
||||
int64 time = 10;
|
||||
|
||||
// The nonce.
|
||||
uint32 nonce = 11;
|
||||
|
||||
// The bits in hex notation.
|
||||
string bits = 12;
|
||||
|
||||
// The number of transactions in the block.
|
||||
int32 ntx = 13;
|
||||
|
||||
// The hash of the previous block.
|
||||
string previous_block_hash = 14;
|
||||
|
||||
// The raw hex of the block.
|
||||
bytes raw_hex = 15;
|
||||
}
|
||||
|
||||
message GetBlockRequest {
|
||||
// Block hash in hex notation.
|
||||
string hash = 1;
|
||||
}
|
||||
|
||||
message GetBlockResponse {
|
||||
// The block hash (same as provided).
|
||||
string hash = 1;
|
||||
|
||||
// The number of confirmations.
|
||||
int64 confirmations = 2;
|
||||
|
||||
// The block size excluding witness data.
|
||||
int64 stripped_size = 3;
|
||||
|
||||
// The block size (bytes).
|
||||
int64 size = 4;
|
||||
|
||||
// The block weight as defined in BIP 141.
|
||||
int64 weight = 5;
|
||||
|
||||
// The block height or index.
|
||||
int32 height = 6;
|
||||
|
||||
// The block version.
|
||||
int32 version = 7;
|
||||
|
||||
// The block version.
|
||||
string version_hex = 8;
|
||||
|
||||
// The merkle root.
|
||||
string merkleroot = 9;
|
||||
|
||||
// List of transaction ids.
|
||||
repeated string tx = 10;
|
||||
|
||||
// The block time in seconds since epoch (Jan 1 1970 GMT).
|
||||
int64 time = 11;
|
||||
|
||||
// The nonce.
|
||||
uint32 nonce = 12;
|
||||
|
||||
// The bits in hex notation.
|
||||
string bits = 13;
|
||||
|
||||
// The number of transactions in the block.
|
||||
int32 ntx = 14;
|
||||
|
||||
// The hash of the previous block.
|
||||
string previous_block_hash = 15;
|
||||
|
||||
// The raw hex of the block.
|
||||
bytes raw_hex = 16;
|
||||
}
|
||||
|
||||
message GetCFilterRequest {
|
||||
// Block hash in hex notation.
|
||||
string hash = 1;
|
||||
}
|
||||
|
||||
message GetCFilterResponse {
|
||||
// GCS filter.
|
||||
bytes filter = 1;
|
||||
}
|
497
lnrpc/neutrinorpc/neutrino.swagger.json
Normal file
497
lnrpc/neutrinorpc/neutrino.swagger.json
Normal file
@ -0,0 +1,497 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "neutrinorpc/neutrino.proto",
|
||||
"version": "version not set"
|
||||
},
|
||||
"tags": [
|
||||
{
|
||||
"name": "NeutrinoKit"
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/v2/neutrino/addpeer": {
|
||||
"post": {
|
||||
"summary": "AddPeer adds a new peer that has already been connected to the server.",
|
||||
"operationId": "NeutrinoKit_AddPeer",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/neutrinorpcAddPeerResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/rpcStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/neutrinorpcAddPeerRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"NeutrinoKit"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v2/neutrino/block/{hash}": {
|
||||
"get": {
|
||||
"summary": "GetBlock returns a block with a particular block hash.",
|
||||
"operationId": "NeutrinoKit_GetBlock",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/neutrinorpcGetBlockResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/rpcStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "hash",
|
||||
"description": "Block hash in hex notation.",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"NeutrinoKit"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v2/neutrino/blockheader/{hash}": {
|
||||
"get": {
|
||||
"summary": "GetBlockHeader returns a block header with a particular block hash.",
|
||||
"operationId": "NeutrinoKit_GetBlockHeader",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/neutrinorpcGetBlockHeaderResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/rpcStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "hash",
|
||||
"description": "Block hash in hex notation.",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"NeutrinoKit"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v2/neutrino/cfilter/{hash}": {
|
||||
"get": {
|
||||
"summary": "GetCFilter returns a compact filter from a block.",
|
||||
"operationId": "NeutrinoKit_GetCFilter",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/neutrinorpcGetCFilterResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/rpcStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "hash",
|
||||
"description": "Block hash in hex notation.",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"NeutrinoKit"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v2/neutrino/disconnect": {
|
||||
"post": {
|
||||
"summary": "DisconnectPeer disconnects a peer by target address. Both outbound and\ninbound nodes will be searched for the target node. An error message will\nbe returned if the peer was not found.",
|
||||
"operationId": "NeutrinoKit_DisconnectPeer",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/neutrinorpcDisconnectPeerResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/rpcStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/neutrinorpcDisconnectPeerRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"NeutrinoKit"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v2/neutrino/isbanned": {
|
||||
"get": {
|
||||
"summary": "IsBanned returns true if the peer is banned, otherwise false.",
|
||||
"operationId": "NeutrinoKit_IsBanned",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/neutrinorpcIsBannedResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/rpcStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "peer_addrs",
|
||||
"description": "Peer to lookup.",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"NeutrinoKit"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v2/neutrino/status": {
|
||||
"get": {
|
||||
"summary": "Status returns the status of the light client neutrino instance,\nalong with height and hash of the best block, and a list of connected\npeers.",
|
||||
"operationId": "NeutrinoKit_Status",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/neutrinorpcStatusResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/rpcStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"NeutrinoKit"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"neutrinorpcAddPeerRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"peer_addrs": {
|
||||
"type": "string",
|
||||
"description": "Peer to add."
|
||||
}
|
||||
}
|
||||
},
|
||||
"neutrinorpcAddPeerResponse": {
|
||||
"type": "object"
|
||||
},
|
||||
"neutrinorpcDisconnectPeerRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"peer_addrs": {
|
||||
"type": "string",
|
||||
"description": "Peer to disconnect."
|
||||
}
|
||||
}
|
||||
},
|
||||
"neutrinorpcDisconnectPeerResponse": {
|
||||
"type": "object"
|
||||
},
|
||||
"neutrinorpcGetBlockHeaderResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"hash": {
|
||||
"type": "string",
|
||||
"description": "The block hash (same as provided)."
|
||||
},
|
||||
"confirmations": {
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"description": "The number of confirmations."
|
||||
},
|
||||
"stripped_size": {
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"description": "The block size excluding witness data."
|
||||
},
|
||||
"size": {
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"description": "The block size (bytes)."
|
||||
},
|
||||
"weight": {
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"description": "The block weight as defined in BIP 141."
|
||||
},
|
||||
"height": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": "The block height or index."
|
||||
},
|
||||
"version": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": "The block version."
|
||||
},
|
||||
"version_hex": {
|
||||
"type": "string",
|
||||
"description": "The block version."
|
||||
},
|
||||
"merkleroot": {
|
||||
"type": "string",
|
||||
"description": "The merkle root."
|
||||
},
|
||||
"time": {
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"description": "The block time in seconds since epoch (Jan 1 1970 GMT)."
|
||||
},
|
||||
"nonce": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "The nonce."
|
||||
},
|
||||
"bits": {
|
||||
"type": "string",
|
||||
"description": "The bits in hex notation."
|
||||
},
|
||||
"ntx": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": "The number of transactions in the block."
|
||||
},
|
||||
"previous_block_hash": {
|
||||
"type": "string",
|
||||
"description": "The hash of the previous block."
|
||||
},
|
||||
"raw_hex": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"description": "The raw hex of the block."
|
||||
}
|
||||
}
|
||||
},
|
||||
"neutrinorpcGetBlockResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"hash": {
|
||||
"type": "string",
|
||||
"description": "The block hash (same as provided)."
|
||||
},
|
||||
"confirmations": {
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"description": "The number of confirmations."
|
||||
},
|
||||
"stripped_size": {
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"description": "The block size excluding witness data."
|
||||
},
|
||||
"size": {
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"description": "The block size (bytes)."
|
||||
},
|
||||
"weight": {
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"description": "The block weight as defined in BIP 141."
|
||||
},
|
||||
"height": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": "The block height or index."
|
||||
},
|
||||
"version": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": "The block version."
|
||||
},
|
||||
"version_hex": {
|
||||
"type": "string",
|
||||
"description": "The block version."
|
||||
},
|
||||
"merkleroot": {
|
||||
"type": "string",
|
||||
"description": "The merkle root."
|
||||
},
|
||||
"tx": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "List of transaction ids."
|
||||
},
|
||||
"time": {
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"description": "The block time in seconds since epoch (Jan 1 1970 GMT)."
|
||||
},
|
||||
"nonce": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "The nonce."
|
||||
},
|
||||
"bits": {
|
||||
"type": "string",
|
||||
"description": "The bits in hex notation."
|
||||
},
|
||||
"ntx": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": "The number of transactions in the block."
|
||||
},
|
||||
"previous_block_hash": {
|
||||
"type": "string",
|
||||
"description": "The hash of the previous block."
|
||||
},
|
||||
"raw_hex": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"description": "The raw hex of the block."
|
||||
}
|
||||
}
|
||||
},
|
||||
"neutrinorpcGetCFilterResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"filter": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"description": "GCS filter."
|
||||
}
|
||||
}
|
||||
},
|
||||
"neutrinorpcIsBannedResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"banned": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"neutrinorpcStatusResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"active": {
|
||||
"type": "boolean",
|
||||
"description": "Indicates whether the neutrino backend is active or not."
|
||||
},
|
||||
"synced": {
|
||||
"type": "boolean",
|
||||
"description": "Is fully synced."
|
||||
},
|
||||
"block_height": {
|
||||
"type": "integer",
|
||||
"format": "int32",
|
||||
"description": "Best block height."
|
||||
},
|
||||
"block_hash": {
|
||||
"type": "string",
|
||||
"description": "Best block hash."
|
||||
},
|
||||
"peers": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "Connected peers."
|
||||
}
|
||||
}
|
||||
},
|
||||
"protobufAny": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type_url": {
|
||||
"type": "string"
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"format": "byte"
|
||||
}
|
||||
}
|
||||
},
|
||||
"rpcStatus": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"details": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/protobufAny"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
21
lnrpc/neutrinorpc/neutrino.yaml
Normal file
21
lnrpc/neutrinorpc/neutrino.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
type: google.api.Service
|
||||
config_version: 3
|
||||
|
||||
http:
|
||||
rules:
|
||||
- selector: neutrinorpc.NeutrinoKit.Status
|
||||
get: "/v2/neutrino/status"
|
||||
- selector: neutrinorpc.NeutrinoKit.AddPeer
|
||||
post: "/v2/neutrino/addpeer"
|
||||
body: "*"
|
||||
- selector: neutrinorpc.NeutrinoKit.DisconnectPeer
|
||||
post: "/v2/neutrino/disconnect"
|
||||
body: "*"
|
||||
- selector: neutrinorpc.NeutrinoKit.IsBanned
|
||||
get: "/v2/neutrino/isbanned"
|
||||
- selector: neutrinorpc.NeutrinoKit.GetBlock
|
||||
get: "/v2/neutrino/block/{hash}"
|
||||
- selector: neutrinorpc.NeutrinoKit.GetBlockHeader
|
||||
get: "/v2/neutrino/blockheader/{hash}"
|
||||
- selector: neutrinorpc.NeutrinoKit.GetCFilter
|
||||
get: "/v2/neutrino/cfilter/{hash}"
|
353
lnrpc/neutrinorpc/neutrino_grpc.pb.go
Normal file
353
lnrpc/neutrinorpc/neutrino_grpc.pb.go
Normal file
@ -0,0 +1,353 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
|
||||
package neutrinorpc
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
// NeutrinoKitClient is the client API for NeutrinoKit service.
|
||||
//
|
||||
// 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 NeutrinoKitClient interface {
|
||||
//
|
||||
//Status returns the status of the light client neutrino instance,
|
||||
//along with height and hash of the best block, and a list of connected
|
||||
//peers.
|
||||
Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*StatusResponse, error)
|
||||
//
|
||||
//AddPeer adds a new peer that has already been connected to the server.
|
||||
AddPeer(ctx context.Context, in *AddPeerRequest, opts ...grpc.CallOption) (*AddPeerResponse, error)
|
||||
//
|
||||
//DisconnectPeer disconnects a peer by target address. Both outbound and
|
||||
//inbound nodes will be searched for the target node. An error message will
|
||||
//be returned if the peer was not found.
|
||||
DisconnectPeer(ctx context.Context, in *DisconnectPeerRequest, opts ...grpc.CallOption) (*DisconnectPeerResponse, error)
|
||||
//
|
||||
//IsBanned returns true if the peer is banned, otherwise false.
|
||||
IsBanned(ctx context.Context, in *IsBannedRequest, opts ...grpc.CallOption) (*IsBannedResponse, error)
|
||||
//
|
||||
//GetBlockHeader returns a block header with a particular block hash.
|
||||
GetBlockHeader(ctx context.Context, in *GetBlockHeaderRequest, opts ...grpc.CallOption) (*GetBlockHeaderResponse, error)
|
||||
//
|
||||
//GetBlock returns a block with a particular block hash.
|
||||
GetBlock(ctx context.Context, in *GetBlockRequest, opts ...grpc.CallOption) (*GetBlockResponse, error)
|
||||
//
|
||||
//GetCFilter returns a compact filter from a block.
|
||||
GetCFilter(ctx context.Context, in *GetCFilterRequest, opts ...grpc.CallOption) (*GetCFilterResponse, error)
|
||||
}
|
||||
|
||||
type neutrinoKitClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewNeutrinoKitClient(cc grpc.ClientConnInterface) NeutrinoKitClient {
|
||||
return &neutrinoKitClient{cc}
|
||||
}
|
||||
|
||||
func (c *neutrinoKitClient) Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*StatusResponse, error) {
|
||||
out := new(StatusResponse)
|
||||
err := c.cc.Invoke(ctx, "/neutrinorpc.NeutrinoKit/Status", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *neutrinoKitClient) AddPeer(ctx context.Context, in *AddPeerRequest, opts ...grpc.CallOption) (*AddPeerResponse, error) {
|
||||
out := new(AddPeerResponse)
|
||||
err := c.cc.Invoke(ctx, "/neutrinorpc.NeutrinoKit/AddPeer", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *neutrinoKitClient) DisconnectPeer(ctx context.Context, in *DisconnectPeerRequest, opts ...grpc.CallOption) (*DisconnectPeerResponse, error) {
|
||||
out := new(DisconnectPeerResponse)
|
||||
err := c.cc.Invoke(ctx, "/neutrinorpc.NeutrinoKit/DisconnectPeer", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *neutrinoKitClient) IsBanned(ctx context.Context, in *IsBannedRequest, opts ...grpc.CallOption) (*IsBannedResponse, error) {
|
||||
out := new(IsBannedResponse)
|
||||
err := c.cc.Invoke(ctx, "/neutrinorpc.NeutrinoKit/IsBanned", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *neutrinoKitClient) GetBlockHeader(ctx context.Context, in *GetBlockHeaderRequest, opts ...grpc.CallOption) (*GetBlockHeaderResponse, error) {
|
||||
out := new(GetBlockHeaderResponse)
|
||||
err := c.cc.Invoke(ctx, "/neutrinorpc.NeutrinoKit/GetBlockHeader", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *neutrinoKitClient) GetBlock(ctx context.Context, in *GetBlockRequest, opts ...grpc.CallOption) (*GetBlockResponse, error) {
|
||||
out := new(GetBlockResponse)
|
||||
err := c.cc.Invoke(ctx, "/neutrinorpc.NeutrinoKit/GetBlock", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *neutrinoKitClient) GetCFilter(ctx context.Context, in *GetCFilterRequest, opts ...grpc.CallOption) (*GetCFilterResponse, error) {
|
||||
out := new(GetCFilterResponse)
|
||||
err := c.cc.Invoke(ctx, "/neutrinorpc.NeutrinoKit/GetCFilter", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// NeutrinoKitServer is the server API for NeutrinoKit service.
|
||||
// All implementations must embed UnimplementedNeutrinoKitServer
|
||||
// for forward compatibility
|
||||
type NeutrinoKitServer interface {
|
||||
//
|
||||
//Status returns the status of the light client neutrino instance,
|
||||
//along with height and hash of the best block, and a list of connected
|
||||
//peers.
|
||||
Status(context.Context, *StatusRequest) (*StatusResponse, error)
|
||||
//
|
||||
//AddPeer adds a new peer that has already been connected to the server.
|
||||
AddPeer(context.Context, *AddPeerRequest) (*AddPeerResponse, error)
|
||||
//
|
||||
//DisconnectPeer disconnects a peer by target address. Both outbound and
|
||||
//inbound nodes will be searched for the target node. An error message will
|
||||
//be returned if the peer was not found.
|
||||
DisconnectPeer(context.Context, *DisconnectPeerRequest) (*DisconnectPeerResponse, error)
|
||||
//
|
||||
//IsBanned returns true if the peer is banned, otherwise false.
|
||||
IsBanned(context.Context, *IsBannedRequest) (*IsBannedResponse, error)
|
||||
//
|
||||
//GetBlockHeader returns a block header with a particular block hash.
|
||||
GetBlockHeader(context.Context, *GetBlockHeaderRequest) (*GetBlockHeaderResponse, error)
|
||||
//
|
||||
//GetBlock returns a block with a particular block hash.
|
||||
GetBlock(context.Context, *GetBlockRequest) (*GetBlockResponse, error)
|
||||
//
|
||||
//GetCFilter returns a compact filter from a block.
|
||||
GetCFilter(context.Context, *GetCFilterRequest) (*GetCFilterResponse, error)
|
||||
mustEmbedUnimplementedNeutrinoKitServer()
|
||||
}
|
||||
|
||||
// UnimplementedNeutrinoKitServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedNeutrinoKitServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedNeutrinoKitServer) Status(context.Context, *StatusRequest) (*StatusResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Status not implemented")
|
||||
}
|
||||
func (UnimplementedNeutrinoKitServer) AddPeer(context.Context, *AddPeerRequest) (*AddPeerResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method AddPeer not implemented")
|
||||
}
|
||||
func (UnimplementedNeutrinoKitServer) DisconnectPeer(context.Context, *DisconnectPeerRequest) (*DisconnectPeerResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DisconnectPeer not implemented")
|
||||
}
|
||||
func (UnimplementedNeutrinoKitServer) IsBanned(context.Context, *IsBannedRequest) (*IsBannedResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method IsBanned not implemented")
|
||||
}
|
||||
func (UnimplementedNeutrinoKitServer) GetBlockHeader(context.Context, *GetBlockHeaderRequest) (*GetBlockHeaderResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetBlockHeader not implemented")
|
||||
}
|
||||
func (UnimplementedNeutrinoKitServer) GetBlock(context.Context, *GetBlockRequest) (*GetBlockResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetBlock not implemented")
|
||||
}
|
||||
func (UnimplementedNeutrinoKitServer) GetCFilter(context.Context, *GetCFilterRequest) (*GetCFilterResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetCFilter not implemented")
|
||||
}
|
||||
func (UnimplementedNeutrinoKitServer) mustEmbedUnimplementedNeutrinoKitServer() {}
|
||||
|
||||
// UnsafeNeutrinoKitServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to NeutrinoKitServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeNeutrinoKitServer interface {
|
||||
mustEmbedUnimplementedNeutrinoKitServer()
|
||||
}
|
||||
|
||||
func RegisterNeutrinoKitServer(s grpc.ServiceRegistrar, srv NeutrinoKitServer) {
|
||||
s.RegisterService(&NeutrinoKit_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _NeutrinoKit_Status_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(StatusRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(NeutrinoKitServer).Status(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/neutrinorpc.NeutrinoKit/Status",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(NeutrinoKitServer).Status(ctx, req.(*StatusRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _NeutrinoKit_AddPeer_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AddPeerRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(NeutrinoKitServer).AddPeer(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/neutrinorpc.NeutrinoKit/AddPeer",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(NeutrinoKitServer).AddPeer(ctx, req.(*AddPeerRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _NeutrinoKit_DisconnectPeer_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DisconnectPeerRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(NeutrinoKitServer).DisconnectPeer(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/neutrinorpc.NeutrinoKit/DisconnectPeer",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(NeutrinoKitServer).DisconnectPeer(ctx, req.(*DisconnectPeerRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _NeutrinoKit_IsBanned_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(IsBannedRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(NeutrinoKitServer).IsBanned(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/neutrinorpc.NeutrinoKit/IsBanned",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(NeutrinoKitServer).IsBanned(ctx, req.(*IsBannedRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _NeutrinoKit_GetBlockHeader_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetBlockHeaderRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(NeutrinoKitServer).GetBlockHeader(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/neutrinorpc.NeutrinoKit/GetBlockHeader",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(NeutrinoKitServer).GetBlockHeader(ctx, req.(*GetBlockHeaderRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _NeutrinoKit_GetBlock_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetBlockRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(NeutrinoKitServer).GetBlock(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/neutrinorpc.NeutrinoKit/GetBlock",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(NeutrinoKitServer).GetBlock(ctx, req.(*GetBlockRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _NeutrinoKit_GetCFilter_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetCFilterRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(NeutrinoKitServer).GetCFilter(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/neutrinorpc.NeutrinoKit/GetCFilter",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(NeutrinoKitServer).GetCFilter(ctx, req.(*GetCFilterRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// NeutrinoKit_ServiceDesc is the grpc.ServiceDesc for NeutrinoKit service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var NeutrinoKit_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "neutrinorpc.NeutrinoKit",
|
||||
HandlerType: (*NeutrinoKitServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "Status",
|
||||
Handler: _NeutrinoKit_Status_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "AddPeer",
|
||||
Handler: _NeutrinoKit_AddPeer_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DisconnectPeer",
|
||||
Handler: _NeutrinoKit_DisconnectPeer_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "IsBanned",
|
||||
Handler: _NeutrinoKit_IsBanned_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetBlockHeader",
|
||||
Handler: _NeutrinoKit_GetBlockHeader_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetBlock",
|
||||
Handler: _NeutrinoKit_GetBlock_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetCFilter",
|
||||
Handler: _NeutrinoKit_GetCFilter_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "neutrinorpc/neutrino.proto",
|
||||
}
|
425
lnrpc/neutrinorpc/neutrino_server.go
Normal file
425
lnrpc/neutrinorpc/neutrino_server.go
Normal file
@ -0,0 +1,425 @@
|
||||
//go:build neutrinorpc
|
||||
// +build neutrinorpc
|
||||
|
||||
package neutrinorpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"gopkg.in/macaroon-bakery.v2/bakery"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
|
||||
"github.com/btcsuite/btcd/blockchain"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
)
|
||||
|
||||
const (
|
||||
// subServerName is the name of the sub rpc server. We'll use this name
|
||||
// to register ourselves, and we also require that the main
|
||||
// SubServerConfigDispatcher instance recognize it as the name of our
|
||||
// RPC service.
|
||||
subServerName = "NeutrinoKitRPC"
|
||||
)
|
||||
|
||||
var (
|
||||
// macPermissions maps RPC calls to the permissions they require.
|
||||
macPermissions = map[string][]bakery.Op{
|
||||
"/neutrinorpc.NeutrinoKit/Status": {{
|
||||
Entity: "info",
|
||||
Action: "read",
|
||||
}},
|
||||
"/neutrinorpc.NeutrinoKit/AddPeer": {{
|
||||
Entity: "peers",
|
||||
Action: "write",
|
||||
}},
|
||||
"/neutrinorpc.NeutrinoKit/DisconnectPeer": {{
|
||||
Entity: "peers",
|
||||
Action: "write",
|
||||
}},
|
||||
"/neutrinorpc.NeutrinoKit/IsBanned": {{
|
||||
Entity: "info",
|
||||
Action: "read",
|
||||
}},
|
||||
"/neutrinorpc.NeutrinoKit/GetBlock": {{
|
||||
Entity: "onchain",
|
||||
Action: "read",
|
||||
}},
|
||||
"/neutrinorpc.NeutrinoKit/GetBlockHeader": {{
|
||||
Entity: "onchain",
|
||||
Action: "read",
|
||||
}},
|
||||
"/neutrinorpc.NeutrinoKit/GetCFilter": {{
|
||||
Entity: "onchain",
|
||||
Action: "read",
|
||||
}},
|
||||
}
|
||||
|
||||
// ErrNeutrinoNotActive is an error returned when there is no running
|
||||
// neutrino light client instance.
|
||||
ErrNeutrinoNotActive = errors.New("no active neutrino instance")
|
||||
)
|
||||
|
||||
// ServerShell is a shell struct holding a reference to the actual sub-server.
|
||||
// It is used to register the gRPC sub-server with the root server before we
|
||||
// have the necessary dependencies to populate the actual sub-server.
|
||||
type ServerShell struct {
|
||||
NeutrinoKitServer
|
||||
}
|
||||
|
||||
// Server is a sub-server of the main RPC server: the neutrino RPC. This sub
|
||||
// RPC server allows external callers to access the status of the neutrino
|
||||
// currently active within lnd, as well as configuring it at runtime.
|
||||
type Server struct {
|
||||
// Required by the grpc-gateway/v2 library for forward compatibility.
|
||||
// Must be after the atomically used variables to not break struct
|
||||
// alignment.
|
||||
UnimplementedNeutrinoKitServer
|
||||
|
||||
cfg *Config
|
||||
}
|
||||
|
||||
// A compile time check to ensure that NeutrinoKit fully implements the
|
||||
// NeutrinoServer gRPC service.
|
||||
var _ NeutrinoKitServer = (*Server)(nil)
|
||||
|
||||
// New returns a new instance of the neutrinorpc Neutrino sub-server. We also
|
||||
// return the set of permissions for the macaroons that we may create within
|
||||
// this method. If the macaroons we need aren't found in the filepath, then
|
||||
// we'll create them on start up. If we're unable to locate, or create the
|
||||
// macaroons we need, then we'll return with an error.
|
||||
func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
|
||||
// We don't create any new macaroons for this subserver, instead reuse
|
||||
// existing onchain/offchain permissions.
|
||||
server := &Server{
|
||||
cfg: cfg,
|
||||
}
|
||||
|
||||
return server, macPermissions, nil
|
||||
}
|
||||
|
||||
// Start launches any helper goroutines required for the Server to function.
|
||||
//
|
||||
// NOTE: This is part of the lnrpc.SubServer interface.
|
||||
func (s *Server) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop signals any active goroutines for a graceful closure.
|
||||
//
|
||||
// NOTE: This is part of the lnrpc.SubServer interface.
|
||||
func (s *Server) Stop() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Name returns a unique string representation of the sub-server. This can be
|
||||
// used to identify the sub-server and also de-duplicate them.
|
||||
//
|
||||
// NOTE: This is part of the lnrpc.SubServer interface.
|
||||
func (s *Server) Name() string {
|
||||
return subServerName
|
||||
}
|
||||
|
||||
// RegisterWithRootServer will be called by the root gRPC server to direct a
|
||||
// sub RPC server to register itself with the main gRPC root server. Until this
|
||||
// is called, each sub-server won't be able to have
|
||||
// requests routed towards it.
|
||||
//
|
||||
// NOTE: This is part of the lnrpc.GrpcHandler interface.
|
||||
func (r *ServerShell) RegisterWithRootServer(grpcServer *grpc.Server) error {
|
||||
// We make sure that we register it with the main gRPC server to ensure
|
||||
// all our methods are routed properly.
|
||||
RegisterNeutrinoKitServer(grpcServer, r)
|
||||
|
||||
log.Debugf("Neutrino RPC server successfully register with root " +
|
||||
"gRPC server")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterWithRestServer will be called by the root REST mux to direct a sub
|
||||
// RPC server to register itself with the main REST mux server. Until this is
|
||||
// called, each sub-server won't be able to have requests routed towards it.
|
||||
//
|
||||
// NOTE: This is part of the lnrpc.GrpcHandler interface.
|
||||
func (r *ServerShell) RegisterWithRestServer(ctx context.Context,
|
||||
mux *runtime.ServeMux, dest string, opts []grpc.DialOption) error {
|
||||
|
||||
// We make sure that we register it with the main REST server to ensure
|
||||
// all our methods are routed properly.
|
||||
err := RegisterNeutrinoKitHandlerFromEndpoint(ctx, mux, dest, opts)
|
||||
if err != nil {
|
||||
log.Errorf("Could not register Neutrino REST server "+
|
||||
"with root REST server: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("Neutrino REST server successfully registered with " +
|
||||
"root REST server")
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateSubServer populates the subserver's dependencies using the passed
|
||||
// SubServerConfigDispatcher. This method should fully initialize the
|
||||
// sub-server instance, making it ready for action. It returns the macaroon
|
||||
// permissions that the sub-server wishes to pass on to the root server for all
|
||||
// methods routed towards it.
|
||||
//
|
||||
// NOTE: This is part of the lnrpc.GrpcHandler interface.
|
||||
func (r *ServerShell) CreateSubServer(configRegistry lnrpc.SubServerConfigDispatcher) (
|
||||
lnrpc.SubServer, lnrpc.MacaroonPerms, error) {
|
||||
|
||||
subServer, macPermissions, err := createNewSubServer(configRegistry)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
r.NeutrinoKitServer = subServer
|
||||
return subServer, macPermissions, nil
|
||||
}
|
||||
|
||||
// Status returns the current status, best block height and connected peers
|
||||
// of the neutrino node.
|
||||
//
|
||||
// NOTE: Part of the NeutrinoServer interface.
|
||||
func (s *Server) Status(ctx context.Context,
|
||||
in *StatusRequest) (*StatusResponse, error) {
|
||||
|
||||
if s.cfg.NeutrinoCS == nil {
|
||||
return &StatusResponse{}, nil
|
||||
}
|
||||
|
||||
bestBlock, err := s.cfg.NeutrinoCS.BestBlock()
|
||||
if err != nil {
|
||||
return &StatusResponse{},
|
||||
fmt.Errorf("could not get best block: %v", err)
|
||||
}
|
||||
|
||||
peers := s.cfg.NeutrinoCS.Peers()
|
||||
var Peers = make([]string, len(peers))
|
||||
for i, p := range peers {
|
||||
Peers[i] = p.Addr()
|
||||
}
|
||||
|
||||
return &StatusResponse{
|
||||
Active: s.cfg.NeutrinoCS != nil,
|
||||
BlockHeight: bestBlock.Height,
|
||||
BlockHash: bestBlock.Hash.String(),
|
||||
Synced: s.cfg.NeutrinoCS.IsCurrent(),
|
||||
Peers: Peers,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// AddPeer adds a new peer that has already been connected to the server.
|
||||
//
|
||||
// NOTE: Part of the NeutrinoKitServer interface.
|
||||
func (s *Server) AddPeer(ctx context.Context,
|
||||
in *AddPeerRequest) (*AddPeerResponse, error) {
|
||||
|
||||
if s.cfg.NeutrinoCS == nil {
|
||||
return &AddPeerResponse{}, ErrNeutrinoNotActive
|
||||
}
|
||||
|
||||
peer := s.cfg.NeutrinoCS.PeerByAddr(in.PeerAddrs)
|
||||
if peer == nil {
|
||||
return &AddPeerResponse{},
|
||||
fmt.Errorf("could not found peer: %s", in.PeerAddrs)
|
||||
}
|
||||
s.cfg.NeutrinoCS.AddPeer(peer)
|
||||
|
||||
return &AddPeerResponse{}, nil
|
||||
}
|
||||
|
||||
// DisconnectPeer disconnects a peer by target address. Both outbound and
|
||||
// inbound nodes will be searched for the target node. An error message will
|
||||
// be returned if the peer was not found.
|
||||
//
|
||||
// NOTE: Part of the NeutrinoKitServer interface.
|
||||
func (s *Server) DisconnectPeer(ctx context.Context,
|
||||
in *DisconnectPeerRequest) (*DisconnectPeerResponse, error) {
|
||||
|
||||
if s.cfg.NeutrinoCS == nil {
|
||||
return &DisconnectPeerResponse{}, ErrNeutrinoNotActive
|
||||
}
|
||||
|
||||
peer := s.cfg.NeutrinoCS.PeerByAddr(in.PeerAddrs)
|
||||
if peer == nil {
|
||||
return &DisconnectPeerResponse{},
|
||||
fmt.Errorf("could not found peer: %s", in.PeerAddrs)
|
||||
}
|
||||
|
||||
err := s.cfg.NeutrinoCS.DisconnectNodeByAddr(peer.Addr())
|
||||
if err != nil {
|
||||
return &DisconnectPeerResponse{}, err
|
||||
}
|
||||
|
||||
return &DisconnectPeerResponse{}, nil
|
||||
}
|
||||
|
||||
// IsBanned returns true if the peer is banned, otherwise false.
|
||||
//
|
||||
// NOTE: Part of the NeutrinoKitServer interface.
|
||||
func (s *Server) IsBanned(ctx context.Context,
|
||||
in *IsBannedRequest) (*IsBannedResponse, error) {
|
||||
|
||||
if s.cfg.NeutrinoCS == nil {
|
||||
return &IsBannedResponse{}, ErrNeutrinoNotActive
|
||||
}
|
||||
|
||||
return &IsBannedResponse{
|
||||
Banned: s.cfg.NeutrinoCS.IsBanned(in.PeerAddrs),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetBlockHeader returns a block header with a particular block hash. If the
|
||||
// block header is found in the cache, it will be returned immediately.
|
||||
// Otherwise a block will be requested from the network, one peer at a time,
|
||||
// until one answers.
|
||||
//
|
||||
// NOTE: Part of the NeutrinoKitServer interface.
|
||||
func (s *Server) GetBlockHeader(ctx context.Context,
|
||||
in *GetBlockHeaderRequest) (*GetBlockHeaderResponse, error) {
|
||||
|
||||
if s.cfg.NeutrinoCS == nil {
|
||||
return &GetBlockHeaderResponse{}, ErrNeutrinoNotActive
|
||||
}
|
||||
|
||||
var hash chainhash.Hash
|
||||
if err := chainhash.Decode(&hash, in.Hash); err != nil {
|
||||
return &GetBlockHeaderResponse{}, err
|
||||
}
|
||||
|
||||
resp, err := s.getBlock(hash)
|
||||
if err != nil {
|
||||
return &GetBlockHeaderResponse{}, err
|
||||
}
|
||||
|
||||
return &GetBlockHeaderResponse{
|
||||
Hash: resp.Hash,
|
||||
Confirmations: resp.Confirmations,
|
||||
StrippedSize: resp.StrippedSize,
|
||||
Size: resp.Size,
|
||||
Weight: resp.Weight,
|
||||
Height: resp.Height,
|
||||
Version: resp.Version,
|
||||
VersionHex: resp.VersionHex,
|
||||
Merkleroot: resp.Merkleroot,
|
||||
Time: resp.Time,
|
||||
Nonce: resp.Nonce,
|
||||
Bits: resp.Bits,
|
||||
Ntx: resp.Ntx,
|
||||
PreviousBlockHash: resp.PreviousBlockHash,
|
||||
RawHex: resp.RawHex,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetBlock returns a block with a particular block hash. If the block is
|
||||
// found in the cache, it will be returned immediately. Otherwise a block will
|
||||
// be requested from the network, one peer at a time, until one answers.
|
||||
//
|
||||
// NOTE: Part of the NeutrinoKitServer interface.
|
||||
func (s *Server) GetBlock(ctx context.Context,
|
||||
in *GetBlockRequest) (*GetBlockResponse, error) {
|
||||
|
||||
if s.cfg.NeutrinoCS == nil {
|
||||
return &GetBlockResponse{}, ErrNeutrinoNotActive
|
||||
}
|
||||
|
||||
var hash chainhash.Hash
|
||||
if err := chainhash.Decode(&hash, in.Hash); err != nil {
|
||||
return &GetBlockResponse{}, err
|
||||
}
|
||||
|
||||
return s.getBlock(hash)
|
||||
}
|
||||
|
||||
// GetCFilter returns a compact filter of a particular block.
|
||||
// If found, only regular filters will be returned.
|
||||
//
|
||||
// NOTE: Part of the NeutrinoKitServer interface.
|
||||
func (s *Server) GetCFilter(ctx context.Context,
|
||||
in *GetCFilterRequest) (*GetCFilterResponse, error) {
|
||||
|
||||
if s.cfg.NeutrinoCS == nil {
|
||||
return &GetCFilterResponse{}, ErrNeutrinoNotActive
|
||||
}
|
||||
|
||||
var hash chainhash.Hash
|
||||
if err := chainhash.Decode(&hash, in.Hash); err != nil {
|
||||
return &GetCFilterResponse{}, err
|
||||
}
|
||||
|
||||
// GetCFilter returns a compact filter from the database. If it is missing,
|
||||
// it requests the compact filter from the network.
|
||||
filter, err := s.cfg.NeutrinoCS.GetCFilter(hash, wire.GCSFilterRegular)
|
||||
if err != nil {
|
||||
return &GetCFilterResponse{}, err
|
||||
}
|
||||
|
||||
filterlBytes, err := filter.Bytes()
|
||||
if err != nil {
|
||||
return &GetCFilterResponse{}, err
|
||||
}
|
||||
|
||||
return &GetCFilterResponse{Filter: filterlBytes}, nil
|
||||
}
|
||||
|
||||
func (s *Server) getBlock(hash chainhash.Hash) (*GetBlockResponse, error) {
|
||||
block, err := s.cfg.NeutrinoCS.GetBlock(hash)
|
||||
if err != nil {
|
||||
return &GetBlockResponse{}, err
|
||||
}
|
||||
|
||||
header, _, err := s.cfg.NeutrinoCS.BlockHeaders.FetchHeader(&hash)
|
||||
if err != nil {
|
||||
return &GetBlockResponse{}, err
|
||||
}
|
||||
|
||||
blockData, err := block.Bytes()
|
||||
if err != nil {
|
||||
return &GetBlockResponse{}, err
|
||||
}
|
||||
|
||||
strippedData, err := block.BytesNoWitness()
|
||||
if err != nil {
|
||||
return &GetBlockResponse{}, err
|
||||
}
|
||||
|
||||
bestBlock, err := s.cfg.NeutrinoCS.BestBlock()
|
||||
if err != nil {
|
||||
return &GetBlockResponse{}, err
|
||||
}
|
||||
|
||||
// Convert txids to a string array.
|
||||
transactions := block.Transactions()
|
||||
tx := make([]string, len(transactions))
|
||||
for i := range transactions {
|
||||
tx[i] = transactions[i].Hash().String()
|
||||
}
|
||||
|
||||
return &GetBlockResponse{
|
||||
Hash: block.Hash().String(),
|
||||
Confirmations: int64(1 + bestBlock.Height - block.Height()),
|
||||
StrippedSize: int64(len(strippedData)),
|
||||
Size: int64(len(blockData)),
|
||||
Weight: blockchain.GetBlockWeight(block),
|
||||
Height: block.Height(),
|
||||
Version: header.Version,
|
||||
VersionHex: fmt.Sprintf("%0x", header.Version),
|
||||
Merkleroot: header.MerkleRoot.String(),
|
||||
Tx: tx,
|
||||
Time: header.Timestamp.Unix(),
|
||||
Nonce: header.Nonce,
|
||||
// Format bits as a hex.
|
||||
Bits: fmt.Sprintf("%0x", header.Bits),
|
||||
Ntx: int32(len(block.Transactions())),
|
||||
PreviousBlockHash: header.PrevBlock.String(),
|
||||
RawHex: blockData,
|
||||
}, nil
|
||||
}
|
200
lnrpc/neutrinorpc/neutrinokit.pb.json.go
Normal file
200
lnrpc/neutrinorpc/neutrinokit.pb.json.go
Normal file
@ -0,0 +1,200 @@
|
||||
// Code generated by falafel 0.9.1. DO NOT EDIT.
|
||||
// source: neutrino.proto
|
||||
|
||||
// +build js
|
||||
|
||||
package neutrinorpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
gateway "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
)
|
||||
|
||||
func RegisterNeutrinoKitJSONCallbacks(registry map[string]func(ctx context.Context,
|
||||
conn *grpc.ClientConn, reqJSON string, callback func(string, error))) {
|
||||
|
||||
marshaler := &gateway.JSONPb{
|
||||
MarshalOptions: protojson.MarshalOptions{
|
||||
UseProtoNames: true,
|
||||
EmitUnpopulated: true,
|
||||
},
|
||||
}
|
||||
|
||||
registry["neutrinorpc.NeutrinoKit.Status"] = func(ctx context.Context,
|
||||
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {
|
||||
|
||||
req := &StatusRequest{}
|
||||
err := marshaler.Unmarshal([]byte(reqJSON), req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
client := NewNeutrinoKitClient(conn)
|
||||
resp, err := client.Status(ctx, req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
respBytes, err := marshaler.Marshal(resp)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
callback(string(respBytes), nil)
|
||||
}
|
||||
|
||||
registry["neutrinorpc.NeutrinoKit.AddPeer"] = func(ctx context.Context,
|
||||
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {
|
||||
|
||||
req := &AddPeerRequest{}
|
||||
err := marshaler.Unmarshal([]byte(reqJSON), req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
client := NewNeutrinoKitClient(conn)
|
||||
resp, err := client.AddPeer(ctx, req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
respBytes, err := marshaler.Marshal(resp)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
callback(string(respBytes), nil)
|
||||
}
|
||||
|
||||
registry["neutrinorpc.NeutrinoKit.DisconnectPeer"] = func(ctx context.Context,
|
||||
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {
|
||||
|
||||
req := &DisconnectPeerRequest{}
|
||||
err := marshaler.Unmarshal([]byte(reqJSON), req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
client := NewNeutrinoKitClient(conn)
|
||||
resp, err := client.DisconnectPeer(ctx, req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
respBytes, err := marshaler.Marshal(resp)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
callback(string(respBytes), nil)
|
||||
}
|
||||
|
||||
registry["neutrinorpc.NeutrinoKit.IsBanned"] = func(ctx context.Context,
|
||||
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {
|
||||
|
||||
req := &IsBannedRequest{}
|
||||
err := marshaler.Unmarshal([]byte(reqJSON), req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
client := NewNeutrinoKitClient(conn)
|
||||
resp, err := client.IsBanned(ctx, req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
respBytes, err := marshaler.Marshal(resp)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
callback(string(respBytes), nil)
|
||||
}
|
||||
|
||||
registry["neutrinorpc.NeutrinoKit.GetBlockHeader"] = func(ctx context.Context,
|
||||
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {
|
||||
|
||||
req := &GetBlockHeaderRequest{}
|
||||
err := marshaler.Unmarshal([]byte(reqJSON), req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
client := NewNeutrinoKitClient(conn)
|
||||
resp, err := client.GetBlockHeader(ctx, req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
respBytes, err := marshaler.Marshal(resp)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
callback(string(respBytes), nil)
|
||||
}
|
||||
|
||||
registry["neutrinorpc.NeutrinoKit.GetBlock"] = func(ctx context.Context,
|
||||
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {
|
||||
|
||||
req := &GetBlockRequest{}
|
||||
err := marshaler.Unmarshal([]byte(reqJSON), req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
client := NewNeutrinoKitClient(conn)
|
||||
resp, err := client.GetBlock(ctx, req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
respBytes, err := marshaler.Marshal(resp)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
callback(string(respBytes), nil)
|
||||
}
|
||||
|
||||
registry["neutrinorpc.NeutrinoKit.GetCFilter"] = func(ctx context.Context,
|
||||
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {
|
||||
|
||||
req := &GetCFilterRequest{}
|
||||
err := marshaler.Unmarshal([]byte(reqJSON), req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
client := NewNeutrinoKitClient(conn)
|
||||
resp, err := client.GetCFilter(ctx, req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
respBytes, err := marshaler.Marshal(resp)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
callback(string(respBytes), nil)
|
||||
}
|
||||
}
|
2
log.go
2
log.go
@ -25,6 +25,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnrpc/chainrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/devrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/neutrinorpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/peersrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
|
||||
@ -141,6 +142,7 @@ func SetupLoggers(root *build.RotatingLogWriter, interceptor signal.Interceptor)
|
||||
AddSubLogger(root, "SGNR", interceptor, signrpc.UseLogger)
|
||||
AddSubLogger(root, "WLKT", interceptor, walletrpc.UseLogger)
|
||||
AddSubLogger(root, "ARPC", interceptor, autopilotrpc.UseLogger)
|
||||
AddSubLogger(root, "NRPC", interceptor, neutrinorpc.UseLogger)
|
||||
AddSubLogger(root, "DRPC", interceptor, devrpc.UseLogger)
|
||||
AddSubLogger(root, "INVC", interceptor, invoices.UseLogger)
|
||||
AddSubLogger(root, "NANN", interceptor, netann.UseLogger)
|
||||
|
@ -37,9 +37,9 @@ windows-386 \
|
||||
windows-amd64 \
|
||||
windows-arm
|
||||
|
||||
RELEASE_TAGS = autopilotrpc signrpc walletrpc chainrpc invoicesrpc watchtowerrpc monitoring peersrpc kvdb_postgres kvdb_etcd
|
||||
RELEASE_TAGS = autopilotrpc signrpc walletrpc chainrpc invoicesrpc watchtowerrpc neutrinorpc monitoring peersrpc kvdb_postgres kvdb_etcd
|
||||
|
||||
WASM_RELEASE_TAGS = autopilotrpc signrpc walletrpc chainrpc invoicesrpc watchtowerrpc monitoring peersrpc
|
||||
WASM_RELEASE_TAGS = autopilotrpc signrpc walletrpc chainrpc invoicesrpc watchtowerrpc neutrinorpc monitoring peersrpc
|
||||
|
||||
# One can either specify a git tag as the version suffix or one is generated
|
||||
# from the current date.
|
||||
|
@ -1,5 +1,5 @@
|
||||
DEV_TAGS = dev
|
||||
RPC_TAGS = autopilotrpc chainrpc invoicesrpc peersrpc routerrpc signrpc verrpc walletrpc watchtowerrpc wtclientrpc
|
||||
RPC_TAGS = autopilotrpc chainrpc invoicesrpc neutrinorpc peersrpc routerrpc signrpc verrpc walletrpc watchtowerrpc wtclientrpc
|
||||
LOG_TAGS =
|
||||
TEST_FLAGS =
|
||||
ITEST_FLAGS =
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnrpc/chainrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/devrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/neutrinorpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/peersrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
|
||||
@ -66,6 +67,10 @@ type subRPCServerConfigs struct {
|
||||
// as a gRPC service.
|
||||
PeersRPC *peersrpc.Config `group:"peersrpc" namespace:"peersrpc"`
|
||||
|
||||
// NeutrinoKitRPC is a sub-RPC server that exposes functionality allowing
|
||||
// a client to interact with a running neutrino node.
|
||||
NeutrinoKitRPC *neutrinorpc.Config `group:"neutrinorpc" namespace:"neutrinorpc"`
|
||||
|
||||
// RouterRPC is a sub-RPC server the exposes functionality that allows
|
||||
// clients to send payments on the network, and perform Lightning
|
||||
// payment related queries such as requests for estimates of off-chain
|
||||
@ -250,6 +255,13 @@ func (s *subRPCServerConfigs) PopulateDependencies(cfg *Config,
|
||||
reflect.ValueOf(genAmpInvoiceFeatures),
|
||||
)
|
||||
|
||||
case *neutrinorpc.Config:
|
||||
subCfgValue := extractReflectValue(subCfg)
|
||||
|
||||
subCfgValue.FieldByName("NeutrinoCS").Set(
|
||||
reflect.ValueOf(cc.Cfg.NeutrinoCS),
|
||||
)
|
||||
|
||||
// RouterRPC isn't conditionally compiled and doesn't need to be
|
||||
// populated using reflection.
|
||||
case *routerrpc.Config:
|
||||
|
Loading…
Reference in New Issue
Block a user