Package: lnd-rpc
lncm/lnd-rpcThis repo aims to makegrpccommunication with (any version of)lndtrivial.Currently,GoandPythonare supported.GoWhilelndnatively provides.gofiles for grpc communication, importing the entirety oflndsometimes causes issues with dependencies (ex. the infamousbtcdversioning), etc. We aim to solve it by having zero/minimal dependencies, and providing direct access to each version individually.UseThat snippet shows how to import grpc's from here, and use them to init authenticated lnd client.packagemainimport("context""encoding/hex""fmt""io/ioutil""time""google.golang.org/grpc""google.golang.org/grpc/credentials""gopkg.in/macaroon.v2""github.com/lncm/lnd-rpc/v0.10.0/lnrpc")typerpcCredsmap[string]stringfunc(mrpcCreds)RequireTransportSecurity()bool{returntrue}func(mrpcCreds)GetRequestMetadata(_context.Context,_...string)(map[string]string,error){returnm,nil}funcnewCreds(bytes[]byte)rpcCreds{creds:=make(map[string]string)creds["macaroon"]=hex.EncodeToString(bytes)returncreds}funcgetClient(hostnamestring,portint,tlsFile,macaroonFilestring)lnrpc.LightningClient{macaroonBytes,err:=ioutil.ReadFile(macaroonFile)iferr!=nil{panic(fmt.Sprintln("Cannot read macaroon file",err))}mac:=&macaroon.Macaroon{}iferr=mac.UnmarshalBinary(macaroonBytes);err!=nil{panic(fmt.Sprintln("Cannot unmarshal macaroon",err))}ctx,cancel:=context.WithTimeout(context.Background(),5*time.Second)defercancel()transportCredentials,err:=credentials.NewClientTLSFromFile(tlsFile,hostname)iferr!=nil{panic(err)}fullHostname:=fmt.Sprintf("%s:%d",hostname,port)connection,err:=grpc.DialContext(ctx,fullHostname,[]grpc.DialOption{grpc.WithBlock(),grpc.WithTransportCredentials(transportCredentials),grpc.WithPerRPCCredentials(newCreds(macaroonBytes)),}...)iferr!=nil{panic(fmt.Errorf("unable to connect to %s: %w",fullHostname,err))}returnlnrpc.NewLightningClient(connection)}funcmain(){const(hostname="node's hostname"port=10009tlsFile="path/to/tls.cert"macaroonFile="path/to/macaroon/file.macaroon")client:=getClient(hostname,port,tlsFile,macaroonFile)// Do stuff with the client…}Python3This repo also holds the source (and scrips necessary to generate) the contents oflnd-rpcPyPI package.  To use it, install the version of the version you want to use, and…Usepip3installlnd-rpcTODO:Add an example usage heretl;drThis repo helps with:download- download alllnd.proto's, and their dependenciesgenerate-go- generate.gosources for available.protofilesgenerate-python- generate.pysources for available.protofilesEach of these can be done in two ways:Run the script directlyViadocker runDownload./script/downloaddownloadsall.protofiles, and all their dependencies unless a specific version is provided.Run directly./scripts/download --help
download v1.0.0

Download all .proto files necessary to build lnd's gRPC client libraries

Usage: ./scripts/download [options] LND_VERSION

Where LND_VERSION is in a form: [v]MAJOR.MINOR.PATCH (ex: v0.9.0), or "all" to download all versions

Options:

  -h, --help, help      Show this help message
  -G, --no-google       Skip download of google/api/* and google/protobuf/*
  -S, --strip-version   Don't include lnd version in the path (only works if LND_VERSION != "all")
  -o, --output          Download to a specified dir (will be created, if doesn't exist)

Examples:

  ./scripts/download  all                          # Download all lnd versions, and all google/* protos
  ./scripts/download  --no-google  v0.4.2          # Only download protos for lnd v0.4.2, and no google/* protos
  ./scripts/download  -G -S -o=~/last-lnd/ v0.9.0  # Only download protos for lnd v0.9.0, and save them to last-lnd/
                                                   #    in user's HOME directory w/o the /LND_VERSION/ segment in path

github: github.com/lncm/lnd-rpc/DockerNOTE: this one requiresDOCKER_BUILDKIT=1due to usage of--target=# Build with:DOCKER_BUILDKIT=1dockerbuild.\--target=protos-downloader\--tag=lnd-rpc-downloader# Run with:dockerrun--rm-it\--volume=$(pwd)/:/protos/\lnd-rpc-downloader# [VERSION|all]Generate Go./scripts/generate-gogenerates.gofiles forallavailable versions, unless a specific version is provided.Run directly./scripts/generate-go --help
generate-go v1.0.0

Compile all .proto definitions into importable .go files

Usage: generate-go [options] LND_VERSION

Where LND_VERSION is in a form: [v]MAJOR.MINOR.PATCH (ex: v0.9.0), or "all" to generate for all versions

Options:

  -h, --help, help      Show this help message
  -S, --strip-version   Don't include lnd version in the path (only works if LND_VERSION != "all")
  -o, --output          Save generated files to a specified dir (created, if doesn't exist)

Examples:

  ./generate-go all
  ./generate-go  -o /tmp/last/  v0.9.0

github: github.com/lncm/lnd-rpc/Dockerdockerbuild.\--build-arg="LANG=go"\--tag=lnd-rpc-go

dockerrun--rm-it\--volume=$(pwd):/data/go/\lnd-rpc-go# [VERSION|all]Generate Python./scripts/generate-pythongenerates.pyfiles forallavailable versions, unless a specific version is provided.NOTE:All generated versions are published to PyPi usingthis workflowRun directly./scripts/generate-python --help
generate-python v1.0.0

Compile all .proto definitions into .py files

Usage: generate-python [options] LND_VERSION

Where LND_VERSION is in a form: [v]MAJOR.MINOR.PATCH (ex: v0.9.0), or "all" to generate for all versions

Options:

  -h, --help, help      Show this help message
  -S, --strip-version   Don't include lnd version in the path (only works if LND_VERSION != "all")
  -o, --output          Save generated files to a specified dir (created, if doesn't exist)

Examples:

  ./generate-python all
  ./generate-python  -o /tmp/last/  v0.9.0

github: github.com/lncm/lnd-rpc/Dockerdockerbuild.\--build-arg="LANG=python"\--tag=lnd-rpc-python

dockerrun--rm-it\--volume=$(pwd):/data/python/\lnd-rpc-python# [VERSION|all]