edge-currency-plugins 3.2.0 → 3.3.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/android/src/main/assets/edge-currency-plugins/edge-currency-plugins.js +41 -41
- package/lib/common/plugin/PluginState.js +73 -43
- package/lib/common/plugin/ServerScores.js +11 -0
- package/lib/common/plugin/types.js +1 -1
- package/lib/common/utxobased/db/{Processor.js → DataLayer.js} +15 -11
- package/lib/common/utxobased/db/Models/{ProcessorTransaction.js → TransactionData.js} +4 -6
- package/lib/common/utxobased/db/types.js +4 -4
- package/lib/common/utxobased/db/util/utxo.js +8 -8
- package/lib/common/utxobased/engine/ServerStates.js +324 -298
- package/lib/common/utxobased/engine/UtxoEngine.js +58 -55
- package/lib/common/utxobased/engine/{UtxoEngineState.js → UtxoEngineProcessor.js} +650 -714
- package/lib/common/utxobased/engine/types.js +4 -2
- package/lib/common/utxobased/engine/util/getOwnUtxosFromTx.js +4 -4
- package/lib/common/utxobased/info/bitcoin.js +2 -1
- package/lib/common/utxobased/info/bitcoincash.js +2 -1
- package/lib/common/utxobased/info/dash.js +2 -1
- package/lib/common/utxobased/info/digibyte.js +5 -1
- package/lib/common/utxobased/info/dogecoin.js +2 -1
- package/lib/common/utxobased/info/groestlcoin.js +4 -1
- package/lib/common/utxobased/info/litecoin.js +2 -1
- package/lib/common/utxobased/info/zcoin.js +4 -1
- package/lib/common/utxobased/network/Blockbook.js +33 -30
- package/lib/common/utxobased/network/BlockbookElectrum.js +79 -77
- package/lib/common/utxobased/network/Socket.js +84 -48
- package/lib/common/utxobased/network/windowWS.js +2 -2
- package/lib/src/common/plugin/PluginState.d.ts +4 -4
- package/lib/src/common/plugin/ServerScores.d.ts +1 -0
- package/lib/src/common/plugin/types.d.ts +4 -4
- package/lib/src/common/utxobased/db/{Processor.d.ts → DataLayer.d.ts} +17 -11
- package/lib/src/common/utxobased/db/Models/{ProcessorTransaction.d.ts → TransactionData.d.ts} +5 -5
- package/lib/src/common/utxobased/db/Models/baselet.d.ts +4 -4
- package/lib/src/common/utxobased/db/types.d.ts +9 -9
- package/lib/src/common/utxobased/db/util/utxo.d.ts +3 -3
- package/lib/src/common/utxobased/engine/ServerStates.d.ts +7 -7
- package/lib/src/common/utxobased/engine/{UtxoEngineState.d.ts → UtxoEngineProcessor.d.ts} +44 -42
- package/lib/src/common/utxobased/engine/types.d.ts +4 -4
- package/lib/src/common/utxobased/engine/util/getOwnUtxosFromTx.d.ts +3 -3
- package/lib/src/common/utxobased/engine/utils.d.ts +2 -2
- package/lib/src/common/utxobased/keymanager/keymanager.d.ts +3 -3
- package/lib/src/common/utxobased/network/Blockbook.d.ts +8 -7
- package/lib/src/common/utxobased/network/BlockbookElectrum.d.ts +4 -2
- package/lib/src/common/utxobased/network/Socket.d.ts +10 -8
- package/lib/src/common/utxobased/network/types.d.ts +1 -1
- package/lib/src/util/uriKeyParams.d.ts +4 -0
- package/lib/util/uriKeyParams.js +20 -0
- package/package.json +1 -1
- /package/lib/test/common/utxobased/db/{Processor.spec.d.ts → DataLayer.spec.d.ts} +0 -0
|
@@ -13,8 +13,10 @@ var _types3 = require('../../plugin/types');
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const asUtxoInitOptions = _cleaners.asObject({
|
|
19
|
+
nowNodesApiKey: _cleaners.asOptional.call(void 0, _cleaners.asString)
|
|
18
20
|
}); exports.asUtxoInitOptions = asUtxoInitOptions
|
|
19
21
|
|
|
20
22
|
const asUtxoUserSettings = _cleaners.asObject.call(void 0, {
|
|
@@ -6,7 +6,7 @@ var _utils = require('../utils');
|
|
|
6
6
|
|
|
7
7
|
const getOwnUtxosFromTx = async (
|
|
8
8
|
engineInfo,
|
|
9
|
-
|
|
9
|
+
dataLayer,
|
|
10
10
|
tx
|
|
11
11
|
) => {
|
|
12
12
|
const ownUtxos = []
|
|
@@ -18,12 +18,12 @@ var _utils = require('../utils');
|
|
|
18
18
|
const inputUtxoIds = tx.inputs.map(
|
|
19
19
|
input => `${input.txId}_${input.outputIndex}`
|
|
20
20
|
)
|
|
21
|
-
const inputUtxos = await
|
|
21
|
+
const inputUtxos = await dataLayer.fetchUtxos({
|
|
22
22
|
utxoIds: inputUtxoIds
|
|
23
23
|
})
|
|
24
24
|
for (const utxo of inputUtxos) {
|
|
25
25
|
if (utxo == null) continue
|
|
26
|
-
// Must create a new
|
|
26
|
+
// Must create a new UtxoData object when mutating DataLayer objects because
|
|
27
27
|
// memlet may keep a reference in memory.
|
|
28
28
|
ownUtxos.push({ ...utxo, spent: true })
|
|
29
29
|
}
|
|
@@ -34,7 +34,7 @@ var _utils = require('../utils');
|
|
|
34
34
|
|
|
35
35
|
for (const output of tx.outputs) {
|
|
36
36
|
const scriptPubkey = output.scriptPubkey
|
|
37
|
-
const address = await
|
|
37
|
+
const address = await dataLayer.fetchAddress(scriptPubkey)
|
|
38
38
|
if (address != null) {
|
|
39
39
|
const id = `${tx.txid}_${output.n}`
|
|
40
40
|
const path = address.path
|
|
@@ -30,7 +30,11 @@ const currencyInfo = {
|
|
|
30
30
|
..._commonInfo.legacyMemoInfo,
|
|
31
31
|
defaultSettings: {
|
|
32
32
|
customFeeSettings: ['satPerByte'],
|
|
33
|
-
blockbookServers: [
|
|
33
|
+
blockbookServers: [
|
|
34
|
+
'wss://dgb1.trezor.io',
|
|
35
|
+
'wss://dgb2.trezor.io',
|
|
36
|
+
'wss://dgbbook.nownodes.io/wss/%{nowNodesApiKey}'
|
|
37
|
+
],
|
|
34
38
|
enableCustomServers: false
|
|
35
39
|
},
|
|
36
40
|
metaTokens: []
|
|
@@ -36,7 +36,10 @@ const currencyInfo = {
|
|
|
36
36
|
..._commonInfo.legacyMemoInfo,
|
|
37
37
|
defaultSettings: {
|
|
38
38
|
customFeeSettings: ['satPerByte'],
|
|
39
|
-
blockbookServers: [
|
|
39
|
+
blockbookServers: [
|
|
40
|
+
'wss://blockbook.groestlcoin.org',
|
|
41
|
+
'wss://grsbook.nownodes.io/wss/%{nowNodesApiKey}'
|
|
42
|
+
],
|
|
40
43
|
enableCustomServers: false
|
|
41
44
|
},
|
|
42
45
|
metaTokens: []
|
|
@@ -36,7 +36,8 @@ var _commonInfo = require('./commonInfo');
|
|
|
36
36
|
'wss://ltc2.trezor.io',
|
|
37
37
|
'wss://ltc3.trezor.io',
|
|
38
38
|
'wss://ltc4.trezor.io',
|
|
39
|
-
'wss://ltc5.trezor.io'
|
|
39
|
+
'wss://ltc5.trezor.io',
|
|
40
|
+
'wss://ltcbook.nownodes.io/wss/%{nowNodesApiKey}'
|
|
40
41
|
],
|
|
41
42
|
enableCustomServers: false
|
|
42
43
|
},
|
|
@@ -30,7 +30,10 @@ var _commonInfo = require('./commonInfo');
|
|
|
30
30
|
..._commonInfo.legacyMemoInfo,
|
|
31
31
|
defaultSettings: {
|
|
32
32
|
customFeeSettings: ['satPerByte'],
|
|
33
|
-
blockbookServers: [
|
|
33
|
+
blockbookServers: [
|
|
34
|
+
'wss://blockbook.firo.org',
|
|
35
|
+
'wss://firobook.nownodes.io/wss/%{nowNodesApiKey}'
|
|
36
|
+
],
|
|
34
37
|
enableCustomServers: false
|
|
35
38
|
},
|
|
36
39
|
metaTokens: []
|
|
@@ -22,19 +22,17 @@ var _constants = require('../engine/constants');
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
25
|
+
|
|
25
26
|
|
|
26
27
|
var _blockbookApi = require('./blockbookApi');
|
|
27
28
|
var _Deferred = require('./Deferred'); var _Deferred2 = _interopRequireDefault(_Deferred);
|
|
28
|
-
var _Socket = require('./Socket');
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
29
|
|
|
33
30
|
|
|
34
31
|
|
|
35
32
|
|
|
36
33
|
|
|
37
34
|
|
|
35
|
+
var _Socket = require('./Socket');
|
|
38
36
|
|
|
39
37
|
|
|
40
38
|
|
|
@@ -116,7 +114,7 @@ var _Socket = require('./Socket');
|
|
|
116
114
|
connectionUri,
|
|
117
115
|
engineEmitter,
|
|
118
116
|
log,
|
|
119
|
-
|
|
117
|
+
taskGeneratorFn,
|
|
120
118
|
socketEmitter,
|
|
121
119
|
walletId
|
|
122
120
|
} = config
|
|
@@ -172,13 +170,24 @@ var _Socket = require('./Socket');
|
|
|
172
170
|
return await instance.promisifyWsMessage(_blockbookApi.transactionMessage.call(void 0, hash))
|
|
173
171
|
},
|
|
174
172
|
|
|
175
|
-
onQueueSpace(cb) {
|
|
176
|
-
socket.onQueueSpace(cb)
|
|
177
|
-
},
|
|
178
|
-
|
|
179
173
|
async promisifyWsMessage(message) {
|
|
180
174
|
const deferred = new _Deferred2.default()
|
|
181
|
-
|
|
175
|
+
const taskGeneratorFn = async function* ()
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
{
|
|
180
|
+
const value = yield { ...message }
|
|
181
|
+
deferred.resolve(value)
|
|
182
|
+
return false
|
|
183
|
+
}
|
|
184
|
+
const generator = taskGeneratorFn()
|
|
185
|
+
const result = await generator.next()
|
|
186
|
+
// Assertion mask the type checker
|
|
187
|
+
if (result.done !== true) {
|
|
188
|
+
const task = result.value
|
|
189
|
+
socket.submitTask(task, generator)
|
|
190
|
+
}
|
|
182
191
|
return await deferred.promise
|
|
183
192
|
},
|
|
184
193
|
|
|
@@ -223,39 +232,32 @@ var _Socket = require('./Socket');
|
|
|
223
232
|
// Task Methods:
|
|
224
233
|
//
|
|
225
234
|
|
|
226
|
-
addressQueryTask(address, params
|
|
227
|
-
return {
|
|
235
|
+
addressQueryTask: function* (address, params) {
|
|
236
|
+
return yield {
|
|
228
237
|
..._blockbookApi.addressMessage.call(void 0, address, params.asBlockbookAddress, {
|
|
229
238
|
details: 'txs',
|
|
230
239
|
from: params.lastQueriedBlockHeight,
|
|
231
240
|
pageSize: _constants.BLOCKBOOK_TXS_PER_PAGE,
|
|
232
241
|
page: params.page
|
|
233
|
-
})
|
|
234
|
-
deferred
|
|
242
|
+
})
|
|
235
243
|
}
|
|
236
244
|
},
|
|
237
245
|
|
|
238
|
-
transactionQueryTask(txId
|
|
239
|
-
return {
|
|
240
|
-
..._blockbookApi.transactionMessage.call(void 0, txId)
|
|
241
|
-
deferred
|
|
246
|
+
transactionQueryTask: function* (txId) {
|
|
247
|
+
return yield {
|
|
248
|
+
..._blockbookApi.transactionMessage.call(void 0, txId)
|
|
242
249
|
}
|
|
243
250
|
},
|
|
244
251
|
|
|
245
|
-
transactionSpecialQueryTask(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
) {
|
|
249
|
-
return {
|
|
250
|
-
..._blockbookApi.transactionMessageSpecific.call(void 0, txId),
|
|
251
|
-
deferred
|
|
252
|
+
transactionSpecialQueryTask: function* (txId) {
|
|
253
|
+
return yield {
|
|
254
|
+
..._blockbookApi.transactionMessageSpecific.call(void 0, txId)
|
|
252
255
|
}
|
|
253
256
|
},
|
|
254
257
|
|
|
255
|
-
utxoListQueryTask(address, params
|
|
256
|
-
return {
|
|
257
|
-
..._blockbookApi.addressUtxosMessage.call(void 0, address, params.asBlockbookAddress)
|
|
258
|
-
deferred
|
|
258
|
+
utxoListQueryTask: function* (address, params) {
|
|
259
|
+
return yield {
|
|
260
|
+
..._blockbookApi.addressUtxosMessage.call(void 0, address, params.asBlockbookAddress)
|
|
259
261
|
}
|
|
260
262
|
}
|
|
261
263
|
}
|
|
@@ -263,7 +265,8 @@ var _Socket = require('./Socket');
|
|
|
263
265
|
const socket = _Socket.makeSocket.call(void 0, connectionUri, {
|
|
264
266
|
asResponse,
|
|
265
267
|
healthCheck: _nullishCoalesce(config.ping, () => ( ping)),
|
|
266
|
-
|
|
268
|
+
initOptions: config.initOptions,
|
|
269
|
+
taskGeneratorFn,
|
|
267
270
|
log,
|
|
268
271
|
emitter: socketEmitter,
|
|
269
272
|
walletId
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function
|
|
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; }var _altcoinjs = require('altcoin-js');
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -12,10 +12,10 @@ var _cleaners = require('cleaners');
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
+
|
|
15
16
|
var _keymanager = require('../keymanager/keymanager');
|
|
16
17
|
var _Blockbook = require('./Blockbook');
|
|
17
18
|
|
|
18
|
-
var _Deferred = require('./Deferred'); var _Deferred2 = _interopRequireDefault(_Deferred);
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
@@ -37,6 +37,12 @@ var _electrumApi = require('./electrumApi');
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
40
46
|
|
|
41
47
|
|
|
42
48
|
|
|
@@ -78,8 +84,9 @@ const asResponse = (raw) => {
|
|
|
78
84
|
asAddress,
|
|
79
85
|
connectionUri,
|
|
80
86
|
engineEmitter,
|
|
87
|
+
initOptions,
|
|
81
88
|
log,
|
|
82
|
-
|
|
89
|
+
taskGeneratorFn,
|
|
83
90
|
pluginInfo,
|
|
84
91
|
socketEmitter,
|
|
85
92
|
walletId
|
|
@@ -101,86 +108,81 @@ const asResponse = (raw) => {
|
|
|
101
108
|
asResponse,
|
|
102
109
|
connectionUri,
|
|
103
110
|
engineEmitter,
|
|
111
|
+
initOptions,
|
|
104
112
|
log,
|
|
105
|
-
|
|
113
|
+
taskGeneratorFn: async function* (
|
|
106
114
|
uri
|
|
107
|
-
)
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
115
|
+
) {
|
|
116
|
+
const generator = taskGeneratorFn(uri)
|
|
117
|
+
let nextValue
|
|
118
|
+
|
|
119
|
+
while (true) {
|
|
120
|
+
const result = await generator.next(nextValue)
|
|
121
|
+
const task = result.value
|
|
122
|
+
|
|
123
|
+
// If the generator result is not a WsTask we will return it:
|
|
124
|
+
if (_optionalChain([result, 'optionalAccess', _ => _.done]) === true) return result.value
|
|
125
|
+
if (typeof task === 'boolean') return task
|
|
126
|
+
|
|
127
|
+
// Translate getAccountUtxo to blockchain.scripthash.listunspent:
|
|
128
|
+
if (task.method === 'getAccountUtxo') {
|
|
129
|
+
const params = task.params
|
|
130
|
+
const address =
|
|
131
|
+
asAddress != null ? asAddress(params.descriptor) : params.descriptor
|
|
132
|
+
const scriptHash = addressToScriptHash(address)
|
|
133
|
+
|
|
134
|
+
// Safe because yielding WsTask<ListUnspentResponse> should get
|
|
135
|
+
// ListUnspentResponse next.
|
|
136
|
+
const electrumUtxos = (yield {
|
|
137
|
+
..._electrumApi.listUnspentMessage.call(void 0, scriptHash)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
const blockbookUtxos = electrumUtxos.map(
|
|
141
|
+
utxo => ({
|
|
142
|
+
txid: utxo.tx_hash,
|
|
143
|
+
vout: utxo.tx_pos,
|
|
144
|
+
value: utxo.value.toString(),
|
|
145
|
+
height: utxo.height
|
|
146
|
+
})
|
|
147
|
+
)
|
|
148
|
+
nextValue = blockbookUtxos
|
|
149
|
+
continue
|
|
138
150
|
}
|
|
139
|
-
return translatedTask
|
|
140
|
-
}
|
|
141
151
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const translatedTask = {
|
|
176
|
-
..._electrumApi.addressTransactionsMessage.call(void 0, scriptHash),
|
|
177
|
-
deferred
|
|
152
|
+
// Get Address Transactions:
|
|
153
|
+
if (task.method === 'getAccountInfo') {
|
|
154
|
+
const params = task.params
|
|
155
|
+
const address =
|
|
156
|
+
asAddress != null ? asAddress(params.descriptor) : params.descriptor
|
|
157
|
+
const scriptHash = addressToScriptHash(address)
|
|
158
|
+
|
|
159
|
+
// Safe because yielding WsTask<AddressTransactionsResponse> should get
|
|
160
|
+
// AddressTransactionsResponse next.
|
|
161
|
+
const electrumUtxos = (yield {
|
|
162
|
+
..._electrumApi.addressTransactionsMessage.call(void 0, scriptHash)
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
const blockbookUtxos = {
|
|
166
|
+
address, // unused
|
|
167
|
+
balance: '0', // unused
|
|
168
|
+
totalReceived: '0', // unused
|
|
169
|
+
totalSent: '0', // unused
|
|
170
|
+
txs: electrumUtxos.length,
|
|
171
|
+
unconfirmedBalance: '0', // unused
|
|
172
|
+
unconfirmedTxs: electrumUtxos.reduce(
|
|
173
|
+
(sum, tx) => (sum + tx.height >= 0 ? 1 : 0),
|
|
174
|
+
0
|
|
175
|
+
),
|
|
176
|
+
txids: [], // unused
|
|
177
|
+
transactions: [], // TODO: this requires an extra query per txid
|
|
178
|
+
page: 0, // unused
|
|
179
|
+
totalPages: 1,
|
|
180
|
+
itemsOnPage: 0 // unused
|
|
181
|
+
}
|
|
182
|
+
nextValue = blockbookUtxos
|
|
183
|
+
continue
|
|
178
184
|
}
|
|
179
|
-
return translatedTask
|
|
180
185
|
}
|
|
181
|
-
|
|
182
|
-
// Skip unsupported task and continue with the next one:
|
|
183
|
-
return true
|
|
184
186
|
},
|
|
185
187
|
ping: async () => {
|
|
186
188
|
return await instance.promisifyWsMessage(_electrumApi.pingMessage.call(void 0, ))
|