João Almeida
8 years ago
26 changed files with 480 additions and 227 deletions
@ -0,0 +1,121 @@ |
|||
import bitcore from 'bitcore-lib' |
|||
import pushopenchannel from '../push/openchannel' |
|||
import pushclosechannel from '../push/closechannel' |
|||
|
|||
const BufferUtil = bitcore.util.buffer |
|||
|
|||
/** |
|||
* @param {[type]} lnd [description] |
|||
* @param {[type]} event [description] |
|||
* @param {[type]} payload [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function openChannel(lnd, event, payload) { |
|||
const { pubkey, localamt, pushamt } = payload |
|||
const res = { |
|||
node_pubkey: BufferUtil.hexToBuffer(pubkey), |
|||
local_funding_amount: Number(localamt), |
|||
push_sat: Number(pushamt) |
|||
} |
|||
|
|||
return new Promise((resolve, reject) => |
|||
|
|||
pushopenchannel(lnd, event, res) |
|||
.then(data => resolve(data)) |
|||
.catch(error => reject(error)) |
|||
) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [channelBalance description] |
|||
* @param {[type]} lnd [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function channelBalance(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.channelBalance({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [listChannels description] |
|||
* @param {[type]} lnd [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function listChannels(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.listChannels({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [closechannel description] |
|||
* @param {[type]} lnd [description] |
|||
* @param {[type]} event [description] |
|||
* @param {[type]} payload [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function closeChannel(lnd, event, payload) { |
|||
const tx = payload.channel_point.funding_txid.match(/.{2}/g).reverse().join('') |
|||
const res = { |
|||
channel_point: { |
|||
funding_txid: BufferUtil.hexToBuffer(tx), |
|||
output_index: Number(payload.channel_point.output_index) |
|||
} |
|||
} |
|||
|
|||
return new Promise((resolve, reject) => |
|||
|
|||
pushclosechannel(lnd, event, res) |
|||
.then(data => resolve(data)) |
|||
.catch(error => reject(error)) |
|||
) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [pendingChannels description] |
|||
* @param {[type]} lnd [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function pendingChannels(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.pendingChannels({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [getChanInfo description] |
|||
* @param {[type]} lnd [description] |
|||
* @param {[type]} channelId [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function getChanInfo(lnd, { chanId }){ |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.getChanInfo({ chan_id: chanId }, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -1,10 +0,0 @@ |
|||
// LND Get Channel Balance
|
|||
export default function channelbalance(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
lnd.channelBalance({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -1,10 +0,0 @@ |
|||
// LND List Channels
|
|||
export default function channels(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
lnd.listChannels({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -1,20 +0,0 @@ |
|||
import bitcore from 'bitcore-lib' |
|||
import pushclosechannel from '../push/closechannel' |
|||
|
|||
const BufferUtil = bitcore.util.buffer |
|||
|
|||
export default function closechannel(lnd, event, payload) { |
|||
const tx = payload.channel_point.funding_txid.match(/.{2}/g).reverse().join('') |
|||
const res = { |
|||
channel_point: { |
|||
funding_txid: BufferUtil.hexToBuffer(tx), |
|||
output_index: Number(payload.channel_point.output_index) |
|||
} |
|||
} |
|||
|
|||
return new Promise((resolve, reject) => |
|||
pushclosechannel(lnd, event, res) |
|||
.then(data => resolve(data)) |
|||
.catch(error => reject(error)) |
|||
) |
|||
} |
@ -1,10 +0,0 @@ |
|||
// LND Connect to a peer
|
|||
export default function connectpeer(lnd, { pubkey, host }) { |
|||
return new Promise((resolve, reject) => { |
|||
lnd.connectPeer({ addr: { pubkey, host }, perm: true }, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -1,10 +0,0 @@ |
|||
// LND Create an invoice
|
|||
export default function createInvoice(lnd, { memo, value }) { |
|||
return new Promise((resolve, reject) => { |
|||
lnd.addInvoice({ memo, value }, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -1,10 +0,0 @@ |
|||
// LND Disconnect from a peer
|
|||
export default function disconnectpeer(lnd, { pubkey }) { |
|||
return new Promise((resolve, reject) => { |
|||
lnd.disconnectPeer({ pub_key: pubkey }, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -1,10 +0,0 @@ |
|||
// LND Get Info
|
|||
export default function info(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
lnd.getInfo({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -1,12 +0,0 @@ |
|||
import { decodeInvoice } from '../utils' |
|||
|
|||
// LND Get Invoice
|
|||
export default function invoice(payreq) { |
|||
return new Promise((resolve, reject) => { |
|||
try { |
|||
resolve(decodeInvoice(payreq)) |
|||
} catch (error) { |
|||
reject(error) |
|||
} |
|||
}) |
|||
} |
@ -1,10 +0,0 @@ |
|||
// LND Get Invoices
|
|||
export default function invoices(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
lnd.listInvoices({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -0,0 +1,52 @@ |
|||
import { decodeInvoice } from '../utils' |
|||
|
|||
/** |
|||
* [createInvoice description] |
|||
* @param lnd [description] |
|||
* @param memo [description] |
|||
* @param value [description] |
|||
* @return [description] |
|||
*/ |
|||
export function addInvoice (lnd, { memo, value }) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.addInvoice({ memo, value }, (err, data) => { |
|||
if (err) { reject(err) } |
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
/** |
|||
* [listInvoices description] |
|||
* @param {[type]} lnd [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function listInvoices(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.listInvoices({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
/** |
|||
* @param {[type]} payreq [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function getInvoice(payreq) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
try { |
|||
resolve(decodeInvoice(payreq)) |
|||
} catch (error) { |
|||
reject(error) |
|||
} |
|||
|
|||
}) |
|||
} |
|||
|
|||
//TODO - SubscribeInvoice
|
@ -0,0 +1,86 @@ |
|||
/** |
|||
* [info description] |
|||
* @param {[type]} lnd [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function getInfo(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.getInfo({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [getNodeInfo description] |
|||
* @param {[type]} lnd [description] |
|||
* @param {[type]} pubkey [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function getNodeInfo(lnd, { pubkey }) { |
|||
return new Promise ((resolve, reject) => { |
|||
|
|||
lnd.getNodeInfo({ pub_key: pubkey}, (err, data) => { |
|||
if(err) { reject (err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [describeGraph description] |
|||
* @param {[type]} lnd [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function describeGraph(lnd) { |
|||
return new Promise ((resolve, reject) => { |
|||
|
|||
lnd.describeGraph({}, (err, data) => { |
|||
if(err) { reject (err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [queryRoutes description] |
|||
* @param {[type]} lnd [description] |
|||
* @param {[type]} pubkey [description] |
|||
* @param {[type]} amount [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function queryRoutes(lnd, { pubkey, amount }) { |
|||
return new Promise ((resolve, reject) => { |
|||
|
|||
lnd.queryRoutes({pub_key: pubkey, amt: amount }, (err, data) => { |
|||
if(err) {reject (err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [getNetworkInfo description] |
|||
* @param {[type]} lnd [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function getNetworkInfo(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.getNetworkInfo({}, (err, data) => { |
|||
if(err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -1,10 +0,0 @@ |
|||
// LND Generate New Address
|
|||
export default function info(lnd, type) { |
|||
return new Promise((resolve, reject) => { |
|||
lnd.newAddress({ type }, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -1,19 +0,0 @@ |
|||
import bitcore from 'bitcore-lib' |
|||
import pushopenchannel from '../push/openchannel' |
|||
|
|||
const BufferUtil = bitcore.util.buffer |
|||
|
|||
export default function openchannel(lnd, event, payload) { |
|||
const { pubkey, localamt, pushamt } = payload |
|||
const res = { |
|||
node_pubkey: BufferUtil.hexToBuffer(pubkey), |
|||
local_funding_amount: Number(localamt), |
|||
push_sat: Number(pushamt) |
|||
} |
|||
|
|||
return new Promise((resolve, reject) => |
|||
pushopenchannel(lnd, event, res) |
|||
.then(data => resolve(data)) |
|||
.catch(error => reject(error)) |
|||
) |
|||
} |
@ -1,10 +0,0 @@ |
|||
// LND Pay an invoice
|
|||
export default function payinvoice(lnd, { paymentRequest }) { |
|||
return new Promise((resolve, reject) => { |
|||
lnd.sendPaymentSync({ payment_request: paymentRequest }, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -1,10 +0,0 @@ |
|||
// LND Get Payments
|
|||
export default function payments(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
lnd.listPayments({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -0,0 +1,33 @@ |
|||
/** |
|||
* [sendPaymentSync description] |
|||
* @param {[type]} lnd [description] |
|||
* @param {[type]} paymentRequest [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function sendPaymentSync(lnd, { paymentRequest }) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.sendPaymentSync({ payment_request: paymentRequest }, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [listPayments description] |
|||
* @param {[type]} lnd [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function listPayments(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.listPayments({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -1,10 +0,0 @@ |
|||
// LND List Peers
|
|||
export default function peers(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
lnd.listPeers({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -0,0 +1,52 @@ |
|||
/** |
|||
* [connectpeer description] |
|||
* @param {[type]} lnd [description] |
|||
* @param {[type]} pubkey [description] |
|||
* @param {[type]} host [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function connectPeer(lnd, { pubkey, host }) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.connectPeer({ addr: { pubkey, host }, perm: true }, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [disconnectpeer description] |
|||
* @param {[type]} lnd [description] |
|||
* @param {[type]} pubkey [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function disconnectPeer(lnd, { pubkey }) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.disconnectPeer({ pub_key: pubkey }, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [peers description] |
|||
* @param {[type]} lnd [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function listPeers(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.listPeers({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -1,10 +0,0 @@ |
|||
// LND Get Pending Channels
|
|||
export default function channels(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
lnd.pendingChannels({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -1,10 +0,0 @@ |
|||
// LND send coins on chain
|
|||
export default function sendcoins(lnd, { addr, amount }) { |
|||
return new Promise((resolve, reject) => { |
|||
lnd.sendCoins({ addr, amount }, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -0,0 +1,85 @@ |
|||
/** |
|||
* [walletbalance description] |
|||
* @param {[type]} lnd [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function walletBalance(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.walletBalance({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [newAddress description] |
|||
* @param {[type]} lnd [description] |
|||
* @param {[type]} type [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function newAddress(lnd, type) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.newAddress({type}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
/** |
|||
* [newWitnessAddress description] |
|||
* @param {[type]} lnd [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function newWitnessAddress(lnd, { addr }) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.newWitnessAddress({ address: addr}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [getTransactions description] |
|||
* @param {[type]} lnd [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function getTransactions(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.getTransactions({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
|
|||
/** |
|||
* [sendcoins description] |
|||
* @param {[type]} lnd [description] |
|||
* @param {[type]} addr [description] |
|||
* @param {[type]} amount [description] |
|||
* @return {[type]} [description] |
|||
*/ |
|||
export function sendCoins(lnd, { addr, amount }) { |
|||
return new Promise((resolve, reject) => { |
|||
|
|||
lnd.sendCoins({ addr, amount }, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
@ -1,10 +0,0 @@ |
|||
// LND Get Wallet Balance
|
|||
export default function walletbalance(lnd) { |
|||
return new Promise((resolve, reject) => { |
|||
lnd.walletBalance({}, (err, data) => { |
|||
if (err) { reject(err) } |
|||
|
|||
resolve(data) |
|||
}) |
|||
}) |
|||
} |
Loading…
Reference in new issue