From 78c20ae68bcb25a887a89107b6bff2d3a27bc775 Mon Sep 17 00:00:00 2001 From: Fahmi Akbar Wildana Date: Wed, 9 Jan 2019 09:19:07 +0700 Subject: [PATCH] revert(lib): bring back "must need conf.js" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ♦️ seems changing `byteballcore/conf` at instantiation not possible 🔸 need to check if they are some `bytbeallcore/*` that read `conf.js` hardcoded, not via `byteballcore/conf` 🔹 potential solution: shim `byteballcore/conf` at compile time --- src/options/index.ts | 32 ++++++++++++++++++++++++++++---- src/options/types.ts | 10 +++++++++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/options/index.ts b/src/options/index.ts index f731d06..1da0038 100644 --- a/src/options/index.ts +++ b/src/options/index.ts @@ -7,20 +7,39 @@ const filterEnum = ($enum: PlainObject, blacklist: string[] = []) => Object }, {} ) +let _options: Partial + +export function getOption() { + const {constants, conf, ...others} = _options + Object.assign(constants, require('byteballcore/constants')) + Object.assign(conf, require('byteballcore/conf')) + return {...others, conf, constants} +} + /** * This function do all necessary thing for merging the option * It make it possible to set `byteballcore/constants` and `bytballcore/conf` programatically */ -export default function (option: Partial = {}) { +export function setOption(option: Partial = {}) { if (!option.constants) option.constants = {} + if (!option.conf) option.conf = {} + else throw new Error(`\`Bot.setOption({ conf: {} })\` not yet implemented (needs workaround) + please consider using "conf.js" file 😉`) // default conf regardless LIVENET or TESTNET option.conf = { - bServeAsHub: false, - bLight: true + bLight: true, + ...option.conf } + // #region TODO: remove this if not buggy + const {bLight, storage} = option.conf + if (bLight && (!storage || storage === 'sqlite')) option.conf.database = { + filename: 'byteball-light.sqlite', ...option.conf.database + } + // #endregion + const conf_keys = ['hub', 'port'] //#region begin merging option `conf` and `constants` @@ -52,11 +71,16 @@ export default function (option: Partial = {}) { ...option.conf } } + _options = option //#endregion // don't place this 👇 on top because it immediately print something upon require() 😓 Object.assign(require('byteballcore/constants'), option.constants) - Object.assign(require('byteballcore/conf'), option.conf) + + /// can't merge it maybe because of https://github.com/byteball/byteballcore/blame/cd764e9bd1edd00e93ee46c2e2ec029c6a52210b/conf.js#L73-L103 + /// or https://github.com/byteball/byteballcore/blame/cd764e9bd1edd00e93ee46c2e2ec029c6a52210b/conf.js#L3 + // Object.assign(require('byteballcore/conf'), option.conf) //👈🤔 TODO: need workaround + } export * from './types' diff --git a/src/options/types.ts b/src/options/types.ts index a6b1c97..117aaa0 100644 --- a/src/options/types.ts +++ b/src/options/types.ts @@ -17,6 +17,10 @@ export enum TESTNET { attestedInDefinitionUpgradeMci = 616000, altBranchByBestParentUpgradeMci = 642000, //#endregion + + //#region botbyte + explorer = 'https://testnetexplorer.byteball.org/#', + //#endregion } export enum LIVENET { @@ -36,6 +40,10 @@ export enum LIVENET { attestedInDefinitionUpgradeMci = spendUnconfirmedUpgradeMci, altBranchByBestParentUpgradeMci = 3009824, //#endregion + + //#region botbyte + explorer = 'https://explorer.byteball.org/#', + //#endregion } // #region Database config @@ -43,7 +51,7 @@ export enum LIVENET { * @see https://github.com/byteball/byteballcore/blob/master/conf.js#L105-L116 */ interface IDatabase { - max_connections: number + max_connections?: number } interface IMySql extends IDatabase {