LN-Zap / node-lnd-grpc

Zap Wallet - Easy to use async gRPC wrapper for lnd ⚡️
44 stars 16 forks source link

'Lightning.walletBalance is not a function error' thrown #395

Closed hvmelo closed 2 years ago

hvmelo commented 2 years ago

Hi, I'm trying to use the module with a LND localserver hosted in a docker container. My LND server is version 0.14.1-beta. I'm doing exactly as instructed in the tutorial but get the following error:

var balance = await Lightning.walletBalance();

TypeError: Lightning.walletBalance is not a function
    at file:///Users/hvmelo/Developer/lnd_grpc_test2/index.js:20:31
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

This is my index.js:

import LndGrpc from 'lnd-grpc'

const grpc =  new LndGrpc({
    host: 'localhost:10009',
    cert: 'local/tls.cert',
    macaroon: 'local/admin.macaroon',
    version: '0.14.1-beta',
    waitForMacaroon: 30 * 1000, // 30 seconds
    waitForCert: true,
  })

await grpc.connect()

console.log(grpc.state)

// Make some api calls...
const { Lightning, Autopilot, Invoices } = grpc.services
// Fetch current balance.
var balance = await Lightning.walletBalance();
console.log(balance);

This is the debug console:

lnrpc:grpc Initializing LndGrpc with config: { host: 'localhost:10009', cert: 'local/tls.cert', macaroon: 'local/admin.macaroon', version: '0.14.1-beta', waitForMacaroon: 30000, waitForCert: true } +0ms
  lnrpc:grpc Connecting to lnd gRPC service +8ms
  lnrpc:service:State Connecting to State gRPC service +0ms
  lnrpc:service:State Establishing gRPC connection to State with proto file /Users/hvmelo/Developer/lnd_grpc_test2/node_modules/lnd-grpc/proto/0.14.1-beta/lnrpc/stateservice.proto and connection options { 'grpc.max_send_message_length': -1, 'grpc.max_receive_message_length': -1, 'grpc.keepalive_permit_without_calls': 1 } +0ms
  lnrpc:util waiting for file: local/tls.cert +0ms
  lnrpc:util found file: local/tls.cert +2ms
  lnrpc:service:State Connected to State gRPC service +260ms
  lnrpc:service:State Calling State.getState async with: { payload: {}, options: {} } +0ms
  lnrpc:grpc Got wallet state as { state: 'SERVER_ACTIVE' } +280ms

It seems the proto services for Lightning are not being loaded, since it actually works when I force the following code right before walletBalance():

await Lightning.onBeforeConnect();

Am I doing something wrong or there is an issue to be fixed here?

Thanks.

hvmelo commented 2 years ago

After spending some time digging in, I noticed there is this new state since version 0.14.0-beta called SERVER_ACTIVE. In the docs it says "SERVER_ACTIVE means that the lnd server is ready to accept calls". I don't know the actual difference from RPC_ACTIVE to SERVER_ACTIVE. Anyway, it breaks the lib code because it waits for RPC_ACTIVE. Seems to be something easy to fix.

hvmelo commented 2 years ago

Working on version 0.5.3. Thank you for fixing!