edge-currency-plugins 3.2.0 → 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 (47) hide show
  1. package/android/src/main/assets/edge-currency-plugins/edge-currency-plugins.js +41 -41
  2. package/lib/common/plugin/PluginState.js +73 -43
  3. package/lib/common/plugin/ServerScores.js +11 -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 +324 -298
  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 +84 -48
  25. package/lib/common/utxobased/network/windowWS.js +2 -2
  26. package/lib/src/common/plugin/PluginState.d.ts +4 -4
  27. package/lib/src/common/plugin/ServerScores.d.ts +1 -0
  28. package/lib/src/common/plugin/types.d.ts +4 -4
  29. package/lib/src/common/utxobased/db/{Processor.d.ts → DataLayer.d.ts} +17 -11
  30. package/lib/src/common/utxobased/db/Models/{ProcessorTransaction.d.ts → TransactionData.d.ts} +5 -5
  31. package/lib/src/common/utxobased/db/Models/baselet.d.ts +4 -4
  32. package/lib/src/common/utxobased/db/types.d.ts +9 -9
  33. package/lib/src/common/utxobased/db/util/utxo.d.ts +3 -3
  34. package/lib/src/common/utxobased/engine/ServerStates.d.ts +7 -7
  35. package/lib/src/common/utxobased/engine/{UtxoEngineState.d.ts → UtxoEngineProcessor.d.ts} +44 -42
  36. package/lib/src/common/utxobased/engine/types.d.ts +4 -4
  37. package/lib/src/common/utxobased/engine/util/getOwnUtxosFromTx.d.ts +3 -3
  38. package/lib/src/common/utxobased/engine/utils.d.ts +2 -2
  39. package/lib/src/common/utxobased/keymanager/keymanager.d.ts +3 -3
  40. package/lib/src/common/utxobased/network/Blockbook.d.ts +8 -7
  41. package/lib/src/common/utxobased/network/BlockbookElectrum.d.ts +4 -2
  42. package/lib/src/common/utxobased/network/Socket.d.ts +10 -8
  43. package/lib/src/common/utxobased/network/types.d.ts +1 -1
  44. package/lib/src/util/uriKeyParams.d.ts +4 -0
  45. package/lib/util/uriKeyParams.js +20 -0
  46. package/package.json +1 -1
  47. /package/lib/test/common/utxobased/db/{Processor.spec.d.ts → DataLayer.spec.d.ts} +0 -0
@@ -25,11 +25,11 @@ var _EngineEmitter = require('../../plugin/EngineEmitter');
25
25
  var _Metadata = require('../../plugin/Metadata');
26
26
 
27
27
  var _upgradeMemos = require('../../upgradeMemos');
28
+ var _DataLayer = require('../db/DataLayer');
28
29
 
29
30
 
30
31
 
31
- var _ProcessorTransaction = require('../db/Models/ProcessorTransaction');
32
- var _Processor = require('../db/Processor');
32
+ var _TransactionData = require('../db/Models/TransactionData');
33
33
 
34
34
  var _utxo = require('../db/util/utxo');
35
35
 
@@ -61,7 +61,10 @@ var _getOwnUtxosFromTx = require('./util/getOwnUtxosFromTx');
61
61
 
62
62
 
63
63
  var _utils3 = require('./utils');
64
- var _UtxoEngineState = require('./UtxoEngineState');
64
+
65
+
66
+
67
+ var _UtxoEngineProcessor = require('./UtxoEngineProcessor');
65
68
  var _UtxoWalletTools = require('./UtxoWalletTools');
66
69
 
67
70
  async function makeUtxoEngine(
@@ -125,14 +128,14 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
125
128
  emitter,
126
129
  log
127
130
  })
128
- const processor = await _Processor.makeProcessor.call(void 0, {
131
+ const dataLayer = await _DataLayer.makeDataLayer.call(void 0, {
129
132
  disklet: walletLocalDisklet
130
133
  })
131
- const engineState = _UtxoEngineState.makeUtxoEngineState.call(void 0, {
134
+ const engineProcessor = _UtxoEngineProcessor.makeUtxoEngineProcessor.call(void 0, {
132
135
  ...config,
133
136
  walletTools,
134
137
  walletInfo,
135
- processor,
138
+ dataLayer,
136
139
  pluginState
137
140
  })
138
141
 
@@ -145,9 +148,9 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
145
148
  if (privateKeyFormat === 'bip32' || privateKeyFormat === 'bip44')
146
149
  return null
147
150
 
148
- // Get the replaced transaction from the processor:
151
+ // Get the replaced transaction from the DataLayer:
149
152
  const replacedTxid = edgeTx.txid
150
- const [replacedTx] = await processor.fetchTransactions({
153
+ const [replacedTx] = await dataLayer.fetchTransactions({
151
154
  txId: replacedTxid
152
155
  })
153
156
 
@@ -165,11 +168,11 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
165
168
  const newFeeRate = Math.round((parseInt(replacedTx.fees) / vBytes) * 2)
166
169
 
167
170
  const replacedTxInputs = replacedTx.inputs
168
- // Recreate UTXOs from processor transaction and mark them as unspent:
171
+ // Recreate UTXOs from DataLayer transaction and mark them as unspent:
169
172
  const replacedTxUtxos = await Promise.all(
170
173
  replacedTxInputs.map(async (_, index) => {
171
- const utxo = await _utxo.utxoFromProcessorTransactionInput.call(void 0,
172
- processor,
174
+ const utxo = await _utxo.utxoFromTransactionDataInput.call(void 0,
175
+ dataLayer,
173
176
  replacedTx,
174
177
  index
175
178
  )
@@ -189,7 +192,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
189
192
  let foundChangeAddress
190
193
  for (const output of replacedTx.outputs) {
191
194
  // Fetch address by output's scriptPubkey to determine output ownership
192
- const ourAddress = await processor.fetchAddress(output.scriptPubkey)
195
+ const ourAddress = await dataLayer.fetchAddress(output.scriptPubkey)
193
196
 
194
197
  // This isn't our output, so include it as a target
195
198
  if (ourAddress == null) {
@@ -235,14 +238,14 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
235
238
  // Use the found change address or generate a new one:
236
239
  const freshAddress =
237
240
  foundChangeAddress == null
238
- ? await engineState.getFreshAddress({ branch: 1 })
241
+ ? await engineProcessor.getFreshAddress({ branch: 1 })
239
242
  : { publicAddress: foundChangeAddress }
240
243
  const freshChangeAddress =
241
244
  _nullishCoalesce(freshAddress.segwitAddress, () => ( freshAddress.publicAddress))
242
245
 
243
246
  // Get all current UTXOs:
244
247
  const currentUtxos = _filterUndefined.filterUndefined.call(void 0,
245
- await processor.fetchUtxos({
248
+ await dataLayer.fetchUtxos({
246
249
  utxoIds: []
247
250
  })
248
251
  )
@@ -305,7 +308,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
305
308
  let nativeAmount = '0'
306
309
  for (const output of newTx.outputs) {
307
310
  const scriptPubkey = output.scriptPubkey.toString('hex')
308
- const own = await processor.fetchAddress(scriptPubkey)
311
+ const own = await dataLayer.fetchAddress(scriptPubkey)
309
312
  if (own == null) {
310
313
  // Not our output
311
314
  nativeAmount = bs.sub(nativeAmount, output.value.toString())
@@ -357,15 +360,15 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
357
360
  metadata.state.balance
358
361
  )
359
362
 
360
- pluginState.addEngine(engineState)
363
+ pluginState.addEngine(engineProcessor)
361
364
  await fees.start()
362
- await engineState.start()
365
+ await engineProcessor.start()
363
366
  },
364
367
 
365
368
  async killEngine() {
366
- await engineState.stop()
369
+ await engineProcessor.stop()
367
370
  fees.stop()
368
- pluginState.removeEngine(engineState)
371
+ pluginState.removeEngine(engineProcessor)
369
372
  },
370
373
 
371
374
  getBalance(_opts) {
@@ -381,7 +384,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
381
384
  },
382
385
 
383
386
  async addGapLimitAddresses(addresses) {
384
- return await engineState.addGapLimitAddresses(addresses)
387
+ return await engineProcessor.addGapLimitAddresses(addresses)
385
388
  },
386
389
 
387
390
  async broadcastTx(transaction) {
@@ -401,7 +404,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
401
404
  )
402
405
  }
403
406
  }
404
- const id = await engineState.broadcastTx(transaction).catch(err => {
407
+ const id = await engineProcessor.broadcastTx(transaction).catch(err => {
405
408
  if (String(err).includes('Error: Blockbook Error: -26: dust')) {
406
409
  throw new (0, _edgecorejs.DustSpendError)()
407
410
  }
@@ -432,7 +435,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
432
435
  walletFormats
433
436
  },
434
437
  metadataState: metadata.state,
435
- processorState: await processor.dumpData(),
438
+ storageState: await dataLayer.dumpData(),
436
439
  pluginState: pluginState.dumpData()
437
440
  }
438
441
  }
@@ -461,11 +464,11 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
461
464
  opts
462
465
  ) {
463
466
  const { forceIndex } = opts
464
- return await engineState.getFreshAddress({ forceIndex })
467
+ return await engineProcessor.getFreshAddress({ forceIndex })
465
468
  },
466
469
 
467
470
  getNumTransactions(_opts) {
468
- return processor.numTransactions()
471
+ return dataLayer.numTransactions()
469
472
  },
470
473
 
471
474
  async getPaymentProtocolInfo(
@@ -482,16 +485,16 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
482
485
  options
483
486
  ) {
484
487
  const txs = _filterUndefined.filterUndefined.call(void 0,
485
- await processor.fetchTransactions({ options })
488
+ await dataLayer.fetchTransactions({ options })
486
489
  )
487
490
  return await Promise.all(
488
491
  txs.map(
489
492
  async (tx) =>
490
- await _ProcessorTransaction.toEdgeTransaction.call(void 0, {
493
+ await _TransactionData.toEdgeTransaction.call(void 0, {
491
494
  walletId: walletInfo.id,
492
495
  tx,
493
496
  walletTools,
494
- processor,
497
+ dataLayer,
495
498
  pluginInfo
496
499
  })
497
500
  )
@@ -500,7 +503,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
500
503
 
501
504
  async isAddressUsed(address) {
502
505
  const scriptPubkey = walletTools.addressToScriptPubkey(address)
503
- const addressData = await processor.fetchAddress(scriptPubkey)
506
+ const addressData = await dataLayer.fetchAddress(scriptPubkey)
504
507
  if (addressData == null) throw new Error('Address not found in wallet')
505
508
  return addressData.used
506
509
  },
@@ -534,7 +537,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
534
537
  const utxos =
535
538
  await _asyncNullishCoalesce(txOptions.utxos, async () => (
536
539
  _filterUndefined.filterUndefined.call(void 0,
537
- (await processor.fetchUtxos({
540
+ (await dataLayer.fetchUtxos({
538
541
  scriptPubkey: utxoScriptPubkey,
539
542
  utxoIds: []
540
543
  }))
@@ -559,7 +562,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
559
562
  const { script } = target.otherParams
560
563
  if (script.type === 'replayProtection') {
561
564
  // construct a replay protection p2sh address
562
- const { publicAddress } = await engineState.deriveScriptAddress(
565
+ const { publicAddress } = await engineProcessor.deriveScriptAddress(
563
566
  script.type
564
567
  )
565
568
  targets.push({
@@ -575,7 +578,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
575
578
  const scriptPubkey = walletTools.addressToScriptPubkey(
576
579
  target.publicAddress
577
580
  )
578
- if ((await processor.fetchAddress(scriptPubkey)) != null) {
581
+ if ((await dataLayer.fetchAddress(scriptPubkey)) != null) {
579
582
  ourReceiveAddresses.push(target.publicAddress)
580
583
  }
581
584
  }
@@ -593,7 +596,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
593
596
  throw new Error('Need to provide Spend Targets')
594
597
  }
595
598
 
596
- const freshAddress = await engineState.getFreshAddress({ branch: 1 })
599
+ const freshAddress = await engineProcessor.getFreshAddress({ branch: 1 })
597
600
  const freshChangeAddress =
598
601
  _nullishCoalesce(_nullishCoalesce(forceChangeAddress, () => (
599
602
  freshAddress.segwitAddress)), () => (
@@ -603,13 +606,13 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
603
606
 
604
607
  let maxUtxo
605
608
  if (txOptions.CPFP != null) {
606
- const [childTx] = await processor.fetchTransactions({
609
+ const [childTx] = await dataLayer.fetchTransactions({
607
610
  txId: txOptions.CPFP
608
611
  })
609
612
  if (childTx == null) throw new Error('transaction not found')
610
613
  const utxos = []
611
614
  for (const txid of childTx.ourOuts) {
612
- const [output] = await processor.fetchUtxos({ utxoIds: [txid] })
615
+ const [output] = await dataLayer.fetchUtxos({ utxoIds: [txid] })
613
616
  if (output != null) utxos.push(output)
614
617
  }
615
618
  maxUtxo = utxos.reduce((a, b) => (bs.gt(a.value, b.value) ? a : b))
@@ -651,7 +654,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
651
654
  )
652
655
  for (const output of tx.outputs) {
653
656
  const scriptPubkey = output.scriptPubkey.toString('hex')
654
- const own = await processor.fetchAddress(scriptPubkey)
657
+ const own = await dataLayer.fetchAddress(scriptPubkey)
655
658
  if (own == null) {
656
659
  // Not our output
657
660
  nativeAmount = bs.sub(nativeAmount, output.value.toString())
@@ -702,7 +705,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
702
705
  await engine.killEngine()
703
706
 
704
707
  // Clear cache and state
705
- await processor.clearAll()
708
+ await dataLayer.clearAll()
706
709
  await pluginState.clearCache()
707
710
  await metadata.clear()
708
711
  await fees.clearCache()
@@ -719,32 +722,32 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
719
722
  const replacedTxid = _optionalChain([edgeTx, 'access', _9 => _9.otherParams, 'optionalAccess', _10 => _10.replacedTxid])
720
723
  if (replacedTxid != null) {
721
724
  // Get the replaced transaction using the replacedTxid
722
- const [rbfTx] = await processor.fetchTransactions({
725
+ const [rbfTx] = await dataLayer.fetchTransactions({
723
726
  txId: replacedTxid
724
727
  })
725
728
  if (rbfTx != null) {
726
729
  rbfTx.blockHeight = -1
727
- await _UtxoEngineState.transactionChanged.call(void 0, {
730
+ await _UtxoEngineProcessor.transactionChanged.call(void 0, {
728
731
  walletId: walletInfo.id,
729
732
  tx: rbfTx,
730
733
  pluginInfo,
731
734
  emitter,
732
735
  walletTools,
733
- processor
736
+ dataLayer
734
737
  })
735
738
  }
736
739
  }
737
740
 
738
- const tx = _ProcessorTransaction.fromEdgeTransaction.call(void 0, edgeTx)
739
- await _UtxoEngineState.transactionChanged.call(void 0, {
741
+ const tx = _TransactionData.fromEdgeTransaction.call(void 0, edgeTx)
742
+ await _UtxoEngineProcessor.transactionChanged.call(void 0, {
740
743
  walletId: walletInfo.id,
741
744
  tx,
742
745
  pluginInfo,
743
746
  emitter,
744
747
  walletTools,
745
- processor
748
+ dataLayer
746
749
  })
747
- await processor.saveTransaction({
750
+ await dataLayer.saveTransaction({
748
751
  tx,
749
752
  scriptPubkeys: _optionalChain([edgeTx, 'access', _11 => _11.otherParams, 'optionalAccess', _12 => _12.ourScriptPubkeys])
750
753
  })
@@ -752,8 +755,8 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
752
755
  /*
753
756
  Get the wallet's UTXOs from the new transaction and save them to the processsor.
754
757
  */
755
- const ownUtxos = await _getOwnUtxosFromTx.getOwnUtxosFromTx.call(void 0, engineInfo, processor, tx)
756
- await engineState.processUtxos(ownUtxos)
758
+ const ownUtxos = await _getOwnUtxosFromTx.getOwnUtxosFromTx.call(void 0, engineInfo, dataLayer, tx)
759
+ await engineProcessor.processUtxos(ownUtxos)
757
760
  },
758
761
 
759
762
  async signMessage(
@@ -764,9 +767,9 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
764
767
  const otherParams = _types7.asUtxoSignMessageOtherParams.call(void 0, opts.otherParams)
765
768
  const { publicAddress } = otherParams
766
769
  const scriptPubkey = walletTools.addressToScriptPubkey(publicAddress)
767
- const processorAddress = await processor.fetchAddress(scriptPubkey)
768
- if (_optionalChain([processorAddress, 'optionalAccess', _13 => _13.path]) == null) {
769
- throw new Error('Missing address to sign with')
770
+ const addressData = await dataLayer.fetchAddress(scriptPubkey)
771
+ if (_optionalChain([addressData, 'optionalAccess', _13 => _13.path]) == null) {
772
+ throw new Error('Missing data-layer address to sign with')
770
773
  }
771
774
  const privateKey = asMaybeCurrencyPrivateKey(privateKeys)
772
775
 
@@ -781,7 +784,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
781
784
  })
782
785
 
783
786
  const signature = await walletTools.signMessageBase64({
784
- path: _optionalChain([processorAddress, 'optionalAccess', _14 => _14.path]),
787
+ path: _optionalChain([addressData, 'optionalAccess', _14 => _14.path]),
785
788
  message,
786
789
  xprivKeys
787
790
  })
@@ -824,7 +827,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
824
827
  psbt.inputs.map(async ({ hash, index: vout }) => {
825
828
  const txId = Buffer.from(hash).reverse().toString('hex')
826
829
 
827
- const [transaction] = await processor.fetchTransactions({ txId })
830
+ const [transaction] = await dataLayer.fetchTransactions({ txId })
828
831
  if (transaction == null)
829
832
  throw new Error(
830
833
  'Unable to find previous transaction data for input'
@@ -838,7 +841,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
838
841
 
839
842
  // Use the scriptPubkey to find the private key from the address
840
843
  // derivation path
841
- const address = await processor.fetchAddress(scriptPubkey)
844
+ const address = await dataLayer.fetchAddress(scriptPubkey)
842
845
  if (address == null) {
843
846
  throw new Error(
844
847
  `Address for scriptPubkey '${scriptPubkey}' not found`
@@ -931,7 +934,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
931
934
  log
932
935
  }
933
936
  const tmpMetadata = await _Metadata.makeMetadata.call(void 0, tmpConfig)
934
- const tmpProcessor = await _Processor.makeProcessor.call(void 0, tmpConfig)
937
+ const tmpDataLayer = await _DataLayer.makeDataLayer.call(void 0, tmpConfig)
935
938
  const tmpWalletTools = _UtxoWalletTools.makeUtxoWalletTools.call(void 0, {
936
939
  pluginInfo,
937
940
  publicKey: tmpWalletInfo.keys.publicKey
@@ -943,7 +946,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
943
946
  try {
944
947
  await tmpState.stop()
945
948
 
946
- const tmpUtxos = (await tmpProcessor.fetchUtxos({
949
+ const tmpUtxos = (await tmpDataLayer.fetchUtxos({
947
950
  utxoIds: []
948
951
  }))
949
952
  if (tmpUtxos === null || tmpUtxos.length < 1) {
@@ -967,7 +970,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
967
970
  }
968
971
  })
969
972
 
970
- const tmpState = _UtxoEngineState.makeUtxoEngineState.call(void 0, {
973
+ const tmpState = _UtxoEngineProcessor.makeUtxoEngineProcessor.call(void 0, {
971
974
  ...config,
972
975
  options: {
973
976
  ...config.options,
@@ -983,7 +986,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
983
986
  gapLimit: 0
984
987
  }
985
988
  },
986
- processor: tmpProcessor,
989
+ dataLayer: tmpDataLayer,
987
990
  walletTools: tmpWalletTools,
988
991
  walletInfo: tmpWalletInfo
989
992
  })