-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathconfig.js
More file actions
256 lines (209 loc) · 8.98 KB
/
Copy pathconfig.js
File metadata and controls
256 lines (209 loc) · 8.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
"use strict";
const debug = require("debug");
const debugLog = debug("btcexp:config");
const fs = require('fs');
const crypto = require('crypto');
const url = require('url');
const path = require('path');
let baseUrl = (process.env.BTCEXP_BASEURL || "/").trim();
if (!baseUrl.startsWith("/")) {
baseUrl = "/" + baseUrl;
}
if (!baseUrl.endsWith("/")) {
baseUrl += "/";
}
const coins = require("./coins.js");
const credentials = require("./credentials.js");
const currentCoin = process.env.BTCEXP_COIN || "BTC";
const rpcCred = credentials.rpc;
if (rpcCred.cookie && !rpcCred.username && !rpcCred.password && fs.existsSync(rpcCred.cookie)) {
console.log(`Loading RPC cookie file: ${rpcCred.cookie}`);
[ rpcCred.username, rpcCred.password ] = fs.readFileSync(rpcCred.cookie).toString().split(':', 2);
if (!rpcCred.password) {
throw new Error(`Cookie file ${rpcCred.cookie} in unexpected format`);
}
}
const cookieSecret = process.env.BTCEXP_COOKIE_SECRET
|| (rpcCred.password && crypto.createHmac('sha256', JSON.stringify(rpcCred))
.update('btc-rpc-explorer-cookie-secret').digest('hex'))
|| "0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f";
const electrumServerUriStrings = (process.env.BTCEXP_ELECTRUM_SERVERS || process.env.BTCEXP_ELECTRUMX_SERVERS || "").split(',').filter(Boolean);
const electrumServers = [];
for (let i = 0; i < electrumServerUriStrings.length; i++) {
const uri = url.parse(electrumServerUriStrings[i]);
electrumServers.push({protocol:uri.protocol.substring(0, uri.protocol.length - 1), host:uri.hostname, port:parseInt(uri.port)});
}
// default=false env vars
[
"BTCEXP_DEMO",
"BTCEXP_PRIVACY_MODE",
"BTCEXP_NO_INMEMORY_RPC_CACHE",
"BTCEXP_RPC_ALLOWALL",
"BTCEXP_ELECTRUM_TXINDEX",
"BTCEXP_UI_HIDE_INFO_NOTES",
].forEach(function(item) {
if (process.env[item] === undefined) {
process.env[item] = "false";
debugLog(`Config(default): ${item}=false`)
}
});
// default=true env vars
[
"BTCEXP_NO_RATES",
"BTCEXP_SLOW_DEVICE_MODE"
].forEach(function(item) {
if (process.env[item] === undefined) {
process.env[item] = "true";
debugLog(`Config(default): ${item}=true`)
}
});
const slowDeviceMode = (process.env.BTCEXP_SLOW_DEVICE_MODE.toLowerCase() == "true");
module.exports = {
host: process.env.BTCEXP_HOST || "127.0.0.1",
port: process.env.PORT || process.env.BTCEXP_PORT || 3002,
baseUrl: baseUrl,
coin: currentCoin,
displayDefaults: {
displayCurrency: (process.env.BTCEXP_DISPLAY_CURRENCY || "btc"),
localCurrency: (process.env.BTCEXP_LOCAL_CURRENCY || "usd"),
theme: (process.env.BTCEXP_UI_THEME || "dark"),
timezone: (process.env.BTCEXP_UI_TIMEZONE || "local"),
autoRefresh: (process.env.BTCEXP_AUTO_REFRESH || "off")
},
cookieSecret: cookieSecret,
privacyMode: (process.env.BTCEXP_PRIVACY_MODE.toLowerCase() == "true"),
slowDeviceMode: slowDeviceMode,
demoSite: (process.env.BTCEXP_DEMO.toLowerCase() == "true"),
queryExchangeRates: (process.env.BTCEXP_NO_RATES.toLowerCase() != "true" && process.env.BTCEXP_PRIVACY_MODE.toLowerCase() != "true"),
noInmemoryRpcCache: (process.env.BTCEXP_NO_INMEMORY_RPC_CACHE.toLowerCase() == "true"),
rpcConcurrency: (process.env.BTCEXP_RPC_CONCURRENCY || (slowDeviceMode ? 3 : 10)),
filesystemCacheDir: (process.env.BTCEXP_FILESYSTEM_CACHE_DIR || path.join(process.cwd(),"./cache")),
noTxIndexSearchDepth: (+process.env.BTCEXP_NOTXINDEX_SEARCH_DEPTH || 3),
rpcBlacklist:
process.env.BTCEXP_RPC_ALLOWALL.toLowerCase() == "true" ? []
: process.env.BTCEXP_RPC_BLACKLIST ? process.env.BTCEXP_RPC_BLACKLIST.split(',').filter(Boolean)
: [
"addnode",
"backupwallet",
"bumpfee",
"clearbanned",
"createmultisig",
"createwallet",
"disconnectnode",
"dumpprivkey",
"dumpwallet",
"encryptwallet",
"generate",
"generatetoaddress",
"getaccountaddrss",
"getaddressesbyaccount",
"getbalance",
"getnewaddress",
"getrawchangeaddress",
"getreceivedbyaccount",
"getreceivedbyaddress",
"gettransaction",
"getunconfirmedbalance",
"getwalletinfo",
"importaddress",
"importmulti",
"importprivkey",
"importprunedfunds",
"importpubkey",
"importwallet",
"invalidateblock",
"keypoolrefill",
"listaccounts",
"listaddressgroupings",
"listlockunspent",
"listreceivedbyaccount",
"listreceivedbyaddress",
"listsinceblock",
"listtransactions",
"listunspent",
"listwallets",
"lockunspent",
"logging",
"move",
"preciousblock",
"pruneblockchain",
"reconsiderblock",
"removeprunedfunds",
"rescanblockchain",
"savemempool",
"sendfrom",
"sendmany",
"sendtoaddress",
"setaccount",
"setban",
"setmocktime",
"setnetworkactive",
"signmessage",
"signmessagewithprivatekey",
"signrawtransaction",
"signrawtransactionwithkey",
"stop",
"submitblock",
"syncwithvalidationinterfacequeue",
"verifychain",
"waitforblock",
"waitforblockheight",
"waitfornewblock",
"walletlock",
"walletpassphrase",
"walletpassphrasechange",
],
addressApi: process.env.BTCEXP_ADDRESS_API,
electrumTxIndex: process.env.BTCEXP_ELECTRUM_TXINDEX != "false",
electrumServers: electrumServers,
redisUrl:process.env.BTCEXP_REDIS_URL,
site: {
hideInfoNotes: process.env.BTCEXP_UI_HIDE_INFO_NOTES,
homepage:{
recentBlocksCount: parseInt(process.env.BTCEXP_UI_HOME_PAGE_LATEST_BLOCKS_COUNT || (slowDeviceMode ? 5 : 10))
},
blockTxPageSize: (slowDeviceMode ? 10 : 20),
addressTxPageSize: 10,
txMaxInput: (slowDeviceMode ? 3 : 15),
browseBlocksPageSize: parseInt(process.env.BTCEXP_UI_BLOCKS_PAGE_BLOCK_COUNT || (slowDeviceMode ? 10 : 25)),
browseMempoolTransactionsPageSize: (slowDeviceMode ? 10 : 25),
addressPage:{
txOutputMaxDefaultDisplay:10
},
valueDisplayMaxLargeDigits: 4,
prioritizedToolIdsList: [0, 10, 11, 9, 3, 4, 16, 12, 2, 5, 15, 1, 6, 7, 13, 8],
toolSections: [
{name: "Basics", items: [0, 2]},
{name: "Mempool", items: [4, 16, 5]},
{name: "Analysis", items: [9, 18, 10, 11, 12, 3]},
{name: "Technical", items: [15, 6, 7, 1]},
{name: "Fun", items: [8, 17, 13]},
]
},
credentials: credentials,
siteTools:[
/* 0 */ {name:"Node Details", url:"./node-details", desc:"Node basics (version, uptime, etc)", fontawesome:"fas fa-info-circle"},
/* 1 */ {name:"Peers", url:"./peers", desc:"Details about the peers connected to this node.", fontawesome:"fas fa-sitemap"},
/* 2 */ {name:"Browse Blocks", url:"./blocks", desc:"Browse all blocks in the blockchain.", fontawesome:"fas fa-cubes"},
/* 3 */ {name:"Transaction Stats", url:"./tx-stats", desc:"See graphs of total transaction volume and transaction rates.", fontawesome:"fas fa-chart-bar"},
/* 4 */ {name:"Mempool Summary", url:"./mempool-summary", desc:"Detailed summary of the current mempool for this node.", fontawesome:"fas fa-hourglass-half"},
/* 5 */ {name:"Browse Mempool", url:"./mempool-transactions", desc:"Browse unconfirmed/pending transactions.", fontawesome:"fas fa-book-open"},
/* 6 */ {name:"RPC Browser", url:"./rpc-browser", desc:"Browse the RPC functionality of this node. See docs and execute commands.", fontawesome:"fas fa-book"},
/* 7 */ {name:"RPC Terminal", url:"./rpc-terminal", desc:"Directly execute RPCs against this node.", fontawesome:"fas fa-terminal"},
/* 8 */ {name:(coins[currentCoin].name + " Fun"), url:"./fun", desc:"Curated fun/interesting historical blockchain data.", fontawesome:"fas fa-flag"},
/* 9 */ {name:"Mining Summary", url:"./mining-summary", desc:"Summary of recent data about miners.", fontawesome:"fas fa-chart-pie"},
/* 10 */ {name:"Block Stats", url:"./block-stats", desc:"Summary data for blocks in configurable range.", fontawesome:"fas fa-layer-group"},
/* 11 */ {name:"Block Analysis", url:"./block-analysis", desc:"Summary analysis for all transactions in a block.", fontawesome:"fas fa-angle-double-down"},
/* 12 */ {name:"Difficulty History", url:"./difficulty-history", desc:"Details of difficulty changes over time.", fontawesome:"fas fa-chart-line"},
/* 13 */ {name:"Whitepaper Extractor", url:"./bitcoin-whitepaper", desc:"Extract the Bitcoin whitepaper from data embedded within the blockchain.", fontawesome:"far fa-file-alt"},
/* 14 */ {name:"Predicted Blocks", url:"./predicted-blocks", desc:"View predicted future blocks based on the current mempool.", fontawesome:"fas fa-arrow-circle-right"},
/* 15 */ {name:"API", url:"./api/docs", desc:"View docs for the public API.", fontawesome:"fas fa-toolbox"},
/* 16 */ {name:"Mining Template", url:"./mining-template", desc:"View a template for the the next block based on the current mempool.", fontawesome:"fas fa-filter"},
/* 17 */ {name:"Quotes", url:"./quotes", desc:"Curated list of Bitcoin-related quotes.", fontawesome:"fas fa-comment-dots"},
/* 18 */ {name:"UTXO Set", url:"./utxo-set", desc:"View the latest UTXO Set.", fontawesome:"fas fa-coins"},
]
};
debugLog(`Config(final): privacyMode=${module.exports.privacyMode}`);
debugLog(`Config(final): slowDeviceMode=${module.exports.slowDeviceMode}`);
debugLog(`Config(final): demo=${module.exports.demoSite}`);
debugLog(`Config(final): rpcAllowAll=${module.exports.rpcBlacklist.length == 0}`);