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
@@ -13,8 +13,10 @@ var _types3 = require('../../plugin/types');
13
13
 
14
14
 
15
15
 
16
- const asUtxoInitOptions = _cleaners.asObject.call(void 0, {
17
- nowNodeApiKey: _cleaners.asOptional.call(void 0, _cleaners.asString)
16
+
17
+
18
+ const asUtxoInitOptions = _cleaners.asObject({
19
+ nowNodesApiKey: _cleaners.asOptional.call(void 0, _cleaners.asString)
18
20
  }); exports.asUtxoInitOptions = asUtxoInitOptions
19
21
 
20
22
  const asUtxoUserSettings = _cleaners.asObject.call(void 0, {
@@ -6,7 +6,7 @@ var _utils = require('../utils');
6
6
 
7
7
  const getOwnUtxosFromTx = async (
8
8
  engineInfo,
9
- processor,
9
+ dataLayer,
10
10
  tx
11
11
  ) => {
12
12
  const ownUtxos = []
@@ -18,12 +18,12 @@ var _utils = require('../utils');
18
18
  const inputUtxoIds = tx.inputs.map(
19
19
  input => `${input.txId}_${input.outputIndex}`
20
20
  )
21
- const inputUtxos = await processor.fetchUtxos({
21
+ const inputUtxos = await dataLayer.fetchUtxos({
22
22
  utxoIds: inputUtxoIds
23
23
  })
24
24
  for (const utxo of inputUtxos) {
25
25
  if (utxo == null) continue
26
- // Must create a new IUTXO object when mutating processor objects because
26
+ // Must create a new UtxoData object when mutating DataLayer objects because
27
27
  // memlet may keep a reference in memory.
28
28
  ownUtxos.push({ ...utxo, spent: true })
29
29
  }
@@ -34,7 +34,7 @@ var _utils = require('../utils');
34
34
 
35
35
  for (const output of tx.outputs) {
36
36
  const scriptPubkey = output.scriptPubkey
37
- const address = await processor.fetchAddress(scriptPubkey)
37
+ const address = await dataLayer.fetchAddress(scriptPubkey)
38
38
  if (address != null) {
39
39
  const id = `${tx.txid}_${output.n}`
40
40
  const path = address.path
@@ -38,7 +38,8 @@ const currencyInfo = {
38
38
  'wss://btc2.trezor.io',
39
39
  'wss://btc3.trezor.io',
40
40
  'wss://btc4.trezor.io',
41
- 'wss://btc5.trezor.io'
41
+ 'wss://btc5.trezor.io',
42
+ 'wss://btcbook.nownodes.io/wss/%{nowNodesApiKey}'
42
43
  ],
43
44
  enableCustomServers: false
44
45
  },
@@ -40,7 +40,8 @@ const currencyInfo = {
40
40
  'wss://bch2.trezor.io',
41
41
  'wss://bch3.trezor.io',
42
42
  'wss://bch4.trezor.io',
43
- 'wss://bch5.trezor.io'
43
+ 'wss://bch5.trezor.io',
44
+ 'wss://bchbook.nownodes.io/wss/%{nowNodesApiKey}'
44
45
  ],
45
46
  enableCustomServers: false
46
47
  },
@@ -38,7 +38,8 @@ const currencyInfo = {
38
38
  'wss://dash2.trezor.io',
39
39
  'wss://dash3.trezor.io',
40
40
  'wss://dash4.trezor.io',
41
- 'wss://dash5.trezor.io'
41
+ 'wss://dash5.trezor.io',
42
+ 'wss://dashbook.nownodes.io/wss/%{nowNodesApiKey}'
42
43
  ],
43
44
  enableCustomServers: false
44
45
  },
@@ -30,7 +30,11 @@ const currencyInfo = {
30
30
  ..._commonInfo.legacyMemoInfo,
31
31
  defaultSettings: {
32
32
  customFeeSettings: ['satPerByte'],
33
- blockbookServers: ['wss://dgb1.trezor.io', 'wss://dgb2.trezor.io'],
33
+ blockbookServers: [
34
+ 'wss://dgb1.trezor.io',
35
+ 'wss://dgb2.trezor.io',
36
+ 'wss://dgbbook.nownodes.io/wss/%{nowNodesApiKey}'
37
+ ],
34
38
  enableCustomServers: false
35
39
  },
36
40
  metaTokens: []
@@ -34,7 +34,8 @@ const currencyInfo = {
34
34
  'wss://doge2.trezor.io',
35
35
  'wss://doge3.trezor.io',
36
36
  'wss://doge4.trezor.io',
37
- 'wss://doge5.trezor.io'
37
+ 'wss://doge5.trezor.io',
38
+ 'wss://dogebook.nownodes.io/wss/%{nowNodesApiKey}'
38
39
  ],
39
40
  enableCustomServers: false
40
41
  },
@@ -36,7 +36,10 @@ const currencyInfo = {
36
36
  ..._commonInfo.legacyMemoInfo,
37
37
  defaultSettings: {
38
38
  customFeeSettings: ['satPerByte'],
39
- blockbookServers: ['wss://blockbook.groestlcoin.org'],
39
+ blockbookServers: [
40
+ 'wss://blockbook.groestlcoin.org',
41
+ 'wss://grsbook.nownodes.io/wss/%{nowNodesApiKey}'
42
+ ],
40
43
  enableCustomServers: false
41
44
  },
42
45
  metaTokens: []
@@ -36,7 +36,8 @@ var _commonInfo = require('./commonInfo');
36
36
  'wss://ltc2.trezor.io',
37
37
  'wss://ltc3.trezor.io',
38
38
  'wss://ltc4.trezor.io',
39
- 'wss://ltc5.trezor.io'
39
+ 'wss://ltc5.trezor.io',
40
+ 'wss://ltcbook.nownodes.io/wss/%{nowNodesApiKey}'
40
41
  ],
41
42
  enableCustomServers: false
42
43
  },
@@ -30,7 +30,10 @@ var _commonInfo = require('./commonInfo');
30
30
  ..._commonInfo.legacyMemoInfo,
31
31
  defaultSettings: {
32
32
  customFeeSettings: ['satPerByte'],
33
- blockbookServers: ['wss://blockbook.firo.org'],
33
+ blockbookServers: [
34
+ 'wss://blockbook.firo.org',
35
+ 'wss://firobook.nownodes.io/wss/%{nowNodesApiKey}'
36
+ ],
34
37
  enableCustomServers: false
35
38
  },
36
39
  metaTokens: []
@@ -22,19 +22,17 @@ var _constants = require('../engine/constants');
22
22
 
23
23
 
24
24
 
25
+
25
26
 
26
27
  var _blockbookApi = require('./blockbookApi');
27
28
  var _Deferred = require('./Deferred'); var _Deferred2 = _interopRequireDefault(_Deferred);
28
- var _Socket = require('./Socket');
29
-
30
-
31
-
32
29
 
33
30
 
34
31
 
35
32
 
36
33
 
37
34
 
35
+ var _Socket = require('./Socket');
38
36
 
39
37
 
40
38
 
@@ -116,7 +114,7 @@ var _Socket = require('./Socket');
116
114
  connectionUri,
117
115
  engineEmitter,
118
116
  log,
119
- onQueueSpaceCB,
117
+ taskGeneratorFn,
120
118
  socketEmitter,
121
119
  walletId
122
120
  } = config
@@ -172,13 +170,24 @@ var _Socket = require('./Socket');
172
170
  return await instance.promisifyWsMessage(_blockbookApi.transactionMessage.call(void 0, hash))
173
171
  },
174
172
 
175
- onQueueSpace(cb) {
176
- socket.onQueueSpace(cb)
177
- },
178
-
179
173
  async promisifyWsMessage(message) {
180
174
  const deferred = new _Deferred2.default()
181
- socket.submitTask({ ...message, deferred })
175
+ const taskGeneratorFn = async function* ()
176
+
177
+
178
+
179
+ {
180
+ const value = yield { ...message }
181
+ deferred.resolve(value)
182
+ return false
183
+ }
184
+ const generator = taskGeneratorFn()
185
+ const result = await generator.next()
186
+ // Assertion mask the type checker
187
+ if (result.done !== true) {
188
+ const task = result.value
189
+ socket.submitTask(task, generator)
190
+ }
182
191
  return await deferred.promise
183
192
  },
184
193
 
@@ -223,39 +232,32 @@ var _Socket = require('./Socket');
223
232
  // Task Methods:
224
233
  //
225
234
 
226
- addressQueryTask(address, params, deferred) {
227
- return {
235
+ addressQueryTask: function* (address, params) {
236
+ return yield {
228
237
  ..._blockbookApi.addressMessage.call(void 0, address, params.asBlockbookAddress, {
229
238
  details: 'txs',
230
239
  from: params.lastQueriedBlockHeight,
231
240
  pageSize: _constants.BLOCKBOOK_TXS_PER_PAGE,
232
241
  page: params.page
233
- }),
234
- deferred
242
+ })
235
243
  }
236
244
  },
237
245
 
238
- transactionQueryTask(txId, deferred) {
239
- return {
240
- ..._blockbookApi.transactionMessage.call(void 0, txId),
241
- deferred
246
+ transactionQueryTask: function* (txId) {
247
+ return yield {
248
+ ..._blockbookApi.transactionMessage.call(void 0, txId)
242
249
  }
243
250
  },
244
251
 
245
- transactionSpecialQueryTask(
246
- txId,
247
- deferred
248
- ) {
249
- return {
250
- ..._blockbookApi.transactionMessageSpecific.call(void 0, txId),
251
- deferred
252
+ transactionSpecialQueryTask: function* (txId) {
253
+ return yield {
254
+ ..._blockbookApi.transactionMessageSpecific.call(void 0, txId)
252
255
  }
253
256
  },
254
257
 
255
- utxoListQueryTask(address, params, deferred) {
256
- return {
257
- ..._blockbookApi.addressUtxosMessage.call(void 0, address, params.asBlockbookAddress),
258
- deferred
258
+ utxoListQueryTask: function* (address, params) {
259
+ return yield {
260
+ ..._blockbookApi.addressUtxosMessage.call(void 0, address, params.asBlockbookAddress)
259
261
  }
260
262
  }
261
263
  }
@@ -263,7 +265,8 @@ var _Socket = require('./Socket');
263
265
  const socket = _Socket.makeSocket.call(void 0, connectionUri, {
264
266
  asResponse,
265
267
  healthCheck: _nullishCoalesce(config.ping, () => ( ping)),
266
- onQueueSpaceCB,
268
+ initOptions: config.initOptions,
269
+ taskGeneratorFn,
267
270
  log,
268
271
  emitter: socketEmitter,
269
272
  walletId
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _altcoinjs = require('altcoin-js');
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _altcoinjs = require('altcoin-js');
2
2
 
3
3
 
4
4
 
@@ -12,10 +12,10 @@ var _cleaners = require('cleaners');
12
12
 
13
13
 
14
14
 
15
+
15
16
  var _keymanager = require('../keymanager/keymanager');
16
17
  var _Blockbook = require('./Blockbook');
17
18
 
18
- var _Deferred = require('./Deferred'); var _Deferred2 = _interopRequireDefault(_Deferred);
19
19
 
20
20
 
21
21
 
@@ -37,6 +37,12 @@ var _electrumApi = require('./electrumApi');
37
37
 
38
38
 
39
39
 
40
+
41
+
42
+
43
+
44
+
45
+
40
46
 
41
47
 
42
48
 
@@ -78,8 +84,9 @@ const asResponse = (raw) => {
78
84
  asAddress,
79
85
  connectionUri,
80
86
  engineEmitter,
87
+ initOptions,
81
88
  log,
82
- onQueueSpaceCB,
89
+ taskGeneratorFn,
83
90
  pluginInfo,
84
91
  socketEmitter,
85
92
  walletId
@@ -101,86 +108,81 @@ const asResponse = (raw) => {
101
108
  asResponse,
102
109
  connectionUri,
103
110
  engineEmitter,
111
+ initOptions,
104
112
  log,
105
- onQueueSpaceCB: async (
113
+ taskGeneratorFn: async function* (
106
114
  uri
107
- ) => {
108
- const task = await onQueueSpaceCB(uri)
109
- if (task == null || typeof task === 'boolean') return task
110
-
111
- // Translate getAccountUtxo to blockchain.scripthash.listunspent:
112
- if (task.method === 'getAccountUtxo') {
113
- const params = task.params
114
- const address =
115
- asAddress != null ? asAddress(params.descriptor) : params.descriptor
116
- const scriptHash = addressToScriptHash(address)
117
-
118
- const deferred = new _Deferred2.default()
119
- deferred.promise
120
- .then((electrumUtxos) => {
121
- const blockbookUtxos = electrumUtxos.map(
122
- utxo => ({
123
- txid: utxo.tx_hash,
124
- vout: utxo.tx_pos,
125
- value: utxo.value.toString(),
126
- height: utxo.height
127
- })
128
- )
129
- task.deferred.resolve(blockbookUtxos)
130
- })
131
- .catch((e) => {
132
- task.deferred.reject(e)
133
- })
134
-
135
- const translatedTask = {
136
- ..._electrumApi.listUnspentMessage.call(void 0, scriptHash),
137
- deferred
115
+ ) {
116
+ const generator = taskGeneratorFn(uri)
117
+ let nextValue
118
+
119
+ while (true) {
120
+ const result = await generator.next(nextValue)
121
+ const task = result.value
122
+
123
+ // If the generator result is not a WsTask we will return it:
124
+ if (_optionalChain([result, 'optionalAccess', _ => _.done]) === true) return result.value
125
+ if (typeof task === 'boolean') return task
126
+
127
+ // Translate getAccountUtxo to blockchain.scripthash.listunspent:
128
+ if (task.method === 'getAccountUtxo') {
129
+ const params = task.params
130
+ const address =
131
+ asAddress != null ? asAddress(params.descriptor) : params.descriptor
132
+ const scriptHash = addressToScriptHash(address)
133
+
134
+ // Safe because yielding WsTask<ListUnspentResponse> should get
135
+ // ListUnspentResponse next.
136
+ const electrumUtxos = (yield {
137
+ ..._electrumApi.listUnspentMessage.call(void 0, scriptHash)
138
+ })
139
+
140
+ const blockbookUtxos = electrumUtxos.map(
141
+ utxo => ({
142
+ txid: utxo.tx_hash,
143
+ vout: utxo.tx_pos,
144
+ value: utxo.value.toString(),
145
+ height: utxo.height
146
+ })
147
+ )
148
+ nextValue = blockbookUtxos
149
+ continue
138
150
  }
139
- return translatedTask
140
- }
141
151
 
142
- // Get Address Transactions:
143
- if (task.method === 'getAccountInfo') {
144
- const params = task.params
145
- const address =
146
- asAddress != null ? asAddress(params.descriptor) : params.descriptor
147
- const scriptHash = addressToScriptHash(address)
148
-
149
- const deferred = new _Deferred2.default()
150
- deferred.promise
151
- .then((electrumUtxos) => {
152
- const blockbookUtxos = {
153
- address, // unused
154
- balance: '0', // unused
155
- totalReceived: '0', // unused
156
- totalSent: '0', // unused
157
- txs: electrumUtxos.length,
158
- unconfirmedBalance: '0', // unused
159
- unconfirmedTxs: electrumUtxos.reduce(
160
- (sum, tx) => (sum + tx.height >= 0 ? 1 : 0),
161
- 0
162
- ),
163
- txids: [], // unused
164
- transactions: [], // TODO: this requires an extra query per txid
165
- page: 0, // unused
166
- totalPages: 1,
167
- itemsOnPage: 0 // unused
168
- }
169
- task.deferred.resolve(blockbookUtxos)
170
- })
171
- .catch((e) => {
172
- task.deferred.reject(e)
173
- })
174
-
175
- const translatedTask = {
176
- ..._electrumApi.addressTransactionsMessage.call(void 0, scriptHash),
177
- deferred
152
+ // Get Address Transactions:
153
+ if (task.method === 'getAccountInfo') {
154
+ const params = task.params
155
+ const address =
156
+ asAddress != null ? asAddress(params.descriptor) : params.descriptor
157
+ const scriptHash = addressToScriptHash(address)
158
+
159
+ // Safe because yielding WsTask<AddressTransactionsResponse> should get
160
+ // AddressTransactionsResponse next.
161
+ const electrumUtxos = (yield {
162
+ ..._electrumApi.addressTransactionsMessage.call(void 0, scriptHash)
163
+ })
164
+
165
+ const blockbookUtxos = {
166
+ address, // unused
167
+ balance: '0', // unused
168
+ totalReceived: '0', // unused
169
+ totalSent: '0', // unused
170
+ txs: electrumUtxos.length,
171
+ unconfirmedBalance: '0', // unused
172
+ unconfirmedTxs: electrumUtxos.reduce(
173
+ (sum, tx) => (sum + tx.height >= 0 ? 1 : 0),
174
+ 0
175
+ ),
176
+ txids: [], // unused
177
+ transactions: [], // TODO: this requires an extra query per txid
178
+ page: 0, // unused
179
+ totalPages: 1,
180
+ itemsOnPage: 0 // unused
181
+ }
182
+ nextValue = blockbookUtxos
183
+ continue
178
184
  }
179
- return translatedTask
180
185
  }
181
-
182
- // Skip unsupported task and continue with the next one:
183
- return true
184
186
  },
185
187
  ping: async () => {
186
188
  return await instance.promisifyWsMessage(_electrumApi.pingMessage.call(void 0, ))