Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions ln/hold_invoice.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
const { createHash, randomBytes } = require('crypto');
const { createHodlInvoice, settleHodlInvoice, cancelHodlInvoice } = require('lightning');
const lightning = require('lightning');
const lnd = require('./connect');

const createHoldInvoice = async ({ description, amount }) => {
try {
const randomSecret = () => randomBytes(32);
const sha256 = buffer => createHash('sha256').update(buffer).digest('hex');

// We create a random secret
const secret = randomSecret();

const id = sha256(secret);
const { request } = await createHodlInvoice({
const hash = sha256(secret);
const { request, id } = await lightning.createHodlInvoice({
lnd,
description,
id,
id: hash,
tokens: amount
});

// We sent back the response hash (id) to be used on testing
return { request, hash: id, secret: secret.toString('hex') };
} catch (e) {
console.log(e);
Expand All @@ -25,7 +27,7 @@ const createHoldInvoice = async ({ description, amount }) => {

const settleHoldInvoice = async ({ secret }) => {
try {
await settleHodlInvoice({ lnd, secret });
await lightning.settleHodlInvoice({ lnd, secret });
} catch (e) {
console.log(e);
return e;
Expand All @@ -34,7 +36,7 @@ const settleHoldInvoice = async ({ secret }) => {

const cancelHoldInvoice = async ({ hash }) => {
try {
await cancelHodlInvoice({ lnd, id: hash });
await lightning.cancelHodlInvoice({ lnd, id: hash });
} catch (e) {
console.log(e);
return e;
Expand Down
Loading