Skip to content
This repository has been archived by the owner on Jun 19, 2021. It is now read-only.

Commit

Permalink
revert(lib): bring back "must need conf.js"
Browse files Browse the repository at this point in the history
♦️ 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
  • Loading branch information
DrSensor committed Jan 9, 2019
1 parent df02201 commit 78c20ae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
32 changes: 28 additions & 4 deletions src/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,39 @@ const filterEnum = ($enum: PlainObject<any>, blacklist: string[] = []) => Object
}, {}
)

let _options: Partial<IOption>

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<IOption> = {}) {
export function setOption(option: Partial<IOption> = {}) {
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`
Expand Down Expand Up @@ -52,11 +71,16 @@ export default function (option: Partial<IOption> = {}) {
...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'
10 changes: 9 additions & 1 deletion src/options/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export enum TESTNET {
attestedInDefinitionUpgradeMci = 616000,
altBranchByBestParentUpgradeMci = 642000,
//#endregion

//#region botbyte
explorer = 'https://testnetexplorer.byteball.org/#',
//#endregion
}

export enum LIVENET {
Expand All @@ -36,14 +40,18 @@ export enum LIVENET {
attestedInDefinitionUpgradeMci = spendUnconfirmedUpgradeMci,
altBranchByBestParentUpgradeMci = 3009824,
//#endregion

//#region botbyte
explorer = 'https://explorer.byteball.org/#',
//#endregion
}

// #region Database config
/**
* @see https://github.com/byteball/byteballcore/blob/master/conf.js#L105-L116
*/
interface IDatabase {
max_connections: number
max_connections?: number
}

interface IMySql extends IDatabase {
Expand Down

0 comments on commit 78c20ae

Please sign in to comment.