@@ -16,82 +16,85 @@ export default function (provider: EthereumProvider, cliSettings: CliSettings) {
16
16
const liveOptions = provider . getOptions ( ) ;
17
17
const accounts = provider . getInitialAccounts ( ) ;
18
18
19
- const addresses = Object . keys ( accounts ) ;
20
- const logs = [ ] ;
21
- logs . push ( "" ) ;
22
- logs . push ( "Available Accounts" ) ;
23
- logs . push ( "==================" ) ;
19
+ const addresses = Object . entries ( accounts ) ;
20
+ let log = "\n" ;
21
+ const appendLog = line => ( log += line + "\n" ) ;
22
+
23
+ appendLog ( "Available Accounts" ) ;
24
+ appendLog ( "==================" ) ;
24
25
if ( addresses . length > 0 ) {
25
- addresses . forEach ( function ( address , index ) {
26
- const balance = accounts [ address ] . balance ;
26
+ let index = 0 ;
27
+ for ( const [ address , account ] of addresses ) {
28
+ const balance = account . balance ;
27
29
const strBalance = balance / WEI ;
28
30
const about = balance % WEI === 0n ? "" : "~" ;
29
- let line = `(${ index } ) ${ toChecksumAddress (
31
+ let line = `(${ index ++ } ) ${ toChecksumAddress (
30
32
address
31
33
) } (${ about } ${ strBalance } ETH)`;
32
34
33
- if ( ! accounts [ address ] . unlocked ) {
35
+ if ( ! account . unlocked ) {
34
36
line += " 🔒" ;
35
37
}
36
38
37
- logs . push ( line ) ;
38
- } ) ;
39
+ appendLog ( line ) ;
40
+ }
39
41
40
- logs . push ( "" ) ;
41
- logs . push ( "Private Keys" ) ;
42
- logs . push ( "==================" ) ;
42
+ appendLog ( "" ) ;
43
+ appendLog ( "Private Keys" ) ;
44
+ appendLog ( "==================" ) ;
43
45
44
- addresses . forEach ( function ( address , index ) {
45
- logs . push ( `(${ index } ) ${ accounts [ address ] . secretKey } ` ) ;
46
- } ) ;
46
+ index = 0 ;
47
+ for ( const [ address , account ] of addresses ) {
48
+ appendLog ( `(${ index ++ } ) ${ account . secretKey } ` ) ;
49
+ }
47
50
48
51
if ( liveOptions . wallet . accountKeysPath != null ) {
49
- logs . push ( "" ) ;
50
- logs . push (
52
+ appendLog ( "" ) ;
53
+ appendLog (
51
54
`Accounts and keys saved to ${ liveOptions . wallet . accountKeysPath } `
52
55
) ;
53
56
}
54
57
} else {
55
- logs . push ( "(no accounts unlocked)" ) ;
58
+ appendLog ( "(no accounts unlocked)" ) ;
56
59
}
57
60
58
61
if ( liveOptions . wallet . accounts == null ) {
59
- logs . push ( "" ) ;
60
- logs . push ( "HD Wallet" ) ;
61
- logs . push ( "==================" ) ;
62
- logs . push ( `Mnemonic: ${ color ( liveOptions . wallet . mnemonic ) } ` ) ;
63
- logs . push (
62
+ appendLog ( "" ) ;
63
+ appendLog ( "HD Wallet" ) ;
64
+ appendLog ( "==================" ) ;
65
+ appendLog ( `Mnemonic: ${ color ( liveOptions . wallet . mnemonic ) } ` ) ;
66
+ appendLog (
64
67
`Base HD Path: ${ color (
65
68
liveOptions . wallet . hdPath . join ( "/" ) + "/{account_index}"
66
69
) } `
67
70
) ;
68
71
}
69
72
70
73
if ( liveOptions . miner . defaultGasPrice ) {
71
- logs . push ( "" ) ;
72
- logs . push ( "Default Gas Price" ) ;
73
- logs . push ( "==================" ) ;
74
- logs . push ( color ( liveOptions . miner . defaultGasPrice . toBigInt ( ) . toString ( ) ) ) ;
74
+ appendLog ( "" ) ;
75
+ appendLog ( "Default Gas Price" ) ;
76
+ appendLog ( "==================" ) ;
77
+ appendLog ( color ( liveOptions . miner . defaultGasPrice . toBigInt ( ) . toString ( ) ) ) ;
75
78
}
76
79
77
80
if ( liveOptions . miner . blockGasLimit ) {
78
- logs . push ( "" ) ;
79
- logs . push ( "BlockGas Limit" ) ;
80
- logs . push ( "==================" ) ;
81
- logs . push ( color ( liveOptions . miner . blockGasLimit . toBigInt ( ) . toString ( ) ) ) ;
81
+ appendLog ( "" ) ;
82
+ appendLog ( "BlockGas Limit" ) ;
83
+ appendLog ( "==================" ) ;
84
+ appendLog ( color ( liveOptions . miner . blockGasLimit . toBigInt ( ) . toString ( ) ) ) ;
82
85
}
83
86
84
87
if ( liveOptions . miner . callGasLimit ) {
85
- logs . push ( "" ) ;
86
- logs . push ( "Call Gas Limit" ) ;
87
- logs . push ( "==================" ) ;
88
- logs . push ( color ( liveOptions . miner . callGasLimit . toBigInt ( ) . toString ( ) ) ) ;
88
+ appendLog ( "" ) ;
89
+ appendLog ( "Call Gas Limit" ) ;
90
+ appendLog ( "==================" ) ;
91
+ appendLog ( color ( liveOptions . miner . callGasLimit . toBigInt ( ) . toString ( ) ) ) ;
89
92
}
90
93
91
94
if ( liveOptions . fork . network || liveOptions . fork . url ) {
92
- logs . push ( "" ) ;
93
- logs . push ( "Forked Chain" ) ;
94
- logs . push ( "==================" ) ;
95
+ appendLog ( "" ) ;
96
+ appendLog ( "Forked Chain" ) ;
97
+ appendLog ( "==================" ) ;
95
98
let location : string ;
96
99
if ( liveOptions . fork . network ) {
97
100
location = `Ethereum ${ capitalizeFirstLetter (
@@ -101,31 +104,31 @@ export default function (provider: EthereumProvider, cliSettings: CliSettings) {
101
104
location = ( liveOptions . fork . url as any ) . toString ( ) ;
102
105
}
103
106
104
- logs . push ( `Location: ${ color ( location ) } ` ) ;
105
- logs . push (
107
+ appendLog ( `Location: ${ color ( location ) } ` ) ;
108
+ appendLog (
106
109
`Block: ${ color ( liveOptions . fork . blockNumber . toString ( ) ) } `
107
110
) ;
108
- logs . push (
111
+ appendLog (
109
112
`Network ID: ${ color ( liveOptions . chain . networkId . toString ( ) ) } `
110
113
) ;
111
- logs . push ( `Time: ${ color ( liveOptions . chain . time . toString ( ) ) } ` ) ;
114
+ appendLog ( `Time: ${ color ( liveOptions . chain . time . toString ( ) ) } ` ) ;
112
115
113
116
if ( liveOptions . fork . requestsPerSecond !== 0 ) {
114
- logs . push (
117
+ appendLog (
115
118
`Requests/Second: ${ color (
116
119
liveOptions . fork . requestsPerSecond . toString ( )
117
120
) } `
118
121
) ;
119
122
}
120
123
}
121
124
122
- logs . push ( "" ) ;
123
- logs . push ( "Chain" ) ;
124
- logs . push ( "==================" ) ;
125
- logs . push ( `Hardfork: ${ color ( liveOptions . chain . hardfork ) } ` ) ;
126
- logs . push ( `Id: ${ color ( liveOptions . chain . chainId . toString ( ) ) } ` ) ;
125
+ appendLog ( "" ) ;
126
+ appendLog ( "Chain" ) ;
127
+ appendLog ( "==================" ) ;
128
+ appendLog ( `Hardfork: ${ color ( liveOptions . chain . hardfork ) } ` ) ;
129
+ appendLog ( `Id: ${ color ( liveOptions . chain . chainId . toString ( ) ) } ` ) ;
127
130
128
- logs . push ( "" ) ;
129
- logs . push ( "RPC Listening on " + cliSettings . host + ":" + cliSettings . port ) ;
130
- console . log ( logs . join ( "\n" ) ) ;
131
+ appendLog ( "" ) ;
132
+ appendLog ( "RPC Listening on " + cliSettings . host + ":" + cliSettings . port ) ;
133
+ console . log ( log ) ;
131
134
}
0 commit comments