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,102 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _events = require('events');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
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
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class EngineEmitter extends _events.EventEmitter {} exports.EngineEmitter = EngineEmitter;
|
|
77
|
+
|
|
78
|
+
var EngineEvent; (function (EngineEvent) {
|
|
79
|
+
const TRANSACTIONS_CHANGED = 'transactions:changed'; EngineEvent["TRANSACTIONS_CHANGED"] = TRANSACTIONS_CHANGED;
|
|
80
|
+
const WALLET_BALANCE_CHANGED = 'wallet:balance:changed'; EngineEvent["WALLET_BALANCE_CHANGED"] = WALLET_BALANCE_CHANGED;
|
|
81
|
+
const ADDRESS_BALANCE_CHANGED = 'address:balance:changed'; EngineEvent["ADDRESS_BALANCE_CHANGED"] = ADDRESS_BALANCE_CHANGED;
|
|
82
|
+
const BLOCK_HEIGHT_CHANGED = 'block:height:changed'; EngineEvent["BLOCK_HEIGHT_CHANGED"] = BLOCK_HEIGHT_CHANGED;
|
|
83
|
+
const NEW_ADDRESS_TRANSACTION = 'address:transaction:changed'; EngineEvent["NEW_ADDRESS_TRANSACTION"] = NEW_ADDRESS_TRANSACTION;
|
|
84
|
+
const ADDRESSES_CHECKED = 'addresses:checked'; EngineEvent["ADDRESSES_CHECKED"] = ADDRESSES_CHECKED;
|
|
85
|
+
const TXIDS_CHANGED = 'txids:changed'; EngineEvent["TXIDS_CHANGED"] = TXIDS_CHANGED;
|
|
86
|
+
const CONNECTION_OPEN = 'connection:open'; EngineEvent["CONNECTION_OPEN"] = CONNECTION_OPEN;
|
|
87
|
+
const CONNECTION_CLOSE = 'connection:close'; EngineEvent["CONNECTION_CLOSE"] = CONNECTION_CLOSE;
|
|
88
|
+
const CONNECTION_TIMER = 'connection:timer'; EngineEvent["CONNECTION_TIMER"] = CONNECTION_TIMER;
|
|
89
|
+
})(EngineEvent || (exports.EngineEvent = EngineEvent = {}));
|
|
90
|
+
|
|
91
|
+
const makeEngineEmitter = (
|
|
92
|
+
callbacks
|
|
93
|
+
) => {
|
|
94
|
+
const emitter = new EngineEmitter()
|
|
95
|
+
|
|
96
|
+
emitter.on(EngineEvent.TRANSACTIONS_CHANGED, callbacks.onTransactionsChanged)
|
|
97
|
+
emitter.on(EngineEvent.WALLET_BALANCE_CHANGED, callbacks.onBalanceChanged)
|
|
98
|
+
emitter.on(EngineEvent.ADDRESSES_CHECKED, callbacks.onAddressesChecked)
|
|
99
|
+
emitter.on(EngineEvent.TXIDS_CHANGED, callbacks.onTxidsChanged)
|
|
100
|
+
|
|
101
|
+
return emitter
|
|
102
|
+
}; exports.makeEngineEmitter = makeEngineEmitter
|
|
@@ -0,0 +1,99 @@
|
|
|
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);
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _memlet = require('memlet');
|
|
5
|
+
|
|
6
|
+
var _awaitlock = require('../utxobased/engine/await-lock'); var _awaitlock2 = _interopRequireDefault(_awaitlock);
|
|
7
|
+
var _makeEngineEmitter = require('./makeEngineEmitter');
|
|
8
|
+
var _types3 = require('./types');
|
|
9
|
+
|
|
10
|
+
const metadataPath = `metadata.json`
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
const makeMetadata = async (
|
|
23
|
+
config
|
|
24
|
+
) => {
|
|
25
|
+
const { disklet, emitter, log } = config
|
|
26
|
+
const memlet = _memlet.makeMemlet.call(void 0, disklet)
|
|
27
|
+
const lock = new (0, _awaitlock2.default)()
|
|
28
|
+
|
|
29
|
+
const instance = {
|
|
30
|
+
get balance() {
|
|
31
|
+
return cache.balance
|
|
32
|
+
},
|
|
33
|
+
get lastSeenBlockHeight() {
|
|
34
|
+
return cache.lastSeenBlockHeight
|
|
35
|
+
},
|
|
36
|
+
clear: async () => {
|
|
37
|
+
await memlet.delete(metadataPath)
|
|
38
|
+
const cleanCache = await resetMetadata()
|
|
39
|
+
Object.assign(cache, cleanCache)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
emitter.on(
|
|
44
|
+
_makeEngineEmitter.EngineEvent.ADDRESS_BALANCE_CHANGED,
|
|
45
|
+
async (currencyCode, balanceDiff) => {
|
|
46
|
+
await lock.acquireAsync()
|
|
47
|
+
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)
|
|
55
|
+
} catch (err) {
|
|
56
|
+
log.error(err)
|
|
57
|
+
} finally {
|
|
58
|
+
lock.release()
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
emitter.on(
|
|
64
|
+
_makeEngineEmitter.EngineEvent.BLOCK_HEIGHT_CHANGED,
|
|
65
|
+
async (_uri, height) => {
|
|
66
|
+
if (height > cache.lastSeenBlockHeight) {
|
|
67
|
+
cache.lastSeenBlockHeight = height
|
|
68
|
+
await setMetadata(cache)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
const fetchMetadata = async () => {
|
|
74
|
+
try {
|
|
75
|
+
const metadata = await memlet.getJson(metadataPath)
|
|
76
|
+
return _types3.asLocalWalletMetadata.call(void 0, metadata)
|
|
77
|
+
} catch (err) {
|
|
78
|
+
log.error(err)
|
|
79
|
+
return await resetMetadata()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const resetMetadata = async () => {
|
|
84
|
+
const data = {
|
|
85
|
+
balance: '0',
|
|
86
|
+
lastSeenBlockHeight: 0
|
|
87
|
+
}
|
|
88
|
+
await memlet.setJson(metadataPath, data)
|
|
89
|
+
return data
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const setMetadata = async (data) => {
|
|
93
|
+
await memlet.setJson(metadataPath, data)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const cache = await fetchMetadata()
|
|
97
|
+
|
|
98
|
+
return instance
|
|
99
|
+
}; exports.makeMetadata = makeMetadata
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// Typescript translation from original code in edge-currency-bitcoin
|
|
2
|
+
|
|
3
|
+
var _cleaners = require('cleaners');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _memlet = require('memlet');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _serverScores = require('./serverScores');
|
|
16
|
+
|
|
17
|
+
// Info server endpoint to getting ServerListInfo data
|
|
18
|
+
const serverListInfoUrl = 'https://info1.edge.app/v1/blockBook/'
|
|
19
|
+
// The filename for ServerInfoCache data (see serverScores.ts)
|
|
20
|
+
// Perhaps this should be in serverScores.ts file, but that'll take some refactoring
|
|
21
|
+
const SERVER_CACHE_FILE = 'serverCache.json'
|
|
22
|
+
|
|
23
|
+
// ServerListInfo data structure from info server and saved to disk
|
|
24
|
+
const asServerListInfo = _cleaners.asObject.call(void 0, _cleaners.asEither.call(void 0, _cleaners.asArray.call(void 0, _cleaners.asString), _cleaners.asNull))
|
|
25
|
+
|
|
26
|
+
/** A JSON object (as opposed to an array or primitive). */
|
|
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
|
+
function makePluginState(settings) {
|
|
61
|
+
const {
|
|
62
|
+
io,
|
|
63
|
+
defaultSettings,
|
|
64
|
+
currencyCode,
|
|
65
|
+
pluginId,
|
|
66
|
+
pluginDisklet,
|
|
67
|
+
log
|
|
68
|
+
} = settings
|
|
69
|
+
const builtInServers = defaultSettings.blockbookServers
|
|
70
|
+
let customServers = []
|
|
71
|
+
let enableCustomServers = defaultSettings.enableCustomServers
|
|
72
|
+
let engines = []
|
|
73
|
+
const memlet = _memlet.makeMemlet.call(void 0, pluginDisklet)
|
|
74
|
+
|
|
75
|
+
let serverCache = {
|
|
76
|
+
customServers: {},
|
|
77
|
+
internalServers: {}
|
|
78
|
+
}
|
|
79
|
+
let serverCacheDirty = false
|
|
80
|
+
let knownServers = {}
|
|
81
|
+
|
|
82
|
+
const saveServerCache = async () => {
|
|
83
|
+
serverScores.printServers(knownServers)
|
|
84
|
+
if (serverCacheDirty) {
|
|
85
|
+
await memlet.setJson(SERVER_CACHE_FILE, serverCache).catch(e => {
|
|
86
|
+
log(`${pluginId} - ${JSON.stringify(e.toString())}`)
|
|
87
|
+
})
|
|
88
|
+
serverCacheDirty = false
|
|
89
|
+
serverScores.scoresLastLoaded = Date.now()
|
|
90
|
+
log(`${pluginId} - Saved server cache`)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const onDirtyServer = (serverUrl) => {
|
|
95
|
+
serverCacheDirty = true
|
|
96
|
+
for (const engine of engines) {
|
|
97
|
+
if (engine.processedPercent === 1) {
|
|
98
|
+
const isFound = engine.getServerList().includes(serverUrl)
|
|
99
|
+
if (isFound) {
|
|
100
|
+
saveServerCache().catch(e => {
|
|
101
|
+
log(`${pluginId} - ${JSON.stringify(e.toString())}`)
|
|
102
|
+
})
|
|
103
|
+
// Early exit because the server cache is no longer dirty after
|
|
104
|
+
// calling saveServerCache
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const serverScores = new (0, _serverScores.ServerScores)({
|
|
112
|
+
log,
|
|
113
|
+
onDirtyServer
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
const fetchServers = async () => {
|
|
117
|
+
log(`${pluginId} - GET ${serverListInfoUrl}`)
|
|
118
|
+
|
|
119
|
+
const response = await io.fetch(serverListInfoUrl)
|
|
120
|
+
const responseBody = await (async () => {
|
|
121
|
+
try {
|
|
122
|
+
if (response.ok) {
|
|
123
|
+
return await response.json()
|
|
124
|
+
}
|
|
125
|
+
log(
|
|
126
|
+
`${pluginId} - Fetching ${serverListInfoUrl} failed with status ${response.status}`
|
|
127
|
+
)
|
|
128
|
+
} catch (err) {
|
|
129
|
+
log(`${pluginId} - Fetching ${serverListInfoUrl} failed: ${err}`)
|
|
130
|
+
}
|
|
131
|
+
return {}
|
|
132
|
+
})()
|
|
133
|
+
|
|
134
|
+
const serverListInfo = asServerListInfo(responseBody)
|
|
135
|
+
|
|
136
|
+
return _nullishCoalesce(serverListInfo[currencyCode], () => ( []))
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const refreshServers = async () => {
|
|
140
|
+
let newServers
|
|
141
|
+
if (enableCustomServers) {
|
|
142
|
+
newServers = customServers
|
|
143
|
+
} else {
|
|
144
|
+
const fetchedServers = await fetchServers()
|
|
145
|
+
newServers = fetchedServers.length > 0 ? fetchedServers : builtInServers
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const serverCacheIndex = enableCustomServers
|
|
149
|
+
? 'customServers'
|
|
150
|
+
: 'internalServers'
|
|
151
|
+
|
|
152
|
+
knownServers = serverCache[serverCacheIndex]
|
|
153
|
+
serverScores.serverScoresLoad(knownServers, newServers)
|
|
154
|
+
await saveServerCache()
|
|
155
|
+
|
|
156
|
+
// Tell the engines about the new servers:
|
|
157
|
+
for (const engine of engines) {
|
|
158
|
+
engine.refillServers()
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
/**
|
|
164
|
+
* Begins notifying the engine of state changes. Used at connection time.
|
|
165
|
+
*/
|
|
166
|
+
addEngine(engineState) {
|
|
167
|
+
engines.push(engineState)
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Stops notifying the engine of state changes. Used at disconnection time.
|
|
172
|
+
*/
|
|
173
|
+
removeEngine(engineState) {
|
|
174
|
+
engines = engines.filter(engine => engine !== engineState)
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
dumpData() {
|
|
178
|
+
return {
|
|
179
|
+
'pluginState.servers_': knownServers
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
async load() {
|
|
184
|
+
try {
|
|
185
|
+
serverCache = _serverScores.asServerCache.call(void 0, await memlet.getJson(SERVER_CACHE_FILE))
|
|
186
|
+
} catch (e) {
|
|
187
|
+
log(`${pluginId}: Failed to load server cache: ${JSON.stringify(e)}`)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Fetch servers in the background:
|
|
191
|
+
refreshServers().catch(e => {
|
|
192
|
+
log(`${pluginId} - ${JSON.stringify(e.toString())}`)
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
return this
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
serverScoreDown(uri) {
|
|
199
|
+
serverScores.serverScoreDown(knownServers, uri)
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
serverScoreUp(uri, score) {
|
|
203
|
+
serverScores.serverScoreUp(knownServers, uri, score)
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
async clearCache() {
|
|
207
|
+
serverScores.clearServerScoreTimes()
|
|
208
|
+
knownServers = {}
|
|
209
|
+
serverCacheDirty = true
|
|
210
|
+
await memlet.delete(SERVER_CACHE_FILE)
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
getLocalServers(
|
|
214
|
+
numServersWanted,
|
|
215
|
+
includePatterns = []
|
|
216
|
+
) {
|
|
217
|
+
return serverScores.getServers(
|
|
218
|
+
knownServers,
|
|
219
|
+
numServersWanted,
|
|
220
|
+
includePatterns
|
|
221
|
+
)
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
refreshServers,
|
|
225
|
+
|
|
226
|
+
async updateServers(settings) {
|
|
227
|
+
enableCustomServers = settings.enableCustomServers
|
|
228
|
+
customServers = settings.blockbookServers
|
|
229
|
+
|
|
230
|
+
const enginesToBeStopped = []
|
|
231
|
+
const disconnects = []
|
|
232
|
+
for (const engine of engines) {
|
|
233
|
+
enginesToBeStopped.push(engine)
|
|
234
|
+
engine.setServerList([])
|
|
235
|
+
disconnects.push(engine.stop())
|
|
236
|
+
}
|
|
237
|
+
await Promise.all(disconnects)
|
|
238
|
+
serverScores.clearServerScoreTimes()
|
|
239
|
+
// We must always clear custom servers in order to enforce a policy of
|
|
240
|
+
// only using the exact customServers provided.
|
|
241
|
+
serverCache = {
|
|
242
|
+
...serverCache,
|
|
243
|
+
customServers: {}
|
|
244
|
+
}
|
|
245
|
+
serverCacheDirty = true
|
|
246
|
+
await saveServerCache()
|
|
247
|
+
await refreshServers()
|
|
248
|
+
for (const engine of enginesToBeStopped) {
|
|
249
|
+
await engine.stop()
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
} exports.makePluginState = makePluginState;
|