edge-currency-plugins 3.2.1 → 3.3.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.
Files changed (48) hide show
  1. package/android/src/main/assets/edge-currency-plugins/edge-currency-plugins.js +41 -41
  2. package/lib/common/plugin/PluginState.js +4 -4
  3. package/lib/common/plugin/ServerScores.js +10 -0
  4. package/lib/common/plugin/types.js +1 -1
  5. package/lib/common/utxobased/db/{Processor.js → DataLayer.js} +15 -11
  6. package/lib/common/utxobased/db/Models/{ProcessorTransaction.js → TransactionData.js} +4 -6
  7. package/lib/common/utxobased/db/types.js +4 -4
  8. package/lib/common/utxobased/db/util/utxo.js +8 -8
  9. package/lib/common/utxobased/engine/ServerStates.js +137 -98
  10. package/lib/common/utxobased/engine/UtxoEngine.js +58 -55
  11. package/lib/common/utxobased/engine/{UtxoEngineState.js → UtxoEngineProcessor.js} +650 -714
  12. package/lib/common/utxobased/engine/types.js +4 -2
  13. package/lib/common/utxobased/engine/util/getOwnUtxosFromTx.js +4 -4
  14. package/lib/common/utxobased/info/bitcoin.js +2 -1
  15. package/lib/common/utxobased/info/bitcoincash.js +2 -1
  16. package/lib/common/utxobased/info/dash.js +2 -1
  17. package/lib/common/utxobased/info/digibyte.js +5 -1
  18. package/lib/common/utxobased/info/dogecoin.js +2 -1
  19. package/lib/common/utxobased/info/groestlcoin.js +5 -2
  20. package/lib/common/utxobased/info/litecoin.js +2 -1
  21. package/lib/common/utxobased/info/zcoin.js +4 -1
  22. package/lib/common/utxobased/network/Blockbook.js +33 -30
  23. package/lib/common/utxobased/network/BlockbookElectrum.js +79 -77
  24. package/lib/common/utxobased/network/Socket.js +79 -49
  25. package/lib/common/utxobased/network/nodejsWS.js +2 -2
  26. package/lib/common/utxobased/network/types.js +5 -0
  27. package/lib/common/utxobased/network/windowWS.js +2 -2
  28. package/lib/src/common/plugin/PluginState.d.ts +3 -3
  29. package/lib/src/common/plugin/types.d.ts +4 -4
  30. package/lib/src/common/utxobased/db/{Processor.d.ts → DataLayer.d.ts} +17 -11
  31. package/lib/src/common/utxobased/db/Models/{ProcessorTransaction.d.ts → TransactionData.d.ts} +5 -5
  32. package/lib/src/common/utxobased/db/Models/baselet.d.ts +4 -4
  33. package/lib/src/common/utxobased/db/types.d.ts +9 -9
  34. package/lib/src/common/utxobased/db/util/utxo.d.ts +3 -3
  35. package/lib/src/common/utxobased/engine/ServerStates.d.ts +7 -7
  36. package/lib/src/common/utxobased/engine/{UtxoEngineState.d.ts → UtxoEngineProcessor.d.ts} +44 -42
  37. package/lib/src/common/utxobased/engine/types.d.ts +4 -4
  38. package/lib/src/common/utxobased/engine/util/getOwnUtxosFromTx.d.ts +3 -3
  39. package/lib/src/common/utxobased/engine/utils.d.ts +2 -2
  40. package/lib/src/common/utxobased/keymanager/keymanager.d.ts +3 -3
  41. package/lib/src/common/utxobased/network/Blockbook.d.ts +8 -7
  42. package/lib/src/common/utxobased/network/BlockbookElectrum.d.ts +4 -2
  43. package/lib/src/common/utxobased/network/Socket.d.ts +10 -8
  44. package/lib/src/common/utxobased/network/types.d.ts +6 -2
  45. package/lib/src/util/uriKeyParams.d.ts +4 -0
  46. package/lib/util/uriKeyParams.js +20 -0
  47. package/package.json +2 -2
  48. /package/lib/test/common/utxobased/db/{Processor.spec.d.ts → DataLayer.spec.d.ts} +0 -0
@@ -142,15 +142,15 @@ const asServerListInfo = _cleaners.asObject.call(void 0, _cleaners.asEither.call
142
142
  /**
143
143
  * Begins notifying the engine of state changes. Used at connection time.
144
144
  */
145
- addEngine(engineState) {
146
- engines.push(engineState)
145
+ addEngine(engineProcessor) {
146
+ engines.push(engineProcessor)
147
147
  },
148
148
 
149
149
  /**
150
150
  * Stops notifying the engine of state changes. Used at disconnection time.
151
151
  */
152
- removeEngine(engineState) {
153
- engines = engines.filter(engine => engine !== engineState)
152
+ removeEngine(engineProcessor) {
153
+ engines = engines.filter(engine => engine !== engineProcessor)
154
154
  },
155
155
 
156
156
  dumpData() {
@@ -3,6 +3,8 @@
3
3
  var _cleaners = require('cleaners');
4
4
 
5
5
 
6
+ var _uriKeyParams = require('../../util/uriKeyParams');
7
+
6
8
 
7
9
  const asServerInfo = _cleaners.asObject.call(void 0, {
8
10
  serverUrl: _cleaners.asString,
@@ -101,6 +103,14 @@ const RE_ADDED_SERVER_SCORE = -10
101
103
  knownServer.responseTime = RESPONSE_TIME_UNINITIALIZED
102
104
  }
103
105
 
106
+ const hasKeyParams = _uriKeyParams.getUriKeyParams.call(void 0, knownServerUrl).length > 0
107
+ if (hasKeyParams) {
108
+ // Lower the score on servers which require key params (e.g. NOWNodes).
109
+ // This is because public, non-authenticated nodes are more affordable.
110
+ // Decrease score by half (or decrease by 50%).
111
+ serverScore = serverScore - (MAX_SCORE + MIN_SCORE)
112
+ }
113
+
104
114
  knownServer.serverScore = serverScore
105
115
  this.onDirtyServer(knownServerUrl)
106
116
  }
@@ -50,7 +50,7 @@ var _types3 = require('../utxobased/db/types');
50
50
 
51
51
 
52
52
  const asTxOptions = _cleaners.asObject({
53
- utxos: _cleaners.asOptional.call(void 0, _cleaners.asArray.call(void 0, _types3.asIUTXO)),
53
+ utxos: _cleaners.asOptional.call(void 0, _cleaners.asArray.call(void 0, _types3.asUtxoData)),
54
54
  subtractFee: _cleaners.asOptional.call(void 0, _cleaners.asBoolean),
55
55
  CPFP: _cleaners.asOptional.call(void 0, _cleaners.asString)
56
56
  }); exports.asTxOptions = asTxOptions
@@ -113,7 +113,13 @@ const BASELET_DIR = 'tables'
113
113
 
114
114
 
115
115
 
116
- async function makeProcessor(
116
+
117
+
118
+
119
+
120
+
121
+
122
+ async function makeDataLayer(
117
123
  config
118
124
  ) {
119
125
  const disklet = _disklet.navigateDisklet.call(void 0, config.disklet, BASELET_DIR)
@@ -126,7 +132,7 @@ const BASELET_DIR = 'tables'
126
132
  /**
127
133
  * Calculates the transaction value supplied (negative) or received (positive). In order to calculate
128
134
  * a value, the `ourIns` and `ourOuts` of the object must be populated with indices.
129
- * @param tx {IProcessorTransaction} A transaction object with `ourIns` and `ourOuts` populated
135
+ * @param tx {TransactionData} A transaction object with `ourIns` and `ourOuts` populated
130
136
  */
131
137
  const calculateTxAmount = (tx) => {
132
138
 
@@ -152,7 +158,7 @@ const BASELET_DIR = 'tables'
152
158
  return ourAmount
153
159
  }
154
160
 
155
- const processor = {
161
+ const dataLayer = {
156
162
  async clearAll() {
157
163
  await memlet.onFlush.next().value
158
164
  await _baselet.clearMemletCache.call(void 0, )
@@ -261,19 +267,17 @@ const BASELET_DIR = 'tables'
261
267
  })
262
268
  },
263
269
 
264
- async saveTransaction(
265
- args
266
- ) {
270
+ async saveTransaction(args) {
267
271
  const { scriptPubkeys = [], tx } = args
268
272
  return await baselets.tx(async tables => {
269
273
  // Check if the transaction already exists
270
- const processorTx = await tables.txById
274
+ const transactionData = await tables.txById
271
275
  .query('', [tx.txid])
272
276
  .then(transactions => transactions[0])
273
277
  .catch(_ => undefined)
274
278
 
275
279
  // Use the existing transaction if it does exist.
276
- const transaction = _nullishCoalesce(processorTx, () => ( tx))
280
+ const transaction = _nullishCoalesce(transactionData, () => ( tx))
277
281
 
278
282
  // Mark the used inputs with the provided script pubkey
279
283
  for (const scriptPubkey of scriptPubkeys) {
@@ -325,7 +329,7 @@ const BASELET_DIR = 'tables'
325
329
  await tables.txById.insert('', transaction.txid, transaction)
326
330
 
327
331
  // Save index entry only for first transaction insert
328
- if (processorTx == null) {
332
+ if (transactionData == null) {
329
333
  await tables.txIdsByDate.insert('', {
330
334
  txid: tx.txid,
331
335
  date: tx.date
@@ -594,5 +598,5 @@ const BASELET_DIR = 'tables'
594
598
  })
595
599
  }
596
600
  }
597
- return processor
598
- } exports.makeProcessor = makeProcessor;
601
+ return dataLayer
602
+ } exports.makeDataLayer = makeDataLayer;
@@ -9,9 +9,7 @@ var _bnjs = require('bn.js'); var _bnjs2 = _interopRequireDefault(_bnjs);
9
9
 
10
10
 
11
11
 
12
- const fromEdgeTransaction = (
13
- tx
14
- ) => {
12
+ const fromEdgeTransaction = (tx) => {
15
13
  const otherParams = tx.otherParams
16
14
  if (otherParams == null) throw new Error('Invalid transaction data')
17
15
  if (otherParams.psbt == null)
@@ -44,7 +42,7 @@ var _bnjs = require('bn.js'); var _bnjs2 = _interopRequireDefault(_bnjs);
44
42
  inputs: inputs,
45
43
  outputs: outputs,
46
44
  // We can leave ourIns/ourOuts blank because they'll be updated by the
47
- // processor when receiving the transaction from blockbook.
45
+ // DataLayer when receiving the transaction from blockbook.
48
46
  // We may want to calculate these preemptively, but for now this will work.
49
47
  ourIns: [],
50
48
  ourOuts: [],
@@ -63,12 +61,12 @@ var _bnjs = require('bn.js'); var _bnjs2 = _interopRequireDefault(_bnjs);
63
61
  const toEdgeTransaction = async (
64
62
  args
65
63
  ) => {
66
- const { tx, processor, walletTools, pluginInfo, walletId } = args
64
+ const { tx, dataLayer, walletTools, pluginInfo, walletId } = args
67
65
  const { currencyInfo } = pluginInfo
68
66
  const ourReceiveAddresses = []
69
67
  for (const out of tx.ourOuts) {
70
68
  const { scriptPubkey } = tx.outputs[parseInt(out)]
71
- const address = await processor.fetchAddress(scriptPubkey)
69
+ const address = await dataLayer.fetchAddress(scriptPubkey)
72
70
 
73
71
  if (_optionalChain([address, 'optionalAccess', _ => _.path]) != null) {
74
72
  const { address: addrStr } = walletTools.scriptPubkeyToAddress({
@@ -15,7 +15,7 @@ var _keymanager = require('../keymanager/keymanager');
15
15
 
16
16
 
17
17
 
18
- const makeIAddress = (
18
+ const makeAddressData = (
19
19
  addressFields
20
20
  ) => {
21
21
  const { scriptPubkey, used = false, ...rest } = addressFields
@@ -28,7 +28,7 @@ var _keymanager = require('../keymanager/keymanager');
28
28
  lastTouched: 0,
29
29
  ...rest
30
30
  }
31
- }; exports.makeIAddress = makeIAddress
31
+ }; exports.makeAddressData = makeAddressData
32
32
 
33
33
 
34
34
 
@@ -42,7 +42,7 @@ var _keymanager = require('../keymanager/keymanager');
42
42
 
43
43
 
44
44
 
45
- const asIUTXO = _cleaners.asObject({
45
+ const asUtxoData = _cleaners.asObject({
46
46
  id: _cleaners.asString,
47
47
  txid: _cleaners.asString,
48
48
  vout: _cleaners.asNumber,
@@ -53,7 +53,7 @@ var _keymanager = require('../keymanager/keymanager');
53
53
  scriptType: _keymanager.asScriptTypeEnum,
54
54
  blockHeight: _cleaners.asNumber,
55
55
  spent: _cleaners.asBoolean
56
- }); exports.asIUTXO = asIUTXO
56
+ }); exports.asUtxoData = asUtxoData
57
57
 
58
58
 
59
59
 
@@ -6,14 +6,14 @@ var _keymanager = require('../../keymanager/keymanager');
6
6
 
7
7
 
8
8
 
9
- const utxoFromProcessorTransactionInput = async (
10
- processor,
11
- processorTransaction,
9
+ const utxoFromTransactionDataInput = async (
10
+ dataLayer,
11
+ transactionData,
12
12
  inputIndex
13
13
  ) => {
14
- const input = processorTransaction.inputs[inputIndex]
14
+ const input = transactionData.inputs[inputIndex]
15
15
  const { scriptPubkey } = input
16
- const address = await processor.fetchAddress(scriptPubkey)
16
+ const address = await dataLayer.fetchAddress(scriptPubkey)
17
17
 
18
18
  if (address == null)
19
19
  throw new Error(`Cannot find address for ${scriptPubkey}`)
@@ -34,7 +34,7 @@ var _keymanager = require('../../keymanager/keymanager');
34
34
  case _keymanager.BIP43PurposeTypeEnum.Airbitz:
35
35
  case _keymanager.BIP43PurposeTypeEnum.Legacy: {
36
36
  return {
37
- script: processorTransaction.hex,
37
+ script: transactionData.hex,
38
38
  scriptType:
39
39
  redeemScript != null ? _keymanager.ScriptTypeEnum.p2sh : _keymanager.ScriptTypeEnum.p2pkh
40
40
  }
@@ -64,7 +64,7 @@ var _keymanager = require('../../keymanager/keymanager');
64
64
  script,
65
65
  redeemScript,
66
66
  scriptType,
67
- blockHeight: processorTransaction.blockHeight,
67
+ blockHeight: transactionData.blockHeight,
68
68
  spent: true
69
69
  }
70
- }; exports.utxoFromProcessorTransactionInput = utxoFromProcessorTransactionInput
70
+ }; exports.utxoFromTransactionDataInput = utxoFromTransactionDataInput
@@ -87,10 +87,6 @@ var _constants = require('./constants');
87
87
 
88
88
 
89
89
 
90
-
91
-
92
-
93
-
94
90
 
95
91
 
96
92
 
@@ -226,6 +222,38 @@ var _constants = require('./constants');
226
222
  // Blockbook instance variable
227
223
  let blockbook
228
224
 
225
+ // Queue space callback
226
+ async function* taskGeneratorFn()
227
+
228
+
229
+ {
230
+ // Exit if the connection is no longer active
231
+ if (uri == null || !(uri in serverStatesCache)) return false
232
+
233
+ const generator = pickNextTaskCB(uri)
234
+ let nextValue
235
+ while (true) {
236
+ const result
237
+
238
+
239
+ = await generator.next(nextValue)
240
+
241
+ if (_optionalChain([result, 'optionalAccess', _ => _.done]) === true) {
242
+ return result.value
243
+ }
244
+
245
+ const task = result.value
246
+
247
+ if (typeof task !== 'boolean') {
248
+ const taskMessage = `${task.method} params: ${JSON.stringify(
249
+ task.params
250
+ )}`
251
+ log(`${uri} nextTask: ${taskMessage}`)
252
+ }
253
+ nextValue = yield task
254
+ }
255
+ }
256
+
229
257
  // Create a new blockbook instance based on the URI scheme
230
258
  if (['electrumwss', 'electrumws'].includes(parsed.scheme)) {
231
259
  // Electrum wrapper
@@ -233,22 +261,9 @@ var _constants = require('./constants');
233
261
  asAddress: pluginInfo.engineInfo.asBlockbookAddress,
234
262
  connectionUri: uri,
235
263
  engineEmitter,
264
+ initOptions,
236
265
  log,
237
- onQueueSpaceCB: async (
238
-
239
- ) => {
240
- // Exit if the connection is no longer active
241
- if (!(uri in serverStatesCache)) return
242
-
243
- const task = await pickNextTaskCB(uri)
244
- if (task != null && typeof task !== 'boolean') {
245
- const taskMessage = `${task.method} params: ${JSON.stringify(
246
- task.params
247
- )}`
248
- log(`${uri} nextTask: ${taskMessage}`)
249
- }
250
- return task
251
- },
266
+ taskGeneratorFn,
252
267
  pluginInfo,
253
268
  socketEmitter,
254
269
  walletId: walletInfo.id
@@ -259,22 +274,9 @@ var _constants = require('./constants');
259
274
  asAddress: pluginInfo.engineInfo.asBlockbookAddress,
260
275
  connectionUri: uri,
261
276
  engineEmitter,
277
+ initOptions,
262
278
  log,
263
- onQueueSpaceCB: async (
264
-
265
- ) => {
266
- // Exit if the connection is no longer active
267
- if (!(uri in serverStatesCache)) return
268
-
269
- const task = await pickNextTaskCB(uri)
270
- if (task != null && typeof task !== 'boolean') {
271
- const taskMessage = `${task.method} params: ${JSON.stringify(
272
- task.params
273
- )}`
274
- log(`${uri} nextTask: ${taskMessage}`)
275
- }
276
- return task
277
- },
279
+ taskGeneratorFn,
278
280
  socketEmitter,
279
281
  walletId: walletInfo.id
280
282
  })
@@ -308,6 +310,50 @@ var _constants = require('./constants');
308
310
  }
309
311
  }
310
312
 
313
+ const deferredWithServerScoring = (
314
+ serverUri,
315
+ deferred
316
+ ) => {
317
+ const serverState = serverStatesCache[serverUri]
318
+ if (serverState == null)
319
+ throw new Error(`No blockbook connection with ${serverUri}`)
320
+
321
+ const queryTime = Date.now()
322
+ const deferredWithScoring = new _Deferred2.default()
323
+ deferredWithScoring.promise.then(
324
+ (value) => {
325
+ pluginState.serverScoreUp(serverUri, Date.now() - queryTime)
326
+ deferred.resolve(value)
327
+ },
328
+ (err) => {
329
+ pluginState.serverScoreDown(serverUri)
330
+ deferred.reject(err)
331
+ }
332
+ )
333
+
334
+ return deferredWithScoring
335
+ }
336
+
337
+ function* withServerScoring(
338
+ serverUri,
339
+ generator
340
+ ) {
341
+ const serverState = serverStatesCache[serverUri]
342
+ if (serverState == null)
343
+ throw new Error(`No blockbook connection with ${serverUri}`)
344
+
345
+ const queryTime = Date.now()
346
+ let result
347
+ try {
348
+ result = yield* generator
349
+ pluginState.serverScoreUp(serverUri, Date.now() - queryTime)
350
+ } catch (error) {
351
+ pluginState.serverScoreDown(serverUri)
352
+ throw error
353
+ }
354
+ return result
355
+ }
356
+
311
357
  const instance = {
312
358
  async broadcastTx(transaction) {
313
359
  return await new Promise((resolve, reject) => {
@@ -363,7 +409,7 @@ var _constants = require('./constants');
363
409
  // /^http(?:s)?:/i
364
410
  // ])
365
411
 
366
- const { nowNodeApiKey } = initOptions
412
+ const { nowNodesApiKey } = initOptions
367
413
  const nowNodeUris = serverConfigs
368
414
  .filter(config => config.type === 'blockbook-nownode')
369
415
  .map(config => config.uris)
@@ -383,7 +429,7 @@ var _constants = require('./constants');
383
429
  }
384
430
 
385
431
  // If there is no key for the NowNode servers:
386
- if (nowNodeApiKey == null) {
432
+ if (nowNodesApiKey == null) {
387
433
  reject(new Error('Missing connection key for fallback servers.'))
388
434
  return
389
435
  }
@@ -395,7 +441,7 @@ var _constants = require('./constants');
395
441
  io.fetchCors(`${uri}/api/v2/sendtx/`, {
396
442
  method: 'POST',
397
443
  headers: {
398
- 'api-key': nowNodeApiKey
444
+ 'api-key': nowNodesApiKey
399
445
  },
400
446
  body: transaction.signedTx
401
447
  })
@@ -451,9 +497,7 @@ var _constants = require('./constants');
451
497
  })
452
498
  },
453
499
 
454
- setPickNextTaskCB(
455
- callback
456
- ) {
500
+ setPickNextTaskCB(callback) {
457
501
  pickNextTaskCB = callback
458
502
  },
459
503
 
@@ -505,13 +549,13 @@ var _constants = require('./constants');
505
549
  },
506
550
 
507
551
  watchAddresses(
508
- uri,
552
+ serverUri,
509
553
  addresses,
510
554
  deferredAddressSub
511
555
  ) {
512
- const serverState = serverStatesCache[uri]
556
+ const serverState = serverStatesCache[serverUri]
513
557
  if (serverState == null)
514
- throw new Error(`No blockbook connection with ${uri}`)
558
+ throw new Error(`No blockbook connection with ${serverUri}`)
515
559
 
516
560
  const { blockbook } = serverState
517
561
 
@@ -520,109 +564,104 @@ var _constants = require('./constants');
520
564
  serverState.addresses.add(address)
521
565
  }
522
566
 
523
- const queryTime = Date.now()
524
567
  const deferred = new _Deferred2.default()
525
- deferred.promise
526
- .then((value) => {
527
- pluginState.serverScoreUp(uri, Date.now() - queryTime)
528
- _optionalChain([deferredAddressSub, 'optionalAccess', _ => _.resolve, 'call', _2 => _2(value)])
529
- })
530
- .catch(() => {
531
- // Remove new addresses to the set of known addresses
532
- for (const address of addresses) {
533
- serverState.addresses.delete(address)
534
- }
535
- pluginState.serverScoreDown(uri)
536
- _optionalChain([deferredAddressSub, 'optionalAccess', _3 => _3.reject, 'call', _4 => _4()])
537
- })
538
- blockbook.watchAddresses(Array.from(serverState.addresses), deferred)
568
+ deferred.promise.catch((err) => {
569
+ // Remove new addresses to the set of known addresses
570
+ for (const address of addresses) {
571
+ serverState.addresses.delete(address)
572
+ }
573
+ // Reject the deferredAddressSub promise if provided
574
+ _optionalChain([deferredAddressSub, 'optionalAccess', _2 => _2.reject, 'call', _3 => _3(err)])
575
+ })
576
+
577
+ blockbook.watchAddresses(
578
+ Array.from(serverState.addresses),
579
+ deferredWithServerScoring(serverUri, deferred)
580
+ )
539
581
  },
540
582
 
541
- watchBlocks(uri) {
542
- const serverState = serverStatesCache[uri]
583
+ watchBlocks(serverUri) {
584
+ const serverState = serverStatesCache[serverUri]
543
585
  if (serverState == null)
544
- throw new Error(`No blockbook connection with ${uri}`)
586
+ throw new Error(`No blockbook connection with ${serverUri}`)
545
587
 
546
588
  const { blockbook } = serverState
547
589
 
548
590
  serverState.blockSubscriptionStatus = 'subscribing'
549
591
 
550
- const queryTime = Date.now()
551
592
  const deferred = new (0, _Deferred2.default)()
552
593
  deferred.promise
553
594
  .then(() => {
554
595
  serverState.blockSubscriptionStatus = 'subscribed'
555
- pluginState.serverScoreUp(uri, Date.now() - queryTime)
556
596
  })
557
597
  .catch(() => {
558
598
  serverState.blockSubscriptionStatus = 'unsubscribed'
559
599
  })
560
- blockbook.watchBlocks(deferred)
600
+ blockbook.watchBlocks(deferredWithServerScoring(serverUri, deferred))
561
601
  },
562
602
 
563
603
  //
564
604
  // Task Methods:
565
605
  //
566
606
 
567
- addressQueryTask(
607
+ addressQueryTask: function* (
568
608
  serverUri,
569
609
  address,
570
- params,
571
- deferred
610
+ params
572
611
  ) {
573
612
  const serverState = serverStatesCache[serverUri]
574
613
  if (serverState == null)
575
614
  throw new Error(`No blockbook connection with ${serverUri}`)
576
615
 
577
- return serverState.blockbook.addressQueryTask(
578
- address,
579
- {
580
- asBlockbookAddress: pluginInfo.engineInfo.asBlockbookAddress,
581
- lastQueriedBlockHeight: params.lastQueriedBlockHeight,
582
- page: params.page
583
- },
584
- deferred
616
+ return yield* withServerScoring(
617
+ serverUri,
618
+ (function* () {
619
+ return yield* serverState.blockbook.addressQueryTask(address, {
620
+ asBlockbookAddress: pluginInfo.engineInfo.asBlockbookAddress,
621
+ lastQueriedBlockHeight: params.lastQueriedBlockHeight,
622
+ page: params.page
623
+ })
624
+ })()
585
625
  )
586
626
  },
587
627
 
588
- transactionQueryTask(
589
- serverUri,
590
- txId,
591
- deferred
592
- ) {
628
+ transactionQueryTask: function* (serverUri, txId) {
593
629
  const serverState = serverStatesCache[serverUri]
594
630
  if (serverState == null)
595
631
  throw new Error(`No blockbook connection with ${serverUri}`)
596
632
 
597
- return serverState.blockbook.transactionQueryTask(txId, deferred)
633
+ return yield* withServerScoring(
634
+ serverUri,
635
+ (function* () {
636
+ return yield* serverState.blockbook.transactionQueryTask(txId)
637
+ })()
638
+ )
598
639
  },
599
640
 
600
- transactionSpecialQueryTask(
601
- serverUri,
602
- txId,
603
- deferred
604
- ) {
641
+ transactionSpecialQueryTask: function* (serverUri, txId) {
605
642
  const serverState = serverStatesCache[serverUri]
606
643
  if (serverState == null)
607
644
  throw new Error(`No blockbook connection with ${serverUri}`)
608
645
 
609
- return serverState.blockbook.transactionSpecialQueryTask(txId, deferred)
646
+ return yield* withServerScoring(
647
+ serverUri,
648
+ (function* () {
649
+ return serverState.blockbook.transactionSpecialQueryTask(txId)
650
+ })()
651
+ )
610
652
  },
611
- utxoListQueryTask(
612
- serverUri,
613
- address,
614
- deferred
615
- ) {
653
+ utxoListQueryTask: function* (serverUri, address) {
616
654
  const serverState = serverStatesCache[serverUri]
617
655
  if (serverState == null)
618
656
  throw new Error(`No blockbook connection with ${serverUri}`)
619
657
 
620
- return serverState.blockbook.utxoListQueryTask(
621
- address,
622
- {
623
- asBlockbookAddress: pluginInfo.engineInfo.asBlockbookAddress
624
- },
625
- deferred
658
+ return yield* withServerScoring(
659
+ serverUri,
660
+ (function* () {
661
+ return yield* serverState.blockbook.utxoListQueryTask(address, {
662
+ asBlockbookAddress: pluginInfo.engineInfo.asBlockbookAddress
663
+ })
664
+ })()
626
665
  )
627
666
  }
628
667
  }