Merge pull request #2095 from mempool/nymkappa/feature/ln-nodes-maxmind
Show maxming data when available is nodes page
This commit is contained in:
		
						commit
						2f0c8d94b0
					
				| @ -4,9 +4,34 @@ import DB from '../../database'; | |||||||
| class NodesApi { | class NodesApi { | ||||||
|   public async $getNode(public_key: string): Promise<any> { |   public async $getNode(public_key: string): Promise<any> { | ||||||
|     try { |     try { | ||||||
|       const query = `SELECT nodes.*, (SELECT COUNT(*) FROM channels WHERE channels.status < 2 AND (channels.node1_public_key = ? OR channels.node2_public_key = ?)) AS channel_count, (SELECT SUM(capacity) FROM channels WHERE channels.status < 2 AND (channels.node1_public_key = ? OR channels.node2_public_key = ?)) AS capacity, (SELECT AVG(capacity) FROM channels WHERE status < 2 AND (node1_public_key = ? OR node2_public_key = ?)) AS channels_capacity_avg FROM nodes WHERE public_key = ?`; |       const query = ` | ||||||
|  |         SELECT nodes.*, geo_names_as.names as as_organization, geo_names_city.names as city, | ||||||
|  |         geo_names_country.names as country, geo_names_subdivision.names as subdivision, | ||||||
|  |           (SELECT Count(*) | ||||||
|  |           FROM channels | ||||||
|  |           WHERE channels.status < 2 AND ( channels.node1_public_key = ? OR channels.node2_public_key = ? )) AS channel_count, | ||||||
|  |           (SELECT Sum(capacity) | ||||||
|  |           FROM channels | ||||||
|  |           WHERE channels.status < 2 AND ( channels.node1_public_key = ? OR channels.node2_public_key = ? )) AS capacity, | ||||||
|  |           (SELECT Avg(capacity) | ||||||
|  |           FROM channels | ||||||
|  |           WHERE status < 2 AND ( node1_public_key = ? OR node2_public_key = ? )) AS channels_capacity_avg | ||||||
|  |         FROM nodes | ||||||
|  |         LEFT JOIN geo_names geo_names_as on geo_names_as.id = as_number | ||||||
|  |         LEFT JOIN geo_names geo_names_city on geo_names_city.id = city_id | ||||||
|  |         LEFT JOIN geo_names geo_names_subdivision on geo_names_subdivision.id = subdivision_id | ||||||
|  |         LEFT JOIN geo_names geo_names_country on geo_names_country.id = country_id | ||||||
|  |         WHERE public_key = ? | ||||||
|  |       `;
 | ||||||
|       const [rows]: any = await DB.query(query, [public_key, public_key, public_key, public_key, public_key, public_key, public_key]); |       const [rows]: any = await DB.query(query, [public_key, public_key, public_key, public_key, public_key, public_key, public_key]); | ||||||
|       return rows[0]; |       if (rows.length > 0) { | ||||||
|  |         rows[0].as_organization = JSON.parse(rows[0].as_organization); | ||||||
|  |         rows[0].subdivision = JSON.parse(rows[0].subdivision); | ||||||
|  |         rows[0].city = JSON.parse(rows[0].city); | ||||||
|  |         rows[0].country = JSON.parse(rows[0].country); | ||||||
|  |         return rows[0]; | ||||||
|  |       } | ||||||
|  |       return null; | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       logger.err('$getNode error: ' + (e instanceof Error ? e.message : e)); |       logger.err('$getNode error: ' + (e instanceof Error ? e.message : e)); | ||||||
|       throw e; |       throw e; | ||||||
|  | |||||||
| @ -33,6 +33,14 @@ | |||||||
|                   <app-sats [satoshis]="node.channels_capacity_avg"></app-sats><app-fiat [value]="node.channels_capacity_avg" digitsInfo="1.0-0"></app-fiat> |                   <app-sats [satoshis]="node.channels_capacity_avg"></app-sats><app-fiat [value]="node.channels_capacity_avg" digitsInfo="1.0-0"></app-fiat> | ||||||
|                 </td> |                 </td> | ||||||
|               </tr> |               </tr> | ||||||
|  |               <tr *ngIf="node.country && node.city && node.subdivision"> | ||||||
|  |                 <td i18n="location">Location</td> | ||||||
|  |                 <td>{{ node.city.en }}, {{ node.subdivision.en }}<br>{{ node.country.en }}</td> | ||||||
|  |               </tr> | ||||||
|  |               <tr *ngIf="node.country && !node.city"> | ||||||
|  |                 <td i18n="location">Location</td> | ||||||
|  |                 <td>{{ node.country.en }}</td> | ||||||
|  |               </tr> | ||||||
|             </tbody> |             </tbody> | ||||||
|           </table> |           </table> | ||||||
|         </div> |         </div> | ||||||
| @ -56,6 +64,12 @@ | |||||||
|                 <td i18n="address.balance">Color</td> |                 <td i18n="address.balance">Color</td> | ||||||
|                 <td><div [ngStyle]="{'color': node.color}">{{ node.color }}</div></td> |                 <td><div [ngStyle]="{'color': node.color}">{{ node.color }}</div></td> | ||||||
|               </tr> |               </tr> | ||||||
|  |               <tr *ngIf="node.country"> | ||||||
|  |                 <td i18n="isp">ISP</td> | ||||||
|  |                 <td> | ||||||
|  |                   {{ node.as_organization }} [ASN {{node.as_number}}] | ||||||
|  |                 </td> | ||||||
|  |               </tr> | ||||||
|             </tbody> |             </tbody> | ||||||
|           </table> |           </table> | ||||||
|         </div> |         </div> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user