edge-currency-plugins 3.16.0 → 3.17.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 (26) hide show
  1. package/android/src/main/assets/edge-currency-plugins/edge-currency-plugins.js +51 -49
  2. package/lib/common/plugin/types.js +11 -0
  3. package/lib/common/utxobased/engine/ServerStates.js +17 -1
  4. package/lib/common/utxobased/engine/UtxoEngineProcessor.js +53 -18
  5. package/lib/common/utxobased/info/all.js +6 -0
  6. package/lib/common/utxobased/info/bitcoin.js +1 -1
  7. package/lib/common/utxobased/info/ecashbitcoin.js +90 -0
  8. package/lib/common/utxobased/info/ecashbitcoinbetanet.js +91 -0
  9. package/lib/common/utxobased/keymanager/keymanager.js +6 -1
  10. package/lib/common/utxobased/network/Blockbook.js +3 -1
  11. package/lib/common/utxobased/network/BlockbookElectrum.js +243 -77
  12. package/lib/common/utxobased/network/Socket.js +26 -20
  13. package/lib/common/utxobased/network/electrumApi.js +49 -1
  14. package/lib/src/common/plugin/types.d.ts +10 -0
  15. package/lib/src/common/utxobased/engine/ServerStates.d.ts +1 -0
  16. package/lib/src/common/utxobased/engine/UtxoEngineProcessor.d.ts +2 -0
  17. package/lib/src/common/utxobased/info/all.d.ts +2 -0
  18. package/lib/src/common/utxobased/info/ecashbitcoin.d.ts +3 -0
  19. package/lib/src/common/utxobased/info/ecashbitcoinbetanet.d.ts +3 -0
  20. package/lib/src/common/utxobased/network/Blockbook.d.ts +3 -1
  21. package/lib/src/common/utxobased/network/BlockbookElectrum.d.ts +2 -0
  22. package/lib/src/common/utxobased/network/electrumApi.d.ts +21 -0
  23. package/lib/test/common/utxobased/engine/UtxoEngineProcessor.spec.d.ts +1 -0
  24. package/lib/test/common/utxobased/keymanager/coins/ecashbitcointransactiontest.spec.d.ts +1 -0
  25. package/lib/test/common/utxobased/network/BlockbookElectrum.spec.d.ts +1 -0
  26. package/package.json +1 -1
@@ -314,6 +314,17 @@ var _types3 = require('../utxobased/db/types');
314
314
 
315
315
 
316
316
 
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
317
328
 
318
329
 
319
330
 
@@ -16,6 +16,9 @@ var _Blockbook = require('../network/Blockbook');
16
16
 
17
17
 
18
18
  var _blockbookApi = require('../network/blockbookApi');
19
+
20
+
21
+
19
22
  var _BlockbookElectrum = require('../network/BlockbookElectrum');
20
23
  var _Deferred = require('../network/Deferred'); var _Deferred2 = _interopRequireDefault(_Deferred);
21
24
 
@@ -116,6 +119,7 @@ var _constants = require('./constants');
116
119
 
117
120
 
118
121
 
122
+
119
123
 
120
124
 
121
125
  /**
@@ -510,7 +514,7 @@ const withTimeout = async (
510
514
  }
511
515
 
512
516
  // Create a new blockbook instance based on the URI scheme
513
- if (['electrumwss', 'electrumws'].includes(parsed.scheme)) {
517
+ if (_BlockbookElectrum.isElectrumUri.call(void 0, uri)) {
514
518
  // Electrum wrapper
515
519
  blockbook = _BlockbookElectrum.makeBlockbookElectrum.call(void 0, {
516
520
  asAddress: pluginInfo.engineInfo.asBlockbookAddress,
@@ -862,6 +866,18 @@ const withTimeout = async (
862
866
  return true
863
867
  },
864
868
 
869
+ serverCanGetAddressHistory(uri, address) {
870
+ // Electrum only reports how many transactions an address has, so the
871
+ // history goes to a connected Blockbook server whenever there is one.
872
+ // Without one, the counts still let the wallet finish syncing:
873
+ const hasBlockbook = Object.entries(serverStatesCache).some(
874
+ ([otherUri, state]) =>
875
+ !_BlockbookElectrum.isElectrumUri.call(void 0, otherUri) && state.blockbook.isConnected
876
+ )
877
+ if (_BlockbookElectrum.isElectrumUri.call(void 0, uri) && hasBlockbook) return false
878
+ return instance.serverCanGetAddress(uri, address)
879
+ },
880
+
865
881
  serverIsAwareOfAddress(uri, address) {
866
882
  const serverState = serverStatesCache[uri]
867
883
  if (serverState == null) return false
@@ -38,6 +38,7 @@ var _keymanager = require('../keymanager/keymanager');
38
38
 
39
39
 
40
40
 
41
+ var _BlockbookElectrum = require('../network/BlockbookElectrum');
41
42
 
42
43
  var _awaitlock = require('./await-lock'); var _awaitlock2 = _interopRequireDefault(_awaitlock);
43
44
  var _constants = require('./constants');
@@ -126,6 +127,11 @@ var _utils3 = require('./utils');
126
127
  pendingTimeouts.clear()
127
128
  }
128
129
 
130
+ // Addresses whose history an Electrum server answered. Electrum only
131
+ // reports how many transactions an address has, so a Blockbook server
132
+ // queries these again once one is picking tasks:
133
+ const electrumHistoryAddresses = new Set()
134
+
129
135
  const clearTaskCache = () => {
130
136
  for (const key of Object.keys(taskCache.addressForTransactionsCache)) {
131
137
  _utils.removeItem.call(void 0, taskCache.addressForTransactionsCache, key)
@@ -148,6 +154,7 @@ var _utils3 = require('./utils');
148
154
  for (const key of Object.keys(taskCache.transactionUpdateCache)) {
149
155
  _utils.removeItem.call(void 0, taskCache.transactionUpdateCache, key)
150
156
  }
157
+ electrumHistoryAddresses.clear()
151
158
  }
152
159
 
153
160
  /**
@@ -224,6 +231,28 @@ var _utils3 = require('./utils');
224
231
  }
225
232
  }
226
233
 
234
+ /**
235
+ * Queues already-processed addresses to be queried again. Each query starts
236
+ * from the address's stored lastQueriedBlockHeight, and the address only
237
+ * counts as processed once the new queries complete. Returns how many
238
+ * addresses were re-queued.
239
+ */
240
+ const reopenAddresses = (addresses) => {
241
+ let reopened = 0
242
+ for (const address of addresses) {
243
+ const cacheItem = taskCache.addressSubscribeCache[address]
244
+ if (cacheItem == null || !cacheItem.processing) continue
245
+ cacheItem.processing = false
246
+ taskCache.addressForUtxosCache[address] = {
247
+ processing: false,
248
+ path: cacheItem.path
249
+ }
250
+ progressByScriptPubkey.delete(walletTools.addressToScriptPubkey(address))
251
+ reopened++
252
+ }
253
+ return reopened
254
+ }
255
+
227
256
  const lock = new (0, _awaitlock2.default)()
228
257
 
229
258
  const serverStates = _ServerStates.makeServerStates.call(void 0, {
@@ -243,6 +272,8 @@ var _utils3 = require('./utils');
243
272
  emitter,
244
273
  taskCache,
245
274
  pendingTimeouts,
275
+ electrumHistoryAddresses,
276
+ reopenAddresses,
246
277
  updateProgressRatio,
247
278
  updateSeenTxCheckpoint,
248
279
  io,
@@ -296,21 +327,9 @@ var _utils3 = require('./utils');
296
327
  // query starts from the address's stored lastQueriedBlockHeight, which is
297
328
  // never above the height of the server that answered it, so the range
298
329
  // the dropped server missed is fetched again.
299
- let requeued = 0
300
- for (const [address, cacheItem] of Object.entries(
301
- taskCache.addressSubscribeCache
302
- )) {
303
- if (!cacheItem.processing) continue
304
- cacheItem.processing = false
305
- taskCache.addressForUtxosCache[address] = {
306
- processing: false,
307
- path: cacheItem.path
308
- }
309
- // The re-query has to complete again before the address counts as
310
- // processed:
311
- progressByScriptPubkey.delete(walletTools.addressToScriptPubkey(address))
312
- requeued++
313
- }
330
+ const requeued = reopenAddresses(
331
+ Object.keys(taskCache.addressSubscribeCache)
332
+ )
314
333
  log(`${uri} dropped, re-queued ${requeued} addresses`)
315
334
  })
316
335
 
@@ -774,6 +793,8 @@ const internalGetFreshAddress = async (
774
793
 
775
794
 
776
795
 
796
+
797
+
777
798
 
778
799
 
779
800
 
@@ -926,6 +947,15 @@ const needsTxSpecific = (common) => {
926
947
  const serverState = common.serverStates.getServerState(serverUri)
927
948
  if (serverState == null) return false
928
949
 
950
+ // Re-query the addresses whose history came from Electrum, now that a
951
+ // Blockbook server can answer with their transactions:
952
+ const { electrumHistoryAddresses } = common
953
+ if (!_BlockbookElectrum.isElectrumUri.call(void 0, serverUri) && electrumHistoryAddresses.size > 0) {
954
+ const reopened = common.reopenAddresses(electrumHistoryAddresses)
955
+ electrumHistoryAddresses.clear()
956
+ common.log(`${serverUri} re-queued ${reopened} addresses Electrum answered`)
957
+ }
958
+
929
959
  // subscribe all servers to new blocks
930
960
  if (serverState.blockSubscriptionStatus === 'unsubscribed') {
931
961
  common.serverStates.watchBlocks(serverUri)
@@ -1096,7 +1126,7 @@ const needsTxSpecific = (common) => {
1096
1126
  )) {
1097
1127
  if (
1098
1128
  !cacheItem.processing &&
1099
- common.serverStates.serverCanGetAddress(serverUri, address)
1129
+ common.serverStates.serverCanGetAddressHistory(serverUri, address)
1100
1130
  ) {
1101
1131
  cacheItem.processing = true
1102
1132
 
@@ -1289,9 +1319,10 @@ async function* processAddressForTransactions(
1289
1319
  // answering server has indexed, so a lagging server cannot move
1290
1320
  // lastQueriedBlockHeight past blocks it never saw. A height of 0 means this
1291
1321
  // server has not reported one yet, so nothing it answers can be trusted to
1292
- // move the cursor; the next query covers the range again.
1322
+ // move the cursor; the next query covers the range again. Electrum answers
1323
+ // carry no transactions, so they never move it either:
1293
1324
  const queriedHeight =
1294
- serverState.blockHeight > 0
1325
+ serverState.blockHeight > 0 && !_BlockbookElectrum.isElectrumUri.call(void 0, serverUri)
1295
1326
  ? Math.min(blockHeight, serverState.blockHeight)
1296
1327
  : addressData.lastQueriedBlockHeight
1297
1328
 
@@ -1386,6 +1417,10 @@ async function* processAddressForTransactions(
1386
1417
  // Save/update the fully-processed address
1387
1418
  await common.dataLayer.saveAddress(addressData)
1388
1419
 
1420
+ // Electrum saved no transactions, so a Blockbook server queries this
1421
+ // address again once one is picking tasks:
1422
+ if (_BlockbookElectrum.isElectrumUri.call(void 0, serverUri)) common.electrumHistoryAddresses.add(address)
1423
+
1389
1424
  // Extend the lookahead before counting progress, so any addresses it adds
1390
1425
  // are in the total before this address's flag can bring the ratio to 1:
1391
1426
  await setLookAhead(common)
@@ -12,6 +12,8 @@ var _digibyte = require('./digibyte'); _createNamedExportFrom(_digibyte, 'digiby
12
12
  var _dogecoin = require('./dogecoin'); _createNamedExportFrom(_dogecoin, 'dogecoin', 'info');
13
13
  var _eboost = require('./eboost'); _createNamedExportFrom(_eboost, 'eboost', 'info');
14
14
  var _ecash = require('./ecash'); _createNamedExportFrom(_ecash, 'ecash', 'info');
15
+ var _ecashbitcoin = require('./ecashbitcoin'); _createNamedExportFrom(_ecashbitcoin, 'ecashbitcoin', 'info');
16
+ var _ecashbitcoinbetanet = require('./ecashbitcoinbetanet'); _createNamedExportFrom(_ecashbitcoinbetanet, 'ecashbitcoinbetanet', 'info');
15
17
  var _feathercoin = require('./feathercoin'); _createNamedExportFrom(_feathercoin, 'feathercoin', 'info');
16
18
  var _groestlcoin = require('./groestlcoin'); _createNamedExportFrom(_groestlcoin, 'groestlcoin', 'info');
17
19
  var _litecoin = require('./litecoin'); _createNamedExportFrom(_litecoin, 'litecoin', 'info');
@@ -45,6 +47,8 @@ var _zcoin = require('./zcoin'); _createNamedExportFrom(_zcoin, 'zcoin', 'info')
45
47
 
46
48
 
47
49
 
50
+
51
+
48
52
 
49
53
 
50
54
 
@@ -63,6 +67,8 @@ var _zcoin = require('./zcoin'); _createNamedExportFrom(_zcoin, 'zcoin', 'info')
63
67
  _dogecoin.info,
64
68
  _eboost.info,
65
69
  _ecash.info,
70
+ _ecashbitcoin.info,
71
+ _ecashbitcoinbetanet.info,
66
72
  _feathercoin.info,
67
73
  _groestlcoin.info,
68
74
  _litecoin.info,
@@ -62,7 +62,7 @@ const engineInfo = {
62
62
  }
63
63
  ],
64
64
  formats: ['bip49', 'bip84', 'bip44', 'bip32'],
65
- forks: ['bitcoincash', 'bitcoingold'],
65
+ forks: ['bitcoincash', 'bitcoingold', 'ecashbitcoin', 'ecashbitcoinbetanet'],
66
66
  gapLimit: 25,
67
67
  feeUpdateInterval: 60000,
68
68
  mempoolSpaceFeeInfoServer: 'https://mempool.space/api/v1/fees/precise',
@@ -0,0 +1,90 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _maximumFeeRateCalculator = require('../../plugin/util/maximumFeeRateCalculator');
5
+
6
+
7
+
8
+
9
+ var _commonInfo = require('./commonInfo');
10
+
11
+ const currencyInfo = {
12
+ assetDisplayName: 'eCash',
13
+ canReplaceByFee: true,
14
+ chainDisplayName: 'eCash',
15
+ currencyCode: 'ECX',
16
+ customFeeTemplate: _commonInfo.utxoCustomFeeTemplate,
17
+ memoOptions: _commonInfo.utxoMemoOptions,
18
+ pluginId: 'ecashbitcoin',
19
+ walletType: 'wallet:ecashbitcoin',
20
+
21
+ // Explorers:
22
+ blockExplorer: 'https://explorer.ecash.ninja/block/%s',
23
+ addressExplorer: 'https://explorer.ecash.ninja/address/%s',
24
+ transactionExplorer: 'https://explorer.ecash.ninja/tx/%s',
25
+
26
+ denominations: [
27
+ { name: 'ECX', multiplier: '100000000' },
28
+ { name: 'sats', multiplier: '1', symbol: 's' }
29
+ ],
30
+
31
+ // Deprecated:
32
+ ..._commonInfo.legacyMemoInfo,
33
+ defaultSettings: {
34
+ customFeeSettings: ['satPerByte'],
35
+ blockbookServers: ['wss://blockbook.ecash.ninja/websocket'],
36
+ enableCustomServers: false
37
+ },
38
+ displayName: 'eCash',
39
+ metaTokens: []
40
+ }
41
+
42
+ const engineInfo = {
43
+ formats: ['bip49', 'bip84', 'bip44', 'bip32'],
44
+ // Matches Bitcoin, so wallets split from Bitcoin find every pre-fork address:
45
+ gapLimit: 25,
46
+ feeUpdateInterval: 60000,
47
+ mempoolSpaceFeeInfoServer: 'https://explorer.ecash.ninja/api/v1/fees/precise',
48
+ defaultFeeInfo: {
49
+ lowFeeFudgeFactor: undefined,
50
+ standardFeeLowFudgeFactor: undefined,
51
+ standardFeeHighFudgeFactor: undefined,
52
+ highFeeFudgeFactor: undefined,
53
+
54
+ highFee: '10',
55
+ lowFee: '1',
56
+ standardFeeLow: '2',
57
+ standardFeeHigh: '5',
58
+ standardFeeLowAmount: '173200',
59
+ standardFeeHighAmount: '8670000',
60
+ maximumFeeRate: _maximumFeeRateCalculator.maximumFeeRateCalculator.call(void 0, currencyInfo, 100)
61
+ }
62
+ }
63
+
64
+ const coinInfo = {
65
+ name: 'ecashbitcoin',
66
+ segwit: true,
67
+ coinType: 0,
68
+ // LOCKTIME_THRESHOLD - 2, final only on eCash mainnet:
69
+ lockTime: 499999998,
70
+
71
+ prefixes: {
72
+ messagePrefix: ['\x18Bitcoin Signed Message:\n'],
73
+ wif: [0x80],
74
+ legacyXPriv: [0x0488ade4],
75
+ legacyXPub: [0x0488b21e],
76
+ wrappedSegwitXPriv: [0x049d7878],
77
+ wrappedSegwitXPub: [0x049d7cb2],
78
+ segwitXPriv: [0x04b2430c],
79
+ segwitXPub: [0x04b24746],
80
+ pubkeyHash: [0x00],
81
+ scriptHash: [0x05],
82
+ bech32: ['bc']
83
+ }
84
+ }; exports.coinInfo = coinInfo
85
+
86
+ const info = {
87
+ currencyInfo,
88
+ engineInfo,
89
+ coinInfo: exports.coinInfo
90
+ }; exports.info = info
@@ -0,0 +1,91 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _maximumFeeRateCalculator = require('../../plugin/util/maximumFeeRateCalculator');
5
+
6
+
7
+
8
+
9
+ var _commonInfo = require('./commonInfo');
10
+
11
+ const currencyInfo = {
12
+ assetDisplayName: 'eCash Betanet',
13
+ canReplaceByFee: true,
14
+ chainDisplayName: 'eCash Betanet',
15
+ currencyCode: 'BETAECX',
16
+ customFeeTemplate: _commonInfo.utxoCustomFeeTemplate,
17
+ memoOptions: _commonInfo.utxoMemoOptions,
18
+ pluginId: 'ecashbitcoinbetanet',
19
+ walletType: 'wallet:ecashbitcoinbetanet',
20
+
21
+ // Explorers:
22
+ blockExplorer: 'https://explorer.beta.ecash.ninja/block/%s',
23
+ addressExplorer: 'https://explorer.beta.ecash.ninja/address/%s',
24
+ transactionExplorer: 'https://explorer.beta.ecash.ninja/tx/%s',
25
+
26
+ denominations: [
27
+ { name: 'BETAECX', multiplier: '100000000' },
28
+ { name: 'sats', multiplier: '1', symbol: 's' }
29
+ ],
30
+
31
+ // Deprecated:
32
+ ..._commonInfo.legacyMemoInfo,
33
+ defaultSettings: {
34
+ customFeeSettings: ['satPerByte'],
35
+ blockbookServers: ['wss://blockbook.beta.ecash.ninja/websocket'],
36
+ enableCustomServers: false
37
+ },
38
+ displayName: 'eCash Betanet',
39
+ metaTokens: []
40
+ }
41
+
42
+ const engineInfo = {
43
+ formats: ['bip49', 'bip84', 'bip44', 'bip32'],
44
+ // Matches Bitcoin, so wallets split from Bitcoin find every pre-fork address:
45
+ gapLimit: 25,
46
+ feeUpdateInterval: 60000,
47
+ mempoolSpaceFeeInfoServer:
48
+ 'https://explorer.beta.ecash.ninja/api/v1/fees/precise',
49
+ defaultFeeInfo: {
50
+ lowFeeFudgeFactor: undefined,
51
+ standardFeeLowFudgeFactor: undefined,
52
+ standardFeeHighFudgeFactor: undefined,
53
+ highFeeFudgeFactor: undefined,
54
+
55
+ highFee: '10',
56
+ lowFee: '1',
57
+ standardFeeLow: '2',
58
+ standardFeeHigh: '5',
59
+ standardFeeLowAmount: '173200',
60
+ standardFeeHighAmount: '8670000',
61
+ maximumFeeRate: _maximumFeeRateCalculator.maximumFeeRateCalculator.call(void 0, currencyInfo, 100)
62
+ }
63
+ }
64
+
65
+ const coinInfo = {
66
+ name: 'ecashbitcoinbetanet',
67
+ segwit: true,
68
+ coinType: 0,
69
+ // LOCKTIME_THRESHOLD - 1, final only on eCash betanet:
70
+ lockTime: 499999999,
71
+
72
+ prefixes: {
73
+ messagePrefix: ['\x18Bitcoin Signed Message:\n'],
74
+ wif: [0x80],
75
+ legacyXPriv: [0x0488ade4],
76
+ legacyXPub: [0x0488b21e],
77
+ wrappedSegwitXPriv: [0x049d7878],
78
+ wrappedSegwitXPub: [0x049d7cb2],
79
+ segwitXPriv: [0x04b2430c],
80
+ segwitXPub: [0x04b24746],
81
+ pubkeyHash: [0x00],
82
+ scriptHash: [0x05],
83
+ bech32: ['bc']
84
+ }
85
+ }; exports.coinInfo = coinInfo
86
+
87
+ const info = {
88
+ currencyInfo,
89
+ engineInfo,
90
+ coinInfo: exports.coinInfo
91
+ }; exports.info = info
@@ -1083,14 +1083,18 @@ function signBip322Witness(
1083
1083
 
1084
1084
  function makeTx(args) {
1085
1085
  const { log, outputSort, memos, memoIndex } = args
1086
+ const coin = _coinmapper.getCoinFromString.call(void 0, args.coin)
1087
+
1086
1088
  let sequence = 0xffffffff
1087
1089
  if (args.enableRbf) {
1088
1090
  sequence -= 2
1091
+ } else if (coin.lockTime != null) {
1092
+ // Nodes ignore nLockTime unless an input sequence is non-final:
1093
+ sequence -= 1
1089
1094
  }
1090
1095
 
1091
1096
  // get coin specific replay protection sighhash bits
1092
1097
  let sighashType = _altcoinjs.Transaction.SIGHASH_ALL
1093
- const coin = _coinmapper.getCoinFromString.call(void 0, args.coin)
1094
1098
  if (coin.sighash != null) {
1095
1099
  sighashType = coin.sighash
1096
1100
  }
@@ -1246,6 +1250,7 @@ function signBip322Witness(
1246
1250
  }
1247
1251
 
1248
1252
  const psbt = new (0, _altcoinjs.Psbt)()
1253
+ if (coin.lockTime != null) psbt.setLocktime(coin.lockTime)
1249
1254
  try {
1250
1255
  psbt.addInputs(sortedInputs)
1251
1256
  psbt.addOutputs(sortedOutputs)
@@ -107,6 +107,8 @@ var _Socket = require('./Socket');
107
107
 
108
108
 
109
109
 
110
+
111
+
110
112
 
111
113
 
112
114
 
@@ -232,7 +234,7 @@ var _Socket = require('./Socket');
232
234
  )
233
235
  }
234
236
  socket.subscribe({
235
- ..._blockbookApi.subscribeNewBlockMessage.call(void 0, ),
237
+ ...(_nullishCoalesce(config.subscribeNewBlockMessage, () => ( (0, _blockbookApi.subscribeNewBlockMessage))))(),
236
238
  cb: socketCb,
237
239
  deferred: deferredBlockSub,
238
240
  subscribed: false