Skip to content

Commit

Permalink
[Manually reapplied] Merge pull request #3804 from nymtech/feature/ex…
Browse files Browse the repository at this point in the history
…plorer-gateway-iplocation

This was originally a commit 'b0a45c03b16c74697d8b46428fd83a25a5168add'.
However, we had to manually reapply it due to accidentally messing up the branch history.
  • Loading branch information
jstuczyn committed Aug 25, 2023
2 parents 2fbb901 + 026d52a commit 1ce536c
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 348 deletions.
44 changes: 44 additions & 0 deletions explorer-api/.env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
CONFIGURED=true

RUST_LOG=info
RUST_BACKTRACE=1

BECH32_PREFIX=n
MIX_DENOM=unym
MIX_DENOM_DISPLAY=nym
STAKE_DENOM=unyx
STAKE_DENOM_DISPLAY=nyx
DENOMS_EXPONENT=6

REWARDING_VALIDATOR_ADDRESS=n1pefc2utwpy5w78p2kqdsfmpjxfwmn9d39k5mqa
MIXNET_CONTRACT_ADDRESS=n1xr3rq8yvd7qplsw5yx90ftsr2zdhg4e9z60h5duusgxpv72hud3sjkxkav
VESTING_CONTRACT_ADDRESS=n1unyuj8qnmygvzuex3dwmg9yzt9alhvyeat0uu0jedg2wj33efl5qackslz
BANDWIDTH_CLAIM_CONTRACT_ADDRESS=n19lc9u84cz0yz3fww5283nucc9yvr8gsjmgeul0
COCONUT_BANDWIDTH_CONTRACT_ADDRESS=n16a32stm6kknhq5cc8rx77elr66pygf2hfszw7wvpq746x3uffylqkjar4l
GROUP_CONTRACT_ADDRESS=n1pd7kfgvr5tpcv0xnlv46c4jsq9jg2r799xxrcwqdm4l2jhq2pjwqrmz5ju
MULTISIG_CONTRACT_ADDRESS=n14ph4e660eyqz0j36zlkaey4zgzexm5twkmjlqaequxr2cjm9eprqsmad6k
COCONUT_DKG_CONTRACT_ADDRESS=n1ahg0erc2fs6xx3j5m8sfx3ryuzdjh6kf6qm9plsf865fltekyrfsesac6a
NAME_SERVICE_CONTRACT_ADDRESS=n12ne7qtmdwd0j03t9t5es8md66wq4e5xg9neladrsag8fx3y89rcs36asfp
SERVICE_PROVIDER_DIRECTORY_CONTRACT_ADDRESS=n1ps5yutd7sufwg058qd7ac7ldnlazsvmhzqwucsfxmm445d70u8asqxpur4

STATISTICS_SERVICE_DOMAIN_ADDRESS="http://0.0.0.0"
NYXD="https://sandbox-validator1.nymtech.net"
NYM_API="https://sandbox-nym-api1.nymtech.net/api"

GEOIP_DB_PATH=geo_ip/GeoLite2-City.mmdb
# MaxMind account ID
# TODO replace with your own account ID
GEOIPUPDATE_ACCOUNT_ID=xxx
# MaxMind license key
# TODO replace with your own license key
GEOIPUPDATE_LICENSE_KEY=xxx
# List of space-separated database edition IDs. Edition IDs may
# consist of letters, digits, and dashes. For example, GeoIP2-City
# would download the GeoIP2 City database (GeoIP2-City).
GEOIPUPDATE_EDITION_IDS=GeoLite2-City
# The number of hours between geoipupdate runs. If this is not set
# or is set to 0, geoipupdate will run once and exit.
GEOIPUPDATE_FREQUENCY=72
# The path to the directory where geoipupdate will download the
# database.
GEOIP_DB_DIRECTORY=./geo_ip
1 change: 1 addition & 0 deletions explorer-api/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
explorer-api-state.json
/geo_ip
!.env.dev
18 changes: 10 additions & 8 deletions explorer-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ Features:
- calculates how many nodes are in each country
- proxies mixnode API requests to add HTTPS

## Development

Several environment variables are required. They can be
provisioned via a `.env` file. For convenience a `.env.dev` is
provided, just copy its content into `.env`.

Follow the steps to setup the geoip database.

## GeoIP db install/update

First we need to install the geoip database.
A geoip database needs to be installed.

We use https://github.com/maxmind/geoipupdate to automatically
download and update GeoLite2 binary database. For convenience we
Expand All @@ -37,13 +45,7 @@ When starting the explorer-api, supply the environment variable
`GEOIP_DB_PATH`, pointing to the GeoLite2 binary database file.
It should be previously installed thanks to `geoipupdate` service.

For example:

```shell
GEOIP_DB_PATH=./geo_ip/GeoLite2-City.mmdb cargo run
```

Note: explorer-api binary reads the provided `.env` file.
Note: As mentioned above the explorer-api binary reads the provided `.env` file.

Run as a service and reverse proxy with `nginx` to add `https` with Lets Encrypt.

Expand Down
9 changes: 9 additions & 0 deletions explorer/.env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# When running the explorer API locally
#EXPLORER_API_URL=http://localhost:8000/v1

EXPLORER_API_URL=https://sandbox-explorer.nymtech.net/api/v1
NYM_API_URL=https://sandbox-nym-api1.nymtech.net
VALIDATOR_URL=https://sandbox-validator1.nymtech.net
BIG_DIPPER_URL=https://sandbox-blocks.nymtech.net
CURRENCY_DENOM=unym
CURRENCY_STAKING_DENOM=unyx
3 changes: 2 additions & 1 deletion explorer/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
.DS_Store
detailAPI.md
detailAPI.md
!.env.dev
15 changes: 15 additions & 0 deletions explorer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ You can then open a browser to http://localhost:3000 and start development.

Documentation for developers [can be found here](./docs).

Several environment variables are required. They can be
provisioned via a `.env` file. For convenience a `.env.dev` is
provided, just copy its content into `.env`.

#### Required env vars

```
EXPLORER_API_URL
NYM_API_URL
VALIDATOR_URL
BIG_DIPPER_URL
CURRENCY_DENOM
CURRENCY_STAKING_DENOM
```

## Deployment

Build the UI with (starting in the repository root):
Expand Down
29 changes: 15 additions & 14 deletions explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
"version": "1.0.7",
"private": true,
"license": "Apache-2.0",
"scripts": {
"start": "webpack serve --progress --port 3000",
"build": "webpack build --progress --config webpack.prod.js",
"build:serve": "npx serve dist",
"test": "jest",
"test:watch": "jest --watch",
"tsc": "tsc --noEmit true",
"tsc:watch": "tsc --watch --noEmit true",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
"prestorybook": "yarn --cwd .. build",
"storybook": "start-storybook -p 6006",
"storybook:build": "build-storybook"
},
"dependencies": {
"@cosmjs/math": "^0.26.2",
"@emotion/react": "^11.4.1",
Expand All @@ -18,6 +32,7 @@
"big.js": "^6.2.1",
"d3-scale": "^4.0.0",
"date-fns": "^2.24.0",
"lodash": "^4.17.21",
"i18n-iso-countries": "^6.8.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down Expand Up @@ -95,20 +110,6 @@
"webpack-favicons": "^1.3.8",
"webpack-merge": "^5.8.0"
},
"scripts": {
"start": "webpack serve --progress --port 3000",
"build": "webpack build --progress --config webpack.prod.js",
"build:serve": "npx serve dist",
"test": "jest",
"test:watch": "jest --watch",
"tsc": "tsc --noEmit true",
"tsc:watch": "tsc --watch --noEmit true",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
"prestorybook": "yarn --cwd .. build",
"storybook": "start-storybook -p 6006",
"storybook:build": "build-storybook"
},
"browserslist": {
"production": [
">0.2%",
Expand Down
1 change: 1 addition & 0 deletions explorer/src/api/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const OVERVIEW_API = `${API_BASE_URL}/overview`;
export const MIXNODE_PING = `${API_BASE_URL}/ping`;
export const MIXNODES_API = `${API_BASE_URL}/mix-nodes`;
export const MIXNODE_API = `${API_BASE_URL}/mix-node`;
export const GATEWAYS_EXPLORER_API = `${API_BASE_URL}/gateways`;
export const GATEWAYS_API = `${NYM_API_BASE_URL}/api/v1/status/gateways/detailed`;
export const VALIDATORS_API = `${VALIDATOR_BASE_URL}/validators`;
export const BLOCK_API = `${NYM_API_BASE_URL}/block`;
Expand Down
7 changes: 7 additions & 0 deletions explorer/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import keyBy from 'lodash/keyBy';
import {
API_BASE_URL,
BLOCK_API,
Expand All @@ -11,6 +12,7 @@ import {
UPTIME_STORY_API,
VALIDATORS_API,
SERVICE_PROVIDERS,
GATEWAYS_EXPLORER_API,
} from './constants';

import {
Expand All @@ -32,6 +34,7 @@ import {
GatewayBondAnnotated,
GatewayBond,
DirectoryServiceProvider,
LocatedGateway,
} from '../typeDefs/explorer-api';

function getFromCache(key: string) {
Expand Down Expand Up @@ -98,9 +101,13 @@ export class Api {
static fetchGateways = async (): Promise<GatewayBond[]> => {
const res = await fetch(GATEWAYS_API);
const gatewaysAnnotated: GatewayBondAnnotated[] = await res.json();
const res2 = await fetch(GATEWAYS_EXPLORER_API);
const locatedGateways: LocatedGateway[] = await res2.json();
const locatedGatewaysByOwner = keyBy(locatedGateways, 'owner');
return gatewaysAnnotated.map(({ gateway_bond, node_performance }) => ({
...gateway_bond,
node_performance,
location: locatedGatewaysByOwner[gateway_bond.owner]?.location,
}));
};

Expand Down
4 changes: 2 additions & 2 deletions explorer/src/components/Gateways.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function gatewayToGridRow(arrayOfGateways: GatewayResponse): GatewayRowTy
id: gw.owner,
owner: gw.owner,
identity_key: gw.gateway.identity_key || '',
location: gw?.gateway?.location || '',
location: gw.location?.country_name.toUpperCase() || '',
bond: gw.pledge_amount.amount || 0,
host: gw.gateway.host || '',
version: gw.gateway.version || '',
Expand All @@ -39,7 +39,7 @@ export function gatewayEnrichedToGridRow(gateway: GatewayBond, report: GatewayRe
id: gateway.owner,
owner: gateway.owner,
identity_key: gateway.gateway.identity_key || '',
location: gateway?.gateway?.location || '',
location: gateway.location?.country_name.toUpperCase() || '',
bond: gateway.pledge_amount.amount || 0,
host: gateway.gateway.host || '',
version: gateway.gateway.version || '',
Expand Down
18 changes: 18 additions & 0 deletions explorer/src/typeDefs/explorer-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,31 @@ export interface GatewayBond {
owner: string;
gateway: Gateway;
node_performance: NodePerformance;
location?: Location;
}

export interface GatewayBondAnnotated {
gateway_bond: GatewayBond;
node_performance: NodePerformance;
}

export interface Location {
two_letter_iso_country_code: string;
three_letter_iso_country_code: string;
country_name: string;
latitude?: number;
longitude?: number;
}

export interface LocatedGateway {
pledge_amount: Amount;
owner: string;
block_height: number;
gateway: Gateway;
proxy?: string;
location?: Location;
}

export type GatewayResponse = GatewayBond[];

export interface GatewayReportResponse {
Expand Down
Loading

0 comments on commit 1ce536c

Please sign in to comment.