Skip to content

Commit

Permalink
feat: add fn to generate invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
DhananjayPurohit committed Jul 31, 2024
1 parent 604c0ac commit a3a4ee3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion clients/apps/nodejs/test/tb04-simple-lightning-latch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import client_config from '../client_config.js';
import mercurynodejslib from 'mercurynodejslib';
import { CoinStatus } from 'mercurynodejslib/coin_enum.js';
import crypto from 'crypto';
import { createWallet, removeDatabase, getnewaddress, generateBlock, depositCoin } from './test-utils.mjs';
import { createWallet, depositCoin, generateInvoice } from '../test_utils.js';

describe('TB04 - Lightning Latch', function() {
this.timeout(30000);
Expand Down Expand Up @@ -312,6 +312,8 @@ describe('TB04 - Lightning Latch', function() {

const paymentHash = await mercurynodejslib.paymentHash(clientConfig, wallet_1_name, coin.statechain_id);

const invoice = await generateInvoice(paymentHash.hash, amount);

const transferAddress = await mercurynodejslib.newTransferAddress(clientConfig, wallet_2_name, null);

await mercurynodejslib.transferSend(clientConfig, wallet_1_name, coin.statechain_id, transferAddress.transfer_receive, false, paymentHash.batchId);
Expand Down
14 changes: 13 additions & 1 deletion clients/apps/nodejs/test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ const connectElectr = async () => {
await exec("docker network connect mercurylayer_default mercurylayer_electrs_1");
}

async function generateInvoice(paymentHash, amountInSats) {

const generateInvoiceCommand = `docker exec $(docker ps -qf "name=mercurylayer_alice_1") lncli addinvoice ${paymentHash} --amt ${amountInSats}`;
const { stdout, stderr } = await exec(generateInvoiceCommand);
if (stderr) {
console.error('Error:', stderr);
return null;
}
return stdout.trim();
}

module.exports = {
removeDatabase,
getDatabase,
Expand All @@ -111,5 +122,6 @@ module.exports = {
connectElectr,
disconnectElectr,
connectMercuryServer,
disconnectMercuryServer
disconnectMercuryServer ,
generateInvoice
};

0 comments on commit a3a4ee3

Please sign in to comment.