edge-currency-plugins 3.2.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/assets/edge-currency-plugins/edge-currency-plugins.js +37 -37
- package/lib/common/plugin/PluginState.js +69 -39
- package/lib/common/plugin/ServerScores.js +1 -0
- package/lib/common/utxobased/engine/ServerStates.js +227 -240
- package/lib/common/utxobased/network/Socket.js +15 -9
- package/lib/common/utxobased/network/windowWS.js +2 -2
- package/lib/src/common/plugin/PluginState.d.ts +1 -1
- package/lib/src/common/plugin/ServerScores.d.ts +1 -0
- package/lib/src/common/utxobased/network/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -66,21 +66,26 @@ const asServerListInfo = _cleaners.asObject.call(void 0, _cleaners.asEither.call
|
|
|
66
66
|
pluginDisklet,
|
|
67
67
|
log
|
|
68
68
|
} = settings
|
|
69
|
-
|
|
70
|
-
let customServers = []
|
|
71
|
-
let enableCustomServers = defaultSettings.enableCustomServers
|
|
69
|
+
|
|
72
70
|
let engines = []
|
|
73
71
|
const memlet = _memlet.makeMemlet.call(void 0, pluginDisklet)
|
|
74
72
|
|
|
75
73
|
let serverCache = {
|
|
76
74
|
customServers: {},
|
|
75
|
+
enableCustomServers: defaultSettings.enableCustomServers,
|
|
77
76
|
internalServers: {}
|
|
78
77
|
}
|
|
79
78
|
let serverCacheDirty = false
|
|
80
|
-
|
|
79
|
+
|
|
80
|
+
const getSelectedServerList = () => {
|
|
81
|
+
const serverCacheIndex = serverCache.enableCustomServers
|
|
82
|
+
? 'customServers'
|
|
83
|
+
: 'internalServers'
|
|
84
|
+
return serverCache[serverCacheIndex]
|
|
85
|
+
}
|
|
81
86
|
|
|
82
87
|
const saveServerCache = async () => {
|
|
83
|
-
serverScores.printServers(
|
|
88
|
+
serverScores.printServers(getSelectedServerList())
|
|
84
89
|
if (serverCacheDirty) {
|
|
85
90
|
await memlet.setJson(SERVER_CACHE_FILE, serverCache).catch(e => {
|
|
86
91
|
log(`${pluginId} - ${JSON.stringify(e.toString())}`)
|
|
@@ -133,30 +138,7 @@ const asServerListInfo = _cleaners.asObject.call(void 0, _cleaners.asEither.call
|
|
|
133
138
|
}
|
|
134
139
|
}
|
|
135
140
|
|
|
136
|
-
const
|
|
137
|
-
let newServers
|
|
138
|
-
if (enableCustomServers) {
|
|
139
|
-
newServers = customServers
|
|
140
|
-
} else {
|
|
141
|
-
const fetchedServers = await fetchServers()
|
|
142
|
-
newServers = fetchedServers.length > 0 ? fetchedServers : builtInServers
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const serverCacheIndex = enableCustomServers
|
|
146
|
-
? 'customServers'
|
|
147
|
-
: 'internalServers'
|
|
148
|
-
|
|
149
|
-
knownServers = serverCache[serverCacheIndex]
|
|
150
|
-
serverScores.serverScoresLoad(knownServers, newServers)
|
|
151
|
-
await saveServerCache()
|
|
152
|
-
|
|
153
|
-
// Tell the engines about the new servers:
|
|
154
|
-
for (const engine of engines) {
|
|
155
|
-
engine.refillServers()
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return {
|
|
141
|
+
const instance = {
|
|
160
142
|
/**
|
|
161
143
|
* Begins notifying the engine of state changes. Used at connection time.
|
|
162
144
|
*/
|
|
@@ -173,7 +155,7 @@ const asServerListInfo = _cleaners.asObject.call(void 0, _cleaners.asEither.call
|
|
|
173
155
|
|
|
174
156
|
dumpData() {
|
|
175
157
|
return {
|
|
176
|
-
'pluginState.servers_':
|
|
158
|
+
'pluginState.servers_': getSelectedServerList()
|
|
177
159
|
}
|
|
178
160
|
},
|
|
179
161
|
|
|
@@ -185,7 +167,7 @@ const asServerListInfo = _cleaners.asObject.call(void 0, _cleaners.asEither.call
|
|
|
185
167
|
}
|
|
186
168
|
|
|
187
169
|
// Fetch servers in the background:
|
|
188
|
-
refreshServers().catch(e => {
|
|
170
|
+
instance.refreshServers().catch(e => {
|
|
189
171
|
log(`${pluginId} - ${JSON.stringify(e.toString())}`)
|
|
190
172
|
})
|
|
191
173
|
|
|
@@ -193,16 +175,15 @@ const asServerListInfo = _cleaners.asObject.call(void 0, _cleaners.asEither.call
|
|
|
193
175
|
},
|
|
194
176
|
|
|
195
177
|
serverScoreDown(uri) {
|
|
196
|
-
serverScores.serverScoreDown(
|
|
178
|
+
serverScores.serverScoreDown(getSelectedServerList(), uri)
|
|
197
179
|
},
|
|
198
180
|
|
|
199
181
|
serverScoreUp(uri, score) {
|
|
200
|
-
serverScores.serverScoreUp(
|
|
182
|
+
serverScores.serverScoreUp(getSelectedServerList(), uri, score)
|
|
201
183
|
},
|
|
202
184
|
|
|
203
185
|
async clearCache() {
|
|
204
186
|
serverScores.clearServerScoreTimes()
|
|
205
|
-
knownServers = {}
|
|
206
187
|
serverCacheDirty = true
|
|
207
188
|
await memlet.delete(SERVER_CACHE_FILE)
|
|
208
189
|
},
|
|
@@ -212,18 +193,63 @@ const asServerListInfo = _cleaners.asObject.call(void 0, _cleaners.asEither.call
|
|
|
212
193
|
includePatterns = []
|
|
213
194
|
) {
|
|
214
195
|
return serverScores.getServers(
|
|
215
|
-
|
|
196
|
+
getSelectedServerList(),
|
|
216
197
|
numServersWanted,
|
|
217
198
|
includePatterns
|
|
218
199
|
)
|
|
219
200
|
},
|
|
220
201
|
|
|
221
|
-
refreshServers
|
|
202
|
+
async refreshServers(updatedCustomServers) {
|
|
203
|
+
let newServers
|
|
204
|
+
if (serverCache.enableCustomServers) {
|
|
205
|
+
newServers =
|
|
206
|
+
// Use the updated custom servers if provided
|
|
207
|
+
_nullishCoalesce(_nullishCoalesce(updatedCustomServers, () => (
|
|
208
|
+
// Use the existing custom servers from cache
|
|
209
|
+
Object.keys(serverCache.customServers))), () => (
|
|
210
|
+
// Use the default servers from info file as final fallback
|
|
211
|
+
defaultSettings.blockbookServers))
|
|
212
|
+
} else {
|
|
213
|
+
const fetchedServers = await fetchServers()
|
|
214
|
+
newServers =
|
|
215
|
+
fetchedServers.length > 0
|
|
216
|
+
? // Use the servers from the network query
|
|
217
|
+
fetchedServers
|
|
218
|
+
: // Use the default servers from info file as final fallback
|
|
219
|
+
defaultSettings.blockbookServers
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
serverScores.serverScoresLoad(getSelectedServerList(), newServers)
|
|
223
|
+
await saveServerCache()
|
|
224
|
+
|
|
225
|
+
// Tell the engines about the new servers:
|
|
226
|
+
for (const engine of engines) {
|
|
227
|
+
engine.refillServers()
|
|
228
|
+
}
|
|
229
|
+
},
|
|
222
230
|
|
|
223
231
|
async updateServers(settings) {
|
|
224
|
-
|
|
225
|
-
|
|
232
|
+
const hasServerListChanged = () => {
|
|
233
|
+
const currentCustomServers = Object.keys(serverCache.customServers)
|
|
234
|
+
const newServers = new Set(settings.blockbookServers)
|
|
235
|
+
const existingServers = new Set(currentCustomServers)
|
|
236
|
+
if (newServers.size !== existingServers.size) return true
|
|
237
|
+
for (const server of settings.blockbookServers) {
|
|
238
|
+
if (existingServers.has(server)) continue
|
|
239
|
+
return true
|
|
240
|
+
}
|
|
241
|
+
return false
|
|
242
|
+
}
|
|
226
243
|
|
|
244
|
+
// If no changes to the user settings, then exit early
|
|
245
|
+
if (
|
|
246
|
+
settings.enableCustomServers === serverCache.enableCustomServers &&
|
|
247
|
+
!hasServerListChanged()
|
|
248
|
+
) {
|
|
249
|
+
return
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Stop all engines and clear the server list:
|
|
227
253
|
const enginesToBeStarted = []
|
|
228
254
|
const disconnects = []
|
|
229
255
|
for (const engine of engines) {
|
|
@@ -233,18 +259,22 @@ const asServerListInfo = _cleaners.asObject.call(void 0, _cleaners.asEither.call
|
|
|
233
259
|
}
|
|
234
260
|
await Promise.all(disconnects)
|
|
235
261
|
serverScores.clearServerScoreTimes()
|
|
262
|
+
|
|
236
263
|
// We must always clear custom servers in order to enforce a policy of
|
|
237
264
|
// only using the exact customServers provided.
|
|
238
265
|
serverCache = {
|
|
239
266
|
...serverCache,
|
|
267
|
+
enableCustomServers: settings.enableCustomServers,
|
|
240
268
|
customServers: {}
|
|
241
269
|
}
|
|
242
270
|
serverCacheDirty = true
|
|
243
271
|
await saveServerCache()
|
|
244
|
-
await refreshServers()
|
|
272
|
+
await instance.refreshServers(settings.blockbookServers)
|
|
245
273
|
for (const engine of enginesToBeStarted) {
|
|
246
274
|
await engine.start()
|
|
247
275
|
}
|
|
248
276
|
}
|
|
249
277
|
}
|
|
278
|
+
|
|
279
|
+
return instance
|
|
250
280
|
} exports.makePluginState = makePluginState;
|
|
@@ -16,6 +16,7 @@ var _cleaners = require('cleaners');
|
|
|
16
16
|
|
|
17
17
|
const asServerCache = _cleaners.asObject.call(void 0, {
|
|
18
18
|
customServers: exports.asServerList,
|
|
19
|
+
enableCustomServers: _cleaners.asMaybe.call(void 0, _cleaners.asBoolean, false),
|
|
19
20
|
internalServers: exports.asServerList
|
|
20
21
|
}); exports.asServerCache = asServerCache
|
|
21
22
|
|