UNPKG

@lightninglabs/lnc-rn

Version:

Lightning Node Connect npm module for React Native

32 lines (30 loc) 1.03 kB
import { subscriptionMethods } from '@lightninglabs/lnc-core'; // capitalize the first letter in the string const capitalize = s => s && s[0].toUpperCase() + s.slice(1); /** * Creates a typed Proxy object which calls the request or subscribe * methods depending on which function is called on the object */ export function createRpc(packageName, lnc) { const rpc = {}; return new Proxy(rpc, { get(target, key, c) { const methodName = capitalize(key.toString()); // the full name of the method (ex: lnrpc.Lightning.OpenChannel) const method = `${packageName}.${methodName}`; if (subscriptionMethods.includes(method)) { // call subscribe for streaming methods return request => { return lnc.subscribe(method, request); }; } else { // call request for unary methods return async request => { return await lnc.request(method, request); }; } } }); } export default createRpc; //# sourceMappingURL=createRpc.js.map