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

Commit 78c20ae

Browse files
committed
revert(lib): bring back "must need conf.js"
♦️ 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
1 parent df02201 commit 78c20ae

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

src/options/index.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,39 @@ const filterEnum = ($enum: PlainObject<any>, blacklist: string[] = []) => Object
77
}, {}
88
)
99

10+
let _options: Partial<IOption>
11+
12+
export function getOption() {
13+
const {constants, conf, ...others} = _options
14+
Object.assign(constants, require('byteballcore/constants'))
15+
Object.assign(conf, require('byteballcore/conf'))
16+
return {...others, conf, constants}
17+
}
18+
1019
/**
1120
* This function do all necessary thing for merging the option
1221
* It make it possible to set `byteballcore/constants` and `bytballcore/conf` programatically
1322
*/
14-
export default function (option: Partial<IOption> = {}) {
23+
export function setOption(option: Partial<IOption> = {}) {
1524
if (!option.constants) option.constants = {}
25+
1626
if (!option.conf) option.conf = {}
27+
else throw new Error(`\`Bot.setOption({ conf: {} })\` not yet implemented (needs workaround)
28+
please consider using "conf.js" file 😉`)
1729

1830
// default conf regardless LIVENET or TESTNET
1931
option.conf = {
20-
bServeAsHub: false,
21-
bLight: true
32+
bLight: true,
33+
...option.conf
2234
}
2335

36+
// #region TODO: remove this if not buggy
37+
const {bLight, storage} = option.conf
38+
if (bLight && (!storage || storage === 'sqlite')) option.conf.database = {
39+
filename: 'byteball-light.sqlite', ...option.conf.database
40+
}
41+
// #endregion
42+
2443
const conf_keys = ['hub', 'port']
2544

2645
//#region begin merging option `conf` and `constants`
@@ -52,11 +71,16 @@ export default function (option: Partial<IOption> = {}) {
5271
...option.conf
5372
}
5473
}
74+
_options = option
5575
//#endregion
5676

5777
// don't place this 👇 on top because it immediately print something upon require() 😓
5878
Object.assign(require('byteballcore/constants'), option.constants)
59-
Object.assign(require('byteballcore/conf'), option.conf)
79+
80+
/// can't merge it maybe because of https://github.com/byteball/byteballcore/blame/cd764e9bd1edd00e93ee46c2e2ec029c6a52210b/conf.js#L73-L103
81+
/// or https://github.com/byteball/byteballcore/blame/cd764e9bd1edd00e93ee46c2e2ec029c6a52210b/conf.js#L3
82+
// Object.assign(require('byteballcore/conf'), option.conf) //👈🤔 TODO: need workaround
83+
6084
}
6185

6286
export * from './types'

src/options/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export enum TESTNET {
1717
attestedInDefinitionUpgradeMci = 616000,
1818
altBranchByBestParentUpgradeMci = 642000,
1919
//#endregion
20+
21+
//#region botbyte
22+
explorer = 'https://testnetexplorer.byteball.org/#',
23+
//#endregion
2024
}
2125

2226
export enum LIVENET {
@@ -36,14 +40,18 @@ export enum LIVENET {
3640
attestedInDefinitionUpgradeMci = spendUnconfirmedUpgradeMci,
3741
altBranchByBestParentUpgradeMci = 3009824,
3842
//#endregion
43+
44+
//#region botbyte
45+
explorer = 'https://explorer.byteball.org/#',
46+
//#endregion
3947
}
4048

4149
// #region Database config
4250
/**
4351
* @see https://github.com/byteball/byteballcore/blob/master/conf.js#L105-L116
4452
*/
4553
interface IDatabase {
46-
max_connections: number
54+
max_connections?: number
4755
}
4856

4957
interface IMySql extends IDatabase {

0 commit comments

Comments
 (0)