Remove xml parser - Read only .topology file and assume json format
This commit is contained in:
		
							parent
							
								
									b71d90d749
								
							
						
					
					
						commit
						51c3d8a5a3
					
				
							
								
								
									
										34
									
								
								backend/package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										34
									
								
								backend/package-lock.json
									
									
									
										generated
									
									
									
								
							@ -16,7 +16,6 @@
 | 
			
		||||
        "bitcoinjs-lib": "6.0.2",
 | 
			
		||||
        "crypto-js": "^4.0.0",
 | 
			
		||||
        "express": "^4.18.0",
 | 
			
		||||
        "fast-xml-parser": "^4.0.9",
 | 
			
		||||
        "maxmind": "^4.3.6",
 | 
			
		||||
        "mysql2": "2.3.3",
 | 
			
		||||
        "node-worker-threads-pool": "^1.5.1",
 | 
			
		||||
@ -3136,21 +3135,6 @@
 | 
			
		||||
      "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==",
 | 
			
		||||
      "dev": true
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/fast-xml-parser": {
 | 
			
		||||
      "version": "4.0.9",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.0.9.tgz",
 | 
			
		||||
      "integrity": "sha512-4G8EzDg2Nb1Qurs3f7BpFV4+jpMVsdgLVuG1Uv8O2OHJfVCg7gcA53obuKbmVqzd4Y7YXVBK05oJG7hzGIdyzg==",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "strnum": "^1.0.5"
 | 
			
		||||
      },
 | 
			
		||||
      "bin": {
 | 
			
		||||
        "fxparser": "src/cli/cli.js"
 | 
			
		||||
      },
 | 
			
		||||
      "funding": {
 | 
			
		||||
        "type": "paypal",
 | 
			
		||||
        "url": "https://paypal.me/naturalintelligence"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/fastq": {
 | 
			
		||||
      "version": "1.13.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.13.0.tgz",
 | 
			
		||||
@ -5636,11 +5620,6 @@
 | 
			
		||||
        "url": "https://github.com/sponsors/sindresorhus"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/strnum": {
 | 
			
		||||
      "version": "1.0.5",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz",
 | 
			
		||||
      "integrity": "sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA=="
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/supports-color": {
 | 
			
		||||
      "version": "7.2.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
 | 
			
		||||
@ -8556,14 +8535,6 @@
 | 
			
		||||
      "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==",
 | 
			
		||||
      "dev": true
 | 
			
		||||
    },
 | 
			
		||||
    "fast-xml-parser": {
 | 
			
		||||
      "version": "4.0.9",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.0.9.tgz",
 | 
			
		||||
      "integrity": "sha512-4G8EzDg2Nb1Qurs3f7BpFV4+jpMVsdgLVuG1Uv8O2OHJfVCg7gcA53obuKbmVqzd4Y7YXVBK05oJG7hzGIdyzg==",
 | 
			
		||||
      "requires": {
 | 
			
		||||
        "strnum": "^1.0.5"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "fastq": {
 | 
			
		||||
      "version": "1.13.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.13.0.tgz",
 | 
			
		||||
@ -10398,11 +10369,6 @@
 | 
			
		||||
      "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==",
 | 
			
		||||
      "dev": true
 | 
			
		||||
    },
 | 
			
		||||
    "strnum": {
 | 
			
		||||
      "version": "1.0.5",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz",
 | 
			
		||||
      "integrity": "sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA=="
 | 
			
		||||
    },
 | 
			
		||||
    "supports-color": {
 | 
			
		||||
      "version": "7.2.0",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
 | 
			
		||||
 | 
			
		||||
@ -38,7 +38,6 @@
 | 
			
		||||
    "bitcoinjs-lib": "6.0.2",
 | 
			
		||||
    "crypto-js": "^4.0.0",
 | 
			
		||||
    "express": "^4.18.0",
 | 
			
		||||
    "fast-xml-parser": "^4.0.9",
 | 
			
		||||
    "maxmind": "^4.3.6",
 | 
			
		||||
    "mysql2": "2.3.3",
 | 
			
		||||
    "node-worker-threads-pool": "^1.5.1",
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,5 @@
 | 
			
		||||
import DB from '../../../database';
 | 
			
		||||
import { promises } from 'fs';
 | 
			
		||||
import { XMLParser } from 'fast-xml-parser';
 | 
			
		||||
import logger from '../../../logger';
 | 
			
		||||
import fundingTxFetcher from './funding-tx-fetcher';
 | 
			
		||||
import config from '../../../config';
 | 
			
		||||
@ -35,7 +34,6 @@ interface Channel {
 | 
			
		||||
 | 
			
		||||
class LightningStatsImporter {
 | 
			
		||||
  topologiesFolder = config.LIGHTNING.TOPOLOGY_FOLDER;
 | 
			
		||||
  parser = new XMLParser();
 | 
			
		||||
 | 
			
		||||
  async $run(): Promise<void> {
 | 
			
		||||
    const [channels]: any[] = await DB.query('SELECT short_id from channels;');
 | 
			
		||||
@ -294,7 +292,7 @@ class LightningStatsImporter {
 | 
			
		||||
        continue;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (filename.indexOf('.json') === -1) {
 | 
			
		||||
      if (filename.indexOf('.topology') === -1) {
 | 
			
		||||
        continue;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
@ -342,75 +340,6 @@ class LightningStatsImporter {
 | 
			
		||||
      logger.info(`Lightning network stats historical import completed`);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Parse the file content into XML, and return a list of nodes and channels
 | 
			
		||||
   */
 | 
			
		||||
  private parseFile(fileContent): any {
 | 
			
		||||
    const graph = this.parser.parse(fileContent);
 | 
			
		||||
    if (Object.keys(graph).length === 0) {
 | 
			
		||||
      return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const nodes: Node[] = [];
 | 
			
		||||
    const channels: Channel[] = [];
 | 
			
		||||
 | 
			
		||||
    // If there is only one entry, the parser does not return an array, so we override this
 | 
			
		||||
    if (!Array.isArray(graph.graphml.graph.node)) {
 | 
			
		||||
      graph.graphml.graph.node = [graph.graphml.graph.node];
 | 
			
		||||
    }
 | 
			
		||||
    if (!Array.isArray(graph.graphml.graph.edge)) {
 | 
			
		||||
      graph.graphml.graph.edge = [graph.graphml.graph.edge];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (const node of graph.graphml.graph.node) {
 | 
			
		||||
      if (!node.data) {
 | 
			
		||||
        continue;
 | 
			
		||||
      }
 | 
			
		||||
      const addresses: unknown[] = [];
 | 
			
		||||
      const sockets = node.data[5].split(',');
 | 
			
		||||
      for (const socket of sockets) {
 | 
			
		||||
        const parts = socket.split('://');
 | 
			
		||||
        addresses.push({
 | 
			
		||||
          network: parts[0],
 | 
			
		||||
          addr: parts[1],
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
      nodes.push({
 | 
			
		||||
        id: node.data[0],
 | 
			
		||||
        timestamp: node.data[1],
 | 
			
		||||
        features: node.data[2],
 | 
			
		||||
        rgb_color: node.data[3],
 | 
			
		||||
        alias: node.data[4],
 | 
			
		||||
        addresses: addresses,
 | 
			
		||||
        out_degree: node.data[6],
 | 
			
		||||
        in_degree: node.data[7],
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (const channel of graph.graphml.graph.edge) {
 | 
			
		||||
      if (!channel.data) {
 | 
			
		||||
        continue;
 | 
			
		||||
      }
 | 
			
		||||
      channels.push({
 | 
			
		||||
        channel_id: channel.data[0],
 | 
			
		||||
        node1_pub: channel.data[1],
 | 
			
		||||
        node2_pub: channel.data[2],
 | 
			
		||||
        timestamp: channel.data[3],
 | 
			
		||||
        features: channel.data[4],
 | 
			
		||||
        fee_base_msat: channel.data[5],
 | 
			
		||||
        fee_rate_milli_msat: channel.data[6],
 | 
			
		||||
        htlc_minimim_msat: channel.data[7],
 | 
			
		||||
        cltv_expiry_delta: channel.data[8],
 | 
			
		||||
        htlc_maximum_msat: channel.data[9],
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return {
 | 
			
		||||
      nodes: nodes,
 | 
			
		||||
      edges: channels,
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default new LightningStatsImporter;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user