robosats/.github/workflows/scripts/lnproxy-sync.js
+shyfire131 3bd7ade298
Fix lnproxy support and add lnproxy relays workflow (#586)
* Use new lnproxy API

- Use POST instead of GET, so create and send a body parameter
- Path is /spec/ instead of /api/, and list of relays from lnproxy will contain /spec already, so path parameter for ApiClient.post() is an empty string

* add lnproxy sync workflow

* Use new lnproxy JSON structure

* Remove virtualenv

doing this so that the “scripts” subfolder in .github/workflows can be added

* Move workflow script to subfolder

* Add translation support

Locale strings not added yet

* Simplify coordinator updates, automatic migrations and collect statics (#583)

* Delete commited proto files

* Run sync workflow weekly instead of hourly

* Tweak display name for relays

* Update sync script to be append-only

* Use new naming convention for relays

* Fix bitcoinNetwork hydration

* PR Feedback

- Change hook deps from settings.network to settings
- routing_msat param updates for lnproxy API

* Actually set host in settings

* Updated parsing of LnProxy response

---------

Co-authored-by: +shyfire131 <shyfire131@shyfire131.net>
Co-authored-by: Reckless_Satoshi <90936742+Reckless-Satoshi@users.noreply.github.com>
Co-authored-by: Reckless_Satoshi <reckless.satoshi@protonmail.com>
2023-05-18 11:14:11 +00:00

46 lines
1.4 KiB
JavaScript

const fs = require('fs');
let incomingRelays = JSON.parse(fs.readFileSync('./lnproxy_tmplist.json'));
let existingRelays = JSON.parse(fs.readFileSync('./frontend/static/lnproxies.json'))
let newRelays = [];
let torCount = 0;
let i2pCount = 0;
let clearnetCount = 0;
//Merge relay lists. URL is the unique ID used to merge records and only inserts supported. No updates or deletes
let existingRelayURLs = existingRelays.map((relay) => relay.url);
let newIncomingRelays = incomingRelays.filter((relay)=> existingRelayURLs.indexOf(relay) === -1)
for (let url of newIncomingRelays) {
let relayType;
const LNPROXY_API_PATH = '/spec'
const fqdn = url.replace(LNPROXY_API_PATH, '');
if (fqdn.endsWith('.onion')) {
relayType = "TOR";
torCount++;
}
else if (fqdn.endsWith('i2p')) {
relayType = "I2P";
i2pCount++;
}
else {
relayType = "Clearnet";
clearnetCount++;
}
let relayName = `${relayType}${relayType === "TOR" ? torCount : ''}${relayType === "I2P" ? i2pCount : ''}${relayType === "Clearnet" ? clearnetCount : ''} ${url.split('/')[2].substring(0,6)}`
newRelays.push({
name: relayName,
url: url,
relayType: relayType,
network: "mainnet" //TODO: testnet
});
}
if (newRelays.length > 0) {
existingRelays.push(...newRelays);
fs.writeFileSync('./frontend/static/lnproxies.json', JSON.stringify(existingRelays, null, 2));
}