edge-currency-plugins 1.0.0-rc.2 → 1.0.0-rc.5
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.
|
@@ -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) {
|
|
@@ -286,7 +286,10 @@ var _utils = require('./utils');
|
|
|
286
286
|
await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async _6 => _6.utxos]), async () => (
|
|
287
287
|
((await processor.fetchUtxos({ utxoIds: [] })) )))
|
|
288
288
|
|
|
289
|
-
if (
|
|
289
|
+
if (
|
|
290
|
+
bs.gt(totalAmountToSend, `${_utils.sumUtxos.call(void 0, utxos)}`) ||
|
|
291
|
+
utxos.length === 0
|
|
292
|
+
) {
|
|
290
293
|
throw new (0, _types.InsufficientFundsError)(currencyInfo.currencyCode)
|
|
291
294
|
}
|
|
292
295
|
|
|
@@ -302,7 +305,7 @@ var _utils = require('./utils');
|
|
|
302
305
|
const { script } = target.otherParams
|
|
303
306
|
if (script.type === 'replayProtection') {
|
|
304
307
|
// construct a replay protection p2sh address
|
|
305
|
-
const { publicAddress } = await
|
|
308
|
+
const { publicAddress } = await engineState.deriveScriptAddress(
|
|
306
309
|
script.type
|
|
307
310
|
)
|
|
308
311
|
targets.push({
|
|
@@ -328,7 +331,7 @@ var _utils = require('./utils');
|
|
|
328
331
|
throw new Error('Need to provide Spend Targets')
|
|
329
332
|
}
|
|
330
333
|
|
|
331
|
-
const freshAddress = await
|
|
334
|
+
const freshAddress = await engineState.getFreshAddress(1)
|
|
332
335
|
const freshChangeAddress =
|
|
333
336
|
_nullishCoalesce(freshAddress.segwitAddress, () => ( freshAddress.publicAddress))
|
|
334
337
|
const setRBF = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.setRBF]), () => ( false))
|
|
@@ -467,7 +470,7 @@ var _utils = require('./utils');
|
|
|
467
470
|
Get the wallet's UTXOs from the new transaction and save them to the processsor.
|
|
468
471
|
*/
|
|
469
472
|
const utxos = await _getOwnUtxosFromTx.getOwnUtxosFromTx.call(void 0, engineInfo, processor, tx)
|
|
470
|
-
await
|
|
473
|
+
await engineState.processUtxos(utxos)
|
|
471
474
|
},
|
|
472
475
|
|
|
473
476
|
async signTx(transaction) {
|
|
@@ -82,6 +82,8 @@ var _utils3 = require('./utils');
|
|
|
82
82
|
|
|
83
83
|
|
|
84
84
|
|
|
85
|
+
|
|
86
|
+
|
|
85
87
|
|
|
86
88
|
|
|
87
89
|
|
|
@@ -138,8 +140,11 @@ var _utils3 = require('./utils');
|
|
|
138
140
|
**/
|
|
139
141
|
const processesPerAddress = 2
|
|
140
142
|
let processedCount = 0
|
|
141
|
-
let processedPercent = 0
|
|
143
|
+
let processedPercent = 0 // last sync ratio emitted
|
|
142
144
|
const updateProgressRatio = async () => {
|
|
145
|
+
// Avoid re-sending sync ratios / sending ratios larger than 1
|
|
146
|
+
if (processedPercent >= 1) return
|
|
147
|
+
|
|
143
148
|
// We expect the total number of progress updates to equal the number of
|
|
144
149
|
// addresses multiplied the number of processes per address.
|
|
145
150
|
const expectedProccessCount =
|
|
@@ -440,6 +445,22 @@ var _utils3 = require('./utils');
|
|
|
440
445
|
}
|
|
441
446
|
}
|
|
442
447
|
}
|
|
448
|
+
},
|
|
449
|
+
async processUtxos(utxos) {
|
|
450
|
+
const utxoMap = new Map()
|
|
451
|
+
for (const utxo of utxos) {
|
|
452
|
+
const utxoSet = _nullishCoalesce(utxoMap.get(utxo.scriptPubkey), () => ( new Set()))
|
|
453
|
+
if (utxoMap.has(utxo.scriptPubkey) == null)
|
|
454
|
+
utxoMap.set(utxo.scriptPubkey, utxoSet)
|
|
455
|
+
utxoSet.add(utxo)
|
|
456
|
+
}
|
|
457
|
+
for (const [scriptPubkey, utxos] of utxoMap.entries()) {
|
|
458
|
+
await processProcessorUtxos({
|
|
459
|
+
...commonArgs,
|
|
460
|
+
scriptPubkey,
|
|
461
|
+
utxos
|
|
462
|
+
})
|
|
463
|
+
}
|
|
443
464
|
}
|
|
444
465
|
}
|
|
445
466
|
} exports.makeUtxoEngineState = makeUtxoEngineState;
|
|
@@ -681,8 +702,7 @@ const addToAddressTransactionCache = async (
|
|
|
681
702
|
await processProcessorUtxos({
|
|
682
703
|
...args,
|
|
683
704
|
scriptPubkey,
|
|
684
|
-
utxos: state.utxos
|
|
685
|
-
path: state.path
|
|
705
|
+
utxos: state.utxos
|
|
686
706
|
})
|
|
687
707
|
_utils.removeItem.call(void 0, processorUtxoCache, scriptPubkey)
|
|
688
708
|
return true
|
|
@@ -1196,7 +1216,6 @@ const processAddressUtxos = async (
|
|
|
1196
1216
|
|
|
1197
1217
|
|
|
1198
1218
|
|
|
1199
|
-
|
|
1200
1219
|
const processProcessorUtxos = async (
|
|
1201
1220
|
args
|
|
1202
1221
|
) => {
|
|
@@ -21,6 +21,7 @@ export interface UtxoEngineState {
|
|
|
21
21
|
getServerList: () => string[];
|
|
22
22
|
setServerList: (serverList: string[]) => void;
|
|
23
23
|
loadWifs: (wifs: string[]) => Promise<void>;
|
|
24
|
+
processUtxos: (utxos: IUTXO[]) => Promise<void>;
|
|
24
25
|
}
|
|
25
26
|
export interface UtxoEngineStateConfig extends EngineConfig {
|
|
26
27
|
walletTools: UTXOPluginWalletTools;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edge-currency-plugins",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.5",
|
|
4
4
|
"description": "Edge currency plugins to fetch and process wallet accounts, balances and transactions.",
|
|
5
5
|
"repository": "https://github.com/EdgeApp/edge-currency-plugins",
|
|
6
6
|
"license": "MIT",
|