Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ env:
# go needs absolute directories, using the $HOME variable doesn't work here.
GOCACHE: /home/runner/work/go/pkg/build
GOPATH: /home/runner/work/go
DOWNLOAD_CACHE: /home/runner/work/download_cache
GO_VERSION: 1.14.4
GO_VERSION: 1.16.x

jobs:
build:
name: build package
name: build package, run linter
runs-on: ubuntu-latest
steps:
- name: git checkout
Expand All @@ -31,17 +30,23 @@ jobs:
uses: actions/cache@v1
with:
path: /home/runner/work/go
key: lnd-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
key: lndclient-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
lnd-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
lnd-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-
lnd-${{ runner.os }}-go-${{ env.GO_VERSION }}-
lnd-${{ runner.os }}-go-
lndclient-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
lndclient-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-
lndclient-${{ runner.os }}-go-${{ env.GO_VERSION }}-
lndclient-${{ runner.os }}-go-

- name: setup go ${{ env.GO_VERSION }}
uses: actions/setup-go@v2
with:
go-version: '~${{ env.GO_VERSION }}'

- name: compile
run: go build
run: make build

- name: lint
run: make lint

- name: unit-race
run: make unit-race
31 changes: 31 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
run:
# timeout for analysis
deadline: 4m

linters-settings:
govet:
# Don't report about shadowed variables
check-shadowing: false
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true

linters:
enable-all: true
disable:
# Init functions are used by loggers throughout the codebase.
- gochecknoinits

# Global variables are used by loggers.
- gochecknoglobals

# Some lines are over 80 characters on purpose and we don't want to make
# them even longer by marking them as 'nolint'.
- lll

# We don't care (enough) about misaligned structs to lint that.
- maligned

# We have long functions, especially in tests. Moving or renaming those
# would trigger funlen problems that we may not want to solve at that time.
- funlen
82 changes: 82 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
PKG := github.com/lightninglabs/lndclient

LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint

GO_BIN := ${GOPATH}/bin
LINT_BIN := $(GO_BIN)/golangci-lint

LINT_COMMIT := v1.18.0

DEPGET := cd /tmp && go get -v
GOBUILD := go build -v
GOINSTALL := go install -v
GOTEST := go test -v

GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'| grep -v '/vendor/'

COMMIT := $(shell git describe --abbrev=40 --dirty)
LDFLAGS := -X $(PKG).Commit=$(COMMIT)

RM := rm -f
CP := cp
MAKE := make
XARGS := xargs -L 1

# Linting uses a lot of memory, so keep it under control by limiting the number
# of workers if requested.
ifneq ($(workers),)
LINT_WORKERS = --concurrency=$(workers)
endif

LINT = $(LINT_BIN) run -v $(LINT_WORKERS)

GREEN := "\\033[0;32m"
NC := "\\033[0m"
define print
echo $(GREEN)$1$(NC)
endef

default: build

all: build check install

# ============
# DEPENDENCIES
# ============
$(LINT_BIN):
@$(call print, "Fetching linter")
$(DEPGET) $(LINT_PKG)@$(LINT_COMMIT)

# ============
# INSTALLATION
# ============

build:
@$(call print, "Building lndclient.")
$(GOBUILD) -ldflags="$(LDFLAGS)" $(PKG)

# =======
# TESTING
# =======

check: unit

unit:
@$(call print, "Running unit tests.")
$(GOTEST)

unit-race:
@$(call print, "Running unit race tests.")
env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race

# =========
# UTILITIES
# =========
fmt:
@$(call print, "Formatting source.")
gofmt -l -w -s $(GOFILES_NOVENDOR)

lint: $(LINT_BIN)
@$(call print, "Linting source.")
$(LINT)
4 changes: 2 additions & 2 deletions chainnotifier_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ func (s *chainNotifierClient) RegisterSpendNtfn(ctx context.Context,
return
}

switch c := spendEvent.Event.(type) {
case *chainrpc.SpendEvent_Spend:
c, ok := spendEvent.Event.(*chainrpc.SpendEvent_Spend)
if ok {
err := processSpendDetail(c.Spend)
if err != nil {
errChan <- err
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module github.com/lightninglabs/lndclient

go 1.13

require (
github.com/btcsuite/btcd v0.20.1-beta.0.20200730232343-1db1b6f8217f
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
Expand All @@ -12,3 +10,5 @@ require (
google.golang.org/grpc v1.24.0
gopkg.in/macaroon.v2 v2.1.0
)

go 1.15
1 change: 1 addition & 0 deletions invoices_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func newInvoicesClient(conn *grpc.ClientConn,
return &invoicesClient{
client: invoicesrpc.NewInvoicesClient(conn),
invoiceMac: invoiceMac,
timeout: timeout,
}
}

Expand Down
30 changes: 15 additions & 15 deletions lightning_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ type LightningClient interface {

// GetChanInfo returns the channel info for the passed channel,
// including the routing policy for both end.
GetChanInfo(ctx context.Context, chanId uint64) (*ChannelEdge, error)
GetChanInfo(ctx context.Context, chanID uint64) (*ChannelEdge, error)

// ListPeers gets a list the peers we are currently connected to.
ListPeers(ctx context.Context) ([]Peer, error)
Expand Down Expand Up @@ -2000,8 +2000,8 @@ func (s *lightningClient) ChannelBackups(ctx context.Context) ([]byte, error) {

// getOutPoint is a helper go convert a hash and output index to
// a wire.OutPoint object.
func getOutPoint(txId []byte, idx uint32) (*wire.OutPoint, error) {
hash, err := chainhash.NewHash(txId)
func getOutPoint(txID []byte, idx uint32) (*wire.OutPoint, error) {
hash, err := chainhash.NewHash(txID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -2052,10 +2052,10 @@ func getChannelEventUpdate(rpcChannelEventUpdate *lnrpc.ChannelEventUpdate) (
case lnrpc.ChannelEventUpdate_ACTIVE_CHANNEL:
result.UpdateType = ActiveChannelUpdate
channelPoint := rpcChannelEventUpdate.GetActiveChannel()
fundingTxId := channelPoint.FundingTxid.(*lnrpc.ChannelPoint_FundingTxidBytes)
fundingTxID := channelPoint.FundingTxid.(*lnrpc.ChannelPoint_FundingTxidBytes)

result.ChannelPoint, err = getOutPoint(
fundingTxId.FundingTxidBytes,
fundingTxID.FundingTxidBytes,
channelPoint.OutputIndex,
)
if err != nil {
Expand All @@ -2065,10 +2065,10 @@ func getChannelEventUpdate(rpcChannelEventUpdate *lnrpc.ChannelEventUpdate) (
case lnrpc.ChannelEventUpdate_INACTIVE_CHANNEL:
result.UpdateType = InactiveChannelUpdate
channelPoint := rpcChannelEventUpdate.GetInactiveChannel()
fundingTxId := channelPoint.FundingTxid.(*lnrpc.ChannelPoint_FundingTxidBytes)
fundingTxID := channelPoint.FundingTxid.(*lnrpc.ChannelPoint_FundingTxidBytes)

result.ChannelPoint, err = getOutPoint(
fundingTxId.FundingTxidBytes,
fundingTxID.FundingTxidBytes,
channelPoint.OutputIndex,
)
if err != nil {
Expand Down Expand Up @@ -2488,7 +2488,7 @@ func (s *lightningClient) UpdateChanPolicy(ctx context.Context,
FundingTxid: &lnrpc.ChannelPoint_FundingTxidBytes{
FundingTxidBytes: chanPoint.Hash[:],
},
OutputIndex: uint32(chanPoint.Index),
OutputIndex: chanPoint.Index,
}
rpcReq.Scope = &lnrpc.PolicyUpdateRequest_ChanPoint{
ChanPoint: rpcChanPoint,
Expand Down Expand Up @@ -2532,10 +2532,10 @@ type RoutingPolicy struct {

// ChannelEdge holds the channel edge information and routing policies.
type ChannelEdge struct {
// The unique channel ID for the channel. The first 3 bytes are the
// block height, the next 3 the index within the block, and the last
// 2 bytes are the output index for the channel.
ChannelId uint64
// ChannelID is the unique channel ID for the channel. The first 3 bytes
// are the block height, the next 3 the index within the block, and the
// last 2 bytes are the output index for the channel.
ChannelID uint64

// ChannelPoint is the funding outpoint of the channel.
ChannelPoint string
Expand Down Expand Up @@ -2575,7 +2575,7 @@ func getRoutingPolicy(policy *lnrpc.RoutingPolicy) *RoutingPolicy {

// GetChanInfo returns the channel info for the passed channel, including the
// routing policy for both end.
func (s *lightningClient) GetChanInfo(ctx context.Context, channelId uint64) (
func (s *lightningClient) GetChanInfo(ctx context.Context, channelID uint64) (
*ChannelEdge, error) {

rpcCtx, cancel := context.WithTimeout(ctx, s.timeout)
Expand All @@ -2584,7 +2584,7 @@ func (s *lightningClient) GetChanInfo(ctx context.Context, channelId uint64) (
rpcCtx = s.adminMac.WithMacaroonAuth(rpcCtx)

rpcRes, err := s.client.GetChanInfo(rpcCtx, &lnrpc.ChanInfoRequest{
ChanId: channelId,
ChanId: channelID,
})
if err != nil {
return nil, err
Expand All @@ -2605,7 +2605,7 @@ func newChannelEdge(rpcRes *lnrpc.ChannelEdge) (*ChannelEdge, error) {
}

return &ChannelEdge{
ChannelId: rpcRes.ChannelId,
ChannelID: rpcRes.ChannelId,
ChannelPoint: rpcRes.ChanPoint,
Capacity: btcutil.Amount(rpcRes.Capacity),
Node1: vertex1,
Expand Down
1 change: 1 addition & 0 deletions signer_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func newSignerClient(conn *grpc.ClientConn,
return &signerClient{
client: signrpc.NewSignerClient(conn),
signerMac: signerMac,
timeout: timeout,
}
}

Expand Down
2 changes: 1 addition & 1 deletion walletkit_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (m *walletKitClient) EstimateFee(ctx context.Context, confTarget int32) (

rpcCtx = m.walletKitMac.WithMacaroonAuth(rpcCtx)
resp, err := m.client.EstimateFee(rpcCtx, &walletrpc.EstimateFeeRequest{
ConfTarget: int32(confTarget),
ConfTarget: confTarget,
})
if err != nil {
return 0, err
Expand Down