edge-currency-plugins 1.0.0-rc.1 → 1.0.0-rc.2
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 +6 -9
- package/lib/common/utxobased/engine/makeUtxoEngineState.js +99 -144
- 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 +8 -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,
|
|
@@ -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
|
)
|
|
@@ -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,
|
|
@@ -15,6 +15,7 @@ var _makeEngineEmitter = require('../../plugin/makeEngineEmitter');
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
|
|
18
19
|
var _utils = require('../../plugin/utils');
|
|
19
20
|
|
|
20
21
|
var _ProcessorTransaction = require('../db/Models/ProcessorTransaction');
|
|
@@ -99,7 +100,6 @@ var _utils3 = require('./utils');
|
|
|
99
100
|
const { walletFormats } = walletInfo.keys
|
|
100
101
|
|
|
101
102
|
const taskCache = {
|
|
102
|
-
addressWatching: false,
|
|
103
103
|
blockWatching: false,
|
|
104
104
|
addressSubscribeCache: {},
|
|
105
105
|
addressTransactionCache: {},
|
|
@@ -110,14 +110,25 @@ var _utils3 = require('./utils');
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
const clearTaskCache = () => {
|
|
113
|
-
taskCache.addressWatching = false
|
|
114
113
|
taskCache.blockWatching = false
|
|
115
|
-
taskCache.addressSubscribeCache
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
taskCache.
|
|
119
|
-
|
|
120
|
-
|
|
114
|
+
for (const key of Object.keys(taskCache.addressSubscribeCache)) {
|
|
115
|
+
_utils.removeItem.call(void 0, taskCache.addressSubscribeCache, key)
|
|
116
|
+
}
|
|
117
|
+
for (const key of Object.keys(taskCache.addressTransactionCache)) {
|
|
118
|
+
_utils.removeItem.call(void 0, taskCache.addressTransactionCache, key)
|
|
119
|
+
}
|
|
120
|
+
for (const key of Object.keys(taskCache.addressUtxoCache)) {
|
|
121
|
+
_utils.removeItem.call(void 0, taskCache.addressUtxoCache, key)
|
|
122
|
+
}
|
|
123
|
+
for (const key of Object.keys(taskCache.rawUtxoCache)) {
|
|
124
|
+
_utils.removeItem.call(void 0, taskCache.rawUtxoCache, key)
|
|
125
|
+
}
|
|
126
|
+
for (const key of Object.keys(taskCache.processorUtxoCache)) {
|
|
127
|
+
_utils.removeItem.call(void 0, taskCache.processorUtxoCache, key)
|
|
128
|
+
}
|
|
129
|
+
for (const key of Object.keys(taskCache.updateTransactionCache)) {
|
|
130
|
+
_utils.removeItem.call(void 0, taskCache.updateTransactionCache, key)
|
|
131
|
+
}
|
|
121
132
|
}
|
|
122
133
|
|
|
123
134
|
/**
|
|
@@ -170,11 +181,10 @@ var _utils3 = require('./utils');
|
|
|
170
181
|
io: config.io,
|
|
171
182
|
log,
|
|
172
183
|
serverStates,
|
|
184
|
+
pluginState,
|
|
173
185
|
walletFormats,
|
|
174
186
|
lock
|
|
175
187
|
}
|
|
176
|
-
const { currencyInfo } = pluginInfo
|
|
177
|
-
const { requiredConfirmations = 1 } = currencyInfo
|
|
178
188
|
|
|
179
189
|
const pickNextTaskCB = async (
|
|
180
190
|
uri
|
|
@@ -196,32 +206,14 @@ var _utils3 = require('./utils');
|
|
|
196
206
|
|
|
197
207
|
emitter.on(
|
|
198
208
|
_makeEngineEmitter.EngineEvent.BLOCK_HEIGHT_CHANGED,
|
|
199
|
-
async (_uri,
|
|
200
|
-
|
|
201
|
-
const unconfirmedTxs = await processor.fetchTransactions({
|
|
209
|
+
async (_uri, _blockHeight) => {
|
|
210
|
+
const txs = await processor.fetchTransactions({
|
|
202
211
|
blockHeight: 0
|
|
203
212
|
})
|
|
204
|
-
for (const tx of
|
|
213
|
+
for (const tx of txs) {
|
|
205
214
|
if (tx == null) continue
|
|
206
215
|
taskCache.updateTransactionCache[tx.txid] = { processing: false }
|
|
207
216
|
}
|
|
208
|
-
|
|
209
|
-
// Trigger transactions change event to update its confirmation status
|
|
210
|
-
const pendingTxs = await processor.fetchTransactions({
|
|
211
|
-
blockHeight: walletBlockHeight - requiredConfirmations,
|
|
212
|
-
blockHeightMax: walletBlockHeight
|
|
213
|
-
})
|
|
214
|
-
for (const tx of pendingTxs) {
|
|
215
|
-
if (tx == null) continue
|
|
216
|
-
await exports.transactionChanged.call(void 0, {
|
|
217
|
-
emitter,
|
|
218
|
-
processor,
|
|
219
|
-
pluginInfo,
|
|
220
|
-
tx,
|
|
221
|
-
walletBlockHeight,
|
|
222
|
-
walletTools
|
|
223
|
-
})
|
|
224
|
-
}
|
|
225
217
|
}
|
|
226
218
|
)
|
|
227
219
|
|
|
@@ -448,7 +440,6 @@ var _utils3 = require('./utils');
|
|
|
448
440
|
}
|
|
449
441
|
}
|
|
450
442
|
}
|
|
451
|
-
taskCache.addressWatching = false
|
|
452
443
|
}
|
|
453
444
|
}
|
|
454
445
|
} exports.makeUtxoEngineState = makeUtxoEngineState;
|
|
@@ -592,7 +583,6 @@ const addToAddressSubscribeCache = (
|
|
|
592
583
|
path,
|
|
593
584
|
processing: false
|
|
594
585
|
}
|
|
595
|
-
taskCache.addressWatching = false
|
|
596
586
|
})
|
|
597
587
|
}
|
|
598
588
|
|
|
@@ -633,28 +623,23 @@ const addToAddressTransactionCache = async (
|
|
|
633
623
|
|
|
634
624
|
|
|
635
625
|
|
|
636
|
-
|
|
637
626
|
const transactionChanged = async (
|
|
638
627
|
args
|
|
639
628
|
) => {
|
|
640
629
|
const {
|
|
641
630
|
emitter,
|
|
642
|
-
walletBlockHeight,
|
|
643
631
|
walletTools,
|
|
644
632
|
processor,
|
|
645
|
-
pluginInfo,
|
|
633
|
+
pluginInfo: { currencyInfo, engineInfo },
|
|
646
634
|
tx
|
|
647
635
|
} = args
|
|
648
|
-
const { currencyInfo } = pluginInfo
|
|
649
|
-
|
|
650
636
|
emitter.emit(_makeEngineEmitter.EngineEvent.TRANSACTIONS_CHANGED, [
|
|
651
637
|
await _ProcessorTransaction.toEdgeTransaction.call(void 0, {
|
|
652
638
|
tx,
|
|
653
639
|
currencyCode: currencyInfo.currencyCode,
|
|
654
|
-
|
|
640
|
+
walletTools,
|
|
655
641
|
processor,
|
|
656
|
-
|
|
657
|
-
walletTools
|
|
642
|
+
engineInfo
|
|
658
643
|
})
|
|
659
644
|
])
|
|
660
645
|
}; exports.transactionChanged = transactionChanged
|
|
@@ -705,8 +690,6 @@ const addToAddressTransactionCache = async (
|
|
|
705
690
|
}
|
|
706
691
|
}
|
|
707
692
|
|
|
708
|
-
const blockHeight = serverStates.getBlockHeight(uri)
|
|
709
|
-
|
|
710
693
|
// Loop unparsed utxos, some require a network call to get the full tx data
|
|
711
694
|
for (const [utxoString, state] of Object.entries(rawUtxoCache)) {
|
|
712
695
|
const utxo = JSON.parse(utxoString)
|
|
@@ -726,6 +709,7 @@ const addToAddressTransactionCache = async (
|
|
|
726
709
|
const wsTask = await processRawUtxo({
|
|
727
710
|
...args,
|
|
728
711
|
...state,
|
|
712
|
+
address: state.address,
|
|
729
713
|
utxo,
|
|
730
714
|
id: `${utxo.txid}_${utxo.vout}`
|
|
731
715
|
})
|
|
@@ -751,62 +735,52 @@ const addToAddressTransactionCache = async (
|
|
|
751
735
|
.then(() => {
|
|
752
736
|
serverState.addresses.add(address)
|
|
753
737
|
})
|
|
754
|
-
.catch(
|
|
755
|
-
|
|
738
|
+
.catch(err => {
|
|
739
|
+
addressUtxoCache[address] = state
|
|
740
|
+
console.error(err)
|
|
741
|
+
args.log('error in addressUtxoCache:', err)
|
|
756
742
|
})
|
|
757
743
|
return wsTask
|
|
758
744
|
}
|
|
759
745
|
}
|
|
760
746
|
|
|
761
747
|
// Check if there are any addresses pending to be subscribed
|
|
762
|
-
if (
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
748
|
+
if (Object.keys(addressSubscribeCache).length > 0) {
|
|
749
|
+
// These are addresse to which the server has not subscribed
|
|
750
|
+
const newAddress = []
|
|
751
|
+
const blockHeight = serverStates.getBlockHeight(uri)
|
|
752
|
+
|
|
753
|
+
// Loop each address in the cache
|
|
767
754
|
for (const [address, state] of Object.entries(addressSubscribeCache)) {
|
|
768
755
|
// Add address in the cache to the set of addresses to watch
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
address,
|
|
781
|
-
path.format,
|
|
782
|
-
path.changeIndex,
|
|
783
|
-
blockHeight,
|
|
784
|
-
addressTransactionCache
|
|
785
|
-
)
|
|
756
|
+
if (!serverStates.serverIsAwareOfAddress(uri, address)) {
|
|
757
|
+
newAddress.push(address)
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// Add to the addressTransactionCache if they're not yet added:
|
|
761
|
+
// Only process newly watched addresses
|
|
762
|
+
if (state.processing) continue
|
|
763
|
+
// Add the newly watched addresses to the UTXO cache
|
|
764
|
+
addressUtxoCache[address] = {
|
|
765
|
+
processing: false,
|
|
766
|
+
path: state.path
|
|
786
767
|
}
|
|
768
|
+
await addToAddressTransactionCache(
|
|
769
|
+
args,
|
|
770
|
+
address,
|
|
771
|
+
state.path.format,
|
|
772
|
+
state.path.changeIndex,
|
|
773
|
+
blockHeight,
|
|
774
|
+
addressTransactionCache
|
|
775
|
+
)
|
|
787
776
|
state.processing = true
|
|
788
777
|
}
|
|
789
778
|
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
.then(() => {
|
|
796
|
-
serverStates.serverScoreUp(uri, Date.now() - queryTime)
|
|
797
|
-
})
|
|
798
|
-
.catch(() => {
|
|
799
|
-
taskCache.addressWatching = false
|
|
800
|
-
})
|
|
801
|
-
deferred.promise.catch(() => {
|
|
802
|
-
taskCache.addressWatching = false
|
|
803
|
-
})
|
|
804
|
-
serverStates.watchAddresses(
|
|
805
|
-
uri,
|
|
806
|
-
Array.from(Object.keys(addressSubscribeCache)),
|
|
807
|
-
deferred
|
|
808
|
-
)
|
|
809
|
-
return true
|
|
779
|
+
// Subscribe to any new addresses
|
|
780
|
+
if (newAddress.length > 0) {
|
|
781
|
+
serverStates.watchAddresses(uri, newAddress)
|
|
782
|
+
return true
|
|
783
|
+
}
|
|
810
784
|
}
|
|
811
785
|
|
|
812
786
|
// filled when transactions potentially changed (e.g. through new block notification)
|
|
@@ -817,18 +791,16 @@ const addToAddressTransactionCache = async (
|
|
|
817
791
|
hasProcessedAtLeastOnce = true
|
|
818
792
|
state.processing = true
|
|
819
793
|
_utils.removeItem.call(void 0, updateTransactionCache, txId)
|
|
820
|
-
const updateTransactionTask = updateTransactions({
|
|
821
|
-
...args,
|
|
822
|
-
walletBlockHeight: blockHeight,
|
|
823
|
-
txId
|
|
824
|
-
})
|
|
794
|
+
const updateTransactionTask = updateTransactions({ ...args, txId })
|
|
825
795
|
// once resolved, add the txid to the server cache
|
|
826
796
|
updateTransactionTask.deferred.promise
|
|
827
797
|
.then(() => {
|
|
828
798
|
serverState.txids.add(txId)
|
|
829
799
|
})
|
|
830
|
-
.catch(
|
|
831
|
-
|
|
800
|
+
.catch(err => {
|
|
801
|
+
updateTransactionCache[txId] = state
|
|
802
|
+
console.error(err)
|
|
803
|
+
args.log('error in updateTransactionCache:', err)
|
|
832
804
|
})
|
|
833
805
|
return updateTransactionTask
|
|
834
806
|
}
|
|
@@ -847,15 +819,17 @@ const addToAddressTransactionCache = async (
|
|
|
847
819
|
// Fetch and process address UTXOs
|
|
848
820
|
const wsTask = await processAddressTransactions({
|
|
849
821
|
...args,
|
|
850
|
-
|
|
822
|
+
addressTransactionState: state,
|
|
851
823
|
address
|
|
852
824
|
})
|
|
853
825
|
wsTask.deferred.promise
|
|
854
826
|
.then(() => {
|
|
855
827
|
serverState.addresses.add(address)
|
|
856
828
|
})
|
|
857
|
-
.catch(
|
|
858
|
-
|
|
829
|
+
.catch(err => {
|
|
830
|
+
addressTransactionCache[address] = state
|
|
831
|
+
console.error(err)
|
|
832
|
+
args.log('error in updateTransactionCache:', err)
|
|
859
833
|
})
|
|
860
834
|
return wsTask
|
|
861
835
|
}
|
|
@@ -866,29 +840,17 @@ const addToAddressTransactionCache = async (
|
|
|
866
840
|
|
|
867
841
|
|
|
868
842
|
|
|
869
|
-
|
|
870
843
|
const updateTransactions = (
|
|
871
844
|
args
|
|
872
845
|
) => {
|
|
873
|
-
const {
|
|
874
|
-
walletBlockHeight,
|
|
875
|
-
emitter,
|
|
876
|
-
walletTools,
|
|
877
|
-
txId,
|
|
878
|
-
pluginInfo,
|
|
879
|
-
processor,
|
|
880
|
-
taskCache
|
|
881
|
-
} = args
|
|
846
|
+
const { emitter, walletTools, txId, pluginInfo, processor, taskCache } = args
|
|
882
847
|
const deferred = new _Deferred2.default()
|
|
883
848
|
deferred.promise
|
|
884
849
|
.then(async (txResponse) => {
|
|
885
850
|
// check if raw tx is still not confirmed, if so, don't change anything
|
|
886
851
|
if (txResponse.blockHeight < 1) return
|
|
887
852
|
// Create new tx from raw tx
|
|
888
|
-
const tx = processTransactionResponse({
|
|
889
|
-
...args,
|
|
890
|
-
txResponse
|
|
891
|
-
})
|
|
853
|
+
const tx = processTransactionResponse({ ...args, txResponse })
|
|
892
854
|
// Remove any existing input utxos from the processor
|
|
893
855
|
for (const input of tx.inputs) {
|
|
894
856
|
await processor.removeUtxos([`${input.txId}_${input.outputIndex}`])
|
|
@@ -909,14 +871,15 @@ const updateTransactions = (
|
|
|
909
871
|
})
|
|
910
872
|
await exports.transactionChanged.call(void 0, {
|
|
911
873
|
emitter,
|
|
874
|
+
walletTools,
|
|
912
875
|
processor,
|
|
913
876
|
pluginInfo,
|
|
914
|
-
tx: processedTx
|
|
915
|
-
walletBlockHeight,
|
|
916
|
-
walletTools
|
|
877
|
+
tx: processedTx
|
|
917
878
|
})
|
|
918
879
|
})
|
|
919
|
-
.catch(
|
|
880
|
+
.catch(err => {
|
|
881
|
+
console.error(err)
|
|
882
|
+
args.log('error in updateTransactions:', err)
|
|
920
883
|
taskCache.updateTransactionCache[txId] = { processing: false }
|
|
921
884
|
})
|
|
922
885
|
return {
|
|
@@ -1023,25 +986,21 @@ const internalGetFreshAddress = async (
|
|
|
1023
986
|
|
|
1024
987
|
|
|
1025
988
|
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
989
|
const processAddressTransactions = async (
|
|
1030
990
|
args
|
|
1031
991
|
) => {
|
|
1032
992
|
const {
|
|
1033
993
|
address,
|
|
1034
|
-
|
|
1035
|
-
blockHeight: walletBlockHeight,
|
|
994
|
+
addressTransactionState,
|
|
1036
995
|
emitter,
|
|
1037
996
|
pluginInfo,
|
|
1038
997
|
processor,
|
|
1039
998
|
walletTools,
|
|
1040
|
-
path,
|
|
1041
999
|
taskCache,
|
|
1042
|
-
|
|
1000
|
+
pluginState,
|
|
1043
1001
|
uri
|
|
1044
1002
|
} = args
|
|
1003
|
+
const { page = 1, blockHeight } = addressTransactionState
|
|
1045
1004
|
const {
|
|
1046
1005
|
engineInfo: { asBlockbookAddress }
|
|
1047
1006
|
} = pluginInfo
|
|
@@ -1057,7 +1016,7 @@ const processAddressTransactions = async (
|
|
|
1057
1016
|
const deferred = new _Deferred2.default()
|
|
1058
1017
|
deferred.promise
|
|
1059
1018
|
.then(async (value) => {
|
|
1060
|
-
|
|
1019
|
+
pluginState.serverScoreUp(uri, Date.now() - queryTime)
|
|
1061
1020
|
const { transactions = [], txs, unconfirmedTxs, totalPages } = value
|
|
1062
1021
|
|
|
1063
1022
|
// If address is used and previously not marked as used, mark as used.
|
|
@@ -1068,21 +1027,17 @@ const processAddressTransactions = async (
|
|
|
1068
1027
|
|
|
1069
1028
|
// Process and save the address's transactions
|
|
1070
1029
|
for (const txResponse of transactions) {
|
|
1071
|
-
const tx = processTransactionResponse({
|
|
1072
|
-
...args,
|
|
1073
|
-
txResponse
|
|
1074
|
-
})
|
|
1030
|
+
const tx = processTransactionResponse({ ...args, txResponse })
|
|
1075
1031
|
const processedTx = await processor.saveTransaction({
|
|
1076
1032
|
tx,
|
|
1077
1033
|
scriptPubkeys: [scriptPubkey]
|
|
1078
1034
|
})
|
|
1079
1035
|
await exports.transactionChanged.call(void 0, {
|
|
1080
1036
|
emitter,
|
|
1037
|
+
walletTools,
|
|
1081
1038
|
processor,
|
|
1082
1039
|
pluginInfo,
|
|
1083
|
-
tx: processedTx
|
|
1084
|
-
walletBlockHeight,
|
|
1085
|
-
walletTools
|
|
1040
|
+
tx: processedTx
|
|
1086
1041
|
})
|
|
1087
1042
|
}
|
|
1088
1043
|
|
|
@@ -1091,16 +1046,15 @@ const processAddressTransactions = async (
|
|
|
1091
1046
|
if (page < totalPages) {
|
|
1092
1047
|
// Add the address back to the cache, incrementing the page
|
|
1093
1048
|
addressTransactionCache[address] = {
|
|
1094
|
-
|
|
1049
|
+
...addressTransactionState,
|
|
1095
1050
|
processing: false,
|
|
1096
|
-
blockHeight: walletBlockHeight,
|
|
1097
1051
|
page: page + 1
|
|
1098
1052
|
}
|
|
1099
1053
|
return
|
|
1100
1054
|
}
|
|
1101
1055
|
|
|
1102
1056
|
// Update the lastQueriedBlockHeight for the address
|
|
1103
|
-
addressData.lastQueriedBlockHeight =
|
|
1057
|
+
addressData.lastQueriedBlockHeight = blockHeight
|
|
1104
1058
|
|
|
1105
1059
|
// Save/update the fully-processed address
|
|
1106
1060
|
await processor.saveAddress(addressData)
|
|
@@ -1114,8 +1068,8 @@ const processAddressTransactions = async (
|
|
|
1114
1068
|
.catch(err => {
|
|
1115
1069
|
// Log the error for debugging purposes without crashing the engine
|
|
1116
1070
|
// This will cause frozen wallet syncs
|
|
1117
|
-
console.error(err
|
|
1118
|
-
|
|
1071
|
+
console.error(err)
|
|
1072
|
+
addressTransactionCache[address] = addressTransactionState
|
|
1119
1073
|
})
|
|
1120
1074
|
|
|
1121
1075
|
return {
|
|
@@ -1136,9 +1090,10 @@ const processAddressTransactions = async (
|
|
|
1136
1090
|
const processTransactionResponse = (
|
|
1137
1091
|
args
|
|
1138
1092
|
) => {
|
|
1139
|
-
const {
|
|
1140
|
-
|
|
1141
|
-
|
|
1093
|
+
const {
|
|
1094
|
+
txResponse,
|
|
1095
|
+
pluginInfo: { coinInfo }
|
|
1096
|
+
} = args
|
|
1142
1097
|
return {
|
|
1143
1098
|
txid: txResponse.txid,
|
|
1144
1099
|
hex: txResponse.hex,
|
|
@@ -1189,7 +1144,7 @@ const processAddressUtxos = async (
|
|
|
1189
1144
|
taskCache,
|
|
1190
1145
|
path,
|
|
1191
1146
|
pluginInfo,
|
|
1192
|
-
|
|
1147
|
+
pluginState,
|
|
1193
1148
|
uri
|
|
1194
1149
|
} = args
|
|
1195
1150
|
const {
|
|
@@ -1200,7 +1155,7 @@ const processAddressUtxos = async (
|
|
|
1200
1155
|
const deferred = new _Deferred2.default()
|
|
1201
1156
|
deferred.promise
|
|
1202
1157
|
.then(async (utxos) => {
|
|
1203
|
-
|
|
1158
|
+
pluginState.serverScoreUp(uri, Date.now() - queryTime)
|
|
1204
1159
|
const scriptPubkey = walletTools.addressToScriptPubkey(address)
|
|
1205
1160
|
const addressData = await processor.fetchAddress(scriptPubkey)
|
|
1206
1161
|
if (addressData == null || addressData.path == null) {
|
|
@@ -1325,7 +1280,7 @@ const processRawUtxo = async (
|
|
|
1325
1280
|
path,
|
|
1326
1281
|
taskCache,
|
|
1327
1282
|
requiredCount,
|
|
1328
|
-
|
|
1283
|
+
pluginState,
|
|
1329
1284
|
uri,
|
|
1330
1285
|
log
|
|
1331
1286
|
} = args
|
|
@@ -1373,7 +1328,7 @@ const processRawUtxo = async (
|
|
|
1373
1328
|
const deferred = new _Deferred2.default()
|
|
1374
1329
|
deferred.promise
|
|
1375
1330
|
.then((txResponse) => {
|
|
1376
|
-
|
|
1331
|
+
pluginState.serverScoreUp(uri, Date.now() - queryTime)
|
|
1377
1332
|
const processedTx = processTransactionResponse({
|
|
1378
1333
|
...args,
|
|
1379
1334
|
txResponse
|
|
@@ -1382,9 +1337,9 @@ const processRawUtxo = async (
|
|
|
1382
1337
|
// Only after we have successfully fetched the tx, set our script and call done
|
|
1383
1338
|
done()
|
|
1384
1339
|
})
|
|
1385
|
-
.catch(
|
|
1340
|
+
.catch(err => {
|
|
1386
1341
|
// If something went wrong, add the UTXO back to the queue
|
|
1387
|
-
log('error in
|
|
1342
|
+
log('error in processRawUtxo:', err)
|
|
1388
1343
|
rawUtxoCache[JSON.stringify(utxo)] = {
|
|
1389
1344
|
processing: false,
|
|
1390
1345
|
path,
|
|
@@ -1,9 +1,15 @@
|
|
|
1
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; } }var _altcoinjs = require('altcoin-js'); var bitcoin = _interopRequireWildcard(_altcoinjs);
|
|
2
|
+
var _cleaners = require('cleaners');
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
var _constants = require('../../constants');
|
|
5
6
|
|
|
6
7
|
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _keymanager = require('../keymanager/keymanager');
|
|
12
|
+
|
|
7
13
|
const currencyInfo = {
|
|
8
14
|
pluginId: 'bitcoinsv',
|
|
9
15
|
walletType: 'wallet:bitcoinsv',
|
|
@@ -18,7 +24,10 @@ const currencyInfo = {
|
|
|
18
24
|
// Configuration options:
|
|
19
25
|
defaultSettings: {
|
|
20
26
|
customFeeSettings: ['satPerByte'],
|
|
21
|
-
blockbookServers: [
|
|
27
|
+
blockbookServers: [
|
|
28
|
+
'wss://bsv-bbwrap1.edge.app',
|
|
29
|
+
'wss://blockbook.siftbitcoin.com:9146'
|
|
30
|
+
],
|
|
22
31
|
enableCustomServers: false
|
|
23
32
|
},
|
|
24
33
|
customFeeTemplate: [
|
|
@@ -54,7 +63,35 @@ const engineInfo = {
|
|
|
54
63
|
standardFeeHigh: '10',
|
|
55
64
|
standardFeeLowAmount: '1000000',
|
|
56
65
|
standardFeeHighAmount: '65000000'
|
|
57
|
-
}
|
|
66
|
+
},
|
|
67
|
+
/*
|
|
68
|
+
This is to support cashaddr and 1-addresses coming from the network.
|
|
69
|
+
We always convert to a 1-address for internal use.
|
|
70
|
+
We send 1-address to the network because all servers should support legacy
|
|
71
|
+
address (this is the uncleaner).
|
|
72
|
+
*/
|
|
73
|
+
asBlockbookAddress: _cleaners.asCodec.call(void 0,
|
|
74
|
+
raw => {
|
|
75
|
+
const networkAddress = _cleaners.asString.call(void 0, raw)
|
|
76
|
+
try {
|
|
77
|
+
// cashaddr
|
|
78
|
+
const address = networkAddress.replace('bitcoincash:', '')
|
|
79
|
+
const scriptPubkey = _keymanager.addressToScriptPubkey.call(void 0, {
|
|
80
|
+
address,
|
|
81
|
+
coin: 'bitcoincash'
|
|
82
|
+
})
|
|
83
|
+
return _keymanager.scriptPubkeyToAddress.call(void 0, {
|
|
84
|
+
scriptPubkey,
|
|
85
|
+
coin: 'bitcoinsv',
|
|
86
|
+
addressType: _keymanager.AddressTypeEnum.p2pkh
|
|
87
|
+
}).address
|
|
88
|
+
} catch (err) {
|
|
89
|
+
// 1address
|
|
90
|
+
return networkAddress
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
address => address
|
|
94
|
+
)
|
|
58
95
|
}
|
|
59
96
|
|
|
60
97
|
const coinInfo = {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { bip32 } from 'altcoin-js';
|
|
3
3
|
import { Cleaner } from 'cleaners';
|
|
4
4
|
import { Disklet } from 'disklet';
|
|
5
|
-
import { EdgeCurrencyEngineOptions, EdgeCurrencyInfo, EdgeCurrencyTools, EdgeIo, EdgeParsedUri,
|
|
6
|
-
import {
|
|
5
|
+
import { EdgeCurrencyEngineOptions, EdgeCurrencyInfo, EdgeCurrencyTools, EdgeIo, EdgeParsedUri, EdgeWalletInfo } from 'edge-core-js/types';
|
|
6
|
+
import { IUTXO } from '../utxobased/db/types';
|
|
7
7
|
import { ScriptTemplates } from '../utxobased/info/scriptTemplates/types';
|
|
8
8
|
import { UtxoPicker } from '../utxobased/keymanager/utxopicker';
|
|
9
9
|
import { EngineEmitter } from './makeEngineEmitter';
|
|
@@ -41,7 +41,6 @@ export interface EngineInfo {
|
|
|
41
41
|
simpleFeeSettings: SimpleFeeSettings;
|
|
42
42
|
scriptTemplates?: ScriptTemplates;
|
|
43
43
|
asBlockbookAddress?: Cleaner<string>;
|
|
44
|
-
validateConfirmations?: (txResponse: IProcessorTransaction, blockHeight: number, requiredConfirmations: number | undefined) => EdgeTransaction['confirmations'];
|
|
45
44
|
}
|
|
46
45
|
/**
|
|
47
46
|
* Coin Info
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EdgeTransaction } from 'edge-core-js/types';
|
|
2
|
-
import {
|
|
2
|
+
import { EngineInfo } from '../../../plugin/types';
|
|
3
3
|
import { UTXOPluginWalletTools } from '../../engine/makeUtxoWalletTools';
|
|
4
4
|
import { Processor } from '../makeProcessor';
|
|
5
5
|
import { IProcessorTransaction } from '../types';
|
|
@@ -7,10 +7,9 @@ export declare const fromEdgeTransaction: (tx: EdgeTransaction) => IProcessorTra
|
|
|
7
7
|
interface ToEdgeTransactionArgs {
|
|
8
8
|
tx: IProcessorTransaction;
|
|
9
9
|
currencyCode: string;
|
|
10
|
-
pluginInfo: PluginInfo;
|
|
11
|
-
processor: Processor;
|
|
12
|
-
walletBlockHeight: number;
|
|
13
10
|
walletTools: UTXOPluginWalletTools;
|
|
11
|
+
processor: Processor;
|
|
12
|
+
engineInfo: EngineInfo;
|
|
14
13
|
}
|
|
15
14
|
export declare const toEdgeTransaction: (args: ToEdgeTransactionArgs) => Promise<EdgeTransaction>;
|
|
16
15
|
export {};
|
|
@@ -3,9 +3,11 @@ import { EngineEmitter } from '../../plugin/makeEngineEmitter';
|
|
|
3
3
|
import { PluginState } from '../../plugin/pluginState';
|
|
4
4
|
import { PluginInfo } from '../../plugin/types';
|
|
5
5
|
import { NumbWalletInfo } from '../keymanager/cleaners';
|
|
6
|
+
import { BlockBook } from '../network/BlockBook';
|
|
6
7
|
import Deferred from '../network/Deferred';
|
|
7
8
|
import { WsTask } from '../network/Socket';
|
|
8
9
|
interface ServerState {
|
|
10
|
+
blockbook: BlockBook;
|
|
9
11
|
blockSubscriptionStatus: 'unsubscribed' | 'subscribing' | 'subscribed';
|
|
10
12
|
blockHeight: number;
|
|
11
13
|
txids: Set<string>;
|
|
@@ -23,13 +25,13 @@ export interface ServerStates {
|
|
|
23
25
|
stop: () => void;
|
|
24
26
|
serverCanGetTx: (uri: string, txid: string) => boolean;
|
|
25
27
|
serverCanGetAddress: (uri: string, address: string) => boolean;
|
|
26
|
-
|
|
28
|
+
serverIsAwareOfAddress: (uri: string, address: string) => boolean;
|
|
27
29
|
getServerState: (uri: string) => ServerState | undefined;
|
|
28
30
|
refillServers: () => void;
|
|
29
31
|
getServerList: () => string[];
|
|
30
32
|
setServerList: (updatedServerList: string[]) => void;
|
|
31
33
|
broadcastTx: (transaction: EdgeTransaction) => Promise<string>;
|
|
32
|
-
watchAddresses: (uri: string, addresses: string[], deferredAddressSub
|
|
34
|
+
watchAddresses: (uri: string, addresses: string[], deferredAddressSub?: Deferred<unknown>) => void;
|
|
33
35
|
watchBlocks: (uri: string) => void;
|
|
34
36
|
getBlockHeight: (uri: string) => number;
|
|
35
37
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EdgeFreshAddress, EdgeIo, EdgeLog, EdgeTransaction } from 'edge-core-js/types';
|
|
2
2
|
import { EngineEmitter } from '../../plugin/makeEngineEmitter';
|
|
3
|
+
import { PluginState } from '../../plugin/pluginState';
|
|
3
4
|
import { ChangePath, CurrencyFormat, EngineConfig, PluginInfo } from '../../plugin/types';
|
|
4
5
|
import { Processor } from '../db/makeProcessor';
|
|
5
6
|
import { IAddress, IProcessorTransaction, IUTXO } from '../db/types';
|
|
@@ -38,18 +39,18 @@ interface CommonArgs {
|
|
|
38
39
|
io: EdgeIo;
|
|
39
40
|
log: EdgeLog;
|
|
40
41
|
serverStates: ServerStates;
|
|
42
|
+
pluginState: PluginState;
|
|
41
43
|
walletFormats: CurrencyFormat[];
|
|
42
44
|
lock: AwaitLock;
|
|
43
45
|
}
|
|
44
46
|
interface TaskCache {
|
|
45
|
-
addressWatching: boolean;
|
|
46
47
|
blockWatching: boolean;
|
|
47
|
-
addressSubscribeCache: AddressSubscribeCache;
|
|
48
|
-
addressUtxoCache: AddressUtxoCache;
|
|
49
|
-
rawUtxoCache: RawUtxoCache;
|
|
50
|
-
processorUtxoCache: ProcessorUtxoCache;
|
|
51
|
-
addressTransactionCache: AddressTransactionCache;
|
|
52
|
-
updateTransactionCache: UpdateTransactionCache;
|
|
48
|
+
readonly addressSubscribeCache: AddressSubscribeCache;
|
|
49
|
+
readonly addressUtxoCache: AddressUtxoCache;
|
|
50
|
+
readonly rawUtxoCache: RawUtxoCache;
|
|
51
|
+
readonly processorUtxoCache: ProcessorUtxoCache;
|
|
52
|
+
readonly addressTransactionCache: AddressTransactionCache;
|
|
53
|
+
readonly updateTransactionCache: UpdateTransactionCache;
|
|
53
54
|
}
|
|
54
55
|
interface UpdateTransactionCache {
|
|
55
56
|
[key: string]: {
|
|
@@ -95,7 +96,6 @@ interface AddressTransactionCache {
|
|
|
95
96
|
interface TransactionChangedArgs {
|
|
96
97
|
tx: IProcessorTransaction;
|
|
97
98
|
emitter: EngineEmitter;
|
|
98
|
-
walletBlockHeight: number;
|
|
99
99
|
walletTools: UTXOPluginWalletTools;
|
|
100
100
|
pluginInfo: PluginInfo;
|
|
101
101
|
processor: Processor;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edge-currency-plugins",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.2",
|
|
4
4
|
"description": "Edge currency plugins to fetch and process wallet accounts, balances and transactions.",
|
|
5
|
-
"repository": "https://github.
|
|
5
|
+
"repository": "https://github.com/EdgeApp/edge-currency-plugins",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Airbitz, Inc.",
|
|
8
8
|
"main": "./lib/index.js",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const defaultValidateConfirmations = (
|
|
6
|
-
tx,
|
|
7
|
-
blockHeight,
|
|
8
|
-
requiredConfirmations = 1
|
|
9
|
-
) => {
|
|
10
|
-
const blockConfirmations =
|
|
11
|
-
tx.blockHeight === 0 ? 0 : 1 + blockHeight - tx.blockHeight
|
|
12
|
-
const confirmations =
|
|
13
|
-
blockConfirmations >= requiredConfirmations
|
|
14
|
-
? 'confirmed'
|
|
15
|
-
: blockConfirmations <= 0
|
|
16
|
-
? 'unconfirmed'
|
|
17
|
-
: blockConfirmations
|
|
18
|
-
return confirmations
|
|
19
|
-
}; exports.defaultValidateConfirmations = defaultValidateConfirmations
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { EdgeTransaction } from 'edge-core-js';
|
|
2
|
-
import { IProcessorTransaction } from '../../db/types';
|
|
3
|
-
export declare const defaultValidateConfirmations: (tx: IProcessorTransaction, blockHeight: number, requiredConfirmations?: number) => EdgeTransaction['confirmations'];
|