Skip to content

Commit

Permalink
add support for milli arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbosworth committed Nov 16, 2019
1 parent 69ebb7b commit 45b8051
Show file tree
Hide file tree
Showing 39 changed files with 694 additions and 240 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Versions

## 47.2.0

- `getPayment`: add `tokens` to indicate amount paid
- `payViaPaymentDetails`: add `max_fee_mtokens`, `mtokens` to specify mtokens
- `payViaPaymentRequest`: add `max_fee_mtokens`, `mtokens` to specify mtokens
- `probeForRoute`: add `max_fee_mtokens`, `mtokens` to specify mtokens
- `subscribeToPastPayment`: add `tokens` to indicate amount paid
- `subscribeToPayViaDetails`: add `max_fee_mtokens`, `mtokens` for mtokens
- `subscribeToPayViaRequest`: add `max_fee_mtokens`, `mtokens` for mtokens
- `subscribeToProbe`: add `max_fee_mtokens`, `mtokens` to specify mtokens

## 47.1.1

- `getForwards`: Fix issue where new forward mtokens field was not included
Expand Down
60 changes: 43 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Supported LND versions:

- v0.7.1-beta
- v0.8.0-beta
- v0.8.1-beta

## Installing LND

Expand Down Expand Up @@ -675,7 +676,7 @@ const details = await decodePaymentRequest({lnd, request});

Delete all forwarding reputations

Requires LND built with routerrpc build tag
Requires LND built with `routerrpc` build tag

{
lnd: <Authenticated gRPC LND API Object>
Expand All @@ -687,6 +688,8 @@ Example:

```node
const {deleteForwardingReputations} = require('ln-service');

// Delete all routing reputations to clear pathfinding memory
await deleteForwardingReputations({});
```

Expand All @@ -701,8 +704,11 @@ Delete all records of payments
@returns via cbk or Promise

Example:

```node
const {deletePayments} = require('ln-service');

// Eliminate all the records of past payments
await deletePayments({lnd});
```

Expand Down Expand Up @@ -974,7 +980,7 @@ Get channels

`is_static_remote_key` will be undefined on LND 0.7.1 and below

`time_offline` and `time_online` will be undefined on 0.8.0 and below
`time_offline` and `time_online` will be undefined on 0.8.1 and below

{
[is_active]: <Limit Results To Only Active Channels Bool> // false
Expand Down Expand Up @@ -1142,7 +1148,7 @@ Get the confidence in being able to send between a direct pair of nodes

Requires LND built with `routerrpc` build tag

Note: this method is not supported in LND 0.8.0 and below.
Note: this method is not supported in LND 0.8.1 and below.

{
from: <From Public Key Hex String>
Expand Down Expand Up @@ -1179,7 +1185,7 @@ Requires LND built with `routerrpc` build tag

Note: In LND v0.7.1 channels reputations are returned.
Note: In LND v0.8.0 peers reputations are returned.
Note: after LND v0.8.0 confidence is not returned per peer.
Note: after LND v0.8.1 confidence is not returned per peer.

{
[confidence]: <Ignore Confidence Higher than N out of 1 Million Number>
Expand Down Expand Up @@ -1222,7 +1228,7 @@ When using an "after" date a "before" date is required.

If a next token is returned, pass it to get additional page of results.

`mtokens` is not supported on LND v0.8.0 or lower
`mtokens` is not supported on LND v0.8.1 or lower

{
[after]: <Get Only Payments Forwarded At Or After ISO 8601 Date String>
Expand Down Expand Up @@ -1486,8 +1492,10 @@ const nodeDetails = await getNode({lnd, public_key: publicKey});

Get the status of a past payment

Requires LND compiled with `routerrpc` build tag

{
id: <Payment Id Hex String>
id: <Payment Preimage Hash Hex String>
lnd: <Authenticated LND gRPC API Object>
}

Expand All @@ -1512,9 +1520,10 @@ Get the status of a past payment
timeout: <Timeout Block Height Number>
}]
id: <Payment Hash Hex String>
mtokens: <Total Millitokens To Pay String>
mtokens: <Total Millitokens Paid String>
secret: <Payment Preimage Hex String>
timeout: <Expiration Block Height Number>
tokens: <Total Tokens Paid Number>
}
}

Expand Down Expand Up @@ -1924,7 +1933,7 @@ const walletInfo = await getWalletInfo({lnd});

Give access to the node by making a macaroon access credential

Note: granting access is not supported in LND versions 0.8.0 and below
Note: granting access is not supported in LND versions 0.8.1 and below

Note: access once given cannot be revoked

Expand Down Expand Up @@ -2398,6 +2407,8 @@ Requires LND built with `routerrpc` build tag

`is_ignoring_past_failures` will turn off LND 0.7.1+ past failure pathfinding

Specifying `max_fee_mtokens`/`mtokens` is not supported in LND 0.8.1 or below

{
[cltv_delta]: <Final CLTV Delta Number>
destination: <Destination Public Key Hex String>
Expand All @@ -2410,6 +2421,9 @@ Requires LND built with `routerrpc` build tag
[is_strict_hints]: <Only Route Through Specified Paths Bool>
lnd: <Authenticated LND gRPC API Object>
[max_fee]: <Maximum Fee Tokens Number>
[max_fee_mtokens]: <Maximum Fee Millitokens to Pay String>
[max_timeout_height]: <Maximum Height of Payment Timeout Number>
[mtokens]: <Millitokens to Pay String>
[pathfinding_timeout]: <Time to Spend Finding a Route Milliseconds Number>
[routes]: [[{
[base_fee_mtokens]: <Base Routing Fee In Millitokens Number>
Expand Down Expand Up @@ -3224,7 +3238,7 @@ sub.on('channel_request', channel => {

Subscribe to the status of a past payment

Requires lnd built with routerrpc build tag
Requires LND built with `routerrpc` build tag

{
[id]: <Payment Request Hash Hex String>
Expand All @@ -3249,9 +3263,10 @@ Requires lnd built with routerrpc build tag
timeout: <Timeout Block Height Number>
}]
id: <Payment Hash Hex String>
mtokens: <Total Millitokens To Pay String>
mtokens: <Total Millitokens Paid String>
secret: <Payment Preimage Hex String>
timeout: <Expiration Block Height Number>
tokens: <Tokens Paid Number>
}

@event 'failed'
Expand All @@ -3278,18 +3293,22 @@ const {secret} = await once(sub, 'confirmed');

Subscribe to the flight of a payment

Requires lnd built with routerrpc build tag
Requires LND built with `routerrpc` build tag

Specifying `max_fee_mtokens`/`mtokens` is not supported in LND 0.8.1 or below

{
[cltv_delta]: <Final CLTV Delta Number>
destination: <Destination Public Key String>
[id]: <Payment Request Hash Hex String>
lnd: <Authenticated LND gRPC API Object>
[max_fee]: <Maximum Fee Tokens To Pay Number>
[max_timeout_height]: <Maximum Expiration CLTV Timeout Height Number>
[max_fee_mtokens]: <Maximum Fee Millitokens to Pay String>
[max_timeout_height]: <Maximum Height of Payment Timeout Number>
[mtokens]: <Millitokens to Pay String>
[outgoing_channel]: <Pay Out of Outgoing Channel Id String>
[pathfinding_timeout]: <Time to Spend Finding a Route Milliseconds Number>
tokens: <Tokens To Pay Number>
[tokens]: <Tokens to Pay Number>
}

@throws
Expand Down Expand Up @@ -3337,13 +3356,18 @@ const [paid] = await once(sub, 'confirmed');

### subscribeToPayViaRequest

Subscribe to the flight of a payment request
Initiate and subscribe to the outcome of a payment request

Requires lnd built with routerrpc build tag
Requires LND built with `routerrpc` build tag

Specifying `max_fee_mtokens`/`mtokens` is not supported in LND 0.8.1 or below

{
lnd: <Authenticated LND gRPC API Object>
[max_fee]: <Maximum Fee Tokens To Pay Number>
[max_fee_mtokens]: <Maximum Fee Millitokens to Pay String>
[max_timeout_height]: <Maximum Height of Payment Timeout Number>
[mtokens]: <Millitokens to Pay String>
[outgoing_channel]: <Pay Out of Outgoing Channel Id String>
[pathfinding_timeout]: <Time to Spend Finding a Route Milliseconds Number>
request: <BOLT 11 Payment Request String>
Expand All @@ -3369,9 +3393,10 @@ Requires lnd built with routerrpc build tag
timeout: <Timeout Block Height Number>
}]
id: <Payment Hash Hex String>
mtokens: <Total Millitokens To Pay String>
mtokens: <Total Millitokens Paid String>
secret: <Payment Preimage Hex String>
timeout: <Expiration Block Height Number>
tokens: <Total Tokens Paid Number>
}

@event 'failed'
Expand Down Expand Up @@ -3587,8 +3612,9 @@ Requires LND built with `routerrpc` build tag
[is_ignoring_past_failures]: <Ignore Past Failures When Finding Path Bool>
[is_strict_hints]: <Only Route Through Specified Paths Bool>
lnd: <Authenticated LND gRPC API Object>
[max_fee]: <Maximum Fee Tokens Number>
[max_fee_mtokens]: <Maximum Fee Millitokens to Probe String>
[max_timeout_height]: <Maximum CLTV Timeout Height Number>
[mtokens]: <Millitokens to Probe String>
[outgoing_channel]: <Outgoing Channel Id String>
[path_timeout_ms]: <Skip Path Attempt After Milliseconds Number>
[probe_timeout_ms]: <Fail Probe After Milliseconds Number>
Expand Down
20 changes: 20 additions & 0 deletions grpc/protos/router.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ message SendPaymentRequest {
/// Number of satoshis to send.
int64 amt = 2;

/**
Number of millisatoshis to send.
The fields amt and amt_msat are mutually exclusive.
*/
int64 amt_msat = 12;

/// The hash to use within the payment's HTLC
bytes payment_hash = 3;

Expand Down Expand Up @@ -44,9 +51,22 @@ message SendPaymentRequest {
If this field is left to the default value of 0, only zero-fee routes will
be considered. This usually means single hop routes connecting directly to
the destination. To send the payment without a fee limit, use max int here.
The fields fee_limit_sat and fee_limit_msat are mutually exclusive.
*/
int64 fee_limit_sat = 7;

/**
The maximum number of millisatoshis that will be paid as a fee of the
payment. If this field is left to the default value of 0, only zero-fee
routes will be considered. This usually means single hop routes connecting
directly to the destination. To send the payment without a fee limit, use
max int here.
The fields fee_limit_sat and fee_limit_msat are mutually exclusive.
*/
int64 fee_limit_msat = 13;

/**
The channel id of the channel that must be taken to the first hop. If zero,
any channel may be used.
Expand Down
5 changes: 5 additions & 0 deletions lightning/create_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {broadcastResponse} = require('./../push');
const createChainAddress = require('./create_chain_address');
const getInvoice = require('./get_invoice');

const invoiceExistsError = 'invoice with payment hash already exists';
const {isArray} = Array;
const msPerSec = 1e3;
const {parse} = Date;
Expand Down Expand Up @@ -105,6 +106,10 @@ module.exports = (args, cbk) => {
value: args.tokens || undefined,
},
(err, response) => {
if (!!err && err.details === invoiceExistsError) {
return cbk([409, 'InvoiceWithGivenHashAlreadyExists']);
}

if (!!err) {
return cbk([503, 'AddInvoiceError', err]);
}
Expand Down
2 changes: 1 addition & 1 deletion lightning/get_channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const msPerSec = 1e3;
`is_static_remote_key` will be undefined on LND 0.7.1 and below
`time_offline` and `time_online` will be undefined on 0.8.0 and below
`time_offline` and `time_online` will be undefined on 0.8.1 and below
{
[is_active]: <Limit Results To Only Active Channels Bool> // false
Expand Down
2 changes: 1 addition & 1 deletion lightning/get_forwards.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {stringify} = JSON;
If a next token is returned, pass it to get additional page of results.
`mtokens` is not supported on LND v0.8.0 or lower
`mtokens` is not supported on LND v0.8.1 or lower
{
[after]: <Get Only Payments Forwarded At Or After ISO 8601 Date String>
Expand Down
2 changes: 1 addition & 1 deletion lightning/get_network_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ module.exports = ({lnd}, cbk) => {
});
}],
},
returnResult({reject, resolve, of: 'getInfo'}));
returnResult({reject, resolve, of: 'getInfo'}, cbk));
});
};
2 changes: 1 addition & 1 deletion lightning/get_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const tokensAsMtokens = tokens => (BigInt(tokens) * BigInt(1000)).toString();
`confidence` is not supported in LND 0.7.1
`max_timeout_height` is not supported in LND 0.7.1
Specifying `payment` identifier and `total_mtokens` isn't in LND 0.8.0, lower
Specifying `payment` identifier and `total_mtokens` isn't in LND 0.8.1, lower
{
[cltv_delta]: <Final CLTV Delta Number>
Expand Down
4 changes: 4 additions & 0 deletions lightning/open_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ module.exports = (args, cbk) => {
return cbk([503, 'ChainUnsupported']);
}

if (/is.not.online/.test(n.details)) {
return cbk([503, 'PeerIsNotOnline']);
}

switch (n.details) {
case 'cannot open channel to self':
return cbk([400, 'CannotOpenChannelToOwnNode']);
Expand Down
2 changes: 1 addition & 1 deletion macaroons/grant_access.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const notSupported = 'unknown service lnrpc.Lightning';

/** Give access to the node by making a macaroon access credential
Note: granting access is not supported in LND versions 0.8.0 and below
Note: granting access is not supported in LND versions 0.8.1 and below
Note: access once given cannot be revoked
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@
"tower_server-integration-tests": "tap --no-coverage test/tower_serverrpc-integration/*.js",
"wallet-integration-tests": "tap --no-coverage test/walletrpc-integration/*.js"
},
"version": "47.1.1"
"version": "47.2.0"
}
2 changes: 1 addition & 1 deletion router/delete_forwarding_reputations.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {returnResult} = require('asyncjs-util');

/** Delete all forwarding reputations
Requires LND built with routerrpc build tag
Requires LND built with `routerrpc` build tag
{
lnd: <Authenticated gRPC LND API Object>
Expand Down
2 changes: 1 addition & 1 deletion router/get_forwarding_confidence.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const unimplementedError = 'unknown service routerrpc.Router';
Requires LND built with `routerrpc` build tag
Note: this method is not supported in LND 0.8.0 and below.
Note: this method is not supported in LND 0.8.1 and below.
{
from: <From Public Key Hex String>
Expand Down
4 changes: 2 additions & 2 deletions router/get_forwarding_reputations.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const timeAsDate = n => new Date(parseInt(n, 10) * 1e3).toISOString();
Note: In LND v0.7.1 channels reputations are returned.
Note: In LND v0.8.0 peers reputations are returned.
Note: after LND v0.8.0 confidence is not returned per peer.
Note: after LND v0.8.1 confidence is not returned per peer.
{
[confidence]: <Ignore Confidence Higher than N out of 1 Million Number>
Expand Down Expand Up @@ -215,7 +215,7 @@ module.exports = ({confidence, lnd, tokens}, cbk) => {
return cbk(null, pairs.map(pair => {
const confidence = probabilityAsConfidence(pair.success_prob);

// Only after LND 0.8.0 there is history for pairs
// Only after LND 0.8.1 there is history for pairs
if (!pair.history || !Number(pair.history.timestamp)) {
return {
confidence: confidence || undefined,
Expand Down
Loading

0 comments on commit 45b8051

Please sign in to comment.