diff --git a/README.md b/README.md index 2c04123..b297d74 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ For running the server, rename the file `sample-cl-rest-config.json` to `cl-rest NOTE: Node.js plugins might not work with lightningd.service setting `MemoryDenyWriteExecute=true` as it denies the creation of writable and executable memory mappings. Ref: https://github.com/Ride-The-Lightning/c-lightning-REST/issues/116 -If running as a plugin, configure the below options in your c-lightning `config` file: +If running as a plugin, configure the below options in your core lightning `config` file: - `rest-port` - `rest-docport` - `rest-protocol` @@ -72,7 +72,7 @@ You can choose from the below options to run the API server Access the APIs on the default port 3001 or the port configured in the config file. -#### Option 2: Run as c-lightning plugin +#### Option 2: Run as a core lightning plugin Pass arguments when launching lightningd: `$ lightningd --plugin=PATH_TO_PLUGIN [--rest-port=N] [--rest-protocol=http|https] [--rest-execmode=MODE]` @@ -228,7 +228,7 @@ C-Lightning commands covered by this API suite is [here](docs/CLTCommandCoverage - rpc (/v1/rpc) - `POST`: additional access to RPC comands. Examples of body param for rpc: #### No param -`{"method": "getinfo}` +`{"method": "getinfo"}` #### One param `{"method":"signmessage", "params": ["message"]}` #### Multiple params diff --git a/cl-rest.js b/cl-rest.js index 98a71ca..f728132 100644 --- a/cl-rest.js +++ b/cl-rest.js @@ -30,7 +30,24 @@ const PORT = config.PORT; const EXECMODE = config.EXECMODE; const DOCPORT = config.DOCPORT; const DOMAIN = config.DOMAIN || "localhost"; -const BIND = config.BIND || "::"; + +// Check if any interface on the device has an IPv6 address +const os = require('os'); +const networkInterfaces = os.networkInterfaces(); +const hasIPv6 = Object.values(networkInterfaces).some((interfaces) => { + return interfaces.some((iface) => { + return iface.family === 'IPv6'; + }); + }); +if (hasIPv6) + var bindaddr = config.BIND || "::"; +else + var bindaddr = config.BIND || "0.0.0.0"; + +const BIND = bindaddr; +global.logger.log("--------------"); +global.logger.log("Bind address -> " + BIND); +global.logger.log("--------------"); //Create certs folder try { diff --git a/controllers/channel.js b/controllers/channel.js index cc317c6..ada55bf 100644 --- a/controllers/channel.js +++ b/controllers/channel.js @@ -222,7 +222,7 @@ exports.listChannels = (req,res) => { } //Function # 3 -//Invoke the 'setchannelfee' command update the fee policy of a channel +//Invoke the 'setchannel' command to update the fee policy of a channel //Arguments - Channel id (required), Base rate (optional), PPM rate (optional) /** * @swagger @@ -230,9 +230,9 @@ exports.listChannels = (req,res) => { * post: * tags: * - Channel Management -* name: setchannelfee +* name: setchannel * summary: Update channel fee policy -* description: Core documentation - https://lightning.readthedocs.io/lightning-setchannelfee.7.html +* description: Core documentation - https://lightning.readthedocs.io/lightning-setchannel.7.html * parameters: * - in: body * name: id @@ -248,6 +248,18 @@ exports.listChannels = (req,res) => { * name: ppm * description: Optional value that is added proportionally per-millionths to any routed payment volume in satoshi * type: integer +* - in: body +* name: htlcmin +* description: Optional value that limits how small an HTLC channel will forward +* type: string +* - in: body +* name: htlcmax +* description: Optional value that limits how large an HTLC channel will forward +* type: string +* - in: body +* name: enforcedelay +* description: Number of seconds to delay before enforcing the new fees/htlc max (default 600) +* type: integer * security: * - MacaroonAuth: [] * responses: @@ -256,21 +268,27 @@ exports.listChannels = (req,res) => { * schema: * type: object * properties: -* base: -* type: string -* description: base -* ppm: -* type: string -* description: ppm * peer_id: * type: string -* description: peer_id +* description: node pubkey of the peer * channel_id: * type: string -* description: channel_id +* description: channel_id of the channel +* fee_base_msat: +* type: string +* description: the resulting fee base +* fee_proportional_millionths: +* type: string +* description: the resulting fee ppm +* minimum_htlc_out_msat: +* type: string +* description: the resulting htlcmin node will advertize +* maximum_htlc_out_msat: +* type: string +* description: the resulting htlcmax node will advertize * short_channel_id: * type: string -* description: short_channel_id +* description: the short_channel_id (if locked in) * 500: * description: Server error */ @@ -282,13 +300,16 @@ exports.setChannelFee = (req,res) => { //Set required params var id = req.body.id; //Set optional params - var base = (req.body.base) ? req.body.base : null; - var ppm = (req.body.ppm) ? req.body.ppm : null; + var feebase = (req.body.base) ? req.body.base : null; + var feeppm = (req.body.ppm) ? req.body.ppm : null; + var htlcmin = (req.body.htlcmin) ? req.body.htlcmin : null; + var htlcmax = (req.body.htlcmax) ? req.body.htlcmax : null; + var enforcedelay = (req.body.enforcedelay) ? req.body.enforcedelay : null; - //Call the setchannelfee command with the params + //Call the setchannel command with the params global.logger.log(req.body); - ln.setchannelfee(id, base, ppm).then(data => { - global.logger.log('setChannelfee success'); + ln.setchannel(id, feebase, feeppm,htlcmin, htlcmax, enforcedelay).then(data => { + global.logger.log('setChannel success'); global.logger.log(data); res.status(201).json(data); }).catch(err => { diff --git a/controllers/payments.js b/controllers/payments.js index fa93b36..3cd0f44 100644 --- a/controllers/payments.js +++ b/controllers/payments.js @@ -52,6 +52,22 @@ var wsServer = require('../utils/webSocketServer'); * name: exemptfee * description: Amount for which the maxfeepercent check is skipped * type: integer +* - in: body +* name: localinvreqid +* description: Used by offers to link a payment attempt to a local invoice_request offer created +* type: string +* - in: body +* name: exclude +* description: JSON array of short-channel-id/direction or node-id which should be excluded from consideration for routing +* type: object +* - in: body +* name: maxfee +* description: Creates an absolute limit on the fee paid. If you specify maxfee you cannot specify either maxfeepercent & exemptfee +* type: integer +* - in: body +* name: description +* description: Only required for bolt11 invoices which do not contain a description themselves, but contain a description hash +* type: string * security: * - MacaroonAuth: [] * responses: @@ -60,9 +76,6 @@ var wsServer = require('../utils/webSocketServer'); * schema: * type: object * properties: -* id: -* type: integer -* description: id * payment_hash: * type: string * description: payment_hash @@ -90,9 +103,9 @@ var wsServer = require('../utils/webSocketServer'); * payment_preimage: * type: string * description: payment_preimage -* bolt11: -* type: string -* description: bolt11 +* parts: +* type: object +* description: how many attempts this took * 500: * description: Server error * schema: @@ -129,6 +142,10 @@ exports.payInvoice = (req,res) => { var retry_for = (req.body.retry_for) ? req.body.retry_for : null; var maxdelay = (req.body.maxdelay) ? req.body.maxdelay : null; var exemptfee = (req.body.exemptfee) ? req.body.exemptfee : null; + var lclnvrqd = (req.body.localinvreqid) ? req.body.localinvreqid : null; + var xcld = (req.body.exclude) ? req.body.exclude : null; + var mxf = (req.body.maxfee) ? req.body.maxfee : null; + var dscrptn = (req.body.description) ? req.body.description : null; //Call the pay command ln.pay(bolt11=invoice, @@ -138,7 +155,11 @@ exports.payInvoice = (req,res) => { maxfeepercent=maxfeepercent, retry_for=retry_for, maxdelay = maxdelay, - exemptfee=exemptfee).then(data => { + exemptfee=exemptfee, + localinvreqid=lclnvrqd, + exclude=xcld, + maxfee=mxf, + description=dscrptn).then(data => { global.logger.log('pay invoice success'); res.status(201).json(data); }).catch(err => { diff --git a/methods.json b/methods.json index 674465b..7910dc6 100644 --- a/methods.json +++ b/methods.json @@ -72,5 +72,6 @@ "peerswap-removepeer", "peerswap-resendmsg", "peerswap-swap-in", - "peerswap-swap-out" + "peerswap-swap-out", + "setchannel" ] \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 956237b..42b3c9a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "c-lightning-rest", - "version": "0.10.1", + "version": "0.10.2", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index 93d0f2c..90c18c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "c-lightning-rest", - "version": "0.10.1", + "version": "0.10.2", "description": "c-lightning REST API suite", "main": "cl-rest.js", "scripts": {