edge-currency-plugins 3.2.1 → 3.3.0

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 (44) 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 +4 -1
  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 +70 -40
  25. package/lib/src/common/plugin/PluginState.d.ts +3 -3
  26. package/lib/src/common/plugin/types.d.ts +4 -4
  27. package/lib/src/common/utxobased/db/{Processor.d.ts → DataLayer.d.ts} +17 -11
  28. package/lib/src/common/utxobased/db/Models/{ProcessorTransaction.d.ts → TransactionData.d.ts} +5 -5
  29. package/lib/src/common/utxobased/db/Models/baselet.d.ts +4 -4
  30. package/lib/src/common/utxobased/db/types.d.ts +9 -9
  31. package/lib/src/common/utxobased/db/util/utxo.d.ts +3 -3
  32. package/lib/src/common/utxobased/engine/ServerStates.d.ts +7 -7
  33. package/lib/src/common/utxobased/engine/{UtxoEngineState.d.ts → UtxoEngineProcessor.d.ts} +44 -42
  34. package/lib/src/common/utxobased/engine/types.d.ts +4 -4
  35. package/lib/src/common/utxobased/engine/util/getOwnUtxosFromTx.d.ts +3 -3
  36. package/lib/src/common/utxobased/engine/utils.d.ts +2 -2
  37. package/lib/src/common/utxobased/keymanager/keymanager.d.ts +3 -3
  38. package/lib/src/common/utxobased/network/Blockbook.d.ts +8 -7
  39. package/lib/src/common/utxobased/network/BlockbookElectrum.d.ts +4 -2
  40. package/lib/src/common/utxobased/network/Socket.d.ts +10 -8
  41. package/lib/src/util/uriKeyParams.d.ts +4 -0
  42. package/lib/util/uriKeyParams.js +20 -0
  43. package/package.json +1 -1
  44. /package/lib/test/common/utxobased/db/{Processor.spec.d.ts → DataLayer.spec.d.ts} +0 -0
@@ -10,13 +10,16 @@
10
10
 
11
11
  var _cleaners = require('cleaners');
12
12
 
13
+ var _urlparse = require('url-parse'); var _urlparse2 = _interopRequireDefault(_urlparse);
13
14
 
15
+ var _uriKeyParams = require('../../../util/uriKeyParams');
14
16
  var _utils = require('../../plugin/utils');
15
17
 
18
+
16
19
  var _nodejsWS = require('./nodejsWS');
17
20
  var _SocketEmitter = require('./SocketEmitter');
18
21
  var _socketQueue = require('./socketQueue');
19
- var _types3 = require('./types');
22
+ var _types5 = require('./types');
20
23
  var _windowWS = require('./windowWS');
21
24
 
22
25
  const TIMER_SLACK = 500
@@ -76,6 +79,12 @@ const WAKE_UP_MS = 5000 // interval at which we wakeUp and potentially onQueueSp
76
79
 
77
80
 
78
81
 
82
+
83
+
84
+
85
+
86
+
87
+
79
88
 
80
89
 
81
90
 
@@ -118,7 +127,6 @@ const asResponseDefault = (raw) => [
118
127
  const version = ''
119
128
  const socketQueueId = walletId + '==' + uri
120
129
  const subscriptions = {}
121
- let onQueueSpace = config.onQueueSpaceCB
122
130
  let pendingRequests = {}
123
131
  let nextId = 0
124
132
  let lastKeepAlive = 0
@@ -131,7 +139,7 @@ const asResponseDefault = (raw) => [
131
139
 
132
140
  const handleError = (e) => {
133
141
  if (trackedError == null) trackedError = e
134
- if (connected && socket != null && socket.readyState === _types3.ReadyState.OPEN)
142
+ if (connected && socket != null && socket.readyState === _types5.ReadyState.OPEN)
135
143
  disconnect()
136
144
  else cancelConnect = true
137
145
  log.error('handled error!', e)
@@ -159,11 +167,9 @@ const asResponseDefault = (raw) => [
159
167
  cancelConnect = false
160
168
  trackedError = undefined
161
169
  for (const request of Object.values(pendingRequests)) {
162
- try {
163
- request.task.deferred.reject(errObj)
164
- } catch (e) {
170
+ request.generator.throw(errObj).catch(e => {
165
171
  log.error(e.message)
166
- }
172
+ })
167
173
  }
168
174
  pendingRequests = {}
169
175
  try {
@@ -211,20 +217,21 @@ const asResponseDefault = (raw) => [
211
217
  lastWakeUp = Date.now()
212
218
  if (connected && version != null) {
213
219
  while (Object.keys(pendingRequests).length < queueSize) {
214
- const task = await onQueueSpace(uri)
215
- if (task == null) break
220
+ const generator = await config.taskGeneratorFn(uri)
221
+ const result = await generator.next()
222
+ const task = result.value
216
223
  if (typeof task === 'boolean') {
217
224
  if (task) continue
218
- break
225
+ else break
219
226
  }
220
- submitTask(task)
227
+ instance.submitTask(task, generator)
221
228
  }
222
229
  }
223
230
  }
224
231
 
225
232
  // add any exception, since the passed in template parameter needs to be re-assigned
226
233
  const subscribe = (subscription) => {
227
- if (socket != null && socket.readyState === _types3.ReadyState.OPEN && connected) {
234
+ if (socket != null && socket.readyState === _types5.ReadyState.OPEN && connected) {
228
235
  const id = subscription.method
229
236
  const message = {
230
237
  id,
@@ -236,19 +243,11 @@ const asResponseDefault = (raw) => [
236
243
  }
237
244
  }
238
245
 
239
- // add any exception, since the passed in template parameter needs to be re-assigned
240
- const submitTask = (task) => {
241
- const id = (nextId++).toString()
242
- const request = { task, startTime: Date.now() }
243
- pendingRequests[id] = request
244
- transmitRequest(id, request)
245
- }
246
-
247
246
  const transmitRequest = (id, request) => {
248
247
  const now = Date.now()
249
248
  if (
250
249
  socket != null &&
251
- socket.readyState === _types3.ReadyState.OPEN &&
250
+ socket.readyState === _types5.ReadyState.OPEN &&
252
251
  connected &&
253
252
  !cancelConnect
254
253
  ) {
@@ -278,11 +277,11 @@ const asResponseDefault = (raw) => [
278
277
 
279
278
  for (const [id, request] of Object.entries(pendingRequests)) {
280
279
  if (request.startTime + timeout < now) {
281
- try {
282
- request.task.deferred.reject(new Error(`Timeout for request ${id}`))
283
- } catch (e) {
284
- log.error(e.message)
285
- }
280
+ request.generator
281
+ .throw(new Error(`Timeout for request ${id}`))
282
+ .catch(e => {
283
+ log.error(e.message)
284
+ })
286
285
  _utils.removeItem.call(void 0, pendingRequests, id)
287
286
  }
288
287
  }
@@ -347,16 +346,29 @@ const asResponseDefault = (raw) => [
347
346
  'message' in error ? error.message : error.connected
348
347
  throw new Error(errorMessage)
349
348
  }
349
+ let nextValue
350
350
  if (request.task.cleaner != null) {
351
- request.task.deferred.resolve(
352
- request.task.cleaner(responseMessage.data)
353
- )
351
+ nextValue = request.task.cleaner(responseMessage.data)
354
352
  } else {
355
- request.task.deferred.resolve(responseMessage.data)
353
+ nextValue = responseMessage.data
356
354
  }
355
+ request.generator
356
+ .next(nextValue)
357
+ .then(result => {
358
+ const task = result.value
359
+ if (typeof task === 'boolean') {
360
+ return
361
+ }
362
+ instance.submitTask(task, request.generator)
363
+ })
364
+ .catch(e => {
365
+ log.error(e.message)
366
+ })
357
367
  } catch (error) {
358
368
  console.log({ uri, error, response: responseMessage, request })
359
- request.task.deferred.reject(error)
369
+ request.generator.throw(error).catch(e => {
370
+ log.error(e.message)
371
+ })
360
372
  }
361
373
  continue
362
374
  }
@@ -375,9 +387,9 @@ const asResponseDefault = (raw) => [
375
387
  setupTimer()
376
388
 
377
389
  // return a Socket
378
- return {
390
+ const instance = {
379
391
  get readyState() {
380
- return _nullishCoalesce(_optionalChain([socket, 'optionalAccess', _2 => _2.readyState]), () => ( _types3.ReadyState.CLOSED))
392
+ return _nullishCoalesce(_optionalChain([socket, 'optionalAccess', _2 => _2.readyState]), () => ( _types5.ReadyState.CLOSED))
381
393
  },
382
394
 
383
395
  async connect() {
@@ -396,11 +408,23 @@ const asResponseDefault = (raw) => [
396
408
  onClose: onSocketClose
397
409
  }
398
410
 
399
- // Append "/websocket" if needed:
411
+ // Append "/websocket" if the uri has no explicit path:
412
+ // We treat URIs with any path or a single trailing slash as having
413
+ // an explicit path.
400
414
  let fullUri = uri
401
415
  if (uri.startsWith('wss:') || uri.startsWith('ws:')) {
402
- fullUri = uri.replace(/\/websocket\/?$/, '') + '/websocket'
416
+ // There is no path and the uri has no trailing slash
417
+ const pathIsExplicitlyEmpty =
418
+ !uri.endsWith('/') && _urlparse2.default.call(void 0, uri).pathname === '/'
419
+ // If path is explicitly empty, then append /websocket
420
+ if (pathIsExplicitlyEmpty) {
421
+ fullUri = uri + '/websocket'
422
+ }
403
423
  }
424
+
425
+ // Replace any "key params" in the URIs (e.g. `%{nowNodesApiKey}`)
426
+ fullUri = _uriKeyParams.replaceKeyParams.call(void 0, fullUri, config.initOptions)
427
+
404
428
  if (uri.startsWith('electrumwss:')) {
405
429
  fullUri = uri.replace(/^electrumwss:/, 'wss:')
406
430
  }
@@ -423,15 +447,21 @@ const asResponseDefault = (raw) => [
423
447
  },
424
448
 
425
449
  isConnected() {
426
- return _optionalChain([socket, 'optionalAccess', _7 => _7.readyState]) === _types3.ReadyState.OPEN
450
+ return _optionalChain([socket, 'optionalAccess', _7 => _7.readyState]) === _types5.ReadyState.OPEN
427
451
  },
428
452
 
429
- submitTask,
430
-
431
- onQueueSpace(cb) {
432
- onQueueSpace = cb
453
+ submitTask: (
454
+ task,
455
+ generator
456
+ ) => {
457
+ const id = (nextId++).toString()
458
+ const request = { task, startTime: Date.now(), generator }
459
+ pendingRequests[id] = request
460
+ transmitRequest(id, request)
433
461
  },
434
462
 
435
463
  subscribe
436
464
  }
465
+
466
+ return instance
437
467
  } exports.makeSocket = makeSocket;
@@ -1,7 +1,7 @@
1
1
  import { Disklet } from 'disklet';
2
2
  import { EdgeIo, EdgeLog } from 'edge-core-js/types';
3
3
  import { UtxoUserSettings } from '../utxobased/engine/types';
4
- import { UtxoEngineState } from '../utxobased/engine/UtxoEngineState';
4
+ import { UtxoEngineProcessor } from '../utxobased/engine/UtxoEngineProcessor';
5
5
  /** A JSON object (as opposed to an array or primitive). */
6
6
  interface JsonObject {
7
7
  [name: string]: unknown;
@@ -19,8 +19,8 @@ export interface PluginStateSettings {
19
19
  log: EdgeLog;
20
20
  }
21
21
  export interface PluginState {
22
- addEngine: (engineState: UtxoEngineState) => void;
23
- removeEngine: (engineState: UtxoEngineState) => void;
22
+ addEngine: (engineProcessor: UtxoEngineProcessor) => void;
23
+ removeEngine: (engineProcessor: UtxoEngineProcessor) => void;
24
24
  dumpData: () => JsonObject;
25
25
  load: () => Promise<PluginState>;
26
26
  serverScoreDown: (uri: string) => void;
@@ -5,7 +5,7 @@ import { Cleaner } from 'cleaners';
5
5
  import { Disklet } from 'disklet';
6
6
  import { EdgeCurrencyEngineOptions, EdgeCurrencyInfo, EdgeCurrencyTools, EdgeIo, EdgeParsedUri, EdgeWalletInfo } from 'edge-core-js/types';
7
7
  import * as wif from 'wif';
8
- import { IProcessorTransaction, IUTXO } from '../utxobased/db/types';
8
+ import { TransactionData, UtxoData } from '../utxobased/db/types';
9
9
  import { UtxoInitOptions } from '../utxobased/engine/types';
10
10
  import { ScriptTemplates } from '../utxobased/info/scriptTemplates/types';
11
11
  import { UtxoPicker } from '../utxobased/keymanager/utxopicker';
@@ -23,7 +23,7 @@ export interface AddressPath {
23
23
  addressIndex: number;
24
24
  }
25
25
  export interface TxOptions {
26
- utxos?: IUTXO[];
26
+ utxos?: UtxoData[];
27
27
  subtractFee?: boolean;
28
28
  CPFP?: string;
29
29
  }
@@ -110,10 +110,10 @@ export interface EngineInfo {
110
110
  * Some currencies require an additional blockbook payload
111
111
  * 'getTransactionSpecific' in order to provide all relevant transaction
112
112
  * data. If this function is defined, it should merge the unknown `specialTx`
113
- * data from the Blockbook endpoint with the `IProcessorTransaction` object
113
+ * data from the Blockbook endpoint with the `TransactionData` object
114
114
  * which is stored to disk.
115
115
  **/
116
- txSpecificHandling?: (tx: IProcessorTransaction, specialTx: unknown) => IProcessorTransaction;
116
+ txSpecificHandling?: (tx: TransactionData, specialTx: unknown) => TransactionData;
117
117
  }
118
118
  export interface ServerConfig {
119
119
  type: 'blockbook-nownode';
@@ -1,12 +1,12 @@
1
1
  import { Disklet } from 'disklet';
2
2
  import { EdgeGetTransactionsOptions } from 'edge-core-js/types';
3
3
  import { AddressPath, ChangePath } from '../../plugin/types';
4
- import { IAddress, IProcessorTransaction, IUTXO } from './types';
5
- interface ProcessorConfig {
4
+ import { AddressData, TransactionData, UtxoData } from './types';
5
+ interface DataLayerConfig {
6
6
  disklet: Disklet;
7
7
  }
8
8
  interface SaveTransactionArgs {
9
- tx: IProcessorTransaction;
9
+ tx: TransactionData;
10
10
  scriptPubkeys?: string[];
11
11
  }
12
12
  interface FetchTransactionArgs {
@@ -28,20 +28,26 @@ interface DumpDataReturn {
28
28
  databaseName: string;
29
29
  data: unknown;
30
30
  }
31
- export interface Processor {
31
+ /**
32
+ * The Data Access Layer for the UTXO-based wallet engine.
33
+ *
34
+ * It provides all the methods necessary to interact with underlying
35
+ * database/storage mechanism.
36
+ */
37
+ export interface DataLayer {
32
38
  clearAll: () => Promise<void>;
33
39
  dumpData: () => Promise<DumpDataReturn[]>;
34
- saveUtxo: (utxo: IUTXO) => Promise<void>;
40
+ saveUtxo: (utxo: UtxoData) => Promise<void>;
35
41
  removeUtxos: (utxoIds: string[]) => Promise<void>;
36
- fetchUtxos: (args: FetchUtxosArgs) => Promise<Array<IUTXO | undefined>>;
37
- saveTransaction: (args: SaveTransactionArgs) => Promise<IProcessorTransaction>;
42
+ fetchUtxos: (args: FetchUtxosArgs) => Promise<Array<UtxoData | undefined>>;
43
+ saveTransaction: (args: SaveTransactionArgs) => Promise<TransactionData>;
38
44
  numTransactions: () => number;
39
45
  removeTransaction: (txId: string) => Promise<void>;
40
- fetchTransactions: (args: FetchTransactionArgs) => Promise<Array<IProcessorTransaction | undefined>>;
41
- saveAddress: (args: IAddress) => Promise<void>;
46
+ fetchTransactions: (args: FetchTransactionArgs) => Promise<Array<TransactionData | undefined>>;
47
+ saveAddress: (args: AddressData) => Promise<void>;
42
48
  numAddressesByFormatPath: (path: ChangePath) => number;
43
49
  lastUsedIndexByFormatPath: (path: ChangePath) => Promise<number>;
44
- fetchAddress: (args: AddressPath | string) => Promise<IAddress | undefined>;
50
+ fetchAddress: (args: AddressPath | string) => Promise<AddressData | undefined>;
45
51
  }
46
- export declare function makeProcessor(config: ProcessorConfig): Promise<Processor>;
52
+ export declare function makeDataLayer(config: DataLayerConfig): Promise<DataLayer>;
47
53
  export {};
@@ -1,14 +1,14 @@
1
1
  import { EdgeTransaction } from 'edge-core-js/types';
2
2
  import { PluginInfo } from '../../../plugin/types';
3
3
  import { UtxoWalletTools } from '../../engine/UtxoWalletTools';
4
- import { Processor } from '../Processor';
5
- import { IProcessorTransaction } from '../types';
6
- export declare const fromEdgeTransaction: (tx: EdgeTransaction) => IProcessorTransaction;
4
+ import { DataLayer } from '../DataLayer';
5
+ import { TransactionData } from '../types';
6
+ export declare const fromEdgeTransaction: (tx: EdgeTransaction) => TransactionData;
7
7
  interface ToEdgeTransactionArgs {
8
8
  walletId: string;
9
- tx: IProcessorTransaction;
9
+ tx: TransactionData;
10
10
  walletTools: UtxoWalletTools;
11
- processor: Processor;
11
+ dataLayer: DataLayer;
12
12
  pluginInfo: PluginInfo;
13
13
  }
14
14
  export declare const toEdgeTransaction: (args: ToEdgeTransactionArgs) => Promise<EdgeTransaction>;
@@ -1,10 +1,10 @@
1
1
  import { CountBase, CountBaseOptions, HashBase, HashBaseOptions, RangeBase, RangeBaseOptions } from 'baselet';
2
2
  import { ChangePath } from '../../../plugin/types';
3
- import { IAddress, IProcessorTransaction, IUTXO } from '../types';
3
+ import { AddressData, TransactionData, UtxoData } from '../types';
4
4
  export declare const addressPathToPrefix: (path: ChangePath) => string;
5
5
  export declare type ScriptPubkeyByPathBaselet = CountBase<string>;
6
6
  export declare const scriptPubkeyByPathOptions: CountBaseOptions;
7
- export declare type AddressByScriptPubkeyBaselet = HashBase<IAddress>;
7
+ export declare type AddressByScriptPubkeyBaselet = HashBase<AddressData>;
8
8
  export declare const addressByScriptPubkeyOptions: HashBaseOptions;
9
9
  export declare type LastUsedByFormatPathBaselet = HashBase<number>;
10
10
  export declare const lastUsedByFormatPathOptions: HashBaseOptions;
@@ -14,7 +14,7 @@ export interface TxIdByBlockHeight {
14
14
  }
15
15
  export declare type TxIdByBlockHeightBaselet = RangeBase<TxIdByBlockHeight, 'blockHeight', 'txid'>;
16
16
  export declare const txIdsByBlockHeightOptions: RangeBaseOptions<'blockHeight', 'txid'>;
17
- export declare type TxByIdBaselet = HashBase<IProcessorTransaction>;
17
+ export declare type TxByIdBaselet = HashBase<TransactionData>;
18
18
  export declare const txByIdOptions: HashBaseOptions;
19
19
  export interface TxIdByDate {
20
20
  txid: string;
@@ -22,7 +22,7 @@ export interface TxIdByDate {
22
22
  }
23
23
  export declare type TxIdByDateBaselet = RangeBase<TxIdByDate, 'date', 'txid'>;
24
24
  export declare const txIdsByDateOptions: RangeBaseOptions<'date', 'txid'>;
25
- export declare type UtxoByIdBaselet = HashBase<IUTXO>;
25
+ export declare type UtxoByIdBaselet = HashBase<UtxoData>;
26
26
  export declare const utxoByIdOptions: HashBaseOptions;
27
27
  export declare type UtxoIdsByScriptPubkeyBaselet = HashBase<string[]>;
28
28
  export declare const utxoIdsByScriptPubkeyOptions: HashBaseOptions;
@@ -1,7 +1,7 @@
1
1
  import { SoftPick } from '../../../util/typeUtil';
2
2
  import { AddressPath } from '../../plugin/types';
3
3
  import { ScriptTypeEnum } from '../keymanager/keymanager';
4
- export interface IAddress {
4
+ export interface AddressData {
5
5
  scriptPubkey: string;
6
6
  redeemScript?: string;
7
7
  lastQueriedBlockHeight: number;
@@ -11,8 +11,8 @@ export interface IAddress {
11
11
  used: boolean;
12
12
  balance?: string;
13
13
  }
14
- export declare const makeIAddress: (addressFields: SoftPick<IAddress, 'scriptPubkey'>) => IAddress;
15
- export interface IUTXO {
14
+ export declare const makeAddressData: (addressFields: SoftPick<AddressData, 'scriptPubkey'>) => AddressData;
15
+ export interface UtxoData {
16
16
  id: string;
17
17
  txid: string;
18
18
  vout: number;
@@ -24,26 +24,26 @@ export interface IUTXO {
24
24
  blockHeight: number;
25
25
  spent: boolean;
26
26
  }
27
- export declare const asIUTXO: import("cleaners").ObjectCleaner<IUTXO>;
28
- export interface IProcessorTransaction {
27
+ export declare const asUtxoData: import("cleaners").ObjectCleaner<UtxoData>;
28
+ export interface TransactionData {
29
29
  txid: string;
30
30
  hex: string;
31
31
  blockHeight: number;
32
32
  confirmations?: 'confirmed' | 'unconfirmed' | 'dropped' | number;
33
33
  date: number;
34
34
  fees: string;
35
- inputs: ITransactionInput[];
36
- outputs: ITransactionOutput[];
35
+ inputs: TransactionDataInput[];
36
+ outputs: TransactionDataOutput[];
37
37
  ourIns: string[];
38
38
  ourOuts: string[];
39
39
  ourAmount: string;
40
40
  }
41
- export interface ITransactionOutput {
41
+ export interface TransactionDataOutput {
42
42
  amount: string;
43
43
  n: number;
44
44
  scriptPubkey: string;
45
45
  }
46
- export interface ITransactionInput {
46
+ export interface TransactionDataInput {
47
47
  amount: string;
48
48
  n: number;
49
49
  outputIndex: number;
@@ -1,3 +1,3 @@
1
- import { Processor } from '../Processor';
2
- import { IProcessorTransaction, IUTXO } from '../types';
3
- export declare const utxoFromProcessorTransactionInput: (processor: Processor, processorTransaction: IProcessorTransaction, inputIndex: number) => Promise<IUTXO>;
1
+ import { DataLayer } from '../DataLayer';
2
+ import { TransactionData, UtxoData } from '../types';
3
+ export declare const utxoFromTransactionDataInput: (dataLayer: DataLayer, transactionData: TransactionData, inputIndex: number) => Promise<UtxoData>;
@@ -6,9 +6,9 @@ import { SafeWalletInfo } from '../keymanager/cleaners';
6
6
  import { Blockbook } from '../network/Blockbook';
7
7
  import { AddressResponse, AddressUtxosResponse, BlockbookTransaction } from '../network/blockbookApi';
8
8
  import Deferred from '../network/Deferred';
9
- import { WsTask } from '../network/Socket';
9
+ import { WsTask, WsTaskGenerator } from '../network/Socket';
10
10
  import { UtxoInitOptions } from './types';
11
- interface ServerState {
11
+ export interface ServerState {
12
12
  blockbook: Blockbook;
13
13
  blockSubscriptionStatus: 'unsubscribed' | 'subscribing' | 'subscribed';
14
14
  blockHeight: number;
@@ -25,7 +25,7 @@ interface ServerStateConfig {
25
25
  walletInfo: SafeWalletInfo;
26
26
  }
27
27
  export interface ServerStates {
28
- setPickNextTaskCB: (callback: (uri: string) => Promise<boolean | WsTask<any> | undefined>) => void;
28
+ setPickNextTaskCB: (callback: (uri: string) => AsyncGenerator<WsTask<unknown> | boolean>) => void;
29
29
  stop: () => void;
30
30
  serverCanGetTx: (uri: string, txid: string) => boolean;
31
31
  serverCanGetAddress: (uri: string, address: string) => boolean;
@@ -41,10 +41,10 @@ export interface ServerStates {
41
41
  addressQueryTask: (serverUri: string, address: string, params: {
42
42
  lastQueriedBlockHeight: number;
43
43
  page: number;
44
- }, deferred: Deferred<AddressResponse>) => WsTask<AddressResponse>;
45
- transactionQueryTask: (serverUri: string, txId: string, deferred: Deferred<BlockbookTransaction>) => WsTask<BlockbookTransaction>;
46
- transactionSpecialQueryTask: (serverUri: string, txId: string, deferred: Deferred<unknown>) => WsTask<unknown>;
47
- utxoListQueryTask: (serverUri: string, address: string, deferred: Deferred<AddressUtxosResponse>) => WsTask<AddressUtxosResponse>;
44
+ }) => WsTaskGenerator<AddressResponse>;
45
+ transactionQueryTask: (serverUri: string, txId: string) => WsTaskGenerator<BlockbookTransaction>;
46
+ transactionSpecialQueryTask: (serverUri: string, txId: string) => WsTaskGenerator<unknown>;
47
+ utxoListQueryTask: (serverUri: string, address: string) => WsTaskGenerator<AddressUtxosResponse>;
48
48
  }
49
49
  export declare function makeServerStates(config: ServerStateConfig): ServerStates;
50
50
  export {};
@@ -1,16 +1,15 @@
1
1
  import { EdgeFreshAddress, EdgeIo, EdgeLog, EdgeTransaction } from 'edge-core-js/types';
2
2
  import { EngineEmitter } from '../../plugin/EngineEmitter';
3
- import { PluginState } from '../../plugin/PluginState';
4
3
  import { ChangePath, CurrencyFormat, EngineConfig, PluginInfo } from '../../plugin/types';
5
- import { Processor } from '../db/Processor';
6
- import { IAddress, IProcessorTransaction, IUTXO } from '../db/types';
4
+ import { DataLayer } from '../db/DataLayer';
5
+ import { AddressData, TransactionData, UtxoData } from '../db/types';
7
6
  import { SafeWalletInfo } from '../keymanager/cleaners';
8
- import { BlockbookAccountUtxo } from '../network/blockbookApi';
7
+ import { AddressResponse, AddressUtxosResponse, BlockbookAccountUtxo, TransactionResponse } from '../network/blockbookApi';
9
8
  import { WsTask } from '../network/Socket';
10
9
  import AwaitLock from './await-lock';
11
10
  import { ServerStates } from './ServerStates';
12
11
  import { UtxoWalletTools } from './UtxoWalletTools';
13
- export interface UtxoEngineState {
12
+ export interface UtxoEngineProcessor {
14
13
  processedPercent: number;
15
14
  start: () => Promise<void>;
16
15
  stop: () => Promise<void>;
@@ -25,47 +24,49 @@ export interface UtxoEngineState {
25
24
  getServerList: () => string[];
26
25
  setServerList: (serverList: string[]) => void;
27
26
  loadWifs: (wifs: string[]) => Promise<void>;
28
- processUtxos: (utxos: IUTXO[]) => Promise<void>;
27
+ processUtxos: (utxos: UtxoData[]) => Promise<void>;
29
28
  }
30
- export interface UtxoEngineStateConfig extends EngineConfig {
29
+ export interface UtxoEngineProcessorConfig extends EngineConfig {
31
30
  walletTools: UtxoWalletTools;
32
31
  walletInfo: SafeWalletInfo;
33
- processor: Processor;
32
+ dataLayer: DataLayer;
34
33
  }
35
- export declare function makeUtxoEngineState(config: UtxoEngineStateConfig): UtxoEngineState;
36
- interface CommonArgs {
34
+ export declare function makeUtxoEngineProcessor(config: UtxoEngineProcessorConfig): UtxoEngineProcessor;
35
+ interface CommonParams {
37
36
  pluginInfo: PluginInfo;
38
37
  walletInfo: SafeWalletInfo;
39
38
  walletTools: UtxoWalletTools;
40
- processor: Processor;
39
+ dataLayer: DataLayer;
41
40
  emitter: EngineEmitter;
42
41
  taskCache: TaskCache;
43
42
  updateProgressRatio: () => void;
44
43
  io: EdgeIo;
45
44
  log: EdgeLog;
46
45
  serverStates: ServerStates;
47
- pluginState: PluginState;
48
46
  walletFormats: CurrencyFormat[];
49
47
  lock: AwaitLock;
50
48
  }
51
49
  interface TaskCache {
52
- blockWatching: boolean;
50
+ readonly addressForTransactionsCache: AddressForTransactionsCache;
51
+ readonly addressForUtxosCache: AddressForUtxosCache;
53
52
  readonly addressSubscribeCache: AddressSubscribeCache;
54
- readonly addressUtxoCache: AddressUtxoCache;
55
- readonly rawUtxoCache: RawUtxoCache;
56
- readonly processorUtxoCache: ProcessorUtxoCache;
57
- readonly addressTransactionCache: AddressTransactionCache;
58
- readonly updateTransactionCache: UpdateTransactionCache;
59
- readonly updateTransactionSpecificCache: UpdateTransactionSpecificCache;
53
+ readonly blockbookUtxoCache: BlockbookUtxoCache;
54
+ readonly dataLayerUtxoCache: DataLayerUtxoCache;
55
+ readonly transactionSpecificUpdateCache: TransactionSpecificUpdateCache;
56
+ readonly transactionUpdateCache: TransactionUpdateCache;
60
57
  }
61
- interface UpdateTransactionCache {
58
+ interface AddressForTransactionsCache {
62
59
  [key: string]: {
63
60
  processing: boolean;
61
+ path: ChangePath;
62
+ page: number;
63
+ blockHeight: number;
64
64
  };
65
65
  }
66
- interface UpdateTransactionSpecificCache {
66
+ interface AddressForUtxosCache {
67
67
  [key: string]: {
68
68
  processing: boolean;
69
+ path: ChangePath;
69
70
  };
70
71
  }
71
72
  interface AddressSubscribeCache {
@@ -74,45 +75,46 @@ interface AddressSubscribeCache {
74
75
  path: ChangePath;
75
76
  };
76
77
  }
77
- interface AddressUtxoCache {
78
+ interface DataLayerUtxoCache {
78
79
  [key: string]: {
79
80
  processing: boolean;
81
+ full: boolean;
82
+ utxos: UtxoData[];
80
83
  path: ChangePath;
81
84
  };
82
85
  }
83
- interface ProcessorUtxoCache {
86
+ interface BlockbookUtxoCache {
84
87
  [key: string]: {
88
+ blockbookUtxo: BlockbookAccountUtxo;
85
89
  processing: boolean;
86
- full: boolean;
87
- utxos: IUTXO[];
88
90
  path: ChangePath;
91
+ address: AddressData;
92
+ requiredCount: number;
89
93
  };
90
94
  }
91
- interface RawUtxoCache {
95
+ interface TransactionSpecificUpdateCache {
92
96
  [key: string]: {
93
- blockbookUtxo: BlockbookAccountUtxo;
94
97
  processing: boolean;
95
- path: ChangePath;
96
- address: IAddress;
97
- requiredCount: number;
98
98
  };
99
99
  }
100
- interface AddressTransactionCache {
100
+ interface TransactionUpdateCache {
101
101
  [key: string]: {
102
102
  processing: boolean;
103
- path: ChangePath;
104
- page: number;
105
- blockHeight: number;
106
103
  };
107
104
  }
108
- interface TransactionChangedArgs {
109
- walletId: string;
110
- tx: IProcessorTransaction;
105
+ export declare const transactionChanged: (args: {
106
+ dataLayer: DataLayer;
111
107
  emitter: EngineEmitter;
112
- walletTools: UtxoWalletTools;
113
108
  pluginInfo: PluginInfo;
114
- processor: Processor;
115
- }
116
- export declare const transactionChanged: (args: TransactionChangedArgs) => Promise<void>;
117
- export declare const pickNextTask: (args: CommonArgs, serverUri: string) => Promise<WsTask<any> | undefined | boolean>;
109
+ tx: TransactionData;
110
+ walletTools: UtxoWalletTools;
111
+ walletId: string;
112
+ }) => Promise<void>;
113
+ /**
114
+ * The pickNextTask generator is responsible for selecting the next WsTask
115
+ * to be done by the network layer. It will yield WsTasks or booleans for early
116
+ * exit, and it will return a boolean when it's done.
117
+ */
118
+ declare type PickNextTaskGenerator = AsyncGenerator<boolean | WsTask<unknown>, boolean, AddressUtxosResponse & AddressResponse & TransactionResponse>;
119
+ export declare function pickNextTask(common: CommonParams, serverUri: string): PickNextTaskGenerator;
118
120
  export {};
@@ -1,9 +1,9 @@
1
1
  import { EdgeSpendInfo } from 'edge-core-js/types';
2
2
  import { Input, Output } from '../keymanager/utxopicker/types';
3
- export declare type UtxoInitOptions = ReturnType<typeof asUtxoInitOptions>;
4
- export declare const asUtxoInitOptions: import("cleaners").ObjectCleaner<{
5
- nowNodeApiKey: string | undefined;
6
- }>;
3
+ export interface UtxoInitOptions {
4
+ nowNodesApiKey?: string;
5
+ }
6
+ export declare const asUtxoInitOptions: import("cleaners").ObjectCleaner<UtxoInitOptions>;
7
7
  export declare const asUtxoUserSettings: import("cleaners").ObjectCleaner<{
8
8
  blockbookServers: string[];
9
9
  enableCustomServers: boolean;
@@ -1,4 +1,4 @@
1
1
  import { EngineInfo } from '../../../plugin/types';
2
- import { Processor } from '../../db/Processor';
3
- import { IProcessorTransaction, IUTXO } from '../../db/types';
4
- export declare const getOwnUtxosFromTx: (engineInfo: EngineInfo, processor: Processor, tx: IProcessorTransaction) => Promise<IUTXO[]>;
2
+ import { DataLayer } from '../../db/DataLayer';
3
+ import { TransactionData, UtxoData } from '../../db/types';
4
+ export declare const getOwnUtxosFromTx: (engineInfo: EngineInfo, dataLayer: DataLayer, tx: TransactionData) => Promise<UtxoData[]>;