mirror of
https://github.com/alexbosworth/balanceofsatoshis.git
synced 2026-08-13 12:33:37 +02:00
merge changes
This commit is contained in:
parent
7f265315f7
commit
75755f41b6
2 changed files with 34 additions and 29 deletions
|
|
@ -25,6 +25,7 @@ const createSecret = () => randomBytes(32).toString('hex');
|
|||
const defaultFilter = ['channels_count > 9'];
|
||||
const defaultMsg = (alias, key) => `Check out my node! ${alias} ${key}`;
|
||||
const directPeersDistance = 0;
|
||||
const featureKeysendBit = 55;
|
||||
const filterLimit = 10;
|
||||
const flatten = arr => [].concat(...arr);
|
||||
const hashOf = n => createHash('sha256').update(n).digest().toString('hex');
|
||||
|
|
@ -98,33 +99,36 @@ module.exports = (args, cbk) => {
|
|||
}],
|
||||
|
||||
// Get the list of tags and filter them.
|
||||
getTags: ['validate', ({}, cbk) => {
|
||||
// Exit early when there are no tags
|
||||
getTags: ['getIdentity', ({getIdentity}, cbk) => {
|
||||
// Exit early when there are no tags specified to advertise to
|
||||
if (!args.tags.length) {
|
||||
return cbk();
|
||||
}
|
||||
|
||||
const matches = [];
|
||||
|
||||
return getTags({fs: args.fs}, (err, res) => {
|
||||
if (!!err) {
|
||||
return cbk(err);
|
||||
}
|
||||
|
||||
const {tags} = res;
|
||||
|
||||
args.tags.forEach(tagName => {
|
||||
const tag = tags.find(t => t.alias === tagName);
|
||||
if (!tag) {
|
||||
return;
|
||||
}
|
||||
|
||||
matches.push(tag.nodes);
|
||||
// Look for a referenced tag that doesn't match a present tag
|
||||
const unknown = args.tags.find(tagName => {
|
||||
return !res.tags.find(t => t.alias === tagName);
|
||||
});
|
||||
|
||||
// Remove duplicates
|
||||
return cbk(null, uniq(flatten(matches)));
|
||||
// Make sure the tag is present
|
||||
if (!!unknown) {
|
||||
return cbk([404, 'FailedToFindTagWithSpecifiedName', {unknown}]);
|
||||
}
|
||||
|
||||
// Collect all the node identity keys
|
||||
const matches = args.tags.map(tagName => {
|
||||
const tag = res.tags.find(t => t.alias === tagName);
|
||||
|
||||
return tag.nodes.filter(n => n !== getIdentity.public_key);
|
||||
});
|
||||
|
||||
// Merge all tagged nodes and remove duplicates
|
||||
return cbk(null, uniq(flatten(matches)));
|
||||
});
|
||||
}],
|
||||
|
||||
|
|
@ -134,11 +138,12 @@ module.exports = (args, cbk) => {
|
|||
}],
|
||||
|
||||
// Get the graph to use to find candidates to send ads to
|
||||
getGraph: ['getChannels', ({getChannels}, cbk) => {
|
||||
getGraph: ['getChannels', 'getTags', ({getChannels, getTags}, cbk) => {
|
||||
// Exit early when when advertising to tags.
|
||||
if (!!args.tags.length) {
|
||||
return cbk();
|
||||
return getNodesGraph({lnd: args.lnd, nodes: getTags}, cbk);
|
||||
}
|
||||
|
||||
// Exit early when using the entire graph
|
||||
if (args.max_hops !== directPeersDistance) {
|
||||
args.logger.info({sending_to_all_graph_nodes: true});
|
||||
|
|
@ -168,24 +173,16 @@ module.exports = (args, cbk) => {
|
|||
nodes: [
|
||||
'getGraph',
|
||||
'getIdentity',
|
||||
'getTags',
|
||||
'message',
|
||||
({getGraph, getIdentity, getTags, message}, cbk) =>
|
||||
({getGraph, getIdentity, message}, cbk) =>
|
||||
{
|
||||
// Exit early if tags are present
|
||||
if (!!getTags) {
|
||||
const nodes = getTags.filter(n => n !== getIdentity.public_key)
|
||||
.map(n => ({public_key: n}));
|
||||
|
||||
return cbk(null, nodes);
|
||||
}
|
||||
|
||||
const {shuffled} = shuffle({array: getGraph.nodes});
|
||||
|
||||
// Only consider 3rd party nodes that have known features
|
||||
const filteredNodes = shuffled
|
||||
.filter(n => n.public_key !== getIdentity.public_key)
|
||||
.filter(n => !!n.features.length)
|
||||
.filter(n => n.features.map(n => n.bit).includes(featureKeysendBit))
|
||||
.map(node => {
|
||||
const channels = getGraph.channels.filter(channel => {
|
||||
const {policies} = channel;
|
||||
|
|
|
|||
|
|
@ -65,6 +65,13 @@ module.exports = ({lnd, nodes}, cbk) => {
|
|||
getNodes: ['validate', ({}, cbk) => {
|
||||
return asyncMap(nodes, (id, cbk) => {
|
||||
return getNode({lnd, public_key: id}, (err, res) => {
|
||||
const [code] = err || [];
|
||||
|
||||
// Exit early when node is not known
|
||||
if (code === 404) {
|
||||
return cbk();
|
||||
}
|
||||
|
||||
if (!!err) {
|
||||
return cbk(err);
|
||||
}
|
||||
|
|
@ -84,11 +91,12 @@ module.exports = ({lnd, nodes}, cbk) => {
|
|||
|
||||
// Separate nodes and channels
|
||||
graph: ['getNodes', ({getNodes}, cbk) => {
|
||||
const allNodes = getNodes.filter(n => !!n);
|
||||
const channels = [];
|
||||
const ids = {};
|
||||
|
||||
// Populate the channels list
|
||||
getNodes.forEach(node => {
|
||||
allNodes.forEach(node => {
|
||||
return node.channels.forEach(channel => {
|
||||
// Exit early when this channel was seen already
|
||||
if (!!ids[channel.id]) {
|
||||
|
|
@ -101,7 +109,7 @@ module.exports = ({lnd, nodes}, cbk) => {
|
|||
});
|
||||
});
|
||||
|
||||
const nodes = getNodes.map(node => ({
|
||||
const nodes = allNodes.map(node => ({
|
||||
alias: node.alias,
|
||||
color: node.color,
|
||||
features: node.features,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue