edge-currency-plugins 2.6.2 → 3.0.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 (56) hide show
  1. package/README.md +61 -2
  2. package/android/build.gradle +45 -0
  3. package/android/src/main/AndroidManifest.xml +2 -0
  4. package/android/src/main/assets/edge-currency-plugins/669.chunk.js +1 -0
  5. package/android/src/main/assets/edge-currency-plugins/edge-currency-plugins.js +76 -0
  6. package/android/src/main/java/app/edge/reactnative/currencyplugins/EdgeCurrencyPluginsModule.java +26 -0
  7. package/android/src/main/java/app/edge/reactnative/currencyplugins/EdgeCurrencyPluginsPackage.java +24 -0
  8. package/edge-currency-plugins.d.ts +34 -0
  9. package/edge-currency-plugins.podspec +28 -0
  10. package/ios/EdgeCurrencyPluginsModule.m +4 -0
  11. package/ios/EdgeCurrencyPluginsModule.swift +20 -0
  12. package/ios/edge-currency-plugins.xcodeproj/project.pbxproj +1 -0
  13. package/lib/common/constants.js +1 -2
  14. package/lib/common/plugin/CurrencyPlugin.js +17 -1
  15. package/lib/common/utxobased/db/Models/ProcessorTransaction.js +3 -2
  16. package/lib/common/utxobased/db/Processor.js +5 -0
  17. package/lib/common/utxobased/engine/ServerStates.js +159 -28
  18. package/lib/common/utxobased/engine/UtxoEngine.js +3 -2
  19. package/lib/common/utxobased/engine/UtxoEngineState.js +66 -72
  20. package/lib/common/utxobased/engine/types.js +3 -1
  21. package/lib/common/utxobased/info/bitcoin.js +1 -6
  22. package/lib/common/utxobased/info/bitcoincash.js +1 -6
  23. package/lib/common/utxobased/info/bitcoincashtestnet.js +0 -5
  24. package/lib/common/utxobased/info/bitcoinsv.js +0 -5
  25. package/lib/common/utxobased/info/bitcointestnet.js +0 -5
  26. package/lib/common/utxobased/info/dash.js +1 -1
  27. package/lib/common/utxobased/info/digibyte.js +1 -1
  28. package/lib/common/utxobased/info/feathercoin.js +0 -5
  29. package/lib/common/utxobased/info/groestlcoin.js +1 -1
  30. package/lib/common/utxobased/info/litecoin.js +1 -6
  31. package/lib/common/utxobased/info/zcoin.js +6 -5
  32. package/lib/common/utxobased/keymanager/keymanager.js +1 -1
  33. package/lib/common/utxobased/keymanager/types.js +2 -1
  34. package/lib/common/utxobased/network/Blockbook.js +178 -105
  35. package/lib/common/utxobased/network/BlockbookElectrum.js +216 -0
  36. package/lib/common/utxobased/network/Socket.js +130 -66
  37. package/lib/common/utxobased/network/blockbookApi.js +6 -6
  38. package/lib/common/utxobased/network/electrumApi.js +203 -0
  39. package/lib/{types.js → declare-modules.d.js} +2 -0
  40. package/lib/index.js +7 -3
  41. package/lib/react-native.js +26 -0
  42. package/lib/src/common/constants.d.ts +0 -1
  43. package/lib/src/common/utxobased/db/Processor.d.ts +6 -1
  44. package/lib/src/common/utxobased/engine/ServerStates.d.ts +8 -0
  45. package/lib/src/common/utxobased/engine/UtxoEngineState.d.ts +1 -4
  46. package/lib/src/common/utxobased/keymanager/types.d.ts +3 -3
  47. package/lib/src/common/utxobased/network/Blockbook.d.ts +20 -7
  48. package/lib/src/common/utxobased/network/BlockbookElectrum.d.ts +25 -0
  49. package/lib/src/common/utxobased/network/Socket.d.ts +11 -0
  50. package/lib/src/common/utxobased/network/blockbookApi.d.ts +2 -16
  51. package/lib/src/common/utxobased/network/electrumApi.d.ts +90 -0
  52. package/lib/src/index.d.ts +5 -1
  53. package/lib/src/react-native.d.ts +10 -0
  54. package/lib/test/utils.d.ts +4 -0
  55. package/package.json +24 -11
  56. package/lib/src/types.d.ts +0 -6
@@ -0,0 +1,26 @@
1
+ package app.edge.reactnative.currencyplugins;
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext;
4
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
5
+ import java.util.HashMap;
6
+ import java.util.Map;
7
+
8
+ public class EdgeCurrencyPluginsModule extends ReactContextBaseJavaModule {
9
+ EdgeCurrencyPluginsModule(ReactApplicationContext context) {
10
+ super(context);
11
+ }
12
+
13
+ @Override
14
+ public Map<String, Object> getConstants() {
15
+ final Map<String, Object> constants = new HashMap<>();
16
+ constants.put(
17
+ "sourceUri",
18
+ "file:///android_asset/edge-currency-plugins/edge-currency-plugins.js");
19
+ return constants;
20
+ }
21
+
22
+ @Override
23
+ public String getName() {
24
+ return "EdgeCurrencyPluginsModule";
25
+ }
26
+ }
@@ -0,0 +1,24 @@
1
+ package app.edge.reactnative.currencyplugins;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.facebook.react.ReactPackage;
5
+ import com.facebook.react.bridge.NativeModule;
6
+ import com.facebook.react.bridge.ReactApplicationContext;
7
+ import com.facebook.react.uimanager.ViewManager;
8
+ import java.util.Collections;
9
+ import java.util.List;
10
+
11
+ public class EdgeCurrencyPluginsPackage implements ReactPackage {
12
+ @NonNull
13
+ @Override
14
+ public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
15
+ return Collections.<NativeModule>singletonList(
16
+ new EdgeCurrencyPluginsModule(reactContext));
17
+ }
18
+
19
+ @NonNull
20
+ @Override
21
+ public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
22
+ return Collections.emptyList();
23
+ }
24
+ }
@@ -0,0 +1,34 @@
1
+ import { EdgeCorePluginOptions, EdgeCurrencyPlugin } from 'edge-core-js/types'
2
+
3
+ import {
4
+ EdgeCurrencyPluginIoOptions,
5
+ EdgeCurrencyPluginNativeIo
6
+ } from './src/react-native'
7
+
8
+ /**
9
+ * Add this to your `nativeIo` object on React Native,
10
+ * as `{ 'edge-currency-plugins': makePluginIo() }`
11
+ */
12
+ export function makePluginIo(
13
+ options?: EdgeCurrencyPluginIoOptions
14
+ ): EdgeCurrencyPluginNativeIo
15
+
16
+ /**
17
+ * Debugging-URI to use on React Native,
18
+ * along with running `yarn start` in this repo.
19
+ */
20
+ export const debugUri: string
21
+
22
+ /* Regular URI to use on React Native. */
23
+ export const pluginUri: string
24
+
25
+ type EdgeCorePluginFactory = (env: EdgeCorePluginOptions) => EdgeCurrencyPlugin
26
+
27
+ /**
28
+ * The Node.js default export.
29
+ */
30
+ declare const plugins: {
31
+ [pluginId: string]: EdgeCorePluginFactory
32
+ }
33
+
34
+ export default plugins
@@ -0,0 +1,28 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = package['name']
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.homepage = package['homepage']
10
+ s.license = package['license']
11
+ s.authors = package['author']
12
+
13
+ s.platform = :ios, "9.0"
14
+ s.requires_arc = true
15
+ s.source = {
16
+ :git => "https://github.com/EdgeApp/edge-currency-plugins.git",
17
+ :tag => "v#{s.version}"
18
+ }
19
+ s.source_files =
20
+ "ios/EdgeCurrencyPluginsModule.swift",
21
+ "ios/EdgeCurrencyPluginsModule.m"
22
+
23
+ s.resource_bundles = {
24
+ "edge-currency-plugins" => "android/src/main/assets/edge-currency-plugins/*.js"
25
+ }
26
+
27
+ s.dependency "React-Core"
28
+ end
@@ -0,0 +1,4 @@
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface RCT_EXTERN_MODULE(EdgeCurrencyPluginsModule, NSObject)
4
+ @end
@@ -0,0 +1,20 @@
1
+ @objc(EdgeCurrencyPluginsModule) class EdgeCurrencyPluginsModule: NSObject {
2
+ @objc static func requiresMainQueueSetup() -> Bool { return false }
3
+
4
+ @objc func constantsToExport() -> NSDictionary {
5
+ return ["sourceUri": sourceUri() ?? ""]
6
+ }
7
+
8
+ func sourceUri() -> String? {
9
+ if let bundleUrl = Bundle.main.url(
10
+ forResource: "edge-currency-plugins",
11
+ withExtension: "bundle"
12
+ ),
13
+ let bundle = Bundle(url: bundleUrl),
14
+ let script = bundle.url(forResource: "edge-currency-plugins", withExtension: "js")
15
+ {
16
+ return script.absoluteString
17
+ }
18
+ return nil
19
+ }
20
+ }
@@ -0,0 +1 @@
1
+ // Placeholder so react-native autolinking can find us
@@ -1,5 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); const IMAGE_SERVER_URL = 'https://content.edge.app'; exports.IMAGE_SERVER_URL = IMAGE_SERVER_URL
2
- const INFO_SERVER_URI = 'https://info1.edge.app'; exports.INFO_SERVER_URI = INFO_SERVER_URI
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); const INFO_SERVER_URI = 'https://info1.edge.app'; exports.INFO_SERVER_URI = INFO_SERVER_URI
3
2
 
4
3
  // Fees
5
4
  const FEES_PATH = 'fees.json'; exports.FEES_PATH = FEES_PATH
@@ -6,6 +6,8 @@
6
6
 
7
7
 
8
8
 
9
+ var _memlet = require('memlet');
10
+
9
11
 
10
12
 
11
13
 
@@ -17,12 +19,14 @@ var _EngineEmitter = require('./EngineEmitter');
17
19
  var _PluginState = require('./PluginState');
18
20
 
19
21
 
22
+ let hasMemletBeenSet = false
23
+
20
24
  function makeCurrencyPlugin(
21
25
  pluginOptions,
22
26
  pluginInfo
23
27
  ) {
24
28
  const { currencyInfo } = pluginInfo
25
- const { io, log, pluginDisklet, initOptions } = pluginOptions
29
+ const { initOptions, io, log, nativeIo, pluginDisklet } = pluginOptions
26
30
  const currencyTools = _CurrencyTools.makeCurrencyTools.call(void 0, io, pluginInfo)
27
31
  const { defaultSettings, pluginId, currencyCode } = currencyInfo
28
32
  const pluginState = _PluginState.makePluginState.call(void 0, {
@@ -33,6 +37,18 @@ var _PluginState = require('./PluginState');
33
37
  log,
34
38
  defaultSettings: _types3.asUtxoUserSettings.call(void 0, defaultSettings)
35
39
  })
40
+
41
+ if (!hasMemletBeenSet) {
42
+ const { memletConfig } = nativeIo[
43
+ 'edge-currency-plugins'
44
+ ]
45
+
46
+ if (memletConfig != null) {
47
+ hasMemletBeenSet = true
48
+ _memlet.setMemletConfig.call(void 0, memletConfig)
49
+ }
50
+ }
51
+
36
52
  return {
37
53
  currencyInfo,
38
54
 
@@ -97,14 +97,15 @@ var _bnjs = require('bn.js'); var _bnjs2 = _interopRequireDefault(_bnjs);
97
97
  confirmations: tx.confirmations,
98
98
  currencyCode: currencyInfo.currencyCode,
99
99
  date: tx.date,
100
+ feeRateUsed,
100
101
  isSend: _biggystring.lt.call(void 0, tx.ourAmount, '0'),
101
102
  memos: [],
102
103
  nativeAmount: tx.ourAmount,
103
104
  networkFee: tx.fees,
104
105
  ourReceiveAddresses,
105
106
  signedTx: tx.hex,
107
+ tokenId: null,
106
108
  txid: tx.txid,
107
- walletId,
108
- feeRateUsed
109
+ walletId
109
110
  }
110
111
  }; exports.toEdgeTransaction = toEdgeTransaction
@@ -102,6 +102,11 @@ const BASELET_DIR = 'tables'
102
102
 
103
103
 
104
104
 
105
+
106
+
107
+
108
+
109
+
105
110
 
106
111
 
107
112
 
@@ -11,7 +11,11 @@ var _Blockbook = require('../network/Blockbook');
11
11
 
12
12
 
13
13
 
14
+
15
+
16
+
14
17
  var _blockbookApi = require('../network/blockbookApi');
18
+ var _BlockbookElectrum = require('../network/BlockbookElectrum');
15
19
  var _Deferred = require('../network/Deferred'); var _Deferred2 = _interopRequireDefault(_Deferred);
16
20
 
17
21
  var _SocketEmitter = require('../network/SocketEmitter');
@@ -43,6 +47,34 @@ var _constants = require('./constants');
43
47
 
44
48
 
45
49
 
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
46
78
 
47
79
 
48
80
 
@@ -137,7 +169,6 @@ var _constants = require('./constants');
137
169
 
138
170
 
139
171
 
140
-
141
172
  const makeServerStatesCacheEntry = (blockbook) => ({
142
173
  blockbook,
143
174
  blockSubscriptionStatus: 'unsubscribed',
@@ -146,7 +177,6 @@ var _constants = require('./constants');
146
177
  blockHeight: 0
147
178
  })
148
179
  const setPickNextTaskCB = (
149
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
150
180
  callback
151
181
  ) => {
152
182
  pickNextTaskCB = callback
@@ -189,7 +219,7 @@ var _constants = require('./constants');
189
219
  }
190
220
 
191
221
  const doRefillServers = () => {
192
- const includePatterns = ['wss:', 'ws:']
222
+ const includePatterns = ['wss:', 'ws:', 'electrumwss:', 'electrumws:']
193
223
  if (serverList.length === 0) {
194
224
  serverList = pluginState.getLocalServers(_constants.NEW_CONNECTIONS, includePatterns)
195
225
  }
@@ -223,31 +253,62 @@ var _constants = require('./constants');
223
253
  continue
224
254
  }
225
255
 
226
- // Make new Blockbook instance
227
- const blockbook = _Blockbook.makeBlockbook.call(void 0, {
228
- asAddress: pluginInfo.engineInfo.asBlockbookAddress,
229
- connectionUri: uri,
230
- engineEmitter,
231
- log,
232
- onQueueSpaceCB: async (
256
+ // Blockbook instance variable
257
+ let blockbook
233
258
 
259
+ // Create a new blockbook instance based on the URI scheme
260
+ if (['electrumwss', 'electrumws'].includes(parsed.scheme)) {
261
+ // Electrum wrapper
262
+ blockbook = _BlockbookElectrum.makeBlockbookElectrum.call(void 0, {
263
+ asAddress: pluginInfo.engineInfo.asBlockbookAddress,
264
+ connectionUri: uri,
265
+ engineEmitter,
266
+ log,
267
+ onQueueSpaceCB: async (
234
268
 
235
269
  ) => {
236
- // Exit if the connection is no longer active
237
- if (!(uri in serverStatesCache)) return
238
-
239
- const task = await pickNextTaskCB(uri)
240
- if (task != null && typeof task !== 'boolean') {
241
- const taskMessage = `${task.method} params: ${JSON.stringify(
242
- task.params
243
- )}`
244
- log(`${uri} nextTask: ${taskMessage}`)
245
- }
246
- return task
247
- },
248
- socketEmitter,
249
- walletId: walletInfo.id
250
- })
270
+ // Exit if the connection is no longer active
271
+ if (!(uri in serverStatesCache)) return
272
+
273
+ const task = await pickNextTaskCB(uri)
274
+ if (task != null && typeof task !== 'boolean') {
275
+ const taskMessage = `${task.method} params: ${JSON.stringify(
276
+ task.params
277
+ )}`
278
+ log(`${uri} nextTask: ${taskMessage}`)
279
+ }
280
+ return task
281
+ },
282
+ pluginInfo,
283
+ socketEmitter,
284
+ walletId: walletInfo.id
285
+ })
286
+ } else {
287
+ // Regular blockbook instance
288
+ blockbook = _Blockbook.makeBlockbook.call(void 0, {
289
+ asAddress: pluginInfo.engineInfo.asBlockbookAddress,
290
+ connectionUri: uri,
291
+ engineEmitter,
292
+ log,
293
+ onQueueSpaceCB: async (
294
+
295
+ ) => {
296
+ // Exit if the connection is no longer active
297
+ if (!(uri in serverStatesCache)) return
298
+
299
+ const task = await pickNextTaskCB(uri)
300
+ if (task != null && typeof task !== 'boolean') {
301
+ const taskMessage = `${task.method} params: ${JSON.stringify(
302
+ task.params
303
+ )}`
304
+ log(`${uri} nextTask: ${taskMessage}`)
305
+ }
306
+ return task
307
+ },
308
+ socketEmitter,
309
+ walletId: walletInfo.id
310
+ })
311
+ }
251
312
 
252
313
  // Make new ServerStates instance
253
314
  serverStatesCache[uri] = makeServerStatesCacheEntry(blockbook)
@@ -366,7 +427,7 @@ var _constants = require('./constants');
366
427
  // Broadcast through any HTTP URI that may be configured, only if no
367
428
  // blockbook instances are connected.
368
429
  if (!isAnyBlockbookConnected) {
369
- // This is for the future when we want to HTTP servers from the user
430
+ // This is for the future when we want to get HTTP servers from the user
370
431
  // settings:
371
432
  // const httpUris = pluginState.getLocalServers(Infinity, [
372
433
  // /^http(?:s)?:/i
@@ -398,6 +459,8 @@ var _constants = require('./constants');
398
459
  }
399
460
 
400
461
  for (const uri of nowNodeUris) {
462
+ log.warn('Falling back to NOWNode server broadcast over HTTP:', uri)
463
+
401
464
  // HTTP Fallback
402
465
  io.fetchCors(`${uri}/api/v2/sendtx/`, {
403
466
  method: 'POST',
@@ -495,7 +558,7 @@ var _constants = require('./constants');
495
558
  return serverStatesCache[uri].blockHeight
496
559
  }
497
560
 
498
- return {
561
+ const instance = {
499
562
  setPickNextTaskCB,
500
563
  stop,
501
564
  serverCanGetTx,
@@ -508,6 +571,74 @@ var _constants = require('./constants');
508
571
  broadcastTx,
509
572
  watchAddresses,
510
573
  watchBlocks,
511
- getBlockHeight
574
+ getBlockHeight,
575
+
576
+ //
577
+ // Task Methods:
578
+ //
579
+
580
+ addressQueryTask(
581
+ serverUri,
582
+ address,
583
+ params,
584
+ deferred
585
+ ) {
586
+ const serverState = serverStatesCache[serverUri]
587
+ if (serverState == null)
588
+ throw new Error(`No blockbook connection with ${serverUri}`)
589
+
590
+ return serverState.blockbook.addressQueryTask(
591
+ address,
592
+ {
593
+ asBlockbookAddress: pluginInfo.engineInfo.asBlockbookAddress,
594
+ lastQueriedBlockHeight: params.lastQueriedBlockHeight,
595
+ page: params.page
596
+ },
597
+ deferred
598
+ )
599
+ },
600
+
601
+ transactionQueryTask(
602
+ serverUri,
603
+ txId,
604
+ deferred
605
+ ) {
606
+ const serverState = serverStatesCache[serverUri]
607
+ if (serverState == null)
608
+ throw new Error(`No blockbook connection with ${serverUri}`)
609
+
610
+ return serverState.blockbook.transactionQueryTask(txId, deferred)
611
+ },
612
+
613
+ transactionSpecialQueryTask(
614
+ serverUri,
615
+ txId,
616
+ deferred
617
+ ) {
618
+ const serverState = serverStatesCache[serverUri]
619
+ if (serverState == null)
620
+ throw new Error(`No blockbook connection with ${serverUri}`)
621
+
622
+ return serverState.blockbook.transactionSpecialQueryTask(txId, deferred)
623
+ },
624
+ utxoListQueryTask(
625
+ serverUri,
626
+ address,
627
+ deferred
628
+ ) {
629
+ const serverState = serverStatesCache[serverUri]
630
+ if (serverState == null)
631
+ throw new Error(`No blockbook connection with ${serverUri}`)
632
+
633
+ return serverState.blockbook.utxoListQueryTask(
634
+ address,
635
+ {
636
+ asBlockbookAddress: pluginInfo.engineInfo.asBlockbookAddress
637
+ },
638
+ deferred
639
+ )
640
+ }
512
641
  }
642
+
643
+ return instance
513
644
  } exports.makeServerStates = makeServerStates;
@@ -543,7 +543,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
543
543
  bs.gt(totalAmountToSend, `${_utils3.sumUtxos.call(void 0, utxos)}`) ||
544
544
  utxos.length === 0
545
545
  ) {
546
- throw new (0, _edgecorejs.InsufficientFundsError)(currencyInfo.currencyCode)
546
+ throw new (0, _edgecorejs.InsufficientFundsError)({ tokenId: null })
547
547
  }
548
548
 
549
549
  let targets = []
@@ -684,6 +684,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
684
684
  otherParams,
685
685
  ourReceiveAddresses,
686
686
  signedTx: '',
687
+ tokenId: null,
687
688
  txid: '',
688
689
  walletId: walletInfo.id
689
690
  }
@@ -948,7 +949,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
948
949
  if (tmpUtxos === null || tmpUtxos.length < 1) {
949
950
  throw new Error('Private key has no funds')
950
951
  }
951
- const destAddress = await this.getFreshAddress({})
952
+ const destAddress = await this.getFreshAddress({ tokenId: null })
952
953
  const nativeAmount = tmpMetadata.state.balance
953
954
  const txOptions = { utxos: tmpUtxos, subtractFee: true }
954
955
  spendInfo.spendTargets = [