cleanup
This commit is contained in:
parent
e9acc97bdc
commit
ce4f379a8b
10 changed files with 40 additions and 204 deletions
|
|
@ -15,6 +15,7 @@
|
|||
# The developer is used by default or you may specify your own
|
||||
# To disable this feature entirely overwrite the env with "null"
|
||||
#LIQUIDITY_PROVIDER_PUB=null
|
||||
#DISABLE_LIQUIDITY_PROVIDER=false
|
||||
|
||||
#DB
|
||||
#DATABASE_FILE=db.sqlite
|
||||
|
|
|
|||
|
|
@ -54,10 +54,4 @@ export const chooseEnvInt = (key: string, dbEnv: Record<string, string | undefin
|
|||
export const chooseEnvBool = (key: string, dbEnv: Record<string, string | undefined>, defaultValue: boolean, addToDb?: EnvCacher): boolean => {
|
||||
const v = chooseEnv(key, dbEnv, defaultValue.toString(), addToDb)
|
||||
return v.toLowerCase() === 'true'
|
||||
}
|
||||
|
||||
export type StringSetting = { t: 'string', v?: string, defaultValue: string }
|
||||
export type NumberSetting = { t: 'number', v?: number, defaultValue: number }
|
||||
export type BooleanSetting = { t: 'boolean', v?: boolean, defaultValue: boolean }
|
||||
export type EnvSetting = StringSetting | NumberSetting | BooleanSetting
|
||||
export type SettingsJson = Record<string, Record<string, EnvSetting>>
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ export default class {
|
|||
outgoingOpsLocked = false
|
||||
liquidProvider: LiquidityProvider
|
||||
utils: Utils
|
||||
constructor(getSettings: () => { lndSettings: LndSettings, lndNodeSettings: LndNodeSettings }, liquidProvider: LiquidityProvider, utils: Utils, addressPaidCb: AddressPaidCb, invoicePaidCb: InvoicePaidCb, newBlockCb: NewBlockCb, htlcCb: HtlcCb, channelEventCb: ChannelEventCb, nodeToUse?: "other" | "third" | "fourth") {
|
||||
constructor(getSettings: () => { lndSettings: LndSettings, lndNodeSettings: LndNodeSettings }, liquidProvider: LiquidityProvider, utils: Utils, addressPaidCb: AddressPaidCb, invoicePaidCb: InvoicePaidCb, newBlockCb: NewBlockCb, htlcCb: HtlcCb, channelEventCb: ChannelEventCb) {
|
||||
this.getSettings = getSettings
|
||||
this.utils = utils
|
||||
this.addressPaidCb = addressPaidCb
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import fs, { watchFile } from "fs";
|
||||
import crypto from 'crypto'
|
||||
import { ERROR, getLogger } from "../helpers/logger.js";
|
||||
import { getDataPath } from "./settings.js";
|
||||
import Storage from "../storage/index.js";
|
||||
import * as Types from '../../../proto/autogenerated/ts/types.js'
|
||||
import LND from "../lnd/lnd.js";
|
||||
|
|
@ -254,4 +253,8 @@ export class AdminManager {
|
|||
closing_txid: Buffer.from(res.txid).toString('hex')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getDataPath = (dataDir: string, dataPath: string) => {
|
||||
return dataDir !== "" ? `${dataDir}/${dataPath}` : dataPath
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ export const initMainHandler = async (log: PubLogger, settingsManager: SettingsM
|
|||
return mainHandler.storage.applicationStorage.GenerateApplicationKeys(app);
|
||||
} // --
|
||||
else {
|
||||
return { privateKey: app.nostr_private_key, publicKey: app.nostr_public_key, appId: app.app_id, name: app.name, avatarUrl: app.avatar_url }
|
||||
return { privateKey: app.nostr_private_key, publicKey: app.nostr_public_key, appId: app.app_id, name: app.name }
|
||||
}
|
||||
}))
|
||||
const liquidityProviderApp = apps.find(app => defaultNames.includes(app.name))
|
||||
|
|
@ -80,7 +80,7 @@ export const initMainHandler = async (log: PubLogger, settingsManager: SettingsM
|
|||
await mainHandler.appUserManager.CleanupInactiveUsers()
|
||||
await mainHandler.appUserManager.CleanupNeverActiveUsers()
|
||||
await mainHandler.paymentManager.watchDog.Start()
|
||||
return { mainHandler, apps, liquidityProviderInfo, liquidityProviderApp, wizard, adminManager, settingsManager }
|
||||
return { mainHandler, apps, liquidityProviderInfo, liquidityProviderApp, wizard, adminManager }
|
||||
}
|
||||
|
||||
const processArgs = async (mainHandler: Main) => {
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@ import os from 'os'
|
|||
import path from 'path'
|
||||
|
||||
export type ServiceFeeSettings = {
|
||||
incomingTxFee: number // Hot
|
||||
outgoingTxFee: number // Hot
|
||||
incomingAppInvoiceFee: number // Hot
|
||||
incomingAppUserInvoiceFee: number // Hot
|
||||
outgoingAppInvoiceFee: number // Hot
|
||||
outgoingAppUserInvoiceFee: number // Hot
|
||||
outgoingAppUserInvoiceFeeBps: number // Hot
|
||||
userToUserFee: number // Hot
|
||||
appToUserFee: number // Hot
|
||||
incomingTxFee: number
|
||||
outgoingTxFee: number
|
||||
incomingAppInvoiceFee: number
|
||||
incomingAppUserInvoiceFee: number
|
||||
outgoingAppInvoiceFee: number
|
||||
outgoingAppUserInvoiceFee: number
|
||||
outgoingAppUserInvoiceFeeBps: number
|
||||
userToUserFee: number
|
||||
appToUserFee: number
|
||||
}
|
||||
|
||||
export const LoadServiceFeeSettingsFromEnv = (dbEnv: Record<string, string | undefined>, addToDb?: EnvCacher): ServiceFeeSettings => {
|
||||
|
|
@ -30,19 +30,19 @@ export const LoadServiceFeeSettingsFromEnv = (dbEnv: Record<string, string | und
|
|||
}
|
||||
|
||||
export type ServiceSettings = {
|
||||
servicePort: number // Cold
|
||||
recordPerformance: boolean // Cold
|
||||
skipSanityCheck: boolean // Cold
|
||||
wizard: boolean // Cold
|
||||
bridgeUrl: string, // Cold
|
||||
shockPushBaseUrl: string // Cold
|
||||
servicePort: number
|
||||
recordPerformance: boolean
|
||||
skipSanityCheck: boolean
|
||||
wizard: boolean
|
||||
bridgeUrl: string,
|
||||
shockPushBaseUrl: string
|
||||
|
||||
serviceUrl: string // Hot
|
||||
disableExternalPayments: boolean // Hot
|
||||
defaultAppName: string // Hot
|
||||
pushBackupsToNostr: boolean // Hot
|
||||
lnurlMetaText: string, // Hot
|
||||
allowHttpUpgrade: boolean // Hot
|
||||
serviceUrl: string
|
||||
disableExternalPayments: boolean
|
||||
defaultAppName: string
|
||||
pushBackupsToNostr: boolean
|
||||
lnurlMetaText: string,
|
||||
allowHttpUpgrade: boolean
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -119,10 +119,6 @@ export type NostrRelaySettings = {
|
|||
maxEventContentLength: number
|
||||
}
|
||||
|
||||
const getEnvOrDefault = (name: string, defaultValue: string): string => {
|
||||
return process.env[name] || defaultValue;
|
||||
}
|
||||
|
||||
export const LoadNosrtRelaySettingsFromEnv = (dbEnv: Record<string, string | undefined>, addToDb?: EnvCacher): NostrRelaySettings => {
|
||||
const relaysEnv = chooseEnv("NOSTR_RELAYS", dbEnv, "wss://relay.lightning.pub", addToDb);
|
||||
const maxEventContentLength = chooseEnvInt("NOSTR_MAX_EVENT_CONTENT_LENGTH", dbEnv, 40000, addToDb)
|
||||
|
|
@ -208,46 +204,3 @@ export const LoadBitcoinCoreSettingsFromEnv = (): BitcoinCoreSettings => {
|
|||
pass: EnvMustBeNonEmptyString("BITCOIN_CORE_PASS")
|
||||
}
|
||||
}
|
||||
|
||||
/* export const LoadTestSettingsFromEnv = (): TestSettings => {
|
||||
|
||||
const settings = LoadMainSettingsFromEnv()
|
||||
return {
|
||||
...settings,
|
||||
storageSettings: GetTestStorageSettings(settings.storageSettings),
|
||||
lndSettings: {
|
||||
...settings.lndSettings,
|
||||
otherNode: {
|
||||
lndAddr: EnvMustBeNonEmptyString("LND_OTHER_ADDR"),
|
||||
lndCertPath: EnvMustBeNonEmptyString("LND_OTHER_CERT_PATH"),
|
||||
lndMacaroonPath: EnvMustBeNonEmptyString("LND_OTHER_MACAROON_PATH")
|
||||
},
|
||||
thirdNode: {
|
||||
lndAddr: EnvMustBeNonEmptyString("LND_THIRD_ADDR"),
|
||||
lndCertPath: EnvMustBeNonEmptyString("LND_THIRD_CERT_PATH"),
|
||||
lndMacaroonPath: EnvMustBeNonEmptyString("LND_THIRD_MACAROON_PATH")
|
||||
},
|
||||
fourthNode: {
|
||||
lndAddr: EnvMustBeNonEmptyString("LND_FOURTH_ADDR"),
|
||||
lndCertPath: EnvMustBeNonEmptyString("LND_FOURTH_CERT_PATH"),
|
||||
lndMacaroonPath: EnvMustBeNonEmptyString("LND_FOURTH_MACAROON_PATH")
|
||||
},
|
||||
},
|
||||
liquiditySettings: {
|
||||
...settings.liquiditySettings,
|
||||
liquidityProviderPub: "",
|
||||
},
|
||||
skipSanityCheck: true,
|
||||
bitcoinCoreSettings: {
|
||||
port: EnvMustBeInteger("BITCOIN_CORE_PORT"),
|
||||
user: EnvMustBeNonEmptyString("BITCOIN_CORE_USER"),
|
||||
pass: EnvMustBeNonEmptyString("BITCOIN_CORE_PASS")
|
||||
},
|
||||
}
|
||||
} */
|
||||
|
||||
|
||||
|
||||
export const getDataPath = (dataDir: string, dataPath: string) => {
|
||||
return dataDir !== "" ? `${dataDir}/${dataPath}` : dataPath
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
import Storage, { StorageSettings } from "../storage/index.js"
|
||||
import { EnvCacher, EnvSetting, SettingsJson, StringSetting } from "../helpers/envParser.js"
|
||||
import { EnvCacher } from "../helpers/envParser.js"
|
||||
import { getLogger, PubLogger } from "../helpers/logger.js"
|
||||
import {
|
||||
BitcoinCoreSettings, LiquiditySettings, LndNodeSettings, LndSettings, LoadBitcoinCoreSettingsFromEnv,
|
||||
LoadFourthLndSettingsFromEnv, LoadLiquiditySettingsFromEnv, LoadSecondLndSettingsFromEnv, LoadThirdLndSettingsFromEnv,
|
||||
LiquiditySettings, LndNodeSettings, LndSettings, LoadLiquiditySettingsFromEnv,
|
||||
LoadLSPSettingsFromEnv, LSPSettings, ServiceFeeSettings, ServiceSettings, LoadServiceFeeSettingsFromEnv,
|
||||
LoadNosrtRelaySettingsFromEnv, LoadServiceSettingsFromEnv, LoadWatchdogSettingsFromEnv
|
||||
LoadNosrtRelaySettingsFromEnv, LoadServiceSettingsFromEnv, LoadWatchdogSettingsFromEnv,
|
||||
LoadLndNodeSettingsFromEnv, LoadLndSettingsFromEnv, NostrRelaySettings, WatchdogSettings
|
||||
} from "./settings.js"
|
||||
import { LoadLndNodeSettingsFromEnv, LoadLndSettingsFromEnv, NostrRelaySettings, WatchdogSettings } from "./settings.js"
|
||||
export default class SettingsManager {
|
||||
storage: Storage
|
||||
private settings: FullSettings | null = null
|
||||
//private testSettings: TestSettings | null = null
|
||||
|
||||
log: PubLogger
|
||||
constructor(storage: Storage) {
|
||||
|
|
@ -39,18 +37,6 @@ export default class SettingsManager {
|
|||
this.settings = f(this.settings)
|
||||
}
|
||||
|
||||
/* async InitTestSettings(): Promise<void> {
|
||||
await this.InitSettings()
|
||||
await this.updateSkipSanityCheck(true)
|
||||
await this.updateDisableLiquidityProvider(true)
|
||||
this.testSettings = {
|
||||
secondLndSettings: LoadSecondLndSettingsFromEnv(),
|
||||
thirdLndSettings: LoadThirdLndSettingsFromEnv(),
|
||||
fourthLndSettings: LoadFourthLndSettingsFromEnv(),
|
||||
bitcoinCoreSettings: LoadBitcoinCoreSettingsFromEnv(),
|
||||
}
|
||||
} */
|
||||
|
||||
async InitSettings(): Promise<FullSettings> {
|
||||
const dbSettings = await this.storage.settingsStorage.getAllDbEnvs()
|
||||
const toAdd: Record<string, string> = {}
|
||||
|
|
@ -58,6 +44,7 @@ export default class SettingsManager {
|
|||
toAdd[key] = value
|
||||
}
|
||||
this.settings = this.loadEnvs(dbSettings, addToDb)
|
||||
this.log("adding", toAdd.length, "settings to db")
|
||||
for (const key in toAdd) {
|
||||
await this.storage.settingsStorage.setDbEnvIFNeeded(key, toAdd[key])
|
||||
}
|
||||
|
|
@ -75,13 +62,6 @@ export default class SettingsManager {
|
|||
return this.settings
|
||||
}
|
||||
|
||||
/* getTestSettings(): TestSettings {
|
||||
if (!this.testSettings) {
|
||||
throw new Error("Test settings not initialized")
|
||||
}
|
||||
return this.testSettings
|
||||
} */
|
||||
|
||||
async updateDefaultAppName(name: string): Promise<boolean> {
|
||||
if (!this.settings) {
|
||||
throw new Error("Settings not initialized")
|
||||
|
|
@ -164,16 +144,9 @@ type FullSettings = {
|
|||
lndNodeSettings: LndNodeSettings
|
||||
lndSettings: LndSettings
|
||||
liquiditySettings: LiquiditySettings
|
||||
watchDogSettings: WatchdogSettings, // Hot
|
||||
nostrRelaySettings: NostrRelaySettings, // Hot
|
||||
serviceFeeSettings: ServiceFeeSettings, // Hot
|
||||
serviceSettings: ServiceSettings, // Hot
|
||||
watchDogSettings: WatchdogSettings,
|
||||
nostrRelaySettings: NostrRelaySettings,
|
||||
serviceFeeSettings: ServiceFeeSettings,
|
||||
serviceSettings: ServiceSettings,
|
||||
lspSettings: LSPSettings
|
||||
}
|
||||
|
||||
/* type TestSettings = {
|
||||
secondLndSettings: LndNodeSettings
|
||||
thirdLndSettings: LndNodeSettings
|
||||
fourthLndSettings: LndNodeSettings
|
||||
bitcoinCoreSettings: BitcoinCoreSettings
|
||||
} */
|
||||
}
|
||||
|
|
@ -207,37 +207,6 @@ export default class Handler {
|
|||
}
|
||||
}
|
||||
|
||||
/* async Connect() {
|
||||
const log = getLogger({})
|
||||
log("conneting to relay...", this.settings.relays[0])
|
||||
let relay: Relay | null = null
|
||||
//const relay = relayInit(this.settings.relays[0]) // TODO: create multiple conns for multiple relays
|
||||
try {
|
||||
relay = await Relay.connect(this.settings.relays[0])
|
||||
if (!relay.connected) {
|
||||
throw new Error("failed to connect to relay")
|
||||
}
|
||||
} catch (err:any) {
|
||||
log("failed to connect to relay, will try again in 2 seconds", err.message || err)
|
||||
setTimeout(() => {
|
||||
this.Connect()
|
||||
}, 2000)
|
||||
return
|
||||
}
|
||||
|
||||
log("connected, subbing...")
|
||||
relay.onclose = (() => {
|
||||
log("relay disconnected, will try to reconnect in 2 seconds")
|
||||
relay.close()
|
||||
setTimeout(() => {
|
||||
this.Connect()
|
||||
}, 2000)
|
||||
})
|
||||
|
||||
this.Subscribe(relay)
|
||||
|
||||
} */
|
||||
|
||||
Subscribe(relay: Relay) {
|
||||
const appIds = Object.keys(this.apps)
|
||||
this.log("🔍 [NOSTR SUBSCRIPTION] Setting up subscription", {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import { EnvSetting, SettingsJson } from "../helpers/envParser.js";
|
||||
import { StorageInterface } from "./db/storageInterface.js";
|
||||
import { AdminSettings } from "./entity/AdminSettings.js";
|
||||
export default class SettingsStorage {
|
||||
|
|
|
|||
|
|
@ -187,13 +187,6 @@ export class Wizard {
|
|||
return
|
||||
}
|
||||
|
||||
async updateConfigs(pendingConfig: WizardSettings): Promise<void> {
|
||||
await this.settings.updateDefaultAppName(pendingConfig.sourceName)
|
||||
await this.settings.updateRelayUrl(pendingConfig.relayUrl)
|
||||
await this.settings.updateDisableLiquidityProvider(pendingConfig.automateLiquidity)
|
||||
await this.settings.updatePushBackupsToNostr(pendingConfig.pushBackupsToNostr)
|
||||
}
|
||||
|
||||
updateDefaultApp = async (currentName: string, avatarUrl?: string): Promise<void> => {
|
||||
const newName = this.settings.getSettings().serviceSettings.defaultAppName
|
||||
try {
|
||||
|
|
@ -207,53 +200,4 @@ export class Wizard {
|
|||
this.log(`Error updating app info: ${(e as Error).message}`)
|
||||
}
|
||||
}
|
||||
/*
|
||||
updateEnvFile = (pendingConfig: WizardSettings) => {
|
||||
let envFileContent: string[] = []
|
||||
try {
|
||||
envFileContent = fs.readFileSync('.env', 'utf-8').split('\n')
|
||||
} catch (err: any) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
const toMerge: string[] = []
|
||||
const sourceNameIndex = envFileContent.findIndex(line => line.startsWith('DEFAULT_APP_NAME'))
|
||||
if (sourceNameIndex === -1) {
|
||||
toMerge.push(`DEFAULT_APP_NAME=${pendingConfig.sourceName}`)
|
||||
} else {
|
||||
envFileContent[sourceNameIndex] = `DEFAULT_APP_NAME=${pendingConfig.sourceName}`
|
||||
}
|
||||
|
||||
const relayUrlIndex = envFileContent.findIndex(line => line.startsWith('RELAY_URL'))
|
||||
if (relayUrlIndex === -1) {
|
||||
toMerge.push(`RELAY_URL=${pendingConfig.relayUrl}`)
|
||||
} else {
|
||||
envFileContent[relayUrlIndex] = `RELAY_URL=${pendingConfig.relayUrl}`
|
||||
}
|
||||
|
||||
const automateLiquidityIndex = envFileContent.findIndex(line => line.startsWith('LIQUIDITY_PROVIDER_PUB'))
|
||||
if (pendingConfig.automateLiquidity) {
|
||||
if (automateLiquidityIndex !== -1) {
|
||||
envFileContent.splice(automateLiquidityIndex, 1)
|
||||
}
|
||||
} else {
|
||||
if (automateLiquidityIndex === -1) {
|
||||
toMerge.push(`LIQUIDITY_PROVIDER_PUB=null`)
|
||||
} else {
|
||||
envFileContent[automateLiquidityIndex] = `LIQUIDITY_PROVIDER_PUB=null`
|
||||
}
|
||||
}
|
||||
|
||||
const pushBackupsToNostrIndex = envFileContent.findIndex(line => line.startsWith('PUSH_BACKUPS_TO_NOSTR'))
|
||||
if (pushBackupsToNostrIndex === -1) {
|
||||
toMerge.push(`PUSH_BACKUPS_TO_NOSTR=${pendingConfig.pushBackupsToNostr ? 'true' : 'false'}`)
|
||||
} else {
|
||||
envFileContent[pushBackupsToNostrIndex] = `PUSH_BACKUPS_TO_NOSTR=${pendingConfig.pushBackupsToNostr ? 'true' : 'false'}`
|
||||
}
|
||||
const merged = [...envFileContent, ...toMerge].join('\n')
|
||||
fs.writeFileSync('.env', merged)
|
||||
loadEnvFile()
|
||||
} */
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue