diff --git a/.env.example b/.env.example index 9ce3069..1a30a0e 100644 --- a/.env.example +++ b/.env.example @@ -18,6 +18,8 @@ HOSTNAME=127.0.0.1 LOCK_GAS_PRICE=0x22ecb25c00 LOCK_CHAIN_ID=0x4571 LOCK_GENESIS_TIME="2023-04-05T02:18:09" +SHOW_MINER=true +SHOW_ENDPOINTS=false # Prometheus Metrics PROMETHEUS_PORT=9102 diff --git a/README.md b/README.md index 0b38a1c..3e8e76c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ## [`Bun` Binary Releases](https://github.com/pinax-network/eos-evm-miner/releases) ``` -$ wget https://github.com/pinax-network/eos-evm-miner/releases/download/v0.4.2/eos-evm-miner +$ wget https://github.com/pinax-network/eos-evm-miner/releases/download/v0.5.0/eos-evm-miner $ chmod +x ./eos-evm-miner ``` diff --git a/bin/cli.ts b/bin/cli.ts index 4d2a865..45325a7 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -13,6 +13,22 @@ program.name(pkg.name) .description("EOS EVM Miner JSON RPC Server") .version(pkg.version, '-v, --version', `version for ${pkg.name}`) + +export interface StartOptions extends DefaultOptions { + port?: number; + metricsListenPort?: number; + hostname?: string; + verbose?: boolean; + metricsDisabled?: boolean; + lockGasPrice?: string; + lockChainId?: string; + lockGenesisTime?: string; + rpcEvmEndpoint?: string; + rpcEndpoint?: string; + showEndpoints?: boolean; + showMiner?: boolean; +} + // Start JSON RPC Server defaultOptions(program.command("start")) .description("Start JSON RPC Server") @@ -26,6 +42,8 @@ defaultOptions(program.command("start")) .option('--lock-genesis-time', `Lock genesis time (ex: "${EXAMPLE_LOCK_GENESIS_TIME}")`) .option('--rpc-endpoint', `EOS RPC endpoint (ex: "${DEFAULT_RPC_ENDPOINT}")`) .option('--rpc-evm-endpoint', `EOS RPC endpoint (ex: "${DEFAULT_RPC_EVM_ENDPOINT}")`) + .option('--show-endpoints', 'If set, will display all RPC endpoints used by the server') + .option('--show-miner', 'If set, will display all miner account details used by the server') .action(options => { start(options); }); diff --git a/index.ts b/index.ts index 303b53a..8d84566 100644 --- a/index.ts +++ b/index.ts @@ -1,9 +1,8 @@ -import pkg from "./package.json" assert { type: "json" }; + import { JSONRPCRequest, JSONRPCResponse, JSONRPCServer, JSONRPCServerMiddlewareNext, createJSONRPCErrorResponse } from "json-rpc-2.0"; -import { Session } from "@wharfkit/session"; -import { DEFAULT_HOSTNAME, HOSTNAME, LOCK_GAS_PRICE, PORT,PROMETHEUS_PORT, METRICS_DISABLED, VERBOSE, LOCK_CHAIN_ID, LOCK_GENESIS_TIME, RPC_EVM_ENDPOINT } from "./src/config.js"; +import { HOSTNAME, LOCK_GAS_PRICE, PORT,PROMETHEUS_PORT, METRICS_DISABLED, VERBOSE, LOCK_CHAIN_ID, LOCK_GENESIS_TIME, RPC_EVM_ENDPOINT, SHOW_ENDPOINTS, SHOW_MINER } from "./src/config.js"; import { logger } from "./src/logger.js"; -import { DefaultOptions } from "./bin/cli.js"; +import { StartOptions } from "./bin/cli.js"; import * as prometheus from "./src/prometheus.js" import { eth_sendRawTransaction } from "./src/eth_sendRawTransaction.js"; import { eth_gasPrice } from "./src/eth_gasPrice.js"; @@ -14,19 +13,7 @@ import { net_version } from "./src/net_version.js"; import { eth_getCode } from "./src/eth_getCode.js"; import { createSession } from "./src/createSession.js"; import { createClient } from "./src/createClient.js"; - -export interface StartOptions extends DefaultOptions { - port?: number; - metricsListenPort?: number; - hostname?: string; - verbose?: boolean; - metricsDisabled?: boolean; - lockGasPrice?: string; - lockChainId?: string; - lockGenesisTime?: string; - rpcEvmEndpoint?: string; - rpcEndpoint?: string; -} +import { banner } from "./src/banner.js"; export default function (options: StartOptions) { const port = options.port ?? PORT; @@ -38,6 +25,8 @@ export default function (options: StartOptions) { const lockGenesisTime = options.lockGenesisTime ?? LOCK_GENESIS_TIME; const verbose = options.verbose ?? VERBOSE; const rpcEvmEndpoint = options.rpcEvmEndpoint ?? RPC_EVM_ENDPOINT; + const showEndpoints = options.showEndpoints ?? SHOW_ENDPOINTS; + const showMiner = options.showMiner ?? SHOW_MINER; // create Wharfkit session const session = createSession(options); @@ -47,9 +36,10 @@ export default function (options: StartOptions) { const client = createClient(rpcEvmEndpoint); // enable logging if verbose enabled + const banner_text = banner(session, port, {showMiner, showEndpoints, rpcEvmEndpoint, hostname, metricsListenPort, metricsDisabled}) if (verbose) { logger.settings.type = "json"; - console.log(banner(session, port, rpcEvmEndpoint, hostname, metricsListenPort, metricsDisabled)); + console.log(banner_text); } server.addMethod("eth_sendRawTransaction", async params => { @@ -140,7 +130,7 @@ export default function (options: StartOptions) { fetch: async (request: Request) => { const url = new URL(request.url); if ( request.method == "GET" ) { - if ( url.pathname == "/" ) return new Response(banner(session, port, rpcEvmEndpoint, hostname, metricsListenPort, metricsDisabled)); + if ( url.pathname == "/" ) return new Response(banner_text); const info = await session.client.v1.chain.get_info(); return toJSON(info.toJSON()); } @@ -170,22 +160,3 @@ function toJSON(obj: any, status: number = 200) { const body = JSON.stringify(obj); return new Response(body, { status, headers }); } - -function banner( session: Session, port: number, rpcEvmEndpoint?: string, hostname?: string, metricsListenPort?: number, metricsDisabled?: boolean ) { - let text = ` - - ███████╗ ██████╗ ███████╗ ███████╗██╗ ██╗███╗ ███╗ - ██╔════╝██╔═══██╗██╔════╝ ██╔════╝██║ ██║████╗ ████║ - █████╗ ██║ ██║███████╗ █████╗ ██║ ██║██╔████╔██║ - ██╔══╝ ██║ ██║╚════██║ ██╔══╝ ╚██╗ ██╔╝██║╚██╔╝██║ - ███████╗╚██████╔╝███████║ ███████╗ ╚████╔╝ ██║ ╚═╝ ██║ - ╚══════╝ ╚═════╝ ╚══════╝ ╚══════╝ ╚═══╝ ╚═╝ ╚═╝ -` - text += ` EOS EVM Miner v${pkg.version} listen @ ${hostname ?? DEFAULT_HOSTNAME}:${port.toString()}\n` - if ( !metricsDisabled ) text += ` Prometheus metrics listen @ ${hostname ?? DEFAULT_HOSTNAME}:${metricsListenPort?.toString()}\n`; - text += ` RPC Nodeos proxy @ ${session.chain.url.toString()}\n` - text += ` RPC EVM proxy @ ${rpcEvmEndpoint}\n` - text += ` EVM miner [${session.actor.toString()}]\n`; - text += ` ${session.walletPlugin.metadata.publicKey}\n` - return text; -} diff --git a/package.json b/package.json index 3a9e9f7..cf24d81 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "@enf/eos-evm-miner", - "version": "0.4.4", + "version": "0.5.0", "description": "EOS EVM miner", "type": "module", "exports": "./dist/index.js", diff --git a/src/banner.ts b/src/banner.ts new file mode 100644 index 0000000..7fe855f --- /dev/null +++ b/src/banner.ts @@ -0,0 +1,27 @@ +import pkg from "../package.json" assert { type: "json" }; +import { Session } from "@wharfkit/session"; +import { StartOptions } from "../bin/cli.js"; +import { DEFAULT_HOSTNAME } from "./config.js"; + +export function banner( session: Session, port: number, options: StartOptions = {} ) { + const host = `${options.hostname ?? DEFAULT_HOSTNAME}:${port.toString()}`; + const host_metrics = `${options.hostname ?? DEFAULT_HOSTNAME}:${options.metricsListenPort?.toString()}` + const publicKey = session.walletPlugin.metadata.publicKey; + let text = ` + + ███████╗ ██████╗ ███████╗ ███████╗██╗ ██╗███╗ ███╗ + ██╔════╝██╔═══██╗██╔════╝ ██╔════╝██║ ██║████╗ ████║ + █████╗ ██║ ██║███████╗ █████╗ ██║ ██║██╔████╔██║ + ██╔══╝ ██║ ██║╚════██║ ██╔══╝ ╚██╗ ██╔╝██║╚██╔╝██║ + ███████╗╚██████╔╝███████║ ███████╗ ╚████╔╝ ██║ ╚═╝ ██║ + ╚══════╝ ╚═════╝ ╚══════╝ ╚══════╝ ╚═══╝ ╚═╝ ╚═╝ +` + text += ` EOS EVM Miner v${pkg.version}\n` + if ( options.showEndpoints ) text += ` Ethereum JSON-RPC API listening on @ ${host}\n` + if ( options.showEndpoints && !options.metricsDisabled ) text += ` Prometheus metrics listening on @ ${host_metrics}\n`; + if ( options.showEndpoints ) text += ` RPC Nodeos proxy @ ${session.chain.url.toString()}\n` + if ( options.showEndpoints ) text += ` RPC EVM proxy @ ${options.rpcEvmEndpoint}\n` + if ( options.showMiner ) text += ` EVM miner [${session.actor.toString()}]\n`; + if ( options.showMiner && publicKey ) text += ` ${publicKey}\n` + return text; +} diff --git a/src/config.ts b/src/config.ts index ad71af3..487443f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -11,6 +11,8 @@ export const DEFAULT_RPC_ENDPOINT = 'https://eos.api.eosnation.io'; export const DEFAULT_RPC_EVM_ENDPOINT = 'https://api.evm.eosnetwork.com'; export const DEFAULT_METRICS_DISABLED = false; export const DEFAULT_VERBOSE = false; +export const DEFAULT_SHOW_MINER = true; +export const DEFAULT_SHOW_ENDPOINTS = false; // examples export const EXAMPLE_LOCK_CHAIN_ID = "0x4571"; @@ -28,6 +30,8 @@ export const RPC_EVM_ENDPOINT = process.env.RPC_EVM_ENDPOINT ?? DEFAULT_RPC_EVM_ export const HOSTNAME = process.env.HOSTNAME; export const METRICS_DISABLED = JSON.parse(process.env.METRICS_DISABLED ?? String(DEFAULT_METRICS_DISABLED)) as boolean; export const VERBOSE = JSON.parse(process.env.VERBOSE ?? String(DEFAULT_VERBOSE)) as boolean; +export const SHOW_ENDPOINTS = JSON.parse(process.env.SHOW_ENDPOINTS ?? String(DEFAULT_SHOW_ENDPOINTS)) as boolean; +export const SHOW_MINER = JSON.parse(process.env.SHOW_MINER ?? String(DEFAULT_SHOW_MINER)) as boolean; // Miner details export const MINER_PERMISSION = process.env.MINER_PERMISSION ?? process.env.PERMISSION ?? DEFAULT_MINER_PERMISSION;