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
@@ -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[]>;
@@ -1,7 +1,7 @@
1
1
  import { Disklet } from 'disklet';
2
2
  import { EdgeParsedUri } from 'edge-core-js/types';
3
3
  import { ChangePath, CurrencyFormat, EngineInfo } from '../../plugin/types';
4
- import { IUTXO } from '../db/types';
4
+ import { UtxoData } from '../db/types';
5
5
  import { ScriptTemplates } from '../info/scriptTemplates/types';
6
6
  import { PrivateKey } from '../keymanager/cleaners';
7
7
  import { AddressTypeEnum, BIP43PurposeTypeEnum, ScriptTypeEnum } from '../keymanager/keymanager';
@@ -55,4 +55,4 @@ export declare const parsePathname: (args: {
55
55
  pathname: string;
56
56
  coin: string;
57
57
  }) => EdgeParsedUri;
58
- export declare const sumUtxos: (utxos: IUTXO[]) => string;
58
+ export declare const sumUtxos: (utxos: UtxoData[]) => string;
@@ -1,6 +1,6 @@
1
1
  import { EdgeLog, EdgeMemo } from 'edge-core-js/types';
2
2
  import { ChangePath, FeeInfo } from '../../plugin/types';
3
- import { IUTXO } from '../db/types';
3
+ import { UtxoData } from '../db/types';
4
4
  import { ScriptTemplate, ScriptTemplates } from '../info/scriptTemplates/types';
5
5
  import * as utxopicker from './utxopicker';
6
6
  export declare enum BIP43PurposeTypeEnum {
@@ -132,8 +132,8 @@ export interface TxOutput {
132
132
  amount: number;
133
133
  }
134
134
  export interface MakeTxArgs {
135
- forceUseUtxo: IUTXO[];
136
- utxos: IUTXO[];
135
+ forceUseUtxo: UtxoData[];
136
+ utxos: UtxoData[];
137
137
  targets: MakeTxTarget[];
138
138
  memos: EdgeMemo[];
139
139
  feeRate: number;
@@ -1,9 +1,10 @@
1
1
  import { Cleaner } from 'cleaners';
2
2
  import { EdgeLog, EdgeTransaction } from 'edge-core-js/types';
3
3
  import { EngineEmitter } from '../../plugin/EngineEmitter';
4
+ import { UtxoInitOptions } from '../engine/types';
4
5
  import { AddressResponse, AddresssMessageParams, AddressUtxosResponse, BlockbookTask, BlockbookTransaction, BroadcastTxResponse, InfoResponse, SubscribeAddressResponse, TransactionResponse } from './blockbookApi';
5
6
  import Deferred from './Deferred';
6
- import { OnQueueSpaceCB, WsResponse, WsTask } from './Socket';
7
+ import { TaskGeneratorFn, WsResponse, WsTaskGenerator } from './Socket';
7
8
  import { SocketEmitter } from './SocketEmitter';
8
9
  export declare type WatchAddressesCB = (response: SubscribeAddressResponse) => void | Promise<void>;
9
10
  export declare type WatchBlocksCB = () => void | Promise<void>;
@@ -18,26 +19,26 @@ export interface Blockbook {
18
19
  fetchTransaction: (hash: string) => Promise<TransactionResponse>;
19
20
  watchAddresses: (addresses: string[], deferredAddressSub: Deferred<unknown>) => void;
20
21
  watchBlocks: (deferredBlockSub: Deferred<unknown>) => void;
21
- onQueueSpace: (cb: OnQueueSpaceCB) => void;
22
22
  promisifyWsMessage: <T>(message: BlockbookTask<T>) => Promise<T>;
23
23
  addressQueryTask: (address: string, params: {
24
24
  asBlockbookAddress?: Cleaner<string> | undefined;
25
25
  lastQueriedBlockHeight: number;
26
26
  page: number;
27
- }, deferred: Deferred<AddressResponse>) => WsTask<AddressResponse>;
28
- transactionQueryTask: (txId: string, deferred: Deferred<BlockbookTransaction>) => WsTask<BlockbookTransaction>;
29
- transactionSpecialQueryTask: (txId: string, deferred: Deferred<unknown>) => WsTask<unknown>;
27
+ }) => WsTaskGenerator<AddressResponse>;
28
+ transactionQueryTask: (txId: string) => WsTaskGenerator<BlockbookTransaction>;
29
+ transactionSpecialQueryTask: (txId: string) => WsTaskGenerator<unknown>;
30
30
  utxoListQueryTask: (address: string, params: {
31
31
  asBlockbookAddress?: Cleaner<string> | undefined;
32
- }, deferred: Deferred<AddressUtxosResponse>) => WsTask<AddressUtxosResponse>;
32
+ }) => WsTaskGenerator<AddressUtxosResponse>;
33
33
  }
34
34
  interface BlockbookConfig {
35
35
  asAddress?: Cleaner<string>;
36
36
  asResponse?: Cleaner<WsResponse>;
37
37
  connectionUri: string;
38
38
  engineEmitter: EngineEmitter;
39
+ initOptions: UtxoInitOptions;
39
40
  log: EdgeLog;
40
- onQueueSpaceCB: OnQueueSpaceCB;
41
+ taskGeneratorFn: TaskGeneratorFn;
41
42
  ping?: () => Promise<void>;
42
43
  socketEmitter: SocketEmitter;
43
44
  walletId: string;
@@ -2,15 +2,17 @@ import { Cleaner } from 'cleaners';
2
2
  import { EdgeLog } from 'edge-core-js/types';
3
3
  import { EngineEmitter } from '../../plugin/EngineEmitter';
4
4
  import { PluginInfo } from '../../plugin/types';
5
+ import { UtxoInitOptions } from '../engine/types';
5
6
  import { Blockbook } from './Blockbook';
6
- import { OnQueueSpaceCB } from './Socket';
7
+ import { TaskGeneratorFn } from './Socket';
7
8
  import { SocketEmitter } from './SocketEmitter';
8
9
  export interface BlockbookElectrumConfig {
9
10
  asAddress?: Cleaner<string>;
10
11
  connectionUri: string;
11
12
  engineEmitter: EngineEmitter;
13
+ initOptions: UtxoInitOptions;
12
14
  log: EdgeLog;
13
- onQueueSpaceCB: OnQueueSpaceCB;
15
+ taskGeneratorFn: TaskGeneratorFn;
14
16
  pluginInfo: PluginInfo;
15
17
  socketEmitter: SocketEmitter;
16
18
  walletId: string;
@@ -1,5 +1,6 @@
1
1
  import { Cleaner } from 'cleaners';
2
2
  import { EdgeLog } from 'edge-core-js/types';
3
+ import { UtxoInitOptions } from '../engine/types';
3
4
  import Deferred from './Deferred';
4
5
  import { SocketEmitter } from './SocketEmitter';
5
6
  import { ReadyState } from './types';
@@ -7,9 +8,10 @@ export declare type OnFailHandler = (error: Error) => void;
7
8
  export interface WsTask<T> {
8
9
  method: string;
9
10
  params: unknown;
10
- deferred: Deferred<T>;
11
11
  cleaner?: Cleaner<T>;
12
12
  }
13
+ export declare type WsTaskGenerator<T> = Generator<WsTask<T>, T, T>;
14
+ export declare type WsTaskAsyncGenerator<T> = AsyncGenerator<WsTask<T> | boolean, boolean, T>;
13
15
  export interface WsSubscription<T> {
14
16
  method: string;
15
17
  params: unknown;
@@ -22,21 +24,21 @@ export interface Socket {
22
24
  readyState: ReadyState;
23
25
  connect: () => Promise<void>;
24
26
  disconnect: () => void;
25
- submitTask: <T>(task: WsTask<T>) => void;
26
- onQueueSpace: (cb: OnQueueSpaceCB) => void;
27
+ submitTask: <T>(task: WsTask<T>, generator: WsTaskAsyncGenerator<T>) => void;
27
28
  subscribe: <T>(subscription: WsSubscription<T>) => void;
28
29
  isConnected: () => boolean;
29
30
  }
30
- export declare type OnQueueSpaceCB = (uri: string) => Promise<WsTask<unknown> | boolean | undefined>;
31
+ export declare type TaskGeneratorFn = (uri: string) => WsTaskAsyncGenerator<unknown>;
31
32
  interface SocketConfig {
32
33
  asResponse?: Cleaner<WsResponse>;
34
+ emitter: SocketEmitter;
35
+ healthCheck: () => Promise<void>;
36
+ initOptions: UtxoInitOptions;
37
+ log: EdgeLog;
33
38
  queueSize?: number;
39
+ taskGeneratorFn: TaskGeneratorFn;
34
40
  timeout?: number;
35
41
  walletId: string;
36
- emitter: SocketEmitter;
37
- log: EdgeLog;
38
- healthCheck: () => Promise<void>;
39
- onQueueSpaceCB: OnQueueSpaceCB;
40
42
  }
41
43
  export declare type WsResponse = WsResponseMessage[];
42
44
  export interface WsResponseMessage {
@@ -1,7 +1,11 @@
1
1
  export interface InnerSocketCallbacks {
2
- onError: (error?: unknown) => void;
2
+ /**
3
+ * Called when the socket closes.
4
+ * See rfc6455 section 7.4.1 for status codes.
5
+ */
6
+ onClose: (code: number, reason: string) => void;
7
+ onError: (error?: Event | Error) => void;
3
8
  onMessage: (message: string) => void;
4
- onClose: (error?: Error) => void;
5
9
  onOpen: () => void;
6
10
  }
7
11
  export declare enum ReadyState {
@@ -0,0 +1,4 @@
1
+ export declare function getUriKeyParams(uri: string): string[];
2
+ export declare function replaceKeyParams<T extends string>(uri: string, options: {
3
+ [P in T]?: string;
4
+ }): string;
@@ -0,0 +1,20 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function getUriKeyParams(uri) {
2
+ const params = uri.match(/%\{(\w|\d)+\}/g)
3
+ return _nullishCoalesce(params, () => ( []))
4
+ } exports.getUriKeyParams = getUriKeyParams;
5
+
6
+ function replaceKeyParams(
7
+ uri,
8
+ options
9
+ ) {
10
+ const keyParams = getUriKeyParams(uri)
11
+
12
+ for (const keyParam of keyParams) {
13
+ const keyIndex = keyParam.replace(/%|{|}/g, '')
14
+ const key = options[keyIndex]
15
+ if (key == null) throw new Error(`Missing key for connection URI ${uri}`)
16
+ uri = uri.replace(keyParam, key)
17
+ }
18
+
19
+ return uri
20
+ } exports.replaceKeyParams = replaceKeyParams;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-plugins",
3
- "version": "3.2.1",
3
+ "version": "3.3.1",
4
4
  "description": "Edge currency plugins to fetch and process wallet accounts, balances and transactions.",
5
5
  "homepage": "https://edge.app/",
6
6
  "repository": "https://github.com/EdgeApp/edge-currency-plugins",
@@ -120,4 +120,4 @@
120
120
  "wif": "^2.0.6"
121
121
  },
122
122
  "react-native": "./lib/react-native.js"
123
- }
123
+ }