edge-currency-plugins 1.0.0-rc.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.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/lib/bch.js +15 -0
- package/lib/bsv.js +15 -0
- package/lib/btc.js +15 -0
- package/lib/common/constants.js +11 -0
- package/lib/common/fees/calcMinerFeePerByte.js +62 -0
- package/lib/common/fees/makeFees.js +182 -0
- package/lib/common/fees/processInfoServerFees.js +30 -0
- package/lib/common/fees/processMempoolSpaceFees.js +38 -0
- package/lib/common/plugin/makeCurrencyPlugin.js +66 -0
- package/lib/common/plugin/makeCurrencyTools.js +211 -0
- package/lib/common/plugin/makeEngineEmitter.js +102 -0
- package/lib/common/plugin/makeMetadata.js +99 -0
- package/lib/common/plugin/pluginState.js +253 -0
- package/lib/common/plugin/serverScores.js +328 -0
- package/lib/common/plugin/types.js +173 -0
- package/lib/common/plugin/utils.js +18 -0
- package/lib/common/utxobased/db/Models/ProcessorTransaction.js +122 -0
- package/lib/common/utxobased/db/Models/baselet.js +81 -0
- package/lib/common/utxobased/db/makeBaselets.js +123 -0
- package/lib/common/utxobased/db/makeMutex.js +17 -0
- package/lib/common/utxobased/db/makeProcessor.js +554 -0
- package/lib/common/utxobased/db/types.js +67 -0
- package/lib/common/utxobased/engine/await-lock.js +65 -0
- package/lib/common/utxobased/engine/constants.js +7 -0
- package/lib/common/utxobased/engine/makeServerStates.js +394 -0
- package/lib/common/utxobased/engine/makeUtxoEngine.js +690 -0
- package/lib/common/utxobased/engine/makeUtxoEngineState.js +1443 -0
- package/lib/common/utxobased/engine/makeUtxoWalletTools.js +216 -0
- package/lib/common/utxobased/engine/paymentRequest.js +102 -0
- package/lib/common/utxobased/engine/types.js +21 -0
- package/lib/common/utxobased/engine/util/defaultValidateConfirmations.js +19 -0
- package/lib/common/utxobased/engine/util/getOwnUtxosFromTx.js +54 -0
- package/lib/common/utxobased/engine/utils.js +239 -0
- package/lib/common/utxobased/info/all.js +67 -0
- package/lib/common/utxobased/info/badcoin.js +73 -0
- package/lib/common/utxobased/info/bitcoin.js +91 -0
- package/lib/common/utxobased/info/bitcoincash.js +93 -0
- package/lib/common/utxobased/info/bitcoincashtestnet.js +72 -0
- package/lib/common/utxobased/info/bitcoingold.js +85 -0
- package/lib/common/utxobased/info/bitcoingoldtestnet.js +71 -0
- package/lib/common/utxobased/info/bitcoinsv.js +76 -0
- package/lib/common/utxobased/info/bitcointestnet.js +81 -0
- package/lib/common/utxobased/info/dash.js +76 -0
- package/lib/common/utxobased/info/digibyte.js +76 -0
- package/lib/common/utxobased/info/dogecoin.js +76 -0
- package/lib/common/utxobased/info/eboost.js +70 -0
- package/lib/common/utxobased/info/feathercoin.js +76 -0
- package/lib/common/utxobased/info/groestlcoin.js +88 -0
- package/lib/common/utxobased/info/litecoin.js +82 -0
- package/lib/common/utxobased/info/qtum.js +67 -0
- package/lib/common/utxobased/info/ravencoin.js +70 -0
- package/lib/common/utxobased/info/scriptTemplates/bitcoincashScriptTemplates.js +56 -0
- package/lib/common/utxobased/info/scriptTemplates/types.js +14 -0
- package/lib/common/utxobased/info/smartcash.js +78 -0
- package/lib/common/utxobased/info/ufo.js +75 -0
- package/lib/common/utxobased/info/utxoPickers/dogeUtxoPicker.js +34 -0
- package/lib/common/utxobased/info/vertcoin.js +82 -0
- package/lib/common/utxobased/info/zcoin.js +72 -0
- package/lib/common/utxobased/keymanager/base.js +60 -0
- package/lib/common/utxobased/keymanager/bip69.js +31 -0
- package/lib/common/utxobased/keymanager/bitcoincashUtils/base32.js +88 -0
- package/lib/common/utxobased/keymanager/bitcoincashUtils/bn.js +210 -0
- package/lib/common/utxobased/keymanager/bitcoincashUtils/cashAddress.js +282 -0
- package/lib/common/utxobased/keymanager/cleaners.js +198 -0
- package/lib/common/utxobased/keymanager/coinmapper.js +12 -0
- package/lib/common/utxobased/keymanager/declarations/base58grscheck.d.js +1 -0
- package/lib/common/utxobased/keymanager/declarations/blake-hash.d.js +1 -0
- package/lib/common/utxobased/keymanager/declarations/bn.d.js +1 -0
- package/lib/common/utxobased/keymanager/declarations/bs58smartcheck.d.js +1 -0
- package/lib/common/utxobased/keymanager/declarations/wif-smart.d.js +1 -0
- package/lib/common/utxobased/keymanager/declarations/wifgrs.d.js +1 -0
- package/lib/common/utxobased/keymanager/keymanager.js +1214 -0
- package/lib/common/utxobased/keymanager/utxopicker/accumulative.js +52 -0
- package/lib/common/utxobased/keymanager/utxopicker/forceUseUtxo.js +59 -0
- package/lib/common/utxobased/keymanager/utxopicker/subtractFee.js +17 -0
- package/lib/common/utxobased/keymanager/utxopicker/types.js +42 -0
- package/lib/common/utxobased/keymanager/utxopicker/utils.js +159 -0
- package/lib/common/utxobased/keymanager/utxopicker.js +17 -0
- package/lib/common/utxobased/network/BlockBook.js +200 -0
- package/lib/common/utxobased/network/BlockBookAPI.js +335 -0
- package/lib/common/utxobased/network/Deferred.js +29 -0
- package/lib/common/utxobased/network/MakeSocketEmitter.js +35 -0
- package/lib/common/utxobased/network/Socket.js +362 -0
- package/lib/common/utxobased/network/nodejsWS.js +59 -0
- package/lib/common/utxobased/network/socketQueue.js +60 -0
- package/lib/common/utxobased/network/types.js +19 -0
- package/lib/common/utxobased/network/windowWS.js +54 -0
- package/lib/firo.js +15 -0
- package/lib/ftc.js +15 -0
- package/lib/index.js +19 -0
- package/lib/ltc.js +15 -0
- package/lib/src/bch.d.ts +3 -0
- package/lib/src/bsv.d.ts +3 -0
- package/lib/src/btc.d.ts +3 -0
- package/lib/src/common/constants.d.ts +9 -0
- package/lib/src/common/fees/calcMinerFeePerByte.d.ts +13 -0
- package/lib/src/common/fees/makeFees.d.ts +20 -0
- package/lib/src/common/fees/processInfoServerFees.d.ts +7 -0
- package/lib/src/common/fees/processMempoolSpaceFees.d.ts +13 -0
- package/lib/src/common/plugin/makeCurrencyPlugin.d.ts +3 -0
- package/lib/src/common/plugin/makeCurrencyTools.d.ts +8 -0
- package/lib/src/common/plugin/makeEngineEmitter.d.ts +23 -0
- package/lib/src/common/plugin/makeMetadata.d.ts +14 -0
- package/lib/src/common/plugin/pluginState.d.ts +34 -0
- package/lib/src/common/plugin/serverScores.d.ts +61 -0
- package/lib/src/common/plugin/types.d.ts +135 -0
- package/lib/src/common/plugin/utils.d.ts +6 -0
- package/lib/src/common/utxobased/db/Models/ProcessorTransaction.d.ts +16 -0
- package/lib/src/common/utxobased/db/Models/baselet.d.ts +28 -0
- package/lib/src/common/utxobased/db/makeBaselets.d.ts +33 -0
- package/lib/src/common/utxobased/db/makeMutex.d.ts +3 -0
- package/lib/src/common/utxobased/db/makeProcessor.d.ts +42 -0
- package/lib/src/common/utxobased/db/types.d.ts +47 -0
- package/lib/src/common/utxobased/engine/await-lock.d.ts +29 -0
- package/lib/src/common/utxobased/engine/constants.d.ts +4 -0
- package/lib/src/common/utxobased/engine/makeServerStates.d.ts +37 -0
- package/lib/src/common/utxobased/engine/makeUtxoEngine.d.ts +3 -0
- package/lib/src/common/utxobased/engine/makeUtxoEngineState.d.ts +108 -0
- package/lib/src/common/utxobased/engine/makeUtxoWalletTools.d.ts +52 -0
- package/lib/src/common/utxobased/engine/paymentRequest.d.ts +18 -0
- package/lib/src/common/utxobased/engine/types.d.ts +19 -0
- package/lib/src/common/utxobased/engine/util/defaultValidateConfirmations.d.ts +3 -0
- package/lib/src/common/utxobased/engine/util/getOwnUtxosFromTx.d.ts +4 -0
- package/lib/src/common/utxobased/engine/utils.d.ts +43 -0
- package/lib/src/common/utxobased/info/all.d.ts +22 -0
- package/lib/src/common/utxobased/info/badcoin.d.ts +3 -0
- package/lib/src/common/utxobased/info/bitcoin.d.ts +3 -0
- package/lib/src/common/utxobased/info/bitcoincash.d.ts +3 -0
- package/lib/src/common/utxobased/info/bitcoincashtestnet.d.ts +3 -0
- package/lib/src/common/utxobased/info/bitcoingold.d.ts +3 -0
- package/lib/src/common/utxobased/info/bitcoingoldtestnet.d.ts +3 -0
- package/lib/src/common/utxobased/info/bitcoinsv.d.ts +3 -0
- package/lib/src/common/utxobased/info/bitcointestnet.d.ts +6 -0
- package/lib/src/common/utxobased/info/dash.d.ts +3 -0
- package/lib/src/common/utxobased/info/digibyte.d.ts +3 -0
- package/lib/src/common/utxobased/info/dogecoin.d.ts +3 -0
- package/lib/src/common/utxobased/info/eboost.d.ts +3 -0
- package/lib/src/common/utxobased/info/feathercoin.d.ts +6 -0
- package/lib/src/common/utxobased/info/groestlcoin.d.ts +3 -0
- package/lib/src/common/utxobased/info/litecoin.d.ts +6 -0
- package/lib/src/common/utxobased/info/qtum.d.ts +3 -0
- package/lib/src/common/utxobased/info/ravencoin.d.ts +3 -0
- package/lib/src/common/utxobased/info/scriptTemplates/bitcoincashScriptTemplates.d.ts +2 -0
- package/lib/src/common/utxobased/info/scriptTemplates/types.d.ts +9 -0
- package/lib/src/common/utxobased/info/smartcash.d.ts +3 -0
- package/lib/src/common/utxobased/info/ufo.d.ts +3 -0
- package/lib/src/common/utxobased/info/utxoPickers/dogeUtxoPicker.d.ts +2 -0
- package/lib/src/common/utxobased/info/vertcoin.d.ts +3 -0
- package/lib/src/common/utxobased/info/zcoin.d.ts +6 -0
- package/lib/src/common/utxobased/keymanager/base.d.ts +9 -0
- package/lib/src/common/utxobased/keymanager/bip69.d.ts +19 -0
- package/lib/src/common/utxobased/keymanager/bitcoincashUtils/base32.d.ts +19 -0
- package/lib/src/common/utxobased/keymanager/bitcoincashUtils/bn.d.ts +2 -0
- package/lib/src/common/utxobased/keymanager/bitcoincashUtils/cashAddress.d.ts +12 -0
- package/lib/src/common/utxobased/keymanager/cleaners.d.ts +55 -0
- package/lib/src/common/utxobased/keymanager/coinmapper.d.ts +2 -0
- package/lib/src/common/utxobased/keymanager/keymanager.d.ts +198 -0
- package/lib/src/common/utxobased/keymanager/utxopicker/accumulative.d.ts +2 -0
- package/lib/src/common/utxobased/keymanager/utxopicker/forceUseUtxo.d.ts +2 -0
- package/lib/src/common/utxobased/keymanager/utxopicker/subtractFee.d.ts +2 -0
- package/lib/src/common/utxobased/keymanager/utxopicker/types.d.ts +36 -0
- package/lib/src/common/utxobased/keymanager/utxopicker/utils.d.ts +15 -0
- package/lib/src/common/utxobased/keymanager/utxopicker.d.ts +8 -0
- package/lib/src/common/utxobased/network/BlockBook.d.ts +33 -0
- package/lib/src/common/utxobased/network/BlockBookAPI.d.ts +163 -0
- package/lib/src/common/utxobased/network/Deferred.d.ts +8 -0
- package/lib/src/common/utxobased/network/MakeSocketEmitter.d.ts +13 -0
- package/lib/src/common/utxobased/network/Socket.d.ts +41 -0
- package/lib/src/common/utxobased/network/nodejsWS.d.ts +2 -0
- package/lib/src/common/utxobased/network/socketQueue.d.ts +8 -0
- package/lib/src/common/utxobased/network/types.d.ts +17 -0
- package/lib/src/common/utxobased/network/windowWS.d.ts +2 -0
- package/lib/src/firo.d.ts +3 -0
- package/lib/src/ftc.d.ts +3 -0
- package/lib/src/index.d.ts +4 -0
- package/lib/src/ltc.d.ts +3 -0
- package/lib/src/tbch.d.ts +3 -0
- package/lib/src/tbtc.d.ts +3 -0
- package/lib/src/tbtg.d.ts +3 -0
- package/lib/src/types.d.ts +6 -0
- package/lib/src/util/delay.d.ts +1 -0
- package/lib/src/util/filterUndefined.d.ts +1 -0
- package/lib/src/util/indexAtProtected.d.ts +5 -0
- package/lib/src/util/typeUtil.d.ts +8 -0
- package/lib/src/util/undefinedIfEmptyString.d.ts +1 -0
- package/lib/src/util/unixTime.d.ts +1 -0
- package/lib/tbch.js +15 -0
- package/lib/tbtc.js +15 -0
- package/lib/tbtg.js +15 -0
- package/lib/test/common/fees/calcMinerFeePerByte.spec.d.ts +1 -0
- package/lib/test/common/fees/fees.spec.d.ts +1 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/common.d.ts +29 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/bitcoin.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/bitcoincash.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/bitcoinsv.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/digibyte.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/feathercoin.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/groestlcoin.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/litecoin.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/smartcash.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/currencies/zcoin.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.fixtures/index.d.ts +2 -0
- package/lib/test/common/plugin/currencyPlugin.spec.d.ts +1 -0
- package/lib/test/common/plugin/makeMetadata.spec.d.ts +1 -0
- package/lib/test/common/plugin/serverScores.spec.d.ts +1 -0
- package/lib/test/common/utxobased/addressFormat/addressFormatIndex/addressFormat.spec.d.ts +1 -0
- package/lib/test/common/utxobased/db/Processor.spec.d.ts +1 -0
- package/lib/test/common/utxobased/engine/PaymentRequest.spec.d.ts +1 -0
- package/lib/test/common/utxobased/engine/UtxoWalletTools.spec.d.ts +1 -0
- package/lib/test/common/utxobased/engine/engine.fixtures/bitcoinTestnet/tests.d.ts +70 -0
- package/lib/test/common/utxobased/engine/engine.fixtures/index.d.ts +65 -0
- package/lib/test/common/utxobased/engine/engine.spec.d.ts +1 -0
- package/lib/test/common/utxobased/keymanager/coins/altcointestfixtures.d.ts +54 -0
- package/lib/test/common/utxobased/keymanager/coins/bitcoincashtransactiontest.spec.d.ts +1 -0
- package/lib/test/common/utxobased/keymanager/coins/bitcointransactiontest.spec.d.ts +1 -0
- package/lib/test/common/utxobased/keymanager/coins/cashaddr.spec.d.ts +1 -0
- package/lib/test/common/utxobased/keymanager/coins/checkdatasig.spec.d.ts +1 -0
- package/lib/test/common/utxobased/keymanager/coins/groestlcointransactiontest.spec.d.ts +1 -0
- package/lib/test/common/utxobased/keymanager/coins/keymanagertest.spec.d.ts +1 -0
- package/lib/test/common/utxobased/network/BlockBook.spec.d.ts +1 -0
- package/lib/test/util/objectKeys.d.ts +8 -0
- package/lib/test/util/testLog.d.ts +3 -0
- package/lib/test/utils.d.ts +10 -0
- package/lib/types.js +7 -0
- package/lib/util/delay.js +4 -0
- package/lib/util/filterUndefined.js +4 -0
- package/lib/util/indexAtProtected.js +9 -0
- package/lib/util/typeUtil.js +9 -0
- package/lib/util/undefinedIfEmptyString.js +2 -0
- package/lib/util/unixTime.js +2 -0
- package/package.json +101 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _utils = require('../../plugin/utils');
|
|
5
|
+
|
|
6
|
+
var _MakeSocketEmitter = require('./MakeSocketEmitter');
|
|
7
|
+
var _nodejsWS = require('./nodejsWS');
|
|
8
|
+
var _socketQueue = require('./socketQueue');
|
|
9
|
+
var _types3 = require('./types');
|
|
10
|
+
var _windowWS = require('./windowWS');
|
|
11
|
+
|
|
12
|
+
const TIMER_SLACK = 500
|
|
13
|
+
const KEEP_ALIVE_MS = 60000 // interval at which we keep the connection alive
|
|
14
|
+
const WAKE_UP_MS = 5000 // interval at which we wakeUp and potentially onQueueSpace
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
function makeSocket(uri, config) {
|
|
72
|
+
let socket
|
|
73
|
+
const { emitter, log, queueSize = 50, walletId } = config
|
|
74
|
+
log('makeSocket connects to', uri)
|
|
75
|
+
const version = ''
|
|
76
|
+
const socketQueueId = walletId + '==' + uri
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
+
const subscriptions = {}
|
|
79
|
+
let onQueueSpace = config.onQueueSpaceCB
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
81
|
+
let pendingMessages = {}
|
|
82
|
+
let nextId = 0
|
|
83
|
+
let lastKeepAlive = 0
|
|
84
|
+
let lastWakeUp = 0
|
|
85
|
+
let connected = false
|
|
86
|
+
let cancelConnect = false
|
|
87
|
+
const timeout = 1000 * (_nullishCoalesce(config.timeout, () => ( 30)))
|
|
88
|
+
let error
|
|
89
|
+
let timer
|
|
90
|
+
|
|
91
|
+
const handleError = (e) => {
|
|
92
|
+
if (error == null) error = e
|
|
93
|
+
if (connected && socket != null && socket.readyState === _types3.ReadyState.OPEN)
|
|
94
|
+
disconnect()
|
|
95
|
+
else cancelConnect = true
|
|
96
|
+
log.error('handled error!', e)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const disconnect = () => {
|
|
100
|
+
log.warn('disconnecting from socket', uri)
|
|
101
|
+
clearTimeout(timer)
|
|
102
|
+
connected = false
|
|
103
|
+
if (socket != null) socket.disconnect()
|
|
104
|
+
_socketQueue.removeIdFromQueue.call(void 0, socketQueueId)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const onSocketClose = () => {
|
|
108
|
+
const err = _nullishCoalesce(error, () => ( new Error('Socket close')))
|
|
109
|
+
log.warn(`onSocketClose due to ${err.message} with server ${uri}`)
|
|
110
|
+
clearTimeout(timer)
|
|
111
|
+
connected = false
|
|
112
|
+
socket = null
|
|
113
|
+
cancelConnect = false
|
|
114
|
+
for (const message of Object.values(pendingMessages)) {
|
|
115
|
+
try {
|
|
116
|
+
message.task.deferred.reject(err)
|
|
117
|
+
} catch (e) {
|
|
118
|
+
log.error(e.message)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
pendingMessages = {}
|
|
122
|
+
try {
|
|
123
|
+
emitter.emit(_MakeSocketEmitter.SocketEvent.CONNECTION_CLOSE, uri, err)
|
|
124
|
+
} catch (e) {
|
|
125
|
+
log.error(e.message)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const onSocketConnect = () => {
|
|
130
|
+
log(`onSocketConnect with server ${uri}`)
|
|
131
|
+
if (cancelConnect) {
|
|
132
|
+
if (socket != null) socket.disconnect()
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
connected = true
|
|
136
|
+
lastKeepAlive = Date.now()
|
|
137
|
+
try {
|
|
138
|
+
emitter.emit(_MakeSocketEmitter.SocketEvent.CONNECTION_OPEN, uri)
|
|
139
|
+
} catch (e) {
|
|
140
|
+
handleError(e)
|
|
141
|
+
}
|
|
142
|
+
for (const [id, message] of Object.entries(pendingMessages)) {
|
|
143
|
+
transmitMessage(id, message)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
wakeUp()
|
|
147
|
+
cancelConnect = false
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const wakeUp = () => {
|
|
151
|
+
log(`wakeUp socket with server ${uri}`)
|
|
152
|
+
_socketQueue.pushUpdate.call(void 0, {
|
|
153
|
+
id: socketQueueId,
|
|
154
|
+
updateFunc: () => {
|
|
155
|
+
doWakeUp().catch(err => {
|
|
156
|
+
throw new Error(`wake up error from: ${err.message}`)
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const doWakeUp = async () => {
|
|
163
|
+
log(`doWakeUp socket with server ${uri}`)
|
|
164
|
+
lastWakeUp = Date.now()
|
|
165
|
+
if (connected && version != null) {
|
|
166
|
+
while (Object.keys(pendingMessages).length < queueSize) {
|
|
167
|
+
const task = await _optionalChain([onQueueSpace, 'optionalCall', _ => _(uri)])
|
|
168
|
+
if (task == null) break
|
|
169
|
+
if (typeof task === 'boolean') {
|
|
170
|
+
if (task) continue
|
|
171
|
+
break
|
|
172
|
+
}
|
|
173
|
+
submitTask(task)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// add any exception, since the passed in template parameter needs to be re-assigned
|
|
179
|
+
const subscribe = (subscription) => {
|
|
180
|
+
if (socket != null && socket.readyState === _types3.ReadyState.OPEN && connected) {
|
|
181
|
+
const id = subscription.method
|
|
182
|
+
const message = {
|
|
183
|
+
id,
|
|
184
|
+
method: subscription.method,
|
|
185
|
+
params: _nullishCoalesce(subscription.params, () => ( {}))
|
|
186
|
+
}
|
|
187
|
+
subscriptions[id] = subscription
|
|
188
|
+
socket.send(JSON.stringify(message))
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// add any exception, since the passed in template parameter needs to be re-assigned
|
|
193
|
+
const submitTask = (task) => {
|
|
194
|
+
const id = (nextId++).toString()
|
|
195
|
+
const message = { task, startTime: Date.now() }
|
|
196
|
+
pendingMessages[id] = message
|
|
197
|
+
transmitMessage(id, message)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const transmitMessage = (id, pending) => {
|
|
201
|
+
const now = Date.now()
|
|
202
|
+
if (
|
|
203
|
+
socket != null &&
|
|
204
|
+
socket.readyState === _types3.ReadyState.OPEN &&
|
|
205
|
+
connected &&
|
|
206
|
+
!cancelConnect
|
|
207
|
+
) {
|
|
208
|
+
pending.startTime = now
|
|
209
|
+
const message = {
|
|
210
|
+
id,
|
|
211
|
+
method: pending.task.method,
|
|
212
|
+
params: _nullishCoalesce(pending.task.params, () => ( {}))
|
|
213
|
+
}
|
|
214
|
+
socket.send(JSON.stringify(message))
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const onTimer = () => {
|
|
219
|
+
log(`socket timer with server ${uri} expired, check if healthCheck needed`)
|
|
220
|
+
const now = Date.now() - TIMER_SLACK
|
|
221
|
+
if (lastKeepAlive + KEEP_ALIVE_MS < now) {
|
|
222
|
+
log(`submitting healthCheck to server ${uri}`)
|
|
223
|
+
lastKeepAlive = now
|
|
224
|
+
config
|
|
225
|
+
.healthCheck()
|
|
226
|
+
.then(() => {
|
|
227
|
+
emitter.emit(_MakeSocketEmitter.SocketEvent.CONNECTION_TIMER, uri, now)
|
|
228
|
+
})
|
|
229
|
+
.catch((e) => handleError(e))
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
for (const [id, message] of Object.entries(pendingMessages)) {
|
|
233
|
+
if (message.startTime + timeout < now) {
|
|
234
|
+
try {
|
|
235
|
+
message.task.deferred.reject(new Error('Timeout'))
|
|
236
|
+
} catch (e) {
|
|
237
|
+
log.error(e.message)
|
|
238
|
+
}
|
|
239
|
+
_utils.removeItem.call(void 0, pendingMessages, id)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
wakeUp()
|
|
243
|
+
setupTimer()
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const setupTimer = () => {
|
|
247
|
+
log(`setupTimer with server ${uri}`)
|
|
248
|
+
let nextWakeUp = lastWakeUp + WAKE_UP_MS
|
|
249
|
+
for (const message of Object.values(pendingMessages)) {
|
|
250
|
+
const to = message.startTime + timeout
|
|
251
|
+
if (to < nextWakeUp) nextWakeUp = to
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const now = Date.now() - TIMER_SLACK
|
|
255
|
+
const delay = nextWakeUp < now ? 0 : nextWakeUp - now
|
|
256
|
+
timer = setTimeout(() => onTimer(), delay)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const onMessage = (messageJson) => {
|
|
260
|
+
try {
|
|
261
|
+
const json = JSON.parse(messageJson)
|
|
262
|
+
if (json.id != null) {
|
|
263
|
+
const id = json.id.toString()
|
|
264
|
+
for (const cId of Object.keys(subscriptions)) {
|
|
265
|
+
if (id === cId) {
|
|
266
|
+
const subscription = subscriptions[id]
|
|
267
|
+
if (subscription == null) {
|
|
268
|
+
throw new Error(`cannot find subscription for ${id}`)
|
|
269
|
+
}
|
|
270
|
+
if (_optionalChain([json, 'access', _2 => _2.data, 'optionalAccess', _3 => _3.subscribed]) != null) {
|
|
271
|
+
subscription.subscribed = true
|
|
272
|
+
subscription.deferred.resolve(json.data)
|
|
273
|
+
return
|
|
274
|
+
}
|
|
275
|
+
if (!subscription.subscribed) {
|
|
276
|
+
subscription.deferred.reject()
|
|
277
|
+
}
|
|
278
|
+
subscription.cb(subscription.cleaner(json.data))
|
|
279
|
+
return
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const message = pendingMessages[id]
|
|
283
|
+
if (message == null) {
|
|
284
|
+
throw new Error(`Bad response id in ${messageJson}`)
|
|
285
|
+
}
|
|
286
|
+
_utils.removeItem.call(void 0, pendingMessages, id)
|
|
287
|
+
const { error } = json
|
|
288
|
+
try {
|
|
289
|
+
if (error != null) {
|
|
290
|
+
const errorMessage =
|
|
291
|
+
error.message != null ? error.message : error.connected
|
|
292
|
+
throw new Error(errorMessage)
|
|
293
|
+
}
|
|
294
|
+
if (message.task.cleaner != null) {
|
|
295
|
+
message.task.deferred.resolve(message.task.cleaner(json.data))
|
|
296
|
+
} else {
|
|
297
|
+
message.task.deferred.resolve(json.data)
|
|
298
|
+
}
|
|
299
|
+
} catch (e) {
|
|
300
|
+
if (e instanceof TypeError) console.log({ json, message })
|
|
301
|
+
message.task.deferred.reject(e)
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
} catch (e) {
|
|
305
|
+
handleError(e)
|
|
306
|
+
}
|
|
307
|
+
wakeUp()
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
setupTimer()
|
|
311
|
+
|
|
312
|
+
// return a Socket
|
|
313
|
+
return {
|
|
314
|
+
get readyState() {
|
|
315
|
+
return _nullishCoalesce(_optionalChain([socket, 'optionalAccess', _4 => _4.readyState]), () => ( _types3.ReadyState.CLOSED))
|
|
316
|
+
},
|
|
317
|
+
|
|
318
|
+
async connect() {
|
|
319
|
+
_optionalChain([socket, 'optionalAccess', _5 => _5.disconnect, 'call', _6 => _6()])
|
|
320
|
+
|
|
321
|
+
return await new Promise(resolve => {
|
|
322
|
+
const cbs = {
|
|
323
|
+
onOpen: () => {
|
|
324
|
+
onSocketConnect()
|
|
325
|
+
resolve()
|
|
326
|
+
},
|
|
327
|
+
onMessage: onMessage,
|
|
328
|
+
onError: event => {
|
|
329
|
+
error = new Error(JSON.stringify(event))
|
|
330
|
+
},
|
|
331
|
+
onClose: onSocketClose
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Append "/websocket" if needed:
|
|
335
|
+
const fullUri = uri.replace(/\/websocket\/?$/, '') + '/websocket'
|
|
336
|
+
try {
|
|
337
|
+
socket = _windowWS.setupBrowser.call(void 0, fullUri, cbs)
|
|
338
|
+
} catch (e2) {
|
|
339
|
+
socket = _nodejsWS.setupWS.call(void 0, fullUri, cbs)
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
},
|
|
343
|
+
|
|
344
|
+
disconnect() {
|
|
345
|
+
_optionalChain([socket, 'optionalAccess', _7 => _7.disconnect, 'call', _8 => _8()])
|
|
346
|
+
socket = null
|
|
347
|
+
disconnect()
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
isConnected() {
|
|
351
|
+
return _optionalChain([socket, 'optionalAccess', _9 => _9.readyState]) === _types3.ReadyState.OPEN
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
submitTask,
|
|
355
|
+
|
|
356
|
+
onQueueSpace(cb) {
|
|
357
|
+
onQueueSpace = cb
|
|
358
|
+
},
|
|
359
|
+
|
|
360
|
+
subscribe
|
|
361
|
+
}
|
|
362
|
+
} exports.makeSocket = makeSocket;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _ws = require('ws'); var _ws2 = _interopRequireDefault(_ws);
|
|
2
|
+
|
|
3
|
+
var _types = require('./types');
|
|
4
|
+
|
|
5
|
+
function setupWS(
|
|
6
|
+
uri,
|
|
7
|
+
callbacks
|
|
8
|
+
) {
|
|
9
|
+
const ws = new (0, _ws2.default)(uri, {
|
|
10
|
+
headers: {
|
|
11
|
+
'User-Agent': 'NodeJS-WS-agent'
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
ws.on('open', () => {
|
|
16
|
+
callbacks.onOpen()
|
|
17
|
+
})
|
|
18
|
+
ws.on('message', (data) => {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
20
|
+
callbacks.onMessage(data.toString())
|
|
21
|
+
})
|
|
22
|
+
ws.on('error', error => {
|
|
23
|
+
callbacks.onError(error)
|
|
24
|
+
})
|
|
25
|
+
ws.on('close', _event => {
|
|
26
|
+
callbacks.onClose()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
get readyState() {
|
|
31
|
+
switch (ws.readyState) {
|
|
32
|
+
case _ws2.default.CONNECTING:
|
|
33
|
+
return _types.ReadyState.CONNECTING
|
|
34
|
+
case _ws2.default.OPEN:
|
|
35
|
+
return _types.ReadyState.OPEN
|
|
36
|
+
case _ws2.default.CLOSING:
|
|
37
|
+
return _types.ReadyState.CLOSING
|
|
38
|
+
case _ws2.default.CLOSED:
|
|
39
|
+
default:
|
|
40
|
+
return _types.ReadyState.CLOSED
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
disconnect() {
|
|
45
|
+
if (
|
|
46
|
+
ws == null ||
|
|
47
|
+
ws.readyState === _ws2.default.CLOSING ||
|
|
48
|
+
ws.readyState === _ws2.default.CLOSED
|
|
49
|
+
)
|
|
50
|
+
return
|
|
51
|
+
ws.removeAllListeners()
|
|
52
|
+
ws.close()
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
send(data) {
|
|
56
|
+
ws.send(data)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} exports.setupWS = setupWS;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }const QUEUE_JOBS_PER_RUN = 3
|
|
2
|
+
const QUEUE_RUN_DELAY = 1000
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const updateQueue = []
|
|
11
|
+
let timeOut
|
|
12
|
+
|
|
13
|
+
function pushUpdate(update) {
|
|
14
|
+
const shouldRun = updateQueue.length === 0
|
|
15
|
+
let didUpdate = false
|
|
16
|
+
for (const u of updateQueue) {
|
|
17
|
+
if (u.id === update.id && u.action === update.action) {
|
|
18
|
+
u.updateFunc = update.updateFunc
|
|
19
|
+
didUpdate = true
|
|
20
|
+
break
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (!didUpdate) {
|
|
24
|
+
updateQueue.push(update)
|
|
25
|
+
}
|
|
26
|
+
if (shouldRun) {
|
|
27
|
+
startQueue()
|
|
28
|
+
}
|
|
29
|
+
} exports.pushUpdate = pushUpdate;
|
|
30
|
+
|
|
31
|
+
function removeIdFromQueue(id) {
|
|
32
|
+
for (let i = 0; i < updateQueue.length; i++) {
|
|
33
|
+
const update = updateQueue[i]
|
|
34
|
+
if (id === update.id) {
|
|
35
|
+
updateQueue.splice(i, 1)
|
|
36
|
+
break
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (updateQueue.length === 0) {
|
|
40
|
+
clearTimeout(timeOut)
|
|
41
|
+
}
|
|
42
|
+
} exports.removeIdFromQueue = removeIdFromQueue;
|
|
43
|
+
|
|
44
|
+
function startQueue() {
|
|
45
|
+
const numJobs =
|
|
46
|
+
QUEUE_JOBS_PER_RUN < updateQueue.length
|
|
47
|
+
? QUEUE_JOBS_PER_RUN
|
|
48
|
+
: updateQueue.length
|
|
49
|
+
for (let i = 0; i < numJobs; i++) {
|
|
50
|
+
if (updateQueue.length > 0) {
|
|
51
|
+
const u = updateQueue.shift()
|
|
52
|
+
_optionalChain([u, 'optionalAccess', _ => _.updateFunc, 'call', _2 => _2()])
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (updateQueue.length > 0) {
|
|
56
|
+
timeOut = setTimeout(() => {
|
|
57
|
+
startQueue()
|
|
58
|
+
}, QUEUE_RUN_DELAY)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var ReadyState; (function (ReadyState) {
|
|
9
|
+
const CONNECTING = 0; ReadyState[ReadyState["CONNECTING"] = CONNECTING] = "CONNECTING";
|
|
10
|
+
const OPEN = CONNECTING + 1; ReadyState[ReadyState["OPEN"] = OPEN] = "OPEN";
|
|
11
|
+
const CLOSING = OPEN + 1; ReadyState[ReadyState["CLOSING"] = CLOSING] = "CLOSING";
|
|
12
|
+
const CLOSED = CLOSING + 1; ReadyState[ReadyState["CLOSED"] = CLOSED] = "CLOSED";
|
|
13
|
+
})(ReadyState || (exports.ReadyState = ReadyState = {}));
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _types = require('./types');
|
|
2
|
+
|
|
3
|
+
function setupBrowser(
|
|
4
|
+
uri,
|
|
5
|
+
callbacks
|
|
6
|
+
) {
|
|
7
|
+
if (window.WebSocket == null)
|
|
8
|
+
throw Error('Native browser WebSocket does not exists')
|
|
9
|
+
|
|
10
|
+
const socket = new window.WebSocket(uri)
|
|
11
|
+
socket.onopen = () => {
|
|
12
|
+
callbacks.onOpen()
|
|
13
|
+
}
|
|
14
|
+
socket.onmessage = (message) => {
|
|
15
|
+
callbacks.onMessage(message.data.toString())
|
|
16
|
+
}
|
|
17
|
+
socket.onerror = () => {
|
|
18
|
+
callbacks.onError()
|
|
19
|
+
}
|
|
20
|
+
socket.onclose = () => {
|
|
21
|
+
callbacks.onClose()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
get readyState() {
|
|
26
|
+
switch (socket.readyState) {
|
|
27
|
+
case WebSocket.CONNECTING:
|
|
28
|
+
return _types.ReadyState.CONNECTING
|
|
29
|
+
case WebSocket.OPEN:
|
|
30
|
+
return _types.ReadyState.OPEN
|
|
31
|
+
case WebSocket.CLOSING:
|
|
32
|
+
return _types.ReadyState.CLOSING
|
|
33
|
+
case WebSocket.CLOSED:
|
|
34
|
+
default:
|
|
35
|
+
return _types.ReadyState.CLOSED
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
disconnect() {
|
|
40
|
+
if (
|
|
41
|
+
socket == null ||
|
|
42
|
+
socket.readyState === WebSocket.CLOSING ||
|
|
43
|
+
socket.readyState === WebSocket.CLOSED
|
|
44
|
+
)
|
|
45
|
+
return
|
|
46
|
+
|
|
47
|
+
socket.close()
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
send(data) {
|
|
51
|
+
socket.send(data)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} exports.setupBrowser = setupBrowser;
|
package/lib/firo.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _makeCurrencyPlugin = require('./common/plugin/makeCurrencyPlugin');
|
|
4
|
+
var _zcoin = require('./common/utxobased/info/zcoin');
|
|
5
|
+
|
|
6
|
+
const plugin = (options) =>
|
|
7
|
+
_makeCurrencyPlugin.makeCurrencyPlugin.call(void 0, options, _zcoin.info)
|
|
8
|
+
|
|
9
|
+
if (typeof window !== 'undefined') {
|
|
10
|
+
_optionalChain([window, 'access', _ => _.addEdgeCorePlugins, 'optionalCall', _2 => _2({
|
|
11
|
+
[_zcoin.info.currencyInfo.pluginId]: plugin
|
|
12
|
+
})])
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports. default = plugin
|
package/lib/ftc.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _makeCurrencyPlugin = require('./common/plugin/makeCurrencyPlugin');
|
|
4
|
+
var _feathercoin = require('./common/utxobased/info/feathercoin');
|
|
5
|
+
|
|
6
|
+
const plugin = (options) =>
|
|
7
|
+
_makeCurrencyPlugin.makeCurrencyPlugin.call(void 0, options, _feathercoin.info)
|
|
8
|
+
|
|
9
|
+
if (typeof window !== 'undefined') {
|
|
10
|
+
_optionalChain([window, 'access', _ => _.addEdgeCorePlugins, 'optionalCall', _2 => _2({
|
|
11
|
+
[_feathercoin.info.currencyInfo.pluginId]: plugin
|
|
12
|
+
})])
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports. default = plugin
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _createNamedExportFrom(obj, localName, importedName) { Object.defineProperty(exports, localName, {enumerable: true, get: () => obj[importedName]}); } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _makeCurrencyPlugin = require('./common/plugin/makeCurrencyPlugin');
|
|
4
|
+
var _all = require('./common/utxobased/info/all');
|
|
5
|
+
|
|
6
|
+
const plugins = {}
|
|
7
|
+
|
|
8
|
+
for (const info of _all.all) {
|
|
9
|
+
plugins[info.currencyInfo.pluginId] = (options) =>
|
|
10
|
+
_makeCurrencyPlugin.makeCurrencyPlugin.call(void 0, options, info)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (typeof window !== 'undefined') {
|
|
14
|
+
_optionalChain([window, 'access', _ => _.addEdgeCorePlugins, 'optionalCall', _2 => _2(plugins)])
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports. default = plugins
|
|
18
|
+
|
|
19
|
+
var _memlet = require('memlet'); _createNamedExportFrom(_memlet, 'setMemletConfig', 'setMemletConfig');
|
package/lib/ltc.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _makeCurrencyPlugin = require('./common/plugin/makeCurrencyPlugin');
|
|
4
|
+
var _litecoin = require('./common/utxobased/info/litecoin');
|
|
5
|
+
|
|
6
|
+
const plugin = (options) =>
|
|
7
|
+
_makeCurrencyPlugin.makeCurrencyPlugin.call(void 0, options, _litecoin.info)
|
|
8
|
+
|
|
9
|
+
if (typeof window !== 'undefined') {
|
|
10
|
+
_optionalChain([window, 'access', _ => _.addEdgeCorePlugins, 'optionalCall', _2 => _2({
|
|
11
|
+
[_litecoin.info.currencyInfo.pluginId]: plugin
|
|
12
|
+
})])
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports. default = plugin
|
package/lib/src/bch.d.ts
ADDED
package/lib/src/bsv.d.ts
ADDED
package/lib/src/btc.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const IMAGE_SERVER_URL = "https://content.edge.app";
|
|
2
|
+
export declare const INFO_SERVER_URI = "https://info1.edgesecure.co:8444/v1";
|
|
3
|
+
export declare const FEES_PATH = "fees.json";
|
|
4
|
+
export declare const MAX_FEE = 999999999;
|
|
5
|
+
export declare const LOW_FEE = 2;
|
|
6
|
+
export declare const MAX_HIGH_DELAY = 200;
|
|
7
|
+
export declare const MAX_STANDARD_DELAY = 6;
|
|
8
|
+
export declare const MIN_STANDARD_DELAY = 2;
|
|
9
|
+
export declare const MIN_LOW_DELAY = 1;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EdgeSpendInfo } from 'edge-core-js/types';
|
|
2
|
+
import { SimpleFeeSettings } from '../plugin/types';
|
|
3
|
+
declare type NetworkFeeOption = EdgeSpendInfo['networkFeeOption'];
|
|
4
|
+
/**
|
|
5
|
+
* Calculate the sat/byte mining fee given an amount to spend and a SimpleFeeSettings object
|
|
6
|
+
* @param nativeAmount
|
|
7
|
+
* @param fees
|
|
8
|
+
* @param networkFeeOption
|
|
9
|
+
* @param customNetworkFee
|
|
10
|
+
* @returns {string}
|
|
11
|
+
*/
|
|
12
|
+
export declare const calcMinerFeePerByte: (nativeAmount: string, fees: SimpleFeeSettings, networkFeeOption?: NetworkFeeOption, customNetworkFee?: string | undefined) => string;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Disklet } from 'disklet';
|
|
2
|
+
import { EdgeIo, EdgeLog, EdgeSpendInfo } from 'edge-core-js/types';
|
|
3
|
+
import { PluginInfo, SimpleFeeSettings } from '../plugin/types';
|
|
4
|
+
interface MakeFeesConfig extends Common {
|
|
5
|
+
disklet: Disklet;
|
|
6
|
+
pluginInfo: PluginInfo;
|
|
7
|
+
}
|
|
8
|
+
interface Common {
|
|
9
|
+
io: EdgeIo;
|
|
10
|
+
log: EdgeLog;
|
|
11
|
+
}
|
|
12
|
+
export interface Fees {
|
|
13
|
+
start: () => Promise<void>;
|
|
14
|
+
stop: () => void;
|
|
15
|
+
clearCache: () => Promise<void>;
|
|
16
|
+
getRate: (edgeSpendInfo: EdgeSpendInfo) => Promise<string>;
|
|
17
|
+
fees: SimpleFeeSettings;
|
|
18
|
+
}
|
|
19
|
+
export declare const makeFees: (config: MakeFeesConfig) => Promise<Fees>;
|
|
20
|
+
export {};
|