edge-currency-plugins 2.5.3 → 2.6.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.
- package/lib/bch.js +2 -2
- package/lib/bsv.js +2 -2
- package/lib/btc.js +2 -2
- package/lib/common/plugin/{makeCurrencyPlugin.js → CurrencyPlugin.js} +13 -9
- package/lib/common/plugin/{makeMetadata.js → Metadata.js} +4 -4
- package/lib/common/plugin/{pluginState.js → PluginState.js} +6 -6
- package/lib/common/plugin/{serverScores.js → ServerScores.js} +8 -1
- package/lib/common/plugin/types.js +8 -0
- package/lib/common/utxobased/db/{makeProcessor.js → Processor.js} +3 -3
- package/lib/common/utxobased/engine/{makeServerStates.js → ServerStates.js} +140 -45
- package/lib/common/utxobased/engine/{makeUtxoEngine.js → UtxoEngine.js} +21 -20
- package/lib/common/utxobased/engine/{makeUtxoEngineState.js → UtxoEngineState.js} +27 -22
- package/lib/common/utxobased/engine/types.js +5 -0
- package/lib/common/utxobased/info/bitcoin.js +6 -0
- package/lib/common/utxobased/info/bitcoincash.js +6 -0
- package/lib/common/utxobased/info/dash.js +6 -0
- package/lib/common/utxobased/info/digibyte.js +6 -0
- package/lib/common/utxobased/info/dogecoin.js +6 -0
- package/lib/common/utxobased/info/groestlcoin.js +6 -0
- package/lib/common/utxobased/info/litecoin.js +6 -0
- package/lib/common/utxobased/keymanager/utxopicker/subtractFee.js +2 -1
- package/lib/common/utxobased/network/{BlockBook.js → Blockbook.js} +28 -24
- package/lib/common/utxobased/network/Socket.js +4 -4
- package/lib/firo.js +2 -2
- package/lib/ftc.js +2 -2
- package/lib/index.js +2 -2
- package/lib/ltc.js +2 -2
- package/lib/src/common/plugin/{makeEngineEmitter.d.ts → EngineEmitter.d.ts} +1 -1
- package/lib/src/common/plugin/{makeMetadata.d.ts → Metadata.d.ts} +1 -1
- package/lib/src/common/plugin/{pluginState.d.ts → PluginState.d.ts} +2 -2
- package/lib/src/common/plugin/{serverScores.d.ts → ServerScores.d.ts} +1 -1
- package/lib/src/common/plugin/types.d.ts +9 -2
- package/lib/src/common/utxobased/db/Models/ProcessorTransaction.d.ts +3 -3
- package/lib/src/common/utxobased/db/util/utxo.d.ts +1 -1
- package/lib/src/common/utxobased/engine/{makeServerStates.d.ts → ServerStates.d.ts} +8 -5
- package/lib/src/common/utxobased/engine/{makeUtxoEngineState.d.ts → UtxoEngineState.d.ts} +9 -9
- package/lib/src/common/utxobased/engine/{makeUtxoWalletTools.d.ts → UtxoWalletTools.d.ts} +2 -2
- package/lib/src/common/utxobased/engine/types.d.ts +4 -0
- package/lib/src/common/utxobased/engine/util/getOwnUtxosFromTx.d.ts +1 -1
- package/lib/src/common/utxobased/network/{BlockBook.d.ts → Blockbook.d.ts} +10 -10
- package/lib/src/common/utxobased/network/Socket.d.ts +1 -1
- package/lib/tbch.js +2 -2
- package/lib/tbtc.js +2 -2
- package/lib/tbtg.js +2 -2
- package/package.json +1 -1
- /package/lib/common/plugin/{makeCurrencyTools.js → CurrencyTools.js} +0 -0
- /package/lib/common/plugin/{makeEngineEmitter.js → EngineEmitter.js} +0 -0
- /package/lib/common/utxobased/db/{makeBaselets.js → Baselets.js} +0 -0
- /package/lib/common/utxobased/db/{makeMutex.js → Mutex.js} +0 -0
- /package/lib/common/utxobased/engine/{makeUtxoWalletTools.js → UtxoWalletTools.js} +0 -0
- /package/lib/common/utxobased/network/{MakeSocketEmitter.js → SocketEmitter.js} +0 -0
- /package/lib/common/utxobased/network/{BlockBookAPI.js → blockbookApi.js} +0 -0
- /package/lib/src/common/plugin/{makeCurrencyPlugin.d.ts → CurrencyPlugin.d.ts} +0 -0
- /package/lib/src/common/plugin/{makeCurrencyTools.d.ts → CurrencyTools.d.ts} +0 -0
- /package/lib/src/common/utxobased/db/{makeBaselets.d.ts → Baselets.d.ts} +0 -0
- /package/lib/src/common/utxobased/db/{makeMutex.d.ts → Mutex.d.ts} +0 -0
- /package/lib/src/common/utxobased/db/{makeProcessor.d.ts → Processor.d.ts} +0 -0
- /package/lib/src/common/utxobased/engine/{makeUtxoEngine.d.ts → UtxoEngine.d.ts} +0 -0
- /package/lib/src/common/utxobased/network/{MakeSocketEmitter.d.ts → SocketEmitter.d.ts} +0 -0
- /package/lib/src/common/utxobased/network/{BlockBookAPI.d.ts → blockbookApi.d.ts} +0 -0
- /package/lib/test/common/plugin/{currencyPlugin.fixtures → CurrencyPlugin.fixtures}/common.d.ts +0 -0
- /package/lib/test/common/plugin/{currencyPlugin.fixtures → CurrencyPlugin.fixtures}/currencies/bitcoin.d.ts +0 -0
- /package/lib/test/common/plugin/{currencyPlugin.fixtures → CurrencyPlugin.fixtures}/currencies/bitcoincash.d.ts +0 -0
- /package/lib/test/common/plugin/{currencyPlugin.fixtures → CurrencyPlugin.fixtures}/currencies/bitcoinsv.d.ts +0 -0
- /package/lib/test/common/plugin/{currencyPlugin.fixtures → CurrencyPlugin.fixtures}/currencies/digibyte.d.ts +0 -0
- /package/lib/test/common/plugin/{currencyPlugin.fixtures → CurrencyPlugin.fixtures}/currencies/feathercoin.d.ts +0 -0
- /package/lib/test/common/plugin/{currencyPlugin.fixtures → CurrencyPlugin.fixtures}/currencies/groestlcoin.d.ts +0 -0
- /package/lib/test/common/plugin/{currencyPlugin.fixtures → CurrencyPlugin.fixtures}/currencies/litecoin.d.ts +0 -0
- /package/lib/test/common/plugin/{currencyPlugin.fixtures → CurrencyPlugin.fixtures}/currencies/smartcash.d.ts +0 -0
- /package/lib/test/common/plugin/{currencyPlugin.fixtures → CurrencyPlugin.fixtures}/currencies/zcoin.d.ts +0 -0
- /package/lib/test/common/plugin/{currencyPlugin.fixtures → CurrencyPlugin.fixtures}/index.d.ts +0 -0
- /package/lib/test/common/plugin/{currencyPlugin.spec.d.ts → CurrencyPlugin.spec.d.ts} +0 -0
- /package/lib/test/common/plugin/{makeMetadata.spec.d.ts → Metadata.spec.d.ts} +0 -0
- /package/lib/test/common/plugin/{serverScores.spec.d.ts → ServerScores.spec.d.ts} +0 -0
- /package/lib/test/common/utxobased/network/{BlockBook.spec.d.ts → Blockbook.spec.d.ts} +0 -0
package/lib/bch.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
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
2
|
|
|
3
|
-
var
|
|
3
|
+
var _CurrencyPlugin = require('./common/plugin/CurrencyPlugin');
|
|
4
4
|
var _bitcoincash = require('./common/utxobased/info/bitcoincash');
|
|
5
5
|
|
|
6
6
|
const plugin = (options) =>
|
|
7
|
-
|
|
7
|
+
_CurrencyPlugin.makeCurrencyPlugin.call(void 0, options, _bitcoincash.info)
|
|
8
8
|
|
|
9
9
|
if (typeof window !== 'undefined') {
|
|
10
10
|
_optionalChain([window, 'access', _ => _.addEdgeCorePlugins, 'optionalCall', _2 => _2({
|
package/lib/bsv.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
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
2
|
|
|
3
|
-
var
|
|
3
|
+
var _CurrencyPlugin = require('./common/plugin/CurrencyPlugin');
|
|
4
4
|
var _bitcoinsv = require('./common/utxobased/info/bitcoinsv');
|
|
5
5
|
|
|
6
6
|
const plugin = (options) =>
|
|
7
|
-
|
|
7
|
+
_CurrencyPlugin.makeCurrencyPlugin.call(void 0, options, _bitcoinsv.info)
|
|
8
8
|
|
|
9
9
|
if (typeof window !== 'undefined') {
|
|
10
10
|
_optionalChain([window, 'access', _ => _.addEdgeCorePlugins, 'optionalCall', _2 => _2({
|
package/lib/btc.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
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
2
|
|
|
3
|
-
var
|
|
3
|
+
var _CurrencyPlugin = require('./common/plugin/CurrencyPlugin');
|
|
4
4
|
var _bitcoin = require('./common/utxobased/info/bitcoin');
|
|
5
5
|
|
|
6
6
|
const plugin = (options) =>
|
|
7
|
-
|
|
7
|
+
_CurrencyPlugin.makeCurrencyPlugin.call(void 0, options, _bitcoin.info)
|
|
8
8
|
|
|
9
9
|
if (typeof window !== 'undefined') {
|
|
10
10
|
_optionalChain([window, 'access', _ => _.addEdgeCorePlugins, 'optionalCall', _2 => _2({
|
|
@@ -7,11 +7,14 @@
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
11
13
|
var _types3 = require('../utxobased/engine/types');
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
14
|
+
var _UtxoEngine = require('../utxobased/engine/UtxoEngine');
|
|
15
|
+
var _CurrencyTools = require('./CurrencyTools');
|
|
16
|
+
var _EngineEmitter = require('./EngineEmitter');
|
|
17
|
+
var _PluginState = require('./PluginState');
|
|
15
18
|
|
|
16
19
|
|
|
17
20
|
function makeCurrencyPlugin(
|
|
@@ -19,10 +22,10 @@ var _pluginState = require('./pluginState');
|
|
|
19
22
|
pluginInfo
|
|
20
23
|
) {
|
|
21
24
|
const { currencyInfo } = pluginInfo
|
|
22
|
-
const { io, log, pluginDisklet } = pluginOptions
|
|
23
|
-
const currencyTools =
|
|
25
|
+
const { io, log, pluginDisklet, initOptions } = pluginOptions
|
|
26
|
+
const currencyTools = _CurrencyTools.makeCurrencyTools.call(void 0, io, pluginInfo)
|
|
24
27
|
const { defaultSettings, pluginId, currencyCode } = currencyInfo
|
|
25
|
-
const pluginState =
|
|
28
|
+
const pluginState = _PluginState.makePluginState.call(void 0, {
|
|
26
29
|
io,
|
|
27
30
|
currencyCode,
|
|
28
31
|
pluginId,
|
|
@@ -37,12 +40,13 @@ var _pluginState = require('./pluginState');
|
|
|
37
40
|
walletInfo,
|
|
38
41
|
engineOptions
|
|
39
42
|
) {
|
|
40
|
-
const emitter =
|
|
43
|
+
const emitter = _EngineEmitter.makeEngineEmitter.call(void 0, engineOptions.callbacks)
|
|
41
44
|
const engineConfig = {
|
|
42
45
|
walletInfo,
|
|
43
46
|
pluginInfo,
|
|
44
47
|
pluginDisklet,
|
|
45
48
|
currencyTools,
|
|
49
|
+
initOptions: _types3.asUtxoInitOptions.call(void 0, initOptions),
|
|
46
50
|
io,
|
|
47
51
|
options: {
|
|
48
52
|
...pluginOptions,
|
|
@@ -51,7 +55,7 @@ var _pluginState = require('./pluginState');
|
|
|
51
55
|
},
|
|
52
56
|
pluginState
|
|
53
57
|
}
|
|
54
|
-
const engine = await
|
|
58
|
+
const engine = await _UtxoEngine.makeUtxoEngine.call(void 0, engineConfig)
|
|
55
59
|
|
|
56
60
|
return engine
|
|
57
61
|
},
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
var _memlet = require('memlet');
|
|
5
5
|
|
|
6
6
|
var _awaitlock = require('../utxobased/engine/await-lock'); var _awaitlock2 = _interopRequireDefault(_awaitlock);
|
|
7
|
-
var
|
|
7
|
+
var _EngineEmitter = require('./EngineEmitter');
|
|
8
8
|
var _types3 = require('./types');
|
|
9
9
|
var _utils = require('./utils');
|
|
10
10
|
|
|
@@ -47,14 +47,14 @@ const metadataPath = `metadata.json`
|
|
|
47
47
|
cache.balance = cumulativeBalance
|
|
48
48
|
await setMetadata(cache)
|
|
49
49
|
emitter.emit(
|
|
50
|
-
|
|
50
|
+
_EngineEmitter.EngineEvent.WALLET_BALANCE_CHANGED,
|
|
51
51
|
currencyCode,
|
|
52
52
|
cumulativeBalance
|
|
53
53
|
)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
emitter.on(
|
|
57
|
-
|
|
57
|
+
_EngineEmitter.EngineEvent.ADDRESS_BALANCE_CHANGED,
|
|
58
58
|
async (
|
|
59
59
|
currencyCode,
|
|
60
60
|
addressBalanceChanges
|
|
@@ -79,7 +79,7 @@ const metadataPath = `metadata.json`
|
|
|
79
79
|
)
|
|
80
80
|
|
|
81
81
|
emitter.on(
|
|
82
|
-
|
|
82
|
+
_EngineEmitter.EngineEvent.BLOCK_HEIGHT_CHANGED,
|
|
83
83
|
async (_uri, height) => {
|
|
84
84
|
if (height > cache.lastSeenBlockHeight) {
|
|
85
85
|
cache.lastSeenBlockHeight = height
|
|
@@ -12,12 +12,12 @@ var _memlet = require('memlet');
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _ServerScores = require('./ServerScores');
|
|
16
16
|
|
|
17
17
|
// Info server endpoint to getting ServerListInfo data
|
|
18
|
-
const serverListInfoUrl = 'https://info1.edge.app/v1/
|
|
19
|
-
// The filename for ServerInfoCache data (see
|
|
20
|
-
// Perhaps this should be in
|
|
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
21
|
const SERVER_CACHE_FILE = 'serverCache.json'
|
|
22
22
|
|
|
23
23
|
// ServerListInfo data structure from info server and saved to disk
|
|
@@ -108,7 +108,7 @@ const asServerListInfo = _cleaners.asObject.call(void 0, _cleaners.asEither.call
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
const serverScores = new (0,
|
|
111
|
+
const serverScores = new (0, _ServerScores.ServerScores)({
|
|
112
112
|
log,
|
|
113
113
|
onDirtyServer
|
|
114
114
|
})
|
|
@@ -179,7 +179,7 @@ const asServerListInfo = _cleaners.asObject.call(void 0, _cleaners.asEither.call
|
|
|
179
179
|
|
|
180
180
|
async load() {
|
|
181
181
|
try {
|
|
182
|
-
serverCache =
|
|
182
|
+
serverCache = _ServerScores.asServerCache.call(void 0, await memlet.getJson(SERVER_CACHE_FILE))
|
|
183
183
|
} catch (e) {
|
|
184
184
|
log(`${pluginId}: Failed to load server cache: ${JSON.stringify(e)}`)
|
|
185
185
|
}
|
|
@@ -236,7 +236,14 @@ const RE_ADDED_SERVER_SCORE = -10
|
|
|
236
236
|
const filter = (server) => {
|
|
237
237
|
for (const pattern of includePatterns) {
|
|
238
238
|
// make sure that the server URL starts with the required pattern
|
|
239
|
-
if (
|
|
239
|
+
if (
|
|
240
|
+
typeof pattern === 'string' &&
|
|
241
|
+
server.serverUrl.indexOf(pattern) === 0
|
|
242
|
+
)
|
|
243
|
+
return true
|
|
244
|
+
// Or make sure that the server URL matches regex
|
|
245
|
+
if (pattern instanceof RegExp && pattern.test(server.serverUrl))
|
|
246
|
+
return true
|
|
240
247
|
}
|
|
241
248
|
return false
|
|
242
249
|
}
|
|
@@ -29,6 +29,7 @@ var _types3 = require('../utxobased/db/types');
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
|
|
32
|
+
|
|
32
33
|
const asCurrencyFormat = _cleaners.asValue.call(void 0, 'bip32', 'bip44', 'bip49', 'bip84'); exports.asCurrencyFormat = asCurrencyFormat
|
|
33
34
|
|
|
34
35
|
// Path up to changeIndex
|
|
@@ -144,6 +145,12 @@ var _types3 = require('../utxobased/db/types');
|
|
|
144
145
|
|
|
145
146
|
|
|
146
147
|
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
147
154
|
|
|
148
155
|
|
|
149
156
|
|
|
@@ -205,6 +212,7 @@ var _types3 = require('../utxobased/db/types');
|
|
|
205
212
|
|
|
206
213
|
|
|
207
214
|
|
|
215
|
+
|
|
208
216
|
const asLocalWalletMetadata = _cleaners.asObject.call(void 0, {
|
|
209
217
|
balance: _cleaners.asString,
|
|
210
218
|
// scriptPubkey -> balance
|
|
@@ -6,7 +6,7 @@ var _memlet = require('memlet');
|
|
|
6
6
|
|
|
7
7
|
var _unixTime = require('../../../util/unixTime');
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _Baselets = require('./Baselets');
|
|
10
10
|
var _baselet3 = require('./Models/baselet');
|
|
11
11
|
|
|
12
12
|
|
|
@@ -113,7 +113,7 @@ const BASELET_DIR = 'tables'
|
|
|
113
113
|
) {
|
|
114
114
|
const disklet = _disklet.navigateDisklet.call(void 0, config.disklet, BASELET_DIR)
|
|
115
115
|
let memlet = _memlet.makeMemlet.call(void 0, disklet)
|
|
116
|
-
let baselets = await
|
|
116
|
+
let baselets = await _Baselets.makeBaselets.call(void 0, { storage: memlet }).catch(async error => {
|
|
117
117
|
await memlet.delete('.')
|
|
118
118
|
throw error
|
|
119
119
|
})
|
|
@@ -153,7 +153,7 @@ const BASELET_DIR = 'tables'
|
|
|
153
153
|
await _baselet.clearMemletCache.call(void 0, )
|
|
154
154
|
await disklet.delete('.')
|
|
155
155
|
memlet = _memlet.makeMemlet.call(void 0, disklet)
|
|
156
|
-
baselets = await
|
|
156
|
+
baselets = await _Baselets.makeBaselets.call(void 0, { storage: memlet })
|
|
157
157
|
},
|
|
158
158
|
|
|
159
159
|
async dumpData() {
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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
2
|
var _urijs = require('uri-js');
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _EngineEmitter = require('../../plugin/EngineEmitter');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
var _utils = require('../../plugin/utils');
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _Blockbook = require('../network/Blockbook');
|
|
10
10
|
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _blockbookApi = require('../network/blockbookApi');
|
|
11
15
|
var _Deferred = require('../network/Deferred'); var _Deferred2 = _interopRequireDefault(_Deferred);
|
|
12
|
-
var _MakeSocketEmitter = require('../network/MakeSocketEmitter');
|
|
13
16
|
|
|
17
|
+
var _SocketEmitter = require('../network/SocketEmitter');
|
|
14
18
|
var _socketQueue = require('../network/socketQueue');
|
|
15
19
|
var _constants = require('./constants');
|
|
16
20
|
|
|
@@ -53,12 +57,24 @@ var _constants = require('./constants');
|
|
|
53
57
|
|
|
54
58
|
|
|
55
59
|
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
56
63
|
|
|
57
64
|
|
|
58
65
|
|
|
59
66
|
|
|
60
67
|
function makeServerStates(config) {
|
|
61
|
-
const {
|
|
68
|
+
const {
|
|
69
|
+
engineEmitter,
|
|
70
|
+
initOptions,
|
|
71
|
+
io,
|
|
72
|
+
log,
|
|
73
|
+
pluginInfo,
|
|
74
|
+
pluginState,
|
|
75
|
+
walletInfo
|
|
76
|
+
} = config
|
|
77
|
+
const { serverConfigs = [] } = pluginInfo.engineInfo
|
|
62
78
|
log('Making server states')
|
|
63
79
|
|
|
64
80
|
const serverStatesCache = {}
|
|
@@ -68,15 +84,15 @@ var _constants = require('./constants');
|
|
|
68
84
|
let reconnectTimer = setTimeout(() => {
|
|
69
85
|
return
|
|
70
86
|
}, 0)
|
|
71
|
-
const socketEmitter = new (0,
|
|
87
|
+
const socketEmitter = new (0, _SocketEmitter.SocketEmitter)()
|
|
72
88
|
|
|
73
89
|
// set server specific event emitters
|
|
74
|
-
socketEmitter.on(
|
|
90
|
+
socketEmitter.on(_SocketEmitter.SocketEvent.CONNECTION_OPEN, (uri) => {
|
|
75
91
|
reconnectCounter = 0
|
|
76
92
|
log(`${uri} ** Connected **`)
|
|
77
93
|
})
|
|
78
94
|
socketEmitter.on(
|
|
79
|
-
|
|
95
|
+
_SocketEmitter.SocketEvent.CONNECTION_CLOSE,
|
|
80
96
|
(uri, error) => {
|
|
81
97
|
_utils.removeItem.call(void 0, serverStatesCache, uri)
|
|
82
98
|
|
|
@@ -90,7 +106,7 @@ var _constants = require('./constants');
|
|
|
90
106
|
}
|
|
91
107
|
)
|
|
92
108
|
socketEmitter.on(
|
|
93
|
-
|
|
109
|
+
_SocketEmitter.SocketEvent.CONNECTION_TIMER,
|
|
94
110
|
(uri, queryDate) => {
|
|
95
111
|
const queryTime = Date.now() - queryDate
|
|
96
112
|
log(`${uri} returned healthCheck in ${queryTime}ms`)
|
|
@@ -98,7 +114,7 @@ var _constants = require('./constants');
|
|
|
98
114
|
}
|
|
99
115
|
)
|
|
100
116
|
engineEmitter.on(
|
|
101
|
-
|
|
117
|
+
_EngineEmitter.EngineEvent.NEW_ADDRESS_TRANSACTION,
|
|
102
118
|
(uri, newTx) => {
|
|
103
119
|
log(
|
|
104
120
|
`${uri} received received new transaction with id ${newTx.tx.txid} to address ${newTx.address}`
|
|
@@ -110,7 +126,7 @@ var _constants = require('./constants');
|
|
|
110
126
|
}
|
|
111
127
|
)
|
|
112
128
|
engineEmitter.on(
|
|
113
|
-
|
|
129
|
+
_EngineEmitter.EngineEvent.BLOCK_HEIGHT_CHANGED,
|
|
114
130
|
(uri, blockHeight) => {
|
|
115
131
|
log(`${uri} block height changed to ${blockHeight}`)
|
|
116
132
|
serverStatesCache[uri].blockHeight = blockHeight
|
|
@@ -208,9 +224,9 @@ var _constants = require('./constants');
|
|
|
208
224
|
}
|
|
209
225
|
|
|
210
226
|
// Make new Blockbook instance
|
|
211
|
-
const blockbook =
|
|
212
|
-
|
|
213
|
-
|
|
227
|
+
const blockbook = _Blockbook.makeBlockbook.call(void 0, {
|
|
228
|
+
asAddress: pluginInfo.engineInfo.asBlockbookAddress,
|
|
229
|
+
connectionUri: uri,
|
|
214
230
|
engineEmitter,
|
|
215
231
|
log,
|
|
216
232
|
onQueueSpaceCB: async (
|
|
@@ -229,8 +245,8 @@ var _constants = require('./constants');
|
|
|
229
245
|
}
|
|
230
246
|
return task
|
|
231
247
|
},
|
|
232
|
-
|
|
233
|
-
|
|
248
|
+
socketEmitter,
|
|
249
|
+
walletId: walletInfo.id
|
|
234
250
|
})
|
|
235
251
|
|
|
236
252
|
// Make new ServerStates instance
|
|
@@ -249,7 +265,7 @@ var _constants = require('./constants');
|
|
|
249
265
|
serverStatesCache[uri].blockHeight = blockHeight
|
|
250
266
|
|
|
251
267
|
// Emit initial BLOCK_HEIGHT_CHANGED event
|
|
252
|
-
engineEmitter.emit(
|
|
268
|
+
engineEmitter.emit(_EngineEmitter.EngineEvent.BLOCK_HEIGHT_CHANGED, uri, blockHeight)
|
|
253
269
|
|
|
254
270
|
// Increment server score using response time
|
|
255
271
|
const responseTime = Date.now() - startTime
|
|
@@ -304,38 +320,117 @@ var _constants = require('./constants');
|
|
|
304
320
|
|
|
305
321
|
const broadcastTx = async (transaction) => {
|
|
306
322
|
return await new Promise((resolve, reject) => {
|
|
307
|
-
const uris = Object.keys(serverStatesCache).filter(uri => {
|
|
308
|
-
const { blockbook } = serverStatesCache[uri]
|
|
309
|
-
if (blockbook == null) return false
|
|
310
|
-
return blockbook.isConnected
|
|
311
|
-
})
|
|
312
|
-
if (uris == null || uris.length < 1) {
|
|
313
|
-
reject(
|
|
314
|
-
new Error('No available connections\nCheck your internet signal')
|
|
315
|
-
)
|
|
316
|
-
}
|
|
317
323
|
let resolved = false
|
|
318
324
|
let bad = 0
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
325
|
+
|
|
326
|
+
const wsUris = Object.keys(serverStatesCache).filter(
|
|
327
|
+
uri => serverStatesCache[uri].blockbook != null
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
// If there are no blockbook instances, reject the promise
|
|
331
|
+
if (wsUris.length < 1) {
|
|
332
|
+
reject(new Error('Unexpected error. Missing WebSocket connections.'))
|
|
333
|
+
// Exit early if there are blockbook instances
|
|
334
|
+
return
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Determine if there are any connected blockbook instances
|
|
338
|
+
const isAnyBlockbookConnected = wsUris.some(
|
|
339
|
+
uri => serverStatesCache[uri].blockbook.isConnected
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
if (isAnyBlockbookConnected) {
|
|
343
|
+
for (const uri of wsUris) {
|
|
344
|
+
const { blockbook } = serverStatesCache[uri]
|
|
345
|
+
if (blockbook == null) continue
|
|
346
|
+
blockbook
|
|
347
|
+
.broadcastTx(transaction)
|
|
348
|
+
.then(response => {
|
|
349
|
+
if (!resolved) {
|
|
350
|
+
resolved = true
|
|
351
|
+
resolve(response.result)
|
|
352
|
+
}
|
|
353
|
+
})
|
|
354
|
+
.catch((e) => {
|
|
355
|
+
if (++bad === wsUris.length) {
|
|
356
|
+
const msg = e != null ? `With error ${e.message}` : ''
|
|
357
|
+
log.error(
|
|
358
|
+
`broadcastTx fail: ${JSON.stringify(transaction)}\n${msg}`
|
|
359
|
+
)
|
|
360
|
+
reject(e)
|
|
361
|
+
}
|
|
362
|
+
})
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Broadcast through any HTTP URI that may be configured, only if no
|
|
367
|
+
// blockbook instances are connected.
|
|
368
|
+
if (!isAnyBlockbookConnected) {
|
|
369
|
+
// This is for the future when we want to HTTP servers from the user
|
|
370
|
+
// settings:
|
|
371
|
+
// const httpUris = pluginState.getLocalServers(Infinity, [
|
|
372
|
+
// /^http(?:s)?:/i
|
|
373
|
+
// ])
|
|
374
|
+
|
|
375
|
+
const { nowNodeApiKey } = initOptions
|
|
376
|
+
const nowNodeUris = serverConfigs
|
|
377
|
+
.filter(config => config.type === 'blockbook-nownode')
|
|
378
|
+
.map(config => config.uris)
|
|
379
|
+
.flat(1)
|
|
380
|
+
|
|
381
|
+
// If there are no HTTP servers, reject the promise
|
|
382
|
+
if (nowNodeUris.length < 1) {
|
|
383
|
+
// If no HTTP servers are available, and we had no connected blockbook
|
|
384
|
+
// instances, reject the promise with a message indicating no
|
|
385
|
+
// available connections. It's clear we have some connection instances
|
|
386
|
+
// if we gotten to this point, but we just don't have any of those
|
|
387
|
+
// instances connected at this time.
|
|
388
|
+
reject(
|
|
389
|
+
new Error('No available connections. Check your internet signal.')
|
|
390
|
+
)
|
|
391
|
+
return
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// If there is no key for the NowNode servers:
|
|
395
|
+
if (nowNodeApiKey == null) {
|
|
396
|
+
reject(new Error('Missing connection key for fallback servers.'))
|
|
397
|
+
return
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
for (const uri of nowNodeUris) {
|
|
401
|
+
// HTTP Fallback
|
|
402
|
+
io.fetchCors(`${uri}/api/v2/sendtx/`, {
|
|
403
|
+
method: 'POST',
|
|
404
|
+
headers: {
|
|
405
|
+
'api-key': nowNodeApiKey
|
|
406
|
+
},
|
|
407
|
+
body: transaction.signedTx
|
|
338
408
|
})
|
|
409
|
+
.then(async response => {
|
|
410
|
+
if (!response.ok) {
|
|
411
|
+
throw new Error(
|
|
412
|
+
`Failed to broadcast transaction via Blockbook: HTTP ${response.status}`
|
|
413
|
+
)
|
|
414
|
+
}
|
|
415
|
+
const json = await response.json()
|
|
416
|
+
return _blockbookApi.asBlockbookResponse.call(void 0, (0, _blockbookApi.asBroadcastTxResponse))(json)
|
|
417
|
+
})
|
|
418
|
+
.then(response => {
|
|
419
|
+
if (!resolved) {
|
|
420
|
+
resolved = true
|
|
421
|
+
resolve(response.result)
|
|
422
|
+
}
|
|
423
|
+
})
|
|
424
|
+
.catch((e) => {
|
|
425
|
+
if (++bad === nowNodeUris.length) {
|
|
426
|
+
const msg = e != null ? `With error ${e.message}` : ''
|
|
427
|
+
log.error(
|
|
428
|
+
`broadcastTx fail: ${JSON.stringify(transaction)}\n${msg}`
|
|
429
|
+
)
|
|
430
|
+
reject(e)
|
|
431
|
+
}
|
|
432
|
+
})
|
|
433
|
+
}
|
|
339
434
|
}
|
|
340
435
|
})
|
|
341
436
|
}
|
|
@@ -21,15 +21,15 @@ var _edgecorejs = require('edge-core-js');
|
|
|
21
21
|
var _filterUndefined = require('../../../util/filterUndefined');
|
|
22
22
|
var _unixTime = require('../../../util/unixTime');
|
|
23
23
|
var _makeFees = require('../../fees/makeFees');
|
|
24
|
-
var
|
|
25
|
-
var
|
|
24
|
+
var _EngineEmitter = require('../../plugin/EngineEmitter');
|
|
25
|
+
var _Metadata = require('../../plugin/Metadata');
|
|
26
26
|
|
|
27
27
|
var _upgradeMemos = require('../../upgradeMemos');
|
|
28
|
-
var _makeProcessor = require('../db/makeProcessor');
|
|
29
28
|
|
|
30
29
|
|
|
31
30
|
|
|
32
31
|
var _ProcessorTransaction = require('../db/Models/ProcessorTransaction');
|
|
32
|
+
var _Processor = require('../db/Processor');
|
|
33
33
|
|
|
34
34
|
var _utxo = require('../db/util/utxo');
|
|
35
35
|
|
|
@@ -47,8 +47,6 @@ var _cleaners3 = require('../keymanager/cleaners');
|
|
|
47
47
|
var _keymanager = require('../keymanager/keymanager');
|
|
48
48
|
var _types5 = require('../keymanager/types');
|
|
49
49
|
var _utils = require('../keymanager/utxopicker/utils');
|
|
50
|
-
var _makeUtxoEngineState = require('./makeUtxoEngineState');
|
|
51
|
-
var _makeUtxoWalletTools = require('./makeUtxoWalletTools');
|
|
52
50
|
var _paymentRequest = require('./paymentRequest');
|
|
53
51
|
|
|
54
52
|
|
|
@@ -63,6 +61,8 @@ var _getOwnUtxosFromTx = require('./util/getOwnUtxosFromTx');
|
|
|
63
61
|
|
|
64
62
|
|
|
65
63
|
var _utils3 = require('./utils');
|
|
64
|
+
var _UtxoEngineState = require('./UtxoEngineState');
|
|
65
|
+
var _UtxoWalletTools = require('./UtxoWalletTools');
|
|
66
66
|
|
|
67
67
|
async function makeUtxoEngine(
|
|
68
68
|
config
|
|
@@ -111,7 +111,7 @@ var _utils3 = require('./utils');
|
|
|
111
111
|
throw new Error(message)
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
const walletTools =
|
|
114
|
+
const walletTools = _UtxoWalletTools.makeUtxoWalletTools.call(void 0, {
|
|
115
115
|
pluginInfo,
|
|
116
116
|
publicKey
|
|
117
117
|
})
|
|
@@ -123,15 +123,15 @@ var _utils3 = require('./utils');
|
|
|
123
123
|
log: config.options.log
|
|
124
124
|
})
|
|
125
125
|
|
|
126
|
-
const metadata = await
|
|
126
|
+
const metadata = await _Metadata.makeMetadata.call(void 0, {
|
|
127
127
|
disklet: walletLocalDisklet,
|
|
128
128
|
emitter,
|
|
129
129
|
log
|
|
130
130
|
})
|
|
131
|
-
const processor = await
|
|
131
|
+
const processor = await _Processor.makeProcessor.call(void 0, {
|
|
132
132
|
disklet: walletLocalDisklet
|
|
133
133
|
})
|
|
134
|
-
const engineState =
|
|
134
|
+
const engineState = _UtxoEngineState.makeUtxoEngineState.call(void 0, {
|
|
135
135
|
...config,
|
|
136
136
|
walletTools,
|
|
137
137
|
walletInfo,
|
|
@@ -144,8 +144,9 @@ var _utils3 = require('./utils');
|
|
|
144
144
|
const { canReplaceByFee = false } = currencyInfo
|
|
145
145
|
if (!canReplaceByFee) return null
|
|
146
146
|
|
|
147
|
-
// Accelerate for
|
|
148
|
-
if (privateKeyFormat === 'bip32'
|
|
147
|
+
// Accelerate for non-segwit wallets is not supported
|
|
148
|
+
if (privateKeyFormat === 'bip32' || privateKeyFormat === 'bip44')
|
|
149
|
+
return null
|
|
149
150
|
|
|
150
151
|
// Get the replaced transaction from the processor:
|
|
151
152
|
const replacedTxid = edgeTx.txid
|
|
@@ -350,7 +351,7 @@ var _utils3 = require('./utils');
|
|
|
350
351
|
|
|
351
352
|
async startEngine() {
|
|
352
353
|
emitter.emit(
|
|
353
|
-
|
|
354
|
+
_EngineEmitter.EngineEvent.WALLET_BALANCE_CHANGED,
|
|
354
355
|
currencyInfo.currencyCode,
|
|
355
356
|
metadata.state.balance
|
|
356
357
|
)
|
|
@@ -717,7 +718,7 @@ var _utils3 = require('./utils');
|
|
|
717
718
|
})
|
|
718
719
|
if (rbfTx != null) {
|
|
719
720
|
rbfTx.blockHeight = -1
|
|
720
|
-
await
|
|
721
|
+
await _UtxoEngineState.transactionChanged.call(void 0, {
|
|
721
722
|
walletId: walletInfo.id,
|
|
722
723
|
tx: rbfTx,
|
|
723
724
|
pluginInfo,
|
|
@@ -729,7 +730,7 @@ var _utils3 = require('./utils');
|
|
|
729
730
|
}
|
|
730
731
|
|
|
731
732
|
const tx = _ProcessorTransaction.fromEdgeTransaction.call(void 0, edgeTx)
|
|
732
|
-
await
|
|
733
|
+
await _UtxoEngineState.transactionChanged.call(void 0, {
|
|
733
734
|
walletId: walletInfo.id,
|
|
734
735
|
tx,
|
|
735
736
|
pluginInfo,
|
|
@@ -922,21 +923,21 @@ var _utils3 = require('./utils');
|
|
|
922
923
|
// Make temporary wallet disklet
|
|
923
924
|
const tmpDisklet = _disklet.makeMemoryDisklet.call(void 0, )
|
|
924
925
|
const tmpEncryptedDisklet = _disklet.makeMemoryDisklet.call(void 0, )
|
|
925
|
-
const tmpEmitter = new (0,
|
|
926
|
+
const tmpEmitter = new (0, _EngineEmitter.EngineEmitter)()
|
|
926
927
|
const tmpConfig = {
|
|
927
928
|
disklet: tmpDisklet,
|
|
928
929
|
emitter: tmpEmitter,
|
|
929
930
|
log
|
|
930
931
|
}
|
|
931
|
-
const tmpMetadata = await
|
|
932
|
-
const tmpProcessor = await
|
|
933
|
-
const tmpWalletTools =
|
|
932
|
+
const tmpMetadata = await _Metadata.makeMetadata.call(void 0, tmpConfig)
|
|
933
|
+
const tmpProcessor = await _Processor.makeProcessor.call(void 0, tmpConfig)
|
|
934
|
+
const tmpWalletTools = _UtxoWalletTools.makeUtxoWalletTools.call(void 0, {
|
|
934
935
|
pluginInfo,
|
|
935
936
|
publicKey: tmpWalletInfo.keys.publicKey
|
|
936
937
|
})
|
|
937
938
|
|
|
938
939
|
// Max spend after imported wallet finishes sync
|
|
939
|
-
tmpEmitter.on(
|
|
940
|
+
tmpEmitter.on(_EngineEmitter.EngineEvent.ADDRESSES_CHECKED, async (ratio) => {
|
|
940
941
|
if (ratio === 1) {
|
|
941
942
|
try {
|
|
942
943
|
await tmpState.stop()
|
|
@@ -965,7 +966,7 @@ var _utils3 = require('./utils');
|
|
|
965
966
|
}
|
|
966
967
|
})
|
|
967
968
|
|
|
968
|
-
const tmpState =
|
|
969
|
+
const tmpState = _UtxoEngineState.makeUtxoEngineState.call(void 0, {
|
|
969
970
|
...config,
|
|
970
971
|
options: {
|
|
971
972
|
...config.options,
|