From 13cf23ee4070e7e3a979964b20dc28a529df2bae Mon Sep 17 00:00:00 2001 From: Michael Vandeberg Date: Mon, 6 May 2024 14:31:49 -0600 Subject: [PATCH] #7 Allow configuring contract addresses via environment --- app.config.ts | 37 +++++++++++++++++++++++++++---------- utils/providers.ts | 12 +----------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/app.config.ts b/app.config.ts index c82bc43..a27ffc2 100644 --- a/app.config.ts +++ b/app.config.ts @@ -1,3 +1,20 @@ +declare global { + namespace NodeJS { + interface ProcessEnv { + JSONRPC_URL: string, + KOIN_ADDRESS: string, + VHP_ADDRESS: string, + POB_ADDRESS: string, + CLAIM_ADDRESS: string, + GOVERNANCE_ADDRESS: string, + NAMESERVICE_ADDRESS: string, + RESOURCES_ADDRESS: string, + KAP_ADDRESS: string, + NICKNAMES_ADDRESS: string + } + } +} + export type Config = { jsonRPC: string systemContracts: Record @@ -5,18 +22,18 @@ export type Config = { } export const config: Config = { - jsonRPC: 'http://localhost:8080/', + jsonRPC: process.env.JSONRPC_URL || 'http://localhost:8080/', systemContracts: { - koin: '15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL', - vhp: '18tWNU7E4yuQzz7hMVpceb9ixmaWLVyQsr', - pob: '159myq5YUhhoVWu3wsHKHiJYKPKGUrGiyv', - claim: '18zw3ZokdfHtudzaWAUnU4tUvKzKiJeN76', - governance: '19qj51eTbSFJYU7ZagudkpxPgNSzPMfdPX', - nameservice: '19WxDJ9Kcvx4VqQFkpwVmwVEy1hMuwXtQE', - resources: '1HGN9h47CzoFwU2bQZwe6BYoX4TM6pXc4b' + koin: process.env.KOIN_ADDRESS || '15DJN4a8SgrbGhhGksSBASiSYjGnMU8dGL', + vhp: process.env.VHP_ADDRESS || '18tWNU7E4yuQzz7hMVpceb9ixmaWLVyQsr', + pob: process.env.POB_ADDRESS || '159myq5YUhhoVWu3wsHKHiJYKPKGUrGiyv', + claim: process.env.CLAIM_ADDRESS || '18zw3ZokdfHtudzaWAUnU4tUvKzKiJeN76', + governance: process.env.GOVERNANCE_ADDRESS || '19qj51eTbSFJYU7ZagudkpxPgNSzPMfdPX', + nameservice: process.env.NAMESERVICE_ADDRESS || '19WxDJ9Kcvx4VqQFkpwVmwVEy1hMuwXtQE', + resources: process.env.RESOURCES_ADDRESS || '1HGN9h47CzoFwU2bQZwe6BYoX4TM6pXc4b' }, contracts: { - kap: '13tmzDmfqCsbYT26C4CmKxq86d33senqH3', - nicknames:'1KD9Es7LBBjA1FY3ViCgQJ7e6WH1ipKbhz' + kap: process.env.KAP_ADDRESS || '13tmzDmfqCsbYT26C4CmKxq86d33senqH3', + nicknames: process.env.NICKNAMES_ADDRESS || '1KD9Es7LBBjA1FY3ViCgQJ7e6WH1ipKbhz' } } diff --git a/utils/providers.ts b/utils/providers.ts index 9d44128..8c7485d 100644 --- a/utils/providers.ts +++ b/utils/providers.ts @@ -1,16 +1,6 @@ import { config } from '@/app.config' import { Provider } from 'koilib' -declare global { - namespace NodeJS { - interface ProcessEnv { - JSONRPC_URL: string; - } - } -} - export function getProvider() { - const xJsonRpc = process.env.JSONRPC_URL || config.jsonRPC - - return new Provider(xJsonRpc) + return new Provider(config.jsonRPC) }