edge-currency-plugins 3.3.0 → 3.3.2

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.
@@ -128,9 +128,14 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
128
128
  emitter,
129
129
  log
130
130
  })
131
+
131
132
  const dataLayer = await _DataLayer.makeDataLayer.call(void 0, {
132
133
  disklet: walletLocalDisklet
133
134
  })
135
+ // This is a temporary data layer used only once (i.e. nonce) for sweeping
136
+ // private keys.
137
+ let nonceDataLayer
138
+
134
139
  const engineProcessor = _UtxoEngineProcessor.makeUtxoEngineProcessor.call(void 0, {
135
140
  ...config,
136
141
  walletTools,
@@ -509,6 +514,10 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
509
514
  },
510
515
 
511
516
  async makeSpend(edgeSpendInfo) {
517
+ // Define which DatLayer is used for the spend:
518
+ const makeSpendDataLayer = _nullishCoalesce(nonceDataLayer, () => ( dataLayer))
519
+ if (nonceDataLayer != null) nonceDataLayer = undefined
520
+
512
521
  edgeSpendInfo = _upgradeMemos.upgradeMemos.call(void 0, edgeSpendInfo, currencyInfo)
513
522
  const { memos = [], spendTargets } = edgeSpendInfo
514
523
  const spendInfoOtherParams = _types7.asUtxoSpendInfoOtherParams.call(void 0,
@@ -537,7 +546,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
537
546
  const utxos =
538
547
  await _asyncNullishCoalesce(txOptions.utxos, async () => (
539
548
  _filterUndefined.filterUndefined.call(void 0,
540
- (await dataLayer.fetchUtxos({
549
+ (await makeSpendDataLayer.fetchUtxos({
541
550
  scriptPubkey: utxoScriptPubkey,
542
551
  utxoIds: []
543
552
  }))
@@ -578,7 +587,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
578
587
  const scriptPubkey = walletTools.addressToScriptPubkey(
579
588
  target.publicAddress
580
589
  )
581
- if ((await dataLayer.fetchAddress(scriptPubkey)) != null) {
590
+ if ((await makeSpendDataLayer.fetchAddress(scriptPubkey)) != null) {
582
591
  ourReceiveAddresses.push(target.publicAddress)
583
592
  }
584
593
  }
@@ -606,13 +615,15 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
606
615
 
607
616
  let maxUtxo
608
617
  if (txOptions.CPFP != null) {
609
- const [childTx] = await dataLayer.fetchTransactions({
618
+ const [childTx] = await makeSpendDataLayer.fetchTransactions({
610
619
  txId: txOptions.CPFP
611
620
  })
612
621
  if (childTx == null) throw new Error('transaction not found')
613
622
  const utxos = []
614
623
  for (const txid of childTx.ourOuts) {
615
- const [output] = await dataLayer.fetchUtxos({ utxoIds: [txid] })
624
+ const [output] = await makeSpendDataLayer.fetchUtxos({
625
+ utxoIds: [txid]
626
+ })
616
627
  if (output != null) utxos.push(output)
617
628
  }
618
629
  maxUtxo = utxos.reduce((a, b) => (bs.gt(a.value, b.value) ? a : b))
@@ -654,7 +665,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
654
665
  )
655
666
  for (const output of tx.outputs) {
656
667
  const scriptPubkey = output.scriptPubkey.toString('hex')
657
- const own = await dataLayer.fetchAddress(scriptPubkey)
668
+ const own = await makeSpendDataLayer.fetchAddress(scriptPubkey)
658
669
  if (own == null) {
659
670
  // Not our output
660
671
  nativeAmount = bs.sub(nativeAmount, output.value.toString())
@@ -896,16 +907,6 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
896
907
  },
897
908
 
898
909
  async sweepPrivateKeys(spendInfo) {
899
- // Create the promise to return
900
- let success
901
-
902
-
903
- let failure
904
- const end = new Promise((resolve, reject) => {
905
- success = resolve
906
- failure = reject
907
- })
908
-
909
910
  // The temporary wallet info should include all formats for the currency
910
911
  const allFormats = engineInfo.formats
911
912
 
@@ -940,37 +941,47 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
940
941
  publicKey: tmpWalletInfo.keys.publicKey
941
942
  })
942
943
 
943
- // Max spend after imported wallet finishes sync
944
- tmpEmitter.on(_EngineEmitter.EngineEvent.ADDRESSES_CHECKED, async (ratio) => {
945
- if (ratio === 1) {
946
- try {
947
- await tmpState.stop()
948
-
949
- const tmpUtxos = (await tmpDataLayer.fetchUtxos({
950
- utxoIds: []
951
- }))
952
- if (tmpUtxos === null || tmpUtxos.length < 1) {
953
- throw new Error('Private key has no funds')
954
- }
955
- const destAddress = await this.getFreshAddress({ tokenId: null })
956
- const nativeAmount = tmpMetadata.state.balance
957
- const txOptions = { utxos: tmpUtxos, subtractFee: true }
958
- spendInfo.spendTargets = [
959
- { publicAddress: destAddress.publicAddress, nativeAmount }
960
- ]
961
- spendInfo.otherParams = {
962
- ...spendInfo.otherParams,
963
- txOptions
944
+ // Wait for the imported wallet to finish syncing then create an
945
+ // EdgeTransaction using the imported wallet's balance.
946
+ const sweepTxPromise = new Promise((resolve, reject) => {
947
+ // Max spend after imported wallet finishes sync
948
+ tmpEmitter.on(_EngineEmitter.EngineEvent.ADDRESSES_CHECKED, async (ratio) => {
949
+ if (ratio === 1) {
950
+ try {
951
+ await tmpEngineProcessor.stop()
952
+
953
+ const tmpUtxos = (await tmpDataLayer.fetchUtxos({
954
+ utxoIds: []
955
+ }))
956
+ if (tmpUtxos === null || tmpUtxos.length < 1) {
957
+ throw new Error('Private key has no funds')
958
+ }
959
+ const destAddress = await this.getFreshAddress({
960
+ tokenId: null
961
+ })
962
+ const nativeAmount = tmpMetadata.state.balance
963
+ const txOptions = {
964
+ utxos: tmpUtxos,
965
+ subtractFee: true
966
+ }
967
+ spendInfo.spendTargets = [
968
+ { publicAddress: destAddress.publicAddress, nativeAmount }
969
+ ]
970
+ spendInfo.otherParams = {
971
+ ...spendInfo.otherParams,
972
+ txOptions
973
+ }
974
+ nonceDataLayer = tmpDataLayer
975
+ const tx = await engine.makeSpend(spendInfo)
976
+ resolve(tx)
977
+ } catch (e) {
978
+ reject(e)
964
979
  }
965
- const tx = await this.makeSpend(spendInfo)
966
- success(tx)
967
- } catch (e) {
968
- failure(e)
969
980
  }
970
- }
981
+ })
971
982
  })
972
983
 
973
- const tmpState = _UtxoEngineProcessor.makeUtxoEngineProcessor.call(void 0, {
984
+ const tmpEngineProcessor = _UtxoEngineProcessor.makeUtxoEngineProcessor.call(void 0, {
974
985
  ...config,
975
986
  options: {
976
987
  ...config.options,
@@ -990,10 +1001,10 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
990
1001
  walletTools: tmpWalletTools,
991
1002
  walletInfo: tmpWalletInfo
992
1003
  })
993
- await tmpState.loadWifs(privateKeys)
994
- await tmpState.start()
1004
+ await tmpEngineProcessor.loadWifs(privateKeys)
1005
+ await tmpEngineProcessor.start()
995
1006
 
996
- return await end
1007
+ return await sweepTxPromise
997
1008
  },
998
1009
 
999
1010
  otherMethods: {}
@@ -39,7 +39,7 @@ const currencyInfo = {
39
39
  'wss://dash3.trezor.io',
40
40
  'wss://dash4.trezor.io',
41
41
  'wss://dash5.trezor.io',
42
- 'wss://dashbook.nownodes.io/wss/%{nowNodesApiKey}'
42
+ 'wss://dash.nownodes.io/wss/%{nowNodesApiKey}'
43
43
  ],
44
44
  enableCustomServers: false
45
45
  },
@@ -49,7 +49,7 @@ const engineInfo = {
49
49
  serverConfigs: [
50
50
  {
51
51
  type: 'blockbook-nownode',
52
- uris: ['https://grsbook.nownodes.io']
52
+ uris: ['https://grs.nownodes.io']
53
53
  }
54
54
  ],
55
55
  formats: ['bip49', 'bip84', 'bip44', 'bip32'],
@@ -32,7 +32,7 @@ var _commonInfo = require('./commonInfo');
32
32
  customFeeSettings: ['satPerByte'],
33
33
  blockbookServers: [
34
34
  'wss://blockbook.firo.org',
35
- 'wss://firobook.nownodes.io/wss/%{nowNodesApiKey}'
35
+ 'wss://firo.nownodes.io/wss/%{nowNodesApiKey}'
36
36
  ],
37
37
  enableCustomServers: false
38
38
  },
@@ -153,14 +153,14 @@ const asResponseDefault = (raw) => [
153
153
  _socketQueue.removeIdFromQueue.call(void 0, socketQueueId)
154
154
  }
155
155
 
156
- const onSocketClose = () => {
156
+ const onSocketClose = (code) => {
157
157
  const errObj =
158
- trackedError != null
159
- ? trackedError instanceof Error
160
- ? trackedError
161
- : new Error(String(trackedError))
162
- : new Error('Socket closed without error')
163
- log.warn(`onSocketClose with server ${uri}: ${errObj.message}`)
158
+ trackedError == null
159
+ ? new Error('Socket closed without error')
160
+ : trackedError instanceof Error
161
+ ? trackedError
162
+ : new Error(String(trackedError))
163
+ log.warn(`onSocketClose with server ${uri}: ${code} ${errObj.message}`)
164
164
  clearTimeout(timer)
165
165
  connected = false
166
166
  socket = null
@@ -175,7 +175,7 @@ const asResponseDefault = (raw) => [
175
175
  try {
176
176
  emitter.emit(_SocketEmitter.SocketEvent.CONNECTION_CLOSE, uri, errObj)
177
177
  } catch (e) {
178
- log.error(e.message)
178
+ log.error(String(e))
179
179
  }
180
180
  }
181
181
 
@@ -403,7 +403,7 @@ const asResponseDefault = (raw) => [
403
403
  },
404
404
  onMessage: onMessage,
405
405
  onError: err => {
406
- trackedError = new Error(String(err))
406
+ trackedError = err
407
407
  },
408
408
  onClose: onSocketClose
409
409
  }
@@ -22,8 +22,8 @@ var _types = require('./types');
22
22
  ws.on('error', error => {
23
23
  callbacks.onError(error)
24
24
  })
25
- ws.on('close', _event => {
26
- callbacks.onClose()
25
+ ws.on('close', (code, reason) => {
26
+ callbacks.onClose(code, reason)
27
27
  })
28
28
 
29
29
  return {
@@ -5,6 +5,11 @@
5
5
 
6
6
 
7
7
 
8
+
9
+
10
+
11
+
12
+
8
13
  var ReadyState; (function (ReadyState) {
9
14
  const CONNECTING = 0; ReadyState[ReadyState["CONNECTING"] = CONNECTING] = "CONNECTING";
10
15
  const OPEN = CONNECTING + 1; ReadyState[ReadyState["OPEN"] = OPEN] = "OPEN";
@@ -17,8 +17,8 @@
17
17
  socket.onerror = event => {
18
18
  callbacks.onError(event)
19
19
  }
20
- socket.onclose = () => {
21
- callbacks.onClose()
20
+ socket.onclose = event => {
21
+ callbacks.onClose(event.code, event.reason)
22
22
  }
23
23
 
24
24
  return {
@@ -1,7 +1,11 @@
1
1
  export interface InnerSocketCallbacks {
2
- onError: (error?: unknown) => void;
2
+ /**
3
+ * Called when the socket closes.
4
+ * See rfc6455 section 7.4.1 for status codes.
5
+ */
6
+ onClose: (code: number, reason: string) => void;
7
+ onError: (error?: Event | Error) => void;
3
8
  onMessage: (message: string) => void;
4
- onClose: (error?: Error) => void;
5
9
  onOpen: () => void;
6
10
  }
7
11
  export declare enum ReadyState {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-plugins",
3
- "version": "3.3.0",
3
+ "version": "3.3.2",
4
4
  "description": "Edge currency plugins to fetch and process wallet accounts, balances and transactions.",
5
5
  "homepage": "https://edge.app/",
6
6
  "repository": "https://github.com/EdgeApp/edge-currency-plugins",
@@ -120,4 +120,4 @@
120
120
  "wif": "^2.0.6"
121
121
  },
122
122
  "react-native": "./lib/react-native.js"
123
- }
123
+ }