edge-currency-plugins 1.0.0-rc.1 → 1.0.0-rc.4
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/common/plugin/makeCurrencyPlugin.js +3 -3
- package/lib/common/plugin/makeEngineEmitter.js +6 -0
- package/lib/common/plugin/pluginState.js +4 -4
- package/lib/common/plugin/types.js +0 -7
- package/lib/common/utxobased/db/Models/ProcessorTransaction.js +3 -17
- package/lib/common/utxobased/engine/makeServerStates.js +94 -70
- package/lib/common/utxobased/engine/makeUtxoEngine.js +17 -20
- package/lib/common/utxobased/engine/makeUtxoEngineState.js +122 -148
- package/lib/common/utxobased/info/bitcoinsv.js +39 -2
- package/lib/src/common/plugin/types.d.ts +2 -3
- package/lib/src/common/utxobased/db/Models/ProcessorTransaction.d.ts +3 -4
- package/lib/src/common/utxobased/engine/makeServerStates.d.ts +4 -2
- package/lib/src/common/utxobased/engine/makeUtxoEngineState.d.ts +9 -8
- package/package.json +2 -2
- package/lib/common/utxobased/engine/util/defaultValidateConfirmations.js +0 -19
- package/lib/src/common/utxobased/engine/util/defaultValidateConfirmations.d.ts +0 -3
|
@@ -22,7 +22,7 @@ var _pluginState = require('./pluginState');
|
|
|
22
22
|
const { io, log, pluginDisklet } = pluginOptions
|
|
23
23
|
const currencyTools = _makeCurrencyTools.makeCurrencyTools.call(void 0, io, pluginInfo)
|
|
24
24
|
const { defaultSettings, pluginId, currencyCode } = currencyInfo
|
|
25
|
-
const
|
|
25
|
+
const pluginState = _pluginState.makePluginState.call(void 0, {
|
|
26
26
|
io,
|
|
27
27
|
currencyCode,
|
|
28
28
|
pluginId,
|
|
@@ -49,7 +49,7 @@ var _pluginState = require('./pluginState');
|
|
|
49
49
|
...engineOptions,
|
|
50
50
|
emitter
|
|
51
51
|
},
|
|
52
|
-
pluginState
|
|
52
|
+
pluginState
|
|
53
53
|
}
|
|
54
54
|
const engine = await _makeUtxoEngine.makeUtxoEngine.call(void 0, engineConfig)
|
|
55
55
|
|
|
@@ -57,7 +57,7 @@ var _pluginState = require('./pluginState');
|
|
|
57
57
|
},
|
|
58
58
|
|
|
59
59
|
async makeCurrencyTools() {
|
|
60
|
-
|
|
60
|
+
pluginState.load().catch(e => {
|
|
61
61
|
throw e
|
|
62
62
|
})
|
|
63
63
|
return currencyTools
|
|
@@ -95,6 +95,12 @@ var EngineEvent; (function (EngineEvent) {
|
|
|
95
95
|
|
|
96
96
|
emitter.on(EngineEvent.TRANSACTIONS_CHANGED, callbacks.onTransactionsChanged)
|
|
97
97
|
emitter.on(EngineEvent.WALLET_BALANCE_CHANGED, callbacks.onBalanceChanged)
|
|
98
|
+
emitter.on(
|
|
99
|
+
EngineEvent.BLOCK_HEIGHT_CHANGED,
|
|
100
|
+
(_uri, height) => {
|
|
101
|
+
callbacks.onBlockHeightChanged(height)
|
|
102
|
+
}
|
|
103
|
+
)
|
|
98
104
|
emitter.on(EngineEvent.ADDRESSES_CHECKED, callbacks.onAddressesChecked)
|
|
99
105
|
emitter.on(EngineEvent.TXIDS_CHANGED, callbacks.onTxidsChanged)
|
|
100
106
|
|
|
@@ -227,10 +227,10 @@ const asServerListInfo = _cleaners.asObject.call(void 0, _cleaners.asEither.call
|
|
|
227
227
|
enableCustomServers = settings.enableCustomServers
|
|
228
228
|
customServers = settings.blockbookServers
|
|
229
229
|
|
|
230
|
-
const
|
|
230
|
+
const enginesToBeStarted = []
|
|
231
231
|
const disconnects = []
|
|
232
232
|
for (const engine of engines) {
|
|
233
|
-
|
|
233
|
+
enginesToBeStarted.push(engine)
|
|
234
234
|
engine.setServerList([])
|
|
235
235
|
disconnects.push(engine.stop())
|
|
236
236
|
}
|
|
@@ -245,8 +245,8 @@ const asServerListInfo = _cleaners.asObject.call(void 0, _cleaners.asEither.call
|
|
|
245
245
|
serverCacheDirty = true
|
|
246
246
|
await saveServerCache()
|
|
247
247
|
await refreshServers()
|
|
248
|
-
for (const engine of
|
|
249
|
-
await engine.
|
|
248
|
+
for (const engine of enginesToBeStarted) {
|
|
249
|
+
await engine.start()
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
}
|
|
@@ -17,7 +17,6 @@ var _cleaners = require('cleaners');
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
|
|
21
20
|
const asCurrencyFormat = _cleaners.asValue.call(void 0, 'bip32', 'bip44', 'bip49', 'bip84'); exports.asCurrencyFormat = asCurrencyFormat
|
|
22
21
|
|
|
23
22
|
// Path up to changeIndex
|
|
@@ -125,12 +124,6 @@ var _cleaners = require('cleaners');
|
|
|
125
124
|
|
|
126
125
|
|
|
127
126
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
127
|
|
|
135
128
|
|
|
136
129
|
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var _defaultValidateConfirmations = require('../../engine/util/defaultValidateConfirmations');
|
|
7
6
|
var _keymanager = require('../../keymanager/keymanager');
|
|
8
7
|
|
|
9
8
|
|
|
@@ -58,14 +57,10 @@ var _keymanager = require('../../keymanager/keymanager');
|
|
|
58
57
|
|
|
59
58
|
|
|
60
59
|
|
|
61
|
-
|
|
62
60
|
const toEdgeTransaction = async (
|
|
63
61
|
args
|
|
64
62
|
) => {
|
|
65
|
-
const { tx, processor,
|
|
66
|
-
const { currencyInfo, engineInfo } = pluginInfo
|
|
67
|
-
const { validateConfirmations = _defaultValidateConfirmations.defaultValidateConfirmations } = engineInfo
|
|
68
|
-
const { requiredConfirmations } = currencyInfo
|
|
63
|
+
const { tx, processor, walletTools, engineInfo } = args
|
|
69
64
|
|
|
70
65
|
const ourReceiveAddresses = []
|
|
71
66
|
for (const out of tx.ourOuts) {
|
|
@@ -73,7 +68,7 @@ var _keymanager = require('../../keymanager/keymanager');
|
|
|
73
68
|
const address = await processor.fetchAddress(scriptPubkey)
|
|
74
69
|
|
|
75
70
|
/*
|
|
76
|
-
Hack to set replay protection tx to the correct script type through the
|
|
71
|
+
Hack to set replay protection tx to the correct script type through the
|
|
77
72
|
address format.
|
|
78
73
|
|
|
79
74
|
We use a function which can determine whether the derivationLevelScriptHash
|
|
@@ -100,16 +95,9 @@ var _keymanager = require('../../keymanager/keymanager');
|
|
|
100
95
|
}
|
|
101
96
|
}
|
|
102
97
|
|
|
103
|
-
|
|
104
|
-
tx,
|
|
105
|
-
walletBlockHeight,
|
|
106
|
-
requiredConfirmations
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
const edgeTx = {
|
|
98
|
+
return {
|
|
110
99
|
currencyCode: args.currencyCode,
|
|
111
100
|
txid: args.tx.txid,
|
|
112
|
-
confirmations,
|
|
113
101
|
blockHeight: args.tx.blockHeight,
|
|
114
102
|
date: args.tx.date,
|
|
115
103
|
nativeAmount: args.tx.ourAmount,
|
|
@@ -117,6 +105,4 @@ var _keymanager = require('../../keymanager/keymanager');
|
|
|
117
105
|
signedTx: args.tx.hex,
|
|
118
106
|
ourReceiveAddresses
|
|
119
107
|
}
|
|
120
|
-
|
|
121
|
-
return edgeTx
|
|
122
108
|
}; exports.toEdgeTransaction = toEdgeTransaction
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function
|
|
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
4
|
var _makeEngineEmitter = require('../../plugin/makeEngineEmitter');
|
|
@@ -54,8 +54,6 @@ var _constants = require('./constants');
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
57
|
|
|
60
58
|
|
|
61
59
|
|
|
@@ -63,9 +61,8 @@ var _constants = require('./constants');
|
|
|
63
61
|
const { engineEmitter, log, pluginInfo, pluginState, walletInfo } = config
|
|
64
62
|
log('Making server states')
|
|
65
63
|
|
|
66
|
-
|
|
64
|
+
const serverStatesCache = {}
|
|
67
65
|
let isEngineOn = true
|
|
68
|
-
let connections = {}
|
|
69
66
|
let serverList = []
|
|
70
67
|
let reconnectCounter = 0
|
|
71
68
|
let reconnectTimer = setTimeout(() => {
|
|
@@ -81,8 +78,7 @@ var _constants = require('./constants');
|
|
|
81
78
|
socketEmitter.on(
|
|
82
79
|
_MakeSocketEmitter.SocketEvent.CONNECTION_CLOSE,
|
|
83
80
|
(uri, error) => {
|
|
84
|
-
_utils.removeItem.call(void 0,
|
|
85
|
-
_utils.removeItem.call(void 0, serverStates, uri)
|
|
81
|
+
_utils.removeItem.call(void 0, serverStatesCache, uri)
|
|
86
82
|
|
|
87
83
|
const msg =
|
|
88
84
|
error != null ? ` !! Connection ERROR !! ${error.message}` : ''
|
|
@@ -107,7 +103,7 @@ var _constants = require('./constants');
|
|
|
107
103
|
log(
|
|
108
104
|
`${uri} received received new transaction with id ${newTx.tx.txid} to address ${newTx.address}`
|
|
109
105
|
)
|
|
110
|
-
const serverState =
|
|
106
|
+
const serverState = serverStatesCache[uri]
|
|
111
107
|
if (serverState != null) {
|
|
112
108
|
serverState.txids.add(newTx.tx.txid)
|
|
113
109
|
}
|
|
@@ -117,7 +113,7 @@ var _constants = require('./constants');
|
|
|
117
113
|
_makeEngineEmitter.EngineEvent.BLOCK_HEIGHT_CHANGED,
|
|
118
114
|
(uri, blockHeight) => {
|
|
119
115
|
log(`${uri} block height changed to ${blockHeight}`)
|
|
120
|
-
|
|
116
|
+
serverStatesCache[uri].blockHeight = blockHeight
|
|
121
117
|
}
|
|
122
118
|
)
|
|
123
119
|
|
|
@@ -126,7 +122,8 @@ var _constants = require('./constants');
|
|
|
126
122
|
|
|
127
123
|
|
|
128
124
|
|
|
129
|
-
const
|
|
125
|
+
const makeServerStatesCacheEntry = (blockbook) => ({
|
|
126
|
+
blockbook,
|
|
130
127
|
blockSubscriptionStatus: 'unsubscribed',
|
|
131
128
|
txids: new Set(),
|
|
132
129
|
addresses: new Set(),
|
|
@@ -144,13 +141,13 @@ var _constants = require('./constants');
|
|
|
144
141
|
log(`stopping server states`)
|
|
145
142
|
_socketQueue.removeIdFromQueue.call(void 0, walletInfo.id)
|
|
146
143
|
clearTimeout(reconnectTimer)
|
|
147
|
-
for (const uri of Object.keys(
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
144
|
+
for (const uri of Object.keys(serverStatesCache)) {
|
|
145
|
+
const serverState = serverStatesCache[uri]
|
|
146
|
+
const { blockbook } = serverState
|
|
147
|
+
if (blockbook == null) continue
|
|
148
|
+
await blockbook.disconnect()
|
|
149
|
+
_utils.removeItem.call(void 0, serverStatesCache, uri)
|
|
151
150
|
}
|
|
152
|
-
connections = {}
|
|
153
|
-
serverStates = {}
|
|
154
151
|
}
|
|
155
152
|
|
|
156
153
|
const reconnect = () => {
|
|
@@ -166,6 +163,7 @@ var _constants = require('./constants');
|
|
|
166
163
|
|
|
167
164
|
const refillServers = () => {
|
|
168
165
|
log(`refilling servers...`)
|
|
166
|
+
isEngineOn = true
|
|
169
167
|
_socketQueue.pushUpdate.call(void 0, {
|
|
170
168
|
id: walletInfo.id,
|
|
171
169
|
updateFunc: () => {
|
|
@@ -181,16 +179,17 @@ var _constants = require('./constants');
|
|
|
181
179
|
}
|
|
182
180
|
log(`refillServers: Top ${_constants.NEW_CONNECTIONS} servers:`, serverList)
|
|
183
181
|
let chanceToBePicked = 1.25
|
|
184
|
-
while (Object.keys(
|
|
182
|
+
while (Object.keys(serverStatesCache).length < _constants.MAX_CONNECTIONS) {
|
|
185
183
|
if (serverList.length === 0) break
|
|
186
184
|
const uri = serverList.shift()
|
|
187
185
|
if (uri == null) {
|
|
188
186
|
reconnect()
|
|
189
187
|
break
|
|
190
188
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
189
|
+
|
|
190
|
+
// Skip reconnecting to an existing connection
|
|
191
|
+
if (serverStatesCache[uri] != null) continue
|
|
192
|
+
|
|
194
193
|
// Validate the URI of server to make sure it is valid
|
|
195
194
|
const parsed = _urijs.parse.call(void 0, uri)
|
|
196
195
|
if (
|
|
@@ -200,56 +199,54 @@ var _constants = require('./constants');
|
|
|
200
199
|
) {
|
|
201
200
|
continue
|
|
202
201
|
}
|
|
202
|
+
|
|
203
|
+
// Ranomize the URI picking
|
|
203
204
|
chanceToBePicked -= chanceToBePicked > 0.5 ? 0.25 : 0
|
|
204
205
|
if (Math.random() > chanceToBePicked) {
|
|
205
206
|
serverList.push(uri)
|
|
206
207
|
continue
|
|
207
208
|
}
|
|
208
209
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const onQueueSpaceCB = async (
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
) => {
|
|
215
|
-
const blockBook = connections[uri]
|
|
216
|
-
if (blockBook == null) {
|
|
217
|
-
return
|
|
218
|
-
}
|
|
219
|
-
const task = await pickNextTaskCB(uri)
|
|
220
|
-
if (task != null && typeof task !== 'boolean') {
|
|
221
|
-
const taskMessage = `${task.method} params: ${JSON.stringify(
|
|
222
|
-
task.params
|
|
223
|
-
)}`
|
|
224
|
-
log(`${uri} nextTask: ${taskMessage}`)
|
|
225
|
-
}
|
|
226
|
-
return task
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
connections[uri] = _BlockBook.makeBlockBook.call(void 0, {
|
|
210
|
+
// Make new Blockbook instance
|
|
211
|
+
const blockbook = _BlockBook.makeBlockBook.call(void 0, {
|
|
230
212
|
wsAddress: uri,
|
|
231
213
|
socketEmitter,
|
|
232
214
|
engineEmitter,
|
|
233
215
|
log,
|
|
234
|
-
onQueueSpaceCB
|
|
216
|
+
onQueueSpaceCB: async (
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
) => {
|
|
220
|
+
// Exit if the connection is no longer active
|
|
221
|
+
if (!(uri in serverStatesCache)) return
|
|
222
|
+
|
|
223
|
+
const task = await pickNextTaskCB(uri)
|
|
224
|
+
if (task != null && typeof task !== 'boolean') {
|
|
225
|
+
const taskMessage = `${task.method} params: ${JSON.stringify(
|
|
226
|
+
task.params
|
|
227
|
+
)}`
|
|
228
|
+
log(`${uri} nextTask: ${taskMessage}`)
|
|
229
|
+
}
|
|
230
|
+
return task
|
|
231
|
+
},
|
|
235
232
|
walletId: walletInfo.id,
|
|
236
233
|
asAddress: pluginInfo.engineInfo.asBlockbookAddress
|
|
237
234
|
})
|
|
238
235
|
|
|
239
|
-
|
|
240
|
-
|
|
236
|
+
// Make new ServerStates instance
|
|
237
|
+
serverStatesCache[uri] = makeServerStatesCacheEntry(blockbook)
|
|
241
238
|
|
|
242
239
|
// Initialize blockbook connection for server
|
|
243
|
-
|
|
240
|
+
blockbook
|
|
244
241
|
.connect()
|
|
245
242
|
.then(async () => {
|
|
246
243
|
// Fetch block height from blockbook server
|
|
247
244
|
const startTime = Date.now()
|
|
248
|
-
const { bestHeight: blockHeight } = await
|
|
245
|
+
const { bestHeight: blockHeight } = await blockbook.fetchInfo()
|
|
249
246
|
log('height:', blockHeight)
|
|
250
247
|
|
|
251
248
|
// Update server state
|
|
252
|
-
|
|
249
|
+
serverStatesCache[uri].blockHeight = blockHeight
|
|
253
250
|
|
|
254
251
|
// Emit initial BLOCK_HEIGHT_CHANGED event
|
|
255
252
|
engineEmitter.emit(_makeEngineEmitter.EngineEvent.BLOCK_HEIGHT_CHANGED, uri, blockHeight)
|
|
@@ -265,33 +262,36 @@ var _constants = require('./constants');
|
|
|
265
262
|
}
|
|
266
263
|
|
|
267
264
|
const serverCanGetTx = (uri, txid) => {
|
|
268
|
-
const serverState =
|
|
265
|
+
const serverState = serverStatesCache[uri]
|
|
269
266
|
if (serverState == null) return false
|
|
270
267
|
if (serverState.txids.has(txid)) return true
|
|
271
268
|
|
|
272
|
-
for (const state of Object.values(
|
|
269
|
+
for (const state of Object.values(serverStatesCache)) {
|
|
273
270
|
if (state.txids.has(txid)) return false
|
|
274
271
|
}
|
|
275
272
|
return true
|
|
276
273
|
}
|
|
277
274
|
|
|
278
275
|
const serverCanGetAddress = (uri, address) => {
|
|
279
|
-
const serverState =
|
|
276
|
+
const serverState = serverStatesCache[uri]
|
|
280
277
|
if (serverState == null) return false
|
|
281
278
|
if (serverState.addresses.has(address)) return true
|
|
282
279
|
|
|
283
|
-
for (const state of Object.values(
|
|
280
|
+
for (const state of Object.values(serverStatesCache)) {
|
|
284
281
|
if (state.addresses.has(address)) return false
|
|
285
282
|
}
|
|
286
283
|
return true
|
|
287
284
|
}
|
|
288
285
|
|
|
289
|
-
const
|
|
290
|
-
|
|
286
|
+
const serverIsAwareOfAddress = (uri, address) => {
|
|
287
|
+
const serverState = serverStatesCache[uri]
|
|
288
|
+
if (serverState == null) return false
|
|
289
|
+
if (serverState.addresses.has(address)) return true
|
|
290
|
+
return false
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
const getServerState = (uri) => {
|
|
294
|
-
return
|
|
294
|
+
return serverStatesCache[uri]
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
const getServerList = () => {
|
|
@@ -304,10 +304,10 @@ var _constants = require('./constants');
|
|
|
304
304
|
|
|
305
305
|
const broadcastTx = async (transaction) => {
|
|
306
306
|
return await new Promise((resolve, reject) => {
|
|
307
|
-
const uris = Object.keys(
|
|
308
|
-
const
|
|
309
|
-
if (
|
|
310
|
-
return
|
|
307
|
+
const uris = Object.keys(serverStatesCache).filter(uri => {
|
|
308
|
+
const { blockbook } = serverStatesCache[uri]
|
|
309
|
+
if (blockbook == null) return false
|
|
310
|
+
return blockbook.isConnected
|
|
311
311
|
})
|
|
312
312
|
if (uris == null || uris.length < 1) {
|
|
313
313
|
reject(
|
|
@@ -317,9 +317,9 @@ var _constants = require('./constants');
|
|
|
317
317
|
let resolved = false
|
|
318
318
|
let bad = 0
|
|
319
319
|
for (const uri of uris) {
|
|
320
|
-
const
|
|
321
|
-
if (
|
|
322
|
-
|
|
320
|
+
const { blockbook } = serverStatesCache[uri]
|
|
321
|
+
if (blockbook == null) continue
|
|
322
|
+
blockbook
|
|
323
323
|
.broadcastTx(transaction)
|
|
324
324
|
.then(response => {
|
|
325
325
|
if (!resolved) {
|
|
@@ -345,18 +345,42 @@ var _constants = require('./constants');
|
|
|
345
345
|
addresses,
|
|
346
346
|
deferredAddressSub
|
|
347
347
|
) => {
|
|
348
|
-
const
|
|
349
|
-
if (
|
|
348
|
+
const serverState = serverStatesCache[uri]
|
|
349
|
+
if (serverState == null)
|
|
350
350
|
throw new Error(`No blockbook connection with ${uri}`)
|
|
351
|
-
|
|
351
|
+
|
|
352
|
+
const { blockbook } = serverState
|
|
353
|
+
|
|
354
|
+
// Add new addresses to the set of known addresses
|
|
355
|
+
for (const address of addresses) {
|
|
356
|
+
serverState.addresses.add(address)
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const queryTime = Date.now()
|
|
360
|
+
const deferred = new _Deferred2.default()
|
|
361
|
+
deferred.promise
|
|
362
|
+
.then((value) => {
|
|
363
|
+
pluginState.serverScoreUp(uri, Date.now() - queryTime)
|
|
364
|
+
_optionalChain([deferredAddressSub, 'optionalAccess', _ => _.resolve, 'call', _2 => _2(value)])
|
|
365
|
+
})
|
|
366
|
+
.catch(() => {
|
|
367
|
+
// Remove new addresses to the set of known addresses
|
|
368
|
+
for (const address of addresses) {
|
|
369
|
+
serverState.addresses.delete(address)
|
|
370
|
+
}
|
|
371
|
+
pluginState.serverScoreDown(uri)
|
|
372
|
+
_optionalChain([deferredAddressSub, 'optionalAccess', _3 => _3.reject, 'call', _4 => _4()])
|
|
373
|
+
})
|
|
374
|
+
blockbook.watchAddresses(Array.from(addresses), deferred)
|
|
352
375
|
}
|
|
353
376
|
|
|
354
377
|
const watchBlocks = (uri) => {
|
|
355
|
-
const
|
|
356
|
-
if (
|
|
378
|
+
const serverState = serverStatesCache[uri]
|
|
379
|
+
if (serverState == null)
|
|
357
380
|
throw new Error(`No blockbook connection with ${uri}`)
|
|
358
381
|
|
|
359
|
-
const
|
|
382
|
+
const { blockbook } = serverState
|
|
383
|
+
|
|
360
384
|
serverState.blockSubscriptionStatus = 'subscribing'
|
|
361
385
|
|
|
362
386
|
const queryTime = Date.now()
|
|
@@ -364,7 +388,7 @@ var _constants = require('./constants');
|
|
|
364
388
|
deferred.promise
|
|
365
389
|
.then(() => {
|
|
366
390
|
serverState.blockSubscriptionStatus = 'subscribed'
|
|
367
|
-
serverScoreUp(uri, Date.now() - queryTime)
|
|
391
|
+
pluginState.serverScoreUp(uri, Date.now() - queryTime)
|
|
368
392
|
})
|
|
369
393
|
.catch(() => {
|
|
370
394
|
serverState.blockSubscriptionStatus = 'unsubscribed'
|
|
@@ -373,7 +397,7 @@ var _constants = require('./constants');
|
|
|
373
397
|
}
|
|
374
398
|
|
|
375
399
|
const getBlockHeight = (uri) => {
|
|
376
|
-
return
|
|
400
|
+
return serverStatesCache[uri].blockHeight
|
|
377
401
|
}
|
|
378
402
|
|
|
379
403
|
return {
|
|
@@ -381,7 +405,7 @@ var _constants = require('./constants');
|
|
|
381
405
|
stop,
|
|
382
406
|
serverCanGetTx,
|
|
383
407
|
serverCanGetAddress,
|
|
384
|
-
|
|
408
|
+
serverIsAwareOfAddress,
|
|
385
409
|
getServerState,
|
|
386
410
|
refillServers,
|
|
387
411
|
getServerList,
|
|
@@ -104,7 +104,7 @@ var _utils = require('./utils');
|
|
|
104
104
|
const processor = await _makeProcessor.makeProcessor.call(void 0, {
|
|
105
105
|
disklet: walletLocalDisklet
|
|
106
106
|
})
|
|
107
|
-
const
|
|
107
|
+
const engineState = _makeUtxoEngineState.makeUtxoEngineState.call(void 0, {
|
|
108
108
|
...config,
|
|
109
109
|
walletTools,
|
|
110
110
|
walletInfo,
|
|
@@ -120,15 +120,15 @@ var _utils = require('./utils');
|
|
|
120
120
|
metadata.balance
|
|
121
121
|
)
|
|
122
122
|
|
|
123
|
-
pluginState.addEngine(
|
|
123
|
+
pluginState.addEngine(engineState)
|
|
124
124
|
await fees.start()
|
|
125
|
-
await
|
|
125
|
+
await engineState.start()
|
|
126
126
|
},
|
|
127
127
|
|
|
128
128
|
async killEngine() {
|
|
129
|
-
await
|
|
129
|
+
await engineState.stop()
|
|
130
130
|
fees.stop()
|
|
131
|
-
pluginState.removeEngine(
|
|
131
|
+
pluginState.removeEngine(engineState)
|
|
132
132
|
},
|
|
133
133
|
|
|
134
134
|
getBalance(_opts) {
|
|
@@ -144,7 +144,7 @@ var _utils = require('./utils');
|
|
|
144
144
|
},
|
|
145
145
|
|
|
146
146
|
async addGapLimitAddresses(addresses) {
|
|
147
|
-
return await
|
|
147
|
+
return await engineState.addGapLimitAddresses(addresses)
|
|
148
148
|
},
|
|
149
149
|
|
|
150
150
|
async broadcastTx(transaction) {
|
|
@@ -164,7 +164,7 @@ var _utils = require('./utils');
|
|
|
164
164
|
)
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
const id = await
|
|
167
|
+
const id = await engineState.broadcastTx(transaction)
|
|
168
168
|
if (id !== transaction.txid) {
|
|
169
169
|
throw new Error('broadcast response txid does not match original')
|
|
170
170
|
}
|
|
@@ -221,7 +221,7 @@ var _utils = require('./utils');
|
|
|
221
221
|
async getFreshAddress(
|
|
222
222
|
_opts
|
|
223
223
|
) {
|
|
224
|
-
return await
|
|
224
|
+
return await engineState.getFreshAddress()
|
|
225
225
|
},
|
|
226
226
|
|
|
227
227
|
getNumTransactions(_opts) {
|
|
@@ -254,10 +254,9 @@ var _utils = require('./utils');
|
|
|
254
254
|
await _ProcessorTransaction.toEdgeTransaction.call(void 0, {
|
|
255
255
|
tx,
|
|
256
256
|
currencyCode: currencyInfo.currencyCode,
|
|
257
|
-
|
|
257
|
+
walletTools,
|
|
258
258
|
processor,
|
|
259
|
-
|
|
260
|
-
walletTools
|
|
259
|
+
engineInfo
|
|
261
260
|
})
|
|
262
261
|
)
|
|
263
262
|
)
|
|
@@ -303,7 +302,7 @@ var _utils = require('./utils');
|
|
|
303
302
|
const { script } = target.otherParams
|
|
304
303
|
if (script.type === 'replayProtection') {
|
|
305
304
|
// construct a replay protection p2sh address
|
|
306
|
-
const { publicAddress } = await
|
|
305
|
+
const { publicAddress } = await engineState.deriveScriptAddress(
|
|
307
306
|
script.type
|
|
308
307
|
)
|
|
309
308
|
targets.push({
|
|
@@ -329,7 +328,7 @@ var _utils = require('./utils');
|
|
|
329
328
|
throw new Error('Need to provide Spend Targets')
|
|
330
329
|
}
|
|
331
330
|
|
|
332
|
-
const freshAddress = await
|
|
331
|
+
const freshAddress = await engineState.getFreshAddress(1)
|
|
333
332
|
const freshChangeAddress =
|
|
334
333
|
_nullishCoalesce(freshAddress.segwitAddress, () => ( freshAddress.publicAddress))
|
|
335
334
|
const setRBF = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.setRBF]), () => ( false))
|
|
@@ -421,7 +420,6 @@ var _utils = require('./utils');
|
|
|
421
420
|
currencyCode: currencyInfo.currencyCode,
|
|
422
421
|
txid: '',
|
|
423
422
|
date: _unixTime.unixTime.call(void 0, ),
|
|
424
|
-
confirmations: 'unconfirmed',
|
|
425
423
|
blockHeight: 0,
|
|
426
424
|
nativeAmount,
|
|
427
425
|
networkFee,
|
|
@@ -454,12 +452,11 @@ var _utils = require('./utils');
|
|
|
454
452
|
async saveTx(edgeTx) {
|
|
455
453
|
const tx = _ProcessorTransaction.fromEdgeTransaction.call(void 0, edgeTx)
|
|
456
454
|
await _makeUtxoEngineState.transactionChanged.call(void 0, {
|
|
457
|
-
emitter,
|
|
458
|
-
pluginInfo,
|
|
459
|
-
processor,
|
|
460
455
|
tx,
|
|
461
|
-
|
|
462
|
-
|
|
456
|
+
pluginInfo,
|
|
457
|
+
emitter,
|
|
458
|
+
walletTools,
|
|
459
|
+
processor
|
|
463
460
|
})
|
|
464
461
|
await processor.saveTransaction({
|
|
465
462
|
tx,
|
|
@@ -470,7 +467,7 @@ var _utils = require('./utils');
|
|
|
470
467
|
Get the wallet's UTXOs from the new transaction and save them to the processsor.
|
|
471
468
|
*/
|
|
472
469
|
const utxos = await _getOwnUtxosFromTx.getOwnUtxosFromTx.call(void 0, engineInfo, processor, tx)
|
|
473
|
-
await
|
|
470
|
+
await engineState.processUtxos(utxos)
|
|
474
471
|
},
|
|
475
472
|
|
|
476
473
|
async signTx(transaction) {
|