This repository was archived by the owner on Jun 19, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +35
-7
lines changed
Expand file tree Collapse file tree 3 files changed +35
-7
lines changed Original file line number Diff line number Diff line change @@ -12,3 +12,11 @@ export interface IBot {
1212 message ( message : IMessage ) : void
1313 error ( error : Error ) : void
1414}
15+
16+ import conf from 'byteballcore/conf'
17+ import constants from 'byteballcore/constants'
18+ export interface IOption {
19+ testnet : boolean
20+ constants : typeof constants
21+ conf : typeof conf
22+ }
Original file line number Diff line number Diff line change @@ -2,25 +2,27 @@ import {EventEmitter} from 'events'
22import Typed from 'strict-event-emitter-types'
33
44import HWallet from './event-handler'
5- import { IBot } from './event-types'
5+ import { IBot , IOption } from './event-types'
6+ import setOption from './options'
67
78type EventType < T > = Typed < EventEmitter , T >
89
910// TODO: map to https://github.com/byteball/reddit-attestation/blob/master/index.js
1011
11- export default class Bot extends ( EventEmitter as { new ( ) : EventType < IBot > } ) {
12+ export class Bot extends ( EventEmitter as { new ( ) : EventType < IBot > } ) {
13+ static get instance ( ) { return HWallet }
14+ static setOption = setOption
15+
1216 private _device ?: Device
1317 private _wallet ?: Wallet
1418
15- constructor ( ) {
19+ constructor ( option ?: Partial < IOption > ) {
1620 super ( )
17- // #region still doubting 🤔 do I need to simplify this? (and how!)
18- HWallet . started ( ( ) => { this . emit ( 'init' ) } )
19- HWallet . onAsking ( 'passphrase' , ( ) => { this . emit ( 'passphrase' ) } )
20- // #endregion
21+ if ( option ) Bot . setOption ( option )
2122 }
2223
2324 private async init ( ) {
25+ /// use of `await import` is for module thaat immediately run a service 😓
2426 this . _wallet = await import ( 'headless-byteball' )
2527 this . _device = await import ( 'byteballcore/device' )
2628 const eventBus = require ( 'byteballcore/event_bus' )
Original file line number Diff line number Diff line change 1+ import conf from 'byteballcore/conf'
2+ import constants from 'byteballcore/constants'
3+
4+ import { IOption } from './event-types'
5+
6+ export default function ( option : Partial < IOption > ) {
7+ if ( option . testnet ) {
8+ // #region @see https://github.com/byteball/bot-example/blob/master/testnetify.sh#L2
9+ constants . version = '1.0t'
10+ constants . alt = '2'
11+ // #endregion
12+ conf . hub = 'byteball.org/bb-test'
13+ conf . ports = 16611
14+ /// Anything else❓
15+ }
16+ Object . assign ( constants , option . constants )
17+ Object . assign ( conf , option . conf )
18+ }
You can’t perform that action at this time.
0 commit comments