Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "ln-service in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'ln-service' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

beforeEach(() => {
    // boltwall sets up authenticated client when it boots up
    // need to stub this to avoid connection errors and speed up tests
    lndGrpcStub = getLnStub('authenticatedLndGrpc', { lnd: {} })
    // keep known session secret so we can decode macaroons
    sessionSecret = 'my super secret'

    envStub = getEnvStub(sessionSecret)

    const request = parsePaymentRequest({ request: invoice.payreq })

    // stubbed response for invoice related requests made through ln-service
    invoiceResponse = {
      request: invoice.payreq,
      is_confirmed: true,
      id: request.id,
      secret: invoice.secret,
      tokens: 30,
      created_at: '2016-08-29T09:12:33.001Z',
      description: request.description,
    }

    builder = getTestBuilder(sessionSecret)

    getInvStub = getLnStub('getInvoice', invoiceResponse)
    createInvStub = getLnStub('createInvoice', {
// check if we're looking at the invoice challenge
      if (!invoice.length && c.indexOf(invoiceChallenge) > -1) {
        const split = c.split('=')
        assert(split.length === 2, 'Incorrectly encoded invoice challenge')
        invoice = split[split.length - 1].trim()
      }
      // if there are other challenges but we have mac and invoice then we can break
      // as they are not LSAT relevant anyway
      if (invoice.length && macaroon.length) break
    }

    assert(
      invoice.length && macaroon.length,
      'Expected base64 encoded challenge with macaroon and invoice data'
    )
    const request = parsePaymentRequest({ request: invoice })
    const paymentHash = request.id
    const { identifier } = MacaroonsBuilder.deserialize(macaroon)

    return new this({
      id: identifier,
      baseMacaroon: macaroon,
      paymentHash,
      invoice: invoice,
    })
  }
export default function parseEnv(
  req: LndRequest,
  _res: Response,
  next: NextFunction
): void {
  try {
    testEnvVars()
    let { OPEN_NODE_KEY, LND_TLS_CERT, LND_MACAROON, LND_SOCKET } = getEnvVars()
    // if the tests pass above and we don't have a
    // OPEN_NODE_KEY then we need to setup the lnd service
    if (!OPEN_NODE_KEY) {
      const { lnd } = lnService.authenticatedLndGrpc({
        cert: LND_TLS_CERT,
        macaroon: LND_MACAROON,
        socket: LND_SOCKET,
      })
      req.lnd = lnd
    } else {
      const env = process.env.ENVIRONMENT || 'dev'
      const opennode = require('opennode')
      opennode.setCredentials(OPEN_NODE_KEY, env)
      req.opennode = opennode
    }
    next()
  } catch (e) {
    console.error(
      'Problem with configs for connecting to lightning node:',
      e.message
getChannels: ['validate', ({}, cbk) => {
      // Exit early when there is no need to add an outgoing channel id
      if (!args.out_through) {
        return cbk();
      }

      return getChannels({lnd: args.lnd}, cbk);
    }],
const socket = process.env[`SSS_LND_${networkName}_GRPC_HOST`];

  if (!cert) {
    throw new Error('ExpectedDaemonCert');
  }

  if (!macaroon) {
    throw new Error('ExpectedDaemonMacaroon');
  }

  if (!socket) {
    throw new Error('ExpectedDaemonHost');
  }

  try {
    lnd = authenticatedLndGrpc({cert, macaroon, socket}).lnd;
  } catch (err) {
    throw new Error('FailedToInstantiateDaemon');
  }

  const sub = subscribeToInvoices({lnd});

  daemons[network] = {lnd, sub};

  // Clear daemon cache on errors or end of subscription
  // This subscription allows opportunistic reconnecting on remote restarts.
  daemons[network].sub.on('invoice_updated', () => {});
  daemons[network].sub.on('end', () => daemons[network] = null);
  daemons[network].sub.on('error', ({}) => daemons[network] = null);
  daemons[network].sub.on('status', () => {});

  return lnd;
createAddress: ['recover', 'validate', ({recover}, cbk) => {
      // Exit early when there is already a sweep address specified in recovery
      if (!!recover && recover.sweep_address) {
        return cbk(null, {address: recover.sweep_address});
      }

      // Exit early when the sweep out address is directly specified
      if (!!args.out_address) {
        return cbk(null, {address: args.out_address});
      }

      return createChainAddress({format: 'p2wpkh', lnd: args.lnd}, cbk);
    }],
getNode: ['validate', ({}, cbk) => {
        // Exit early when there is no via node specified
        if (!args.via) {
          return cbk();
        }

        return getNode({lnd: args.lnd, public_key: args.via}, cbk);
      }],
({decodeCommand, decodeRequest, maxTokens}, cbk) =>
      {
        let probeTimeout;

        const sub = subscribeToProbe({
          cltv_delta: decodeRequest.cltv_delta + cltvDeltaBuffer,
          destination: decodeRequest.destination,
          lnd: decodeCommand.lnd,
          path_timeout_ms: pathTimeoutMs,
          routes: decodeRequest.routes,
          tokens: decodeRequest.tokens,
        });

        const finished = (err, res) => {
          clearTimeout(probeTimeout);

          sub.removeAllListeners();

          // Switch and return the final result

          return cbk(err, res);
export async function checkInvoiceStatus(
  lnd: any,
  opennode: any,
  invoiceId: string
): Promise {
  if (!invoiceId) throw new Error('Missing invoice id.')

  let status, amount, payreq, createdAt
  if (lnd) {
    const invoiceDetails = await lnService.getInvoice({
      id: invoiceId,
      lnd: lnd,
    })

    // for hodl invoices, status might be "is_held"
    status = invoiceDetails['is_confirmed']
      ? 'paid'
      : invoiceDetails['is_held']
      ? 'held'
      : 'unpaid'
    amount = invoiceDetails.tokens
    payreq = invoiceDetails.request
    createdAt = invoiceDetails.created_at
  } else if (opennode) {
    const data = await opennode.chargeInfo(invoiceId)
    amount = data.amount
    checkLnd: ['lnd', ({lnd}, cbk) => getWalletInfo({lnd}, cbk)],

Is your System Free of Underlying Vulnerabilities?
Find Out Now