aboutsummaryrefslogtreecommitdiffstats
path: root/db/normalized/debits.js
Commit message (Collapse)AuthorAgeFilesLines
* es6 migrationAdam Soltys2022-09-021-1/+1
|
* es6 migrationAdam Soltys2022-09-021-3/+3
|
* update normalized modelsRan Guin2021-07
const fs = require("fs");
const grpc = require("grpc");
const createLnrpc = require("lnrpc");
const { promisify } = require("util");

module.exports = async ({ server, tls, macaroon }) => {
  const lnrpc = await createLnrpc({ server, tls, macaroonPath: macaroon  });

  // Resolve proxy instance
  return new Proxy(lnrpc, {
    /**
     * Promisify each lightning RPC method
     * @param  {lnrpc.Lightning} target
     * @param  {String}          key
     * @return {Promise} {Any}
     */
    get(target, key) {
      const method = target[key];

      if (typeof key === "string" && typeof method === "function") {
        const streaming = key.match(/openChannel$|sendPayment|subscribe.*/);
        let fn;

        if (streaming) {
          if (key === "sendPayment" || key === "sendToRoute") {
            fn = params => method.call(lnrpc, target.meta, params);
          } else {
            fn = params => method.call(lnrpc, params, target.meta);
          }
        } else {
          fn = params => promisify(method).call(lnrpc, params, target.meta);
        }

        return fn;
      }

      return target[key]; // forward
    }
  });
};