edge-currency-plugins 2.6.0 → 2.6.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.
@@ -157,12 +157,17 @@ const BASELET_DIR = 'tables'
157
157
  },
158
158
 
159
159
  async dumpData() {
160
- const allBases = Object.values(baselets.all)
160
+
161
+ const allBases = Object.values(
162
+ baselets.all
163
+ )
161
164
  return await Promise.all(
162
- allBases.map(async base => ({
163
- databaseName: base.databaseName,
164
- data: (await base.dumpData(''))
165
- }))
165
+ allBases.map(async base => {
166
+ return {
167
+ databaseName: base.databaseName,
168
+ data: (await base.dumpData())
169
+ }
170
+ })
166
171
  )
167
172
  },
168
173
 
@@ -399,6 +404,15 @@ const BASELET_DIR = 'tables'
399
404
 
400
405
  async saveAddress(address) {
401
406
  await baselets.address(async tables => {
407
+ // This variable is used to update the scriptPubkeyByPath table.
408
+ // The path table must be written after the address table because the
409
+ // path table is an index of the address table.
410
+ // This variable acts as a catch for that update to be done after the
411
+ // address table is written.
412
+ let indexTableUpdate
413
+
414
+
415
+
402
416
  const [existingAddress] = await tables.addressByScriptPubkey.query('', [
403
417
  address.scriptPubkey
404
418
  ])
@@ -415,14 +429,14 @@ const BASELET_DIR = 'tables'
415
429
  'Attempted to save address with an existing path, but different script pubkey'
416
430
  )
417
431
 
418
- await tables.scriptPubkeyByPath.insert(
419
- _baselet3.addressPathToPrefix.call(void 0, address.path),
420
- address.path.addressIndex,
421
- address.scriptPubkey
422
- )
432
+ indexTableUpdate = {
433
+ path: address.path,
434
+ scriptPubkey: address.scriptPubkey
435
+ }
423
436
 
424
- // check if this address is used and if so, whether it has a higher last used index
425
- if (address.used || (_nullishCoalesce(_optionalChain([existingAddress, 'optionalAccess', _2 => _2.used]), () => ( false)))) {
437
+ // check if this address is used and if so, whether it has a higher
438
+ // last used index
439
+ if (address.used || _optionalChain([existingAddress, 'optionalAccess', _2 => _2.used]) === true) {
426
440
  let [lastUsed] = await tables.lastUsedByFormatPath.query('', [
427
441
  _baselet3.addressPathToPrefix.call(void 0, address.path)
428
442
  ])
@@ -438,6 +452,7 @@ const BASELET_DIR = 'tables'
438
452
  }
439
453
  }
440
454
 
455
+ // Update routine:
441
456
  if (existingAddress != null) {
442
457
  // Only update the lastQueriedBlockHeight on the address if one was given and is greater than the existing value
443
458
  if (
@@ -463,16 +478,21 @@ const BASELET_DIR = 'tables'
463
478
  existingAddress.balance = address.balance
464
479
  }
465
480
 
466
- // Only update the path field if one was given and currently does not have one
467
- // NOTE: Addresses can be stored in the db without a path due to the `EdgeCurrencyEngine.addGapLimitAddresses` function
468
- // Once an address path is known, it should never be updated
481
+ /*
482
+ Only update the path field if one was given and the existing address
483
+ currently does not have one. We never update paths for addresses, only
484
+ insert paths when they're not present.
485
+
486
+ NOTE: Addresses can be stored in the db without a path due to the
487
+ `EdgeCurrencyEngine.addGapLimitAddresses` function. Once an address
488
+ path is known, it should never be updated
489
+ */
469
490
  if (address.path != null && existingAddress.path == null) {
470
491
  existingAddress.path = address.path
471
- await tables.scriptPubkeyByPath.insert(
472
- _baselet3.addressPathToPrefix.call(void 0, address.path),
473
- address.path.addressIndex,
474
- address.scriptPubkey
475
- )
492
+ indexTableUpdate = {
493
+ path: existingAddress.path,
494
+ scriptPubkey: existingAddress.scriptPubkey
495
+ }
476
496
  }
477
497
 
478
498
  // Only update the used flag if one was given and is true
@@ -495,18 +515,32 @@ const BASELET_DIR = 'tables'
495
515
  )
496
516
  }
497
517
  }
518
+
519
+ // Update the address table:
498
520
  await tables.addressByScriptPubkey.insert(
499
521
  '',
500
522
  existingAddress.scriptPubkey,
501
523
  existingAddress
502
524
  )
503
- return
504
525
  }
505
- await tables.addressByScriptPubkey.insert(
506
- '',
507
- address.scriptPubkey,
508
- address
509
- )
526
+
527
+ // Insert routine:
528
+ if (existingAddress == null) {
529
+ await tables.addressByScriptPubkey.insert(
530
+ '',
531
+ address.scriptPubkey,
532
+ address
533
+ )
534
+ }
535
+
536
+ // Insert the path into the index table:
537
+ if (indexTableUpdate != null) {
538
+ await tables.scriptPubkeyByPath.insert(
539
+ _baselet3.addressPathToPrefix.call(void 0, indexTableUpdate.path),
540
+ indexTableUpdate.path.addressIndex,
541
+ indexTableUpdate.scriptPubkey
542
+ )
543
+ }
510
544
  })
511
545
  },
512
546
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-plugins",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
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",
@@ -36,7 +36,7 @@
36
36
  "@bitcoin-js/tiny-secp256k1-asmjs": "^2.2.3",
37
37
  "altcoin-js": "^1.0.0",
38
38
  "async-mutex": "^0.2.6",
39
- "baselet": "^0.2.4",
39
+ "baselet": "^0.3.0",
40
40
  "biggystring": "^4.1.3",
41
41
  "bip32": "^2.0.5",
42
42
  "bip32grs": "^2.0.5",
@@ -107,4 +107,4 @@
107
107
  "typescript": "^4.1.2",
108
108
  "wif": "^2.0.6"
109
109
  }
110
- }
110
+ }