edge-currency-plugins 1.2.2 → 1.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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _biggystring = require('biggystring'); var bs = _interopRequireWildcard(_biggystring);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _biggystring = require('biggystring');
2
2
 
3
3
 
4
4
  var _memlet = require('memlet');
@@ -6,6 +6,7 @@ var _memlet = require('memlet');
6
6
  var _awaitlock = require('../utxobased/engine/await-lock'); var _awaitlock2 = _interopRequireDefault(_awaitlock);
7
7
  var _makeEngineEmitter = require('./makeEngineEmitter');
8
8
  var _types3 = require('./types');
9
+ var _utils = require('./utils');
9
10
 
10
11
  const metadataPath = `metadata.json`
11
12
 
@@ -19,6 +20,7 @@ const metadataPath = `metadata.json`
19
20
 
20
21
 
21
22
 
23
+
22
24
  const makeMetadata = async (
23
25
  config
24
26
  ) => {
@@ -27,11 +29,8 @@ const metadataPath = `metadata.json`
27
29
  const lock = new (0, _awaitlock2.default)()
28
30
 
29
31
  const instance = {
30
- get balance() {
31
- return cache.balance
32
- },
33
- get lastSeenBlockHeight() {
34
- return cache.lastSeenBlockHeight
32
+ get state() {
33
+ return cache
35
34
  },
36
35
  clear: async () => {
37
36
  await memlet.delete(metadataPath)
@@ -40,18 +39,37 @@ const metadataPath = `metadata.json`
40
39
  }
41
40
  }
42
41
 
42
+ const updateWalletBalance = async (currencyCode) => {
43
+ const cumulativeBalance = Object.values(cache.addressBalances).reduce(
44
+ (sum, addressBalance) => _biggystring.add.call(void 0, sum, addressBalance),
45
+ '0'
46
+ )
47
+ cache.balance = cumulativeBalance
48
+ await setMetadata(cache)
49
+ emitter.emit(
50
+ _makeEngineEmitter.EngineEvent.WALLET_BALANCE_CHANGED,
51
+ currencyCode,
52
+ cumulativeBalance
53
+ )
54
+ }
55
+
43
56
  emitter.on(
44
57
  _makeEngineEmitter.EngineEvent.ADDRESS_BALANCE_CHANGED,
45
- async (currencyCode, balanceDiff) => {
58
+ async (
59
+ currencyCode,
60
+ addressBalanceChanges
61
+ ) => {
46
62
  await lock.acquireAsync()
47
63
  try {
48
- cache.balance = bs.add(cache.balance, balanceDiff)
49
- emitter.emit(
50
- _makeEngineEmitter.EngineEvent.WALLET_BALANCE_CHANGED,
51
- currencyCode,
52
- cache.balance
53
- )
54
- await setMetadata(cache)
64
+ addressBalanceChanges.forEach(({ scriptPubkey, balance }) => {
65
+ if (balance === '0') {
66
+ _utils.removeItem.call(void 0, cache.addressBalances, scriptPubkey)
67
+ } else {
68
+ cache.addressBalances[scriptPubkey] = balance
69
+ }
70
+ })
71
+
72
+ await updateWalletBalance(currencyCode)
55
73
  } catch (err) {
56
74
  log.error(err)
57
75
  } finally {
@@ -83,6 +101,7 @@ const metadataPath = `metadata.json`
83
101
  const resetMetadata = async () => {
84
102
  const data = {
85
103
  balance: '0',
104
+ addressBalances: {},
86
105
  lastSeenBlockHeight: 0
87
106
  }
88
107
  await memlet.setJson(metadataPath, data)
@@ -167,5 +167,7 @@ var _cleaners = require('cleaners');
167
167
 
168
168
  const asLocalWalletMetadata = _cleaners.asObject.call(void 0, {
169
169
  balance: _cleaners.asString,
170
+ // scriptPubkey -> balance
171
+ addressBalances: _cleaners.asObject.call(void 0, _cleaners.asString),
170
172
  lastSeenBlockHeight: _cleaners.asNumber
171
173
  }); exports.asLocalWalletMetadata = asLocalWalletMetadata
@@ -58,10 +58,11 @@ var _keymanager = require('../../keymanager/keymanager');
58
58
 
59
59
 
60
60
 
61
+
61
62
  const toEdgeTransaction = async (
62
63
  args
63
64
  ) => {
64
- const { tx, processor, walletTools, pluginInfo } = args
65
+ const { tx, processor, walletTools, pluginInfo, walletId } = args
65
66
  const { engineInfo, currencyInfo } = pluginInfo
66
67
  const ourReceiveAddresses = []
67
68
  for (const out of tx.ourOuts) {
@@ -69,7 +70,7 @@ var _keymanager = require('../../keymanager/keymanager');
69
70
  const address = await processor.fetchAddress(scriptPubkey)
70
71
 
71
72
  /*
72
- Hack to set replay protection tx to the correct script type through the
73
+ Hack to set replay protection tx to the correct script type through the
73
74
  address format.
74
75
 
75
76
  We use a function which can determine whether the derivationLevelScriptHash
@@ -114,6 +115,7 @@ var _keymanager = require('../../keymanager/keymanager');
114
115
  } catch (e) {}
115
116
 
116
117
  return {
118
+ walletId,
117
119
  currencyCode: currencyInfo.currencyCode,
118
120
  txid: tx.txid,
119
121
  blockHeight: tx.blockHeight,
@@ -13,6 +13,7 @@ var _disklet = require('disklet');
13
13
 
14
14
 
15
15
 
16
+
16
17
  var _types = require('edge-core-js/types');
17
18
 
18
19
  var _filterUndefined = require('../../../util/filterUndefined');
@@ -124,7 +125,7 @@ var _utils = require('./utils');
124
125
  emitter.emit(
125
126
  _makeEngineEmitter.EngineEvent.WALLET_BALANCE_CHANGED,
126
127
  currencyInfo.currencyCode,
127
- metadata.balance
128
+ metadata.state.balance
128
129
  )
129
130
 
130
131
  pluginState.addEngine(engineState)
@@ -139,11 +140,11 @@ var _utils = require('./utils');
139
140
  },
140
141
 
141
142
  getBalance(_opts) {
142
- return metadata.balance
143
+ return metadata.state.balance
143
144
  },
144
145
 
145
146
  getBlockHeight() {
146
- return metadata.lastSeenBlockHeight
147
+ return metadata.state.lastSeenBlockHeight
147
148
  },
148
149
 
149
150
  async addCustomToken(_token) {
@@ -196,6 +197,7 @@ var _utils = require('./utils');
196
197
  primaryFormat,
197
198
  walletFormats
198
199
  },
200
+ metadataState: metadata.state,
199
201
  processorState: await processor.dumpData(),
200
202
  pluginState: pluginState.dumpData()
201
203
  }
@@ -226,9 +228,10 @@ var _utils = require('./utils');
226
228
  },
227
229
 
228
230
  async getFreshAddress(
229
- _opts
231
+ opts
230
232
  ) {
231
- return await engineState.getFreshAddress()
233
+ const { forceIndex } = opts
234
+ return await engineState.getFreshAddress({ forceIndex })
232
235
  },
233
236
 
234
237
  getNumTransactions(_opts) {
@@ -259,6 +262,7 @@ var _utils = require('./utils');
259
262
  txs.map(
260
263
  async (tx) =>
261
264
  await _ProcessorTransaction.toEdgeTransaction.call(void 0, {
265
+ walletId: walletInfo.id,
262
266
  tx,
263
267
  walletTools,
264
268
  processor,
@@ -280,7 +284,13 @@ var _utils = require('./utils');
280
284
  options
281
285
  ) {
282
286
  const { spendTargets } = edgeSpendInfo
283
- const { outputSort = 'bip69' } = _nullishCoalesce(edgeSpendInfo.otherParams, () => ( {}))
287
+ const { outputSort = 'bip69', utxoSourceAddress, forceChangeAddress } =
288
+ _nullishCoalesce(edgeSpendInfo.otherParams, () => ( {}))
289
+
290
+ let utxoScriptPubkey
291
+ if (utxoSourceAddress != null) {
292
+ utxoScriptPubkey = walletTools.addressToScriptPubkey(utxoSourceAddress)
293
+ }
284
294
 
285
295
  if (_optionalChain([options, 'optionalAccess', _5 => _5.CPFP]) == null && spendTargets.length < 1) {
286
296
  throw new Error('Need to provide Spend Targets')
@@ -292,7 +302,12 @@ var _utils = require('./utils');
292
302
  )
293
303
  const utxos =
294
304
  await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async _6 => _6.utxos]), async () => (
295
- ((await processor.fetchUtxos({ utxoIds: [] })) )))
305
+ _filterUndefined.filterUndefined.call(void 0,
306
+ (await processor.fetchUtxos({
307
+ scriptPubkey: utxoScriptPubkey,
308
+ utxoIds: []
309
+ }))
310
+ )))
296
311
 
297
312
  if (
298
313
  bs.gt(totalAmountToSend, `${_utils.sumUtxos.call(void 0, utxos)}`) ||
@@ -352,9 +367,12 @@ var _utils = require('./utils');
352
367
  throw new Error('Need to provide Spend Targets')
353
368
  }
354
369
 
355
- const freshAddress = await engineState.getFreshAddress(1)
370
+ const freshAddress = await engineState.getFreshAddress({ branch: 1 })
356
371
  const freshChangeAddress =
357
- _nullishCoalesce(freshAddress.segwitAddress, () => ( freshAddress.publicAddress))
372
+ _nullishCoalesce(_nullishCoalesce(forceChangeAddress, () => (
373
+ freshAddress.segwitAddress)), () => (
374
+ freshAddress.publicAddress))
375
+
358
376
  const setRBF = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.setRBF]), () => ( false))
359
377
  const rbfTxid = edgeSpendInfo.rbfTxid
360
378
  let maxUtxo
@@ -442,6 +460,7 @@ var _utils = require('./utils');
442
460
  }
443
461
 
444
462
  const transaction = {
463
+ walletId: walletInfo.id,
445
464
  ourReceiveAddresses,
446
465
  otherParams,
447
466
  currencyCode: currencyInfo.currencyCode,
@@ -479,6 +498,7 @@ var _utils = require('./utils');
479
498
  async saveTx(edgeTx) {
480
499
  const tx = _ProcessorTransaction.fromEdgeTransaction.call(void 0, edgeTx)
481
500
  await _makeUtxoEngineState.transactionChanged.call(void 0, {
501
+ walletId: walletInfo.id,
482
502
  tx,
483
503
  pluginInfo,
484
504
  emitter,
@@ -567,6 +587,7 @@ var _utils = require('./utils');
567
587
  transaction.signedTx,
568
588
  transaction.currencyCode
569
589
  )
590
+ if (transaction.otherParams == null) transaction.otherParams = {}
570
591
  Object.assign(transaction.otherParams, {
571
592
  paymentProtocolInfo: {
572
593
  ...paymentProtocolInfo,
@@ -644,7 +665,7 @@ var _utils = require('./utils');
644
665
  throw new Error('Private key has no funds')
645
666
  }
646
667
  const destAddress = await this.getFreshAddress({})
647
- const nativeAmount = tmpMetadata.balance
668
+ const nativeAmount = tmpMetadata.state.balance
648
669
  const options = { utxos: tmpUtxos, subtractFee: true }
649
670
  spendInfo.spendTargets = [
650
671
  { publicAddress: destAddress.publicAddress, nativeAmount }
@@ -84,6 +84,9 @@ var _utils3 = require('./utils');
84
84
 
85
85
 
86
86
 
87
+
88
+
89
+
87
90
 
88
91
 
89
92
 
@@ -258,6 +261,11 @@ var _utils3 = require('./utils');
258
261
  // processed by the processor. This happens only once before any call to
259
262
  // setLookAhead.
260
263
  const initializeAddressSubscriptions = async () => {
264
+ const addressBalanceChanges
265
+
266
+
267
+ = []
268
+
261
269
  for (const format of walletFormats) {
262
270
  const branches = _utils3.getFormatSupportedBranches.call(void 0, format)
263
271
  for (const branch of branches) {
@@ -289,6 +297,10 @@ var _utils3 = require('./utils');
289
297
  format
290
298
  })
291
299
  addressesToSubscribe.add(address)
300
+ addressBalanceChanges.push({
301
+ scriptPubkey: processorAddress.scriptPubkey,
302
+ balance: processorAddress.balance
303
+ })
292
304
  }
293
305
  addToAddressSubscribeCache(commonArgs.taskCache, addressesToSubscribe, {
294
306
  format,
@@ -296,6 +308,15 @@ var _utils3 = require('./utils');
296
308
  })
297
309
  }
298
310
  }
311
+
312
+ // Only emit address balance events after processing all initial addresses
313
+ // because we want to only propagate the wallet balance change event after
314
+ // initialization is complete.
315
+ emitter.emit(
316
+ _makeEngineEmitter.EngineEvent.ADDRESS_BALANCE_CHANGED,
317
+ pluginInfo.currencyInfo.currencyCode,
318
+ addressBalanceChanges
319
+ )
299
320
  }
300
321
 
301
322
  return {
@@ -314,28 +335,48 @@ var _utils3 = require('./utils');
314
335
  running = false
315
336
  },
316
337
 
317
- async getFreshAddress(branch = 0) {
338
+ async getFreshAddress({
339
+ branch = 0,
340
+ forceIndex
341
+ }) {
318
342
  const walletPurpose = _utils3.currencyFormatToPurposeType.call(void 0,
319
343
  walletInfo.keys.primaryFormat
320
344
  )
321
345
  if (walletPurpose === _keymanager.BIP43PurposeTypeEnum.Segwit) {
322
- const { address: publicAddress } = await internalGetFreshAddress({
346
+ const {
347
+ address: publicAddress,
348
+ nativeBalance = '0',
349
+ legacyAddress
350
+ } = await internalGetFreshAddress({
323
351
  ...commonArgs,
324
352
  format: _utils3.getCurrencyFormatFromPurposeType.call(void 0,
325
353
  _keymanager.BIP43PurposeTypeEnum.WrappedSegwit
326
354
  ),
355
+ forceIndex,
327
356
  changeIndex: branch
328
357
  })
329
358
 
330
- const { address: segwitAddress } = await internalGetFreshAddress({
359
+ const {
360
+ address: segwitAddress,
361
+ nativeBalance: segwitNativeBalance = '0'
362
+ } = await internalGetFreshAddress({
331
363
  ...commonArgs,
332
364
  format: _utils3.getCurrencyFormatFromPurposeType.call(void 0, _keymanager.BIP43PurposeTypeEnum.Segwit),
365
+ forceIndex,
333
366
  changeIndex: branch
334
367
  })
335
368
 
336
369
  return {
370
+ nativeBalance,
337
371
  publicAddress,
338
- segwitAddress
372
+ legacyNativeBalance:
373
+ legacyAddress !== publicAddress ? nativeBalance : undefined,
374
+ // Legacy address is just a different encoding of the standard public address
375
+ // and therefore would have the same balance
376
+ legacyAddress:
377
+ legacyAddress !== publicAddress ? legacyAddress : undefined,
378
+ segwitAddress,
379
+ segwitNativeBalance
339
380
  }
340
381
  } else {
341
382
  // Airbitz wallets only use branch 0
@@ -345,15 +386,22 @@ var _utils3 = require('./utils');
345
386
 
346
387
  const {
347
388
  address: publicAddress,
389
+ nativeBalance = '0',
348
390
  legacyAddress
349
391
  } = await internalGetFreshAddress({
350
392
  ...commonArgs,
351
393
  format: _utils3.getCurrencyFormatFromPurposeType.call(void 0, walletPurpose),
394
+ forceIndex,
352
395
  changeIndex: branch
353
396
  })
354
397
 
355
398
  return {
399
+ nativeBalance,
356
400
  publicAddress,
401
+ legacyNativeBalance:
402
+ legacyAddress !== publicAddress ? nativeBalance : undefined,
403
+ // Legacy address is just a different encoding of the standard public address
404
+ // and therefore would have the same balance
357
405
  legacyAddress:
358
406
  legacyAddress !== publicAddress ? legacyAddress : undefined
359
407
  }
@@ -656,12 +704,14 @@ const addToAddressTransactionCache = async (
656
704
 
657
705
 
658
706
 
707
+
659
708
  const transactionChanged = async (
660
709
  args
661
710
  ) => {
662
- const { emitter, walletTools, processor, pluginInfo, tx } = args
711
+ const { emitter, walletTools, processor, pluginInfo, tx, walletId } = args
663
712
  emitter.emit(_makeEngineEmitter.EngineEvent.TRANSACTIONS_CHANGED, [
664
713
  await _ProcessorTransaction.toEdgeTransaction.call(void 0, {
714
+ walletId,
665
715
  tx,
666
716
  walletTools,
667
717
  processor,
@@ -912,7 +962,15 @@ const addToAddressTransactionCache = async (
912
962
  const updateTransactionsSpecific = (
913
963
  args
914
964
  ) => {
915
- const { emitter, walletTools, txId, pluginInfo, processor, taskCache } = args
965
+ const {
966
+ walletInfo,
967
+ emitter,
968
+ walletTools,
969
+ txId,
970
+ pluginInfo,
971
+ processor,
972
+ taskCache
973
+ } = args
916
974
  const deferred = new _Deferred2.default()
917
975
  deferred.promise
918
976
  .then(async (txResponse) => {
@@ -932,6 +990,7 @@ const updateTransactionsSpecific = (
932
990
  })
933
991
 
934
992
  await exports.transactionChanged.call(void 0, {
993
+ walletId: walletInfo.id,
935
994
  emitter,
936
995
  walletTools,
937
996
  processor,
@@ -959,6 +1018,7 @@ const updateTransactions = (
959
1018
  args
960
1019
  ) => {
961
1020
  const {
1021
+ walletInfo,
962
1022
  emitter,
963
1023
  walletTools,
964
1024
  txId,
@@ -994,6 +1054,7 @@ const updateTransactions = (
994
1054
  })
995
1055
 
996
1056
  await exports.transactionChanged.call(void 0, {
1057
+ walletId: walletInfo.id,
997
1058
  emitter,
998
1059
  walletTools,
999
1060
  processor,
@@ -1080,10 +1141,19 @@ const internalDeriveScriptAddress = async ({
1080
1141
 
1081
1142
 
1082
1143
 
1144
+
1145
+
1146
+
1083
1147
  const internalGetFreshAddress = async (
1084
1148
  args
1085
1149
  ) => {
1086
- const { format, changeIndex: branch, walletTools, processor } = args
1150
+ const {
1151
+ format,
1152
+ changeIndex: branch,
1153
+ walletTools,
1154
+ processor,
1155
+ forceIndex
1156
+ } = args
1087
1157
 
1088
1158
  const numAddresses = processor.numAddressesByFormatPath({
1089
1159
  format,
@@ -1099,16 +1169,33 @@ const internalGetFreshAddress = async (
1099
1169
  0
1100
1170
  )
1101
1171
  }
1102
- const { scriptPubkey } =
1103
- await _asyncNullishCoalesce((await processor.fetchAddress(path)), async () => (
1104
- (await walletTools.getScriptPubkey(path))))
1172
+ if (forceIndex != null) {
1173
+ path.addressIndex = forceIndex
1174
+ }
1175
+
1176
+ let nativeBalance = '0'
1177
+ let scriptPubkey
1178
+ const iAddress = await processor.fetchAddress(path)
1179
+ if (iAddress != null) {
1180
+ nativeBalance = iAddress.balance
1181
+ scriptPubkey = iAddress.scriptPubkey
1182
+ } else {
1183
+ const scriptPubKeyRet = await walletTools.getScriptPubkey(path)
1184
+ scriptPubkey = scriptPubKeyRet.scriptPubkey
1185
+ }
1186
+
1105
1187
  if (scriptPubkey == null) {
1106
1188
  throw new Error('Unknown address path')
1107
1189
  }
1108
- return walletTools.scriptPubkeyToAddress({
1190
+ const address = walletTools.scriptPubkeyToAddress({
1109
1191
  scriptPubkey,
1110
1192
  format
1111
1193
  })
1194
+
1195
+ return {
1196
+ ...address,
1197
+ nativeBalance
1198
+ }
1112
1199
  }
1113
1200
 
1114
1201
 
@@ -1122,6 +1209,7 @@ const processAddressTransactions = async (
1122
1209
  args
1123
1210
  ) => {
1124
1211
  const {
1212
+ walletInfo,
1125
1213
  address,
1126
1214
  addressTransactionState,
1127
1215
  emitter,
@@ -1166,6 +1254,7 @@ const processAddressTransactions = async (
1166
1254
  scriptPubkeys: [scriptPubkey]
1167
1255
  })
1168
1256
  await exports.transactionChanged.call(void 0, {
1257
+ walletId: walletInfo.id,
1169
1258
  emitter,
1170
1259
  walletTools,
1171
1260
  processor,
@@ -1416,13 +1505,17 @@ const processProcessorUtxos = async (
1416
1505
  //
1417
1506
 
1418
1507
  // Address balance and emit address balance change event
1419
- const diff = _biggystring.sub.call(void 0, newBalance, oldBalance)
1420
- if (diff !== '0') {
1421
- log('balance changed:', { scriptPubkey, diff })
1508
+ if (newBalance !== oldBalance) {
1509
+ log('address balance changed:', { scriptPubkey, oldBalance, newBalance })
1422
1510
  emitter.emit(
1423
1511
  _makeEngineEmitter.EngineEvent.ADDRESS_BALANCE_CHANGED,
1424
1512
  currencyInfo.currencyCode,
1425
- diff
1513
+ [
1514
+ {
1515
+ scriptPubkey,
1516
+ balance: newBalance
1517
+ }
1518
+ ]
1426
1519
  )
1427
1520
 
1428
1521
  // Update balances for address that have this scriptPubkey
@@ -3,8 +3,14 @@ import { EdgeCurrencyEngineCallbacks, EdgeTransaction, EdgeTxidMap } from 'edge-
3
3
  import { EventEmitter } from 'events';
4
4
  import { SubscribeAddressResponse } from '../utxobased/network/BlockBookAPI';
5
5
  export declare interface EngineEmitter {
6
- emit: ((event: EngineEvent.TRANSACTIONS_CHANGED, transactions: EdgeTransaction[]) => boolean) & ((event: EngineEvent.ADDRESS_BALANCE_CHANGED, currencyCode: string, nativeDiff: string) => boolean) & ((event: EngineEvent.WALLET_BALANCE_CHANGED, currencyCode: string, nativeBalance: string) => boolean) & ((event: EngineEvent.BLOCK_HEIGHT_CHANGED, uri: string, blockHeight: number) => boolean) & ((event: EngineEvent.NEW_ADDRESS_TRANSACTION, uri: string, newTx: SubscribeAddressResponse) => boolean) & ((event: EngineEvent.ADDRESSES_CHECKED, progressRatio: number) => boolean) & ((event: EngineEvent.TXIDS_CHANGED, txids: EdgeTxidMap) => boolean);
7
- on: ((event: EngineEvent.TRANSACTIONS_CHANGED, listener: (transactions: EdgeTransaction[]) => Promise<void> | void) => this) & ((event: EngineEvent.ADDRESS_BALANCE_CHANGED, listener: (currencyCode: string, nativeDiff: string) => Promise<void> | void) => this) & ((event: EngineEvent.WALLET_BALANCE_CHANGED, listener: (currencyCode: string, nativeBalance: string) => Promise<void> | void) => this) & ((event: EngineEvent.BLOCK_HEIGHT_CHANGED, listener: (uri: string, blockHeight: number) => Promise<void> | void) => this) & ((event: EngineEvent.NEW_ADDRESS_TRANSACTION, listener: (uri: string, newTx: SubscribeAddressResponse) => Promise<void> | void) => this) & ((event: EngineEvent.ADDRESSES_CHECKED, listener: (progressRatio: number) => Promise<void> | void) => this) & ((event: EngineEvent.TXIDS_CHANGED, listener: (txids: EdgeTxidMap) => Promise<void> | void) => this);
6
+ emit: ((event: EngineEvent.TRANSACTIONS_CHANGED, transactions: EdgeTransaction[]) => boolean) & ((event: EngineEvent.ADDRESS_BALANCE_CHANGED, currencyCode: string, addressBalanceChanges: Array<{
7
+ scriptPubkey: string;
8
+ balance: string;
9
+ }>) => boolean) & ((event: EngineEvent.WALLET_BALANCE_CHANGED, currencyCode: string, nativeBalance: string) => boolean) & ((event: EngineEvent.BLOCK_HEIGHT_CHANGED, uri: string, blockHeight: number) => boolean) & ((event: EngineEvent.NEW_ADDRESS_TRANSACTION, uri: string, newTx: SubscribeAddressResponse) => boolean) & ((event: EngineEvent.ADDRESSES_CHECKED, progressRatio: number) => boolean) & ((event: EngineEvent.TXIDS_CHANGED, txids: EdgeTxidMap) => boolean);
10
+ on: ((event: EngineEvent.TRANSACTIONS_CHANGED, listener: (transactions: EdgeTransaction[]) => Promise<void> | void) => this) & ((event: EngineEvent.ADDRESS_BALANCE_CHANGED, listener: (currencyCode: string, addressBalanceChanges: Array<{
11
+ scriptPubkey: string;
12
+ balance: string;
13
+ }>) => Promise<void> | void) => this) & ((event: EngineEvent.WALLET_BALANCE_CHANGED, listener: (currencyCode: string, nativeBalance: string) => Promise<void> | void) => this) & ((event: EngineEvent.BLOCK_HEIGHT_CHANGED, listener: (uri: string, blockHeight: number) => Promise<void> | void) => this) & ((event: EngineEvent.NEW_ADDRESS_TRANSACTION, listener: (uri: string, newTx: SubscribeAddressResponse) => Promise<void> | void) => this) & ((event: EngineEvent.ADDRESSES_CHECKED, listener: (progressRatio: number) => Promise<void> | void) => this) & ((event: EngineEvent.TXIDS_CHANGED, listener: (txids: EdgeTxidMap) => Promise<void> | void) => this);
8
14
  }
9
15
  export declare class EngineEmitter extends EventEmitter {
10
16
  }
@@ -7,7 +7,8 @@ interface MetadataConfig {
7
7
  emitter: EngineEmitter;
8
8
  log: EdgeLog;
9
9
  }
10
- export interface Metadata extends LocalWalletMetadata {
10
+ export interface Metadata {
11
+ state: LocalWalletMetadata;
11
12
  clear: () => Promise<void>;
12
13
  }
13
14
  export declare const makeMetadata: (config: MetadataConfig) => Promise<Metadata>;
@@ -130,6 +130,9 @@ export interface EngineOptions extends EdgeCurrencyEngineOptions {
130
130
  export declare type LocalWalletMetadata = ReturnType<typeof asLocalWalletMetadata>;
131
131
  export declare const asLocalWalletMetadata: import("cleaners").ObjectCleaner<{
132
132
  balance: string;
133
+ addressBalances: {
134
+ [keys: string]: string;
135
+ };
133
136
  lastSeenBlockHeight: number;
134
137
  }>;
135
138
  export {};
@@ -5,6 +5,7 @@ import { Processor } from '../makeProcessor';
5
5
  import { IProcessorTransaction } from '../types';
6
6
  export declare const fromEdgeTransaction: (tx: EdgeTransaction) => IProcessorTransaction;
7
7
  interface ToEdgeTransactionArgs {
8
+ walletId: string;
8
9
  tx: IProcessorTransaction;
9
10
  walletTools: UTXOPluginWalletTools;
10
11
  processor: Processor;
@@ -14,7 +14,10 @@ export interface UtxoEngineState {
14
14
  start: () => Promise<void>;
15
15
  stop: () => Promise<void>;
16
16
  deriveScriptAddress: (script: string) => Promise<EdgeFreshAddress>;
17
- getFreshAddress: (branch?: number) => Promise<EdgeFreshAddress>;
17
+ getFreshAddress: (params: {
18
+ branch?: number;
19
+ forceIndex?: number;
20
+ }) => Promise<EdgeFreshAddress>;
18
21
  addGapLimitAddresses: (addresses: string[]) => Promise<void>;
19
22
  broadcastTx: (transaction: EdgeTransaction) => Promise<string>;
20
23
  refillServers: () => void;
@@ -101,6 +104,7 @@ interface AddressTransactionCache {
101
104
  };
102
105
  }
103
106
  interface TransactionChangedArgs {
107
+ walletId: string;
104
108
  tx: IProcessorTransaction;
105
109
  emitter: EngineEmitter;
106
110
  walletTools: UTXOPluginWalletTools;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-plugins",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "description": "Edge currency plugins to fetch and process wallet accounts, balances and transactions.",
5
5
  "repository": "https://github.com/EdgeApp/edge-currency-plugins",
6
6
  "license": "MIT",
@@ -48,7 +48,7 @@
48
48
  "bs58smartcheck": "^2.0.4",
49
49
  "cleaners": "^0.3.12",
50
50
  "disklet": "^0.4.5",
51
- "edge-core-js": "^0.19.20",
51
+ "edge-core-js": "^0.19.33",
52
52
  "edge-sync-client": "^0.2.7",
53
53
  "memlet": "^0.1.6",
54
54
  "uri-js": "^4.4.0",