@@ -5,7 +5,8 @@ import LockUtils from 'models/lock-utils'
55import logger from 'utils/logger'
66import genesisBlockHash , { getChain } from './genesis'
77import ChainInfo from 'models/chain-info'
8- import DaoUtils from '../../models/dao-utils' ;
8+ import DaoUtils from '../../models/dao-utils'
9+ import { NetworkWithID , EMPTY_GENESIS_HASH } from 'types/network'
910
1011// only used by main process
1112export class InitDatabase {
@@ -19,9 +20,7 @@ export class InitDatabase {
1920 }
2021
2122 private stopped : boolean = false
22- // private nodeURL: string
2323 private inProcess : boolean = false
24-
2524 private success : boolean = false
2625
2726 public id : number = + new Date ( )
@@ -30,25 +29,29 @@ export class InitDatabase {
3029
3130 private killed : boolean = false
3231
33- public init = async ( url : string ) => {
32+ public init = async ( network : NetworkWithID ) => {
3433 if ( InitDatabase . previous ) {
3534 await InitDatabase . previous . stopAndWait ( )
3635 }
3736
3837 this . inProcess = true
3938
40- let hash : string | undefined
41- let chain : string | undefined
39+ let hash : string = network . genesisHash
40+ let chain : string = network . chain
4241 while ( ! this . stopped && ! this . success ) {
4342 try {
44- hash = await genesisBlockHash ( url )
43+ if ( hash === EMPTY_GENESIS_HASH ) {
44+ hash = await genesisBlockHash ( network . remote )
45+ }
4546 await initConnection ( hash )
46- chain = await getChain ( url )
47+ if ( chain === '' ) {
48+ chain = await getChain ( network . remote )
49+ }
4750 ChainInfo . getInstance ( ) . setChain ( chain )
4851
4952 try {
50- const systemScriptInfo = await LockUtils . systemScript ( url )
51- const daoScriptInfo = await DaoUtils . daoScript ( url )
53+ const systemScriptInfo = await LockUtils . systemScript ( network . remote )
54+ const daoScriptInfo = await DaoUtils . daoScript ( network . remote )
5255 updateMetaInfo ( { genesisBlockHash : hash , systemScriptInfo, chain, daoScriptInfo } )
5356 } catch ( err ) {
5457 logger . error ( 'update systemScriptInfo failed:' , err )
0 commit comments