edge-currency-plugins 1.2.3 → 1.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/lib/common/utxobased/db/Models/ProcessorTransaction.js +4 -2
- package/lib/common/utxobased/engine/makeUtxoEngine.js +26 -6
- package/lib/common/utxobased/engine/makeUtxoEngineState.js +82 -11
- package/lib/src/common/utxobased/db/Models/ProcessorTransaction.d.ts +1 -0
- package/lib/src/common/utxobased/engine/makeUtxoEngineState.d.ts +5 -1
- package/package.json +2 -2
|
@@ -58,10 +58,11 @@ var _keymanager = require('../../keymanager/keymanager');
|
|
|
58
58
|
|
|
59
59
|
|
|
60
60
|
|
|
61
|
+
|
|
61
62
|
const toEdgeTransaction = async (
|
|
62
63
|
args
|
|
63
64
|
) => {
|
|
64
|
-
const { tx, processor, walletTools, pluginInfo } = args
|
|
65
|
+
const { tx, processor, walletTools, pluginInfo, walletId } = args
|
|
65
66
|
const { engineInfo, currencyInfo } = pluginInfo
|
|
66
67
|
const ourReceiveAddresses = []
|
|
67
68
|
for (const out of tx.ourOuts) {
|
|
@@ -69,7 +70,7 @@ var _keymanager = require('../../keymanager/keymanager');
|
|
|
69
70
|
const address = await processor.fetchAddress(scriptPubkey)
|
|
70
71
|
|
|
71
72
|
/*
|
|
72
|
-
Hack to set replay protection tx to the correct script type through the
|
|
73
|
+
Hack to set replay protection tx to the correct script type through the
|
|
73
74
|
address format.
|
|
74
75
|
|
|
75
76
|
We use a function which can determine whether the derivationLevelScriptHash
|
|
@@ -114,6 +115,7 @@ var _keymanager = require('../../keymanager/keymanager');
|
|
|
114
115
|
} catch (e) {}
|
|
115
116
|
|
|
116
117
|
return {
|
|
118
|
+
walletId,
|
|
117
119
|
currencyCode: currencyInfo.currencyCode,
|
|
118
120
|
txid: tx.txid,
|
|
119
121
|
blockHeight: tx.blockHeight,
|
|
@@ -13,6 +13,7 @@ var _disklet = require('disklet');
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
|
|
16
17
|
var _types = require('edge-core-js/types');
|
|
17
18
|
|
|
18
19
|
var _filterUndefined = require('../../../util/filterUndefined');
|
|
@@ -227,9 +228,10 @@ var _utils = require('./utils');
|
|
|
227
228
|
},
|
|
228
229
|
|
|
229
230
|
async getFreshAddress(
|
|
230
|
-
|
|
231
|
+
opts
|
|
231
232
|
) {
|
|
232
|
-
|
|
233
|
+
const { forceIndex } = opts
|
|
234
|
+
return await engineState.getFreshAddress({ forceIndex })
|
|
233
235
|
},
|
|
234
236
|
|
|
235
237
|
getNumTransactions(_opts) {
|
|
@@ -260,6 +262,7 @@ var _utils = require('./utils');
|
|
|
260
262
|
txs.map(
|
|
261
263
|
async (tx) =>
|
|
262
264
|
await _ProcessorTransaction.toEdgeTransaction.call(void 0, {
|
|
265
|
+
walletId: walletInfo.id,
|
|
263
266
|
tx,
|
|
264
267
|
walletTools,
|
|
265
268
|
processor,
|
|
@@ -281,7 +284,13 @@ var _utils = require('./utils');
|
|
|
281
284
|
options
|
|
282
285
|
) {
|
|
283
286
|
const { spendTargets } = edgeSpendInfo
|
|
284
|
-
const { outputSort = 'bip69'
|
|
287
|
+
const { outputSort = 'bip69', utxoSourceAddress, forceChangeAddress } =
|
|
288
|
+
_nullishCoalesce(edgeSpendInfo.otherParams, () => ( {}))
|
|
289
|
+
|
|
290
|
+
let utxoScriptPubkey
|
|
291
|
+
if (utxoSourceAddress != null) {
|
|
292
|
+
utxoScriptPubkey = walletTools.addressToScriptPubkey(utxoSourceAddress)
|
|
293
|
+
}
|
|
285
294
|
|
|
286
295
|
if (_optionalChain([options, 'optionalAccess', _5 => _5.CPFP]) == null && spendTargets.length < 1) {
|
|
287
296
|
throw new Error('Need to provide Spend Targets')
|
|
@@ -293,7 +302,12 @@ var _utils = require('./utils');
|
|
|
293
302
|
)
|
|
294
303
|
const utxos =
|
|
295
304
|
await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async _6 => _6.utxos]), async () => (
|
|
296
|
-
|
|
305
|
+
_filterUndefined.filterUndefined.call(void 0,
|
|
306
|
+
(await processor.fetchUtxos({
|
|
307
|
+
scriptPubkey: utxoScriptPubkey,
|
|
308
|
+
utxoIds: []
|
|
309
|
+
}))
|
|
310
|
+
)))
|
|
297
311
|
|
|
298
312
|
if (
|
|
299
313
|
bs.gt(totalAmountToSend, `${_utils.sumUtxos.call(void 0, utxos)}`) ||
|
|
@@ -353,9 +367,12 @@ var _utils = require('./utils');
|
|
|
353
367
|
throw new Error('Need to provide Spend Targets')
|
|
354
368
|
}
|
|
355
369
|
|
|
356
|
-
const freshAddress = await engineState.getFreshAddress(1)
|
|
370
|
+
const freshAddress = await engineState.getFreshAddress({ branch: 1 })
|
|
357
371
|
const freshChangeAddress =
|
|
358
|
-
_nullishCoalesce(
|
|
372
|
+
_nullishCoalesce(_nullishCoalesce(forceChangeAddress, () => (
|
|
373
|
+
freshAddress.segwitAddress)), () => (
|
|
374
|
+
freshAddress.publicAddress))
|
|
375
|
+
|
|
359
376
|
const setRBF = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _9 => _9.setRBF]), () => ( false))
|
|
360
377
|
const rbfTxid = edgeSpendInfo.rbfTxid
|
|
361
378
|
let maxUtxo
|
|
@@ -443,6 +460,7 @@ var _utils = require('./utils');
|
|
|
443
460
|
}
|
|
444
461
|
|
|
445
462
|
const transaction = {
|
|
463
|
+
walletId: walletInfo.id,
|
|
446
464
|
ourReceiveAddresses,
|
|
447
465
|
otherParams,
|
|
448
466
|
currencyCode: currencyInfo.currencyCode,
|
|
@@ -480,6 +498,7 @@ var _utils = require('./utils');
|
|
|
480
498
|
async saveTx(edgeTx) {
|
|
481
499
|
const tx = _ProcessorTransaction.fromEdgeTransaction.call(void 0, edgeTx)
|
|
482
500
|
await _makeUtxoEngineState.transactionChanged.call(void 0, {
|
|
501
|
+
walletId: walletInfo.id,
|
|
483
502
|
tx,
|
|
484
503
|
pluginInfo,
|
|
485
504
|
emitter,
|
|
@@ -568,6 +587,7 @@ var _utils = require('./utils');
|
|
|
568
587
|
transaction.signedTx,
|
|
569
588
|
transaction.currencyCode
|
|
570
589
|
)
|
|
590
|
+
if (transaction.otherParams == null) transaction.otherParams = {}
|
|
571
591
|
Object.assign(transaction.otherParams, {
|
|
572
592
|
paymentProtocolInfo: {
|
|
573
593
|
...paymentProtocolInfo,
|
|
@@ -84,6 +84,9 @@ var _utils3 = require('./utils');
|
|
|
84
84
|
|
|
85
85
|
|
|
86
86
|
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
87
90
|
|
|
88
91
|
|
|
89
92
|
|
|
@@ -332,28 +335,48 @@ var _utils3 = require('./utils');
|
|
|
332
335
|
running = false
|
|
333
336
|
},
|
|
334
337
|
|
|
335
|
-
async getFreshAddress(
|
|
338
|
+
async getFreshAddress({
|
|
339
|
+
branch = 0,
|
|
340
|
+
forceIndex
|
|
341
|
+
}) {
|
|
336
342
|
const walletPurpose = _utils3.currencyFormatToPurposeType.call(void 0,
|
|
337
343
|
walletInfo.keys.primaryFormat
|
|
338
344
|
)
|
|
339
345
|
if (walletPurpose === _keymanager.BIP43PurposeTypeEnum.Segwit) {
|
|
340
|
-
const {
|
|
346
|
+
const {
|
|
347
|
+
address: publicAddress,
|
|
348
|
+
nativeBalance = '0',
|
|
349
|
+
legacyAddress
|
|
350
|
+
} = await internalGetFreshAddress({
|
|
341
351
|
...commonArgs,
|
|
342
352
|
format: _utils3.getCurrencyFormatFromPurposeType.call(void 0,
|
|
343
353
|
_keymanager.BIP43PurposeTypeEnum.WrappedSegwit
|
|
344
354
|
),
|
|
355
|
+
forceIndex,
|
|
345
356
|
changeIndex: branch
|
|
346
357
|
})
|
|
347
358
|
|
|
348
|
-
const {
|
|
359
|
+
const {
|
|
360
|
+
address: segwitAddress,
|
|
361
|
+
nativeBalance: segwitNativeBalance = '0'
|
|
362
|
+
} = await internalGetFreshAddress({
|
|
349
363
|
...commonArgs,
|
|
350
364
|
format: _utils3.getCurrencyFormatFromPurposeType.call(void 0, _keymanager.BIP43PurposeTypeEnum.Segwit),
|
|
365
|
+
forceIndex,
|
|
351
366
|
changeIndex: branch
|
|
352
367
|
})
|
|
353
368
|
|
|
354
369
|
return {
|
|
370
|
+
nativeBalance,
|
|
355
371
|
publicAddress,
|
|
356
|
-
|
|
372
|
+
legacyNativeBalance:
|
|
373
|
+
legacyAddress !== publicAddress ? nativeBalance : undefined,
|
|
374
|
+
// Legacy address is just a different encoding of the standard public address
|
|
375
|
+
// and therefore would have the same balance
|
|
376
|
+
legacyAddress:
|
|
377
|
+
legacyAddress !== publicAddress ? legacyAddress : undefined,
|
|
378
|
+
segwitAddress,
|
|
379
|
+
segwitNativeBalance
|
|
357
380
|
}
|
|
358
381
|
} else {
|
|
359
382
|
// Airbitz wallets only use branch 0
|
|
@@ -363,15 +386,22 @@ var _utils3 = require('./utils');
|
|
|
363
386
|
|
|
364
387
|
const {
|
|
365
388
|
address: publicAddress,
|
|
389
|
+
nativeBalance = '0',
|
|
366
390
|
legacyAddress
|
|
367
391
|
} = await internalGetFreshAddress({
|
|
368
392
|
...commonArgs,
|
|
369
393
|
format: _utils3.getCurrencyFormatFromPurposeType.call(void 0, walletPurpose),
|
|
394
|
+
forceIndex,
|
|
370
395
|
changeIndex: branch
|
|
371
396
|
})
|
|
372
397
|
|
|
373
398
|
return {
|
|
399
|
+
nativeBalance,
|
|
374
400
|
publicAddress,
|
|
401
|
+
legacyNativeBalance:
|
|
402
|
+
legacyAddress !== publicAddress ? nativeBalance : undefined,
|
|
403
|
+
// Legacy address is just a different encoding of the standard public address
|
|
404
|
+
// and therefore would have the same balance
|
|
375
405
|
legacyAddress:
|
|
376
406
|
legacyAddress !== publicAddress ? legacyAddress : undefined
|
|
377
407
|
}
|
|
@@ -674,12 +704,14 @@ const addToAddressTransactionCache = async (
|
|
|
674
704
|
|
|
675
705
|
|
|
676
706
|
|
|
707
|
+
|
|
677
708
|
const transactionChanged = async (
|
|
678
709
|
args
|
|
679
710
|
) => {
|
|
680
|
-
const { emitter, walletTools, processor, pluginInfo, tx } = args
|
|
711
|
+
const { emitter, walletTools, processor, pluginInfo, tx, walletId } = args
|
|
681
712
|
emitter.emit(_makeEngineEmitter.EngineEvent.TRANSACTIONS_CHANGED, [
|
|
682
713
|
await _ProcessorTransaction.toEdgeTransaction.call(void 0, {
|
|
714
|
+
walletId,
|
|
683
715
|
tx,
|
|
684
716
|
walletTools,
|
|
685
717
|
processor,
|
|
@@ -930,7 +962,15 @@ const addToAddressTransactionCache = async (
|
|
|
930
962
|
const updateTransactionsSpecific = (
|
|
931
963
|
args
|
|
932
964
|
) => {
|
|
933
|
-
const {
|
|
965
|
+
const {
|
|
966
|
+
walletInfo,
|
|
967
|
+
emitter,
|
|
968
|
+
walletTools,
|
|
969
|
+
txId,
|
|
970
|
+
pluginInfo,
|
|
971
|
+
processor,
|
|
972
|
+
taskCache
|
|
973
|
+
} = args
|
|
934
974
|
const deferred = new _Deferred2.default()
|
|
935
975
|
deferred.promise
|
|
936
976
|
.then(async (txResponse) => {
|
|
@@ -950,6 +990,7 @@ const updateTransactionsSpecific = (
|
|
|
950
990
|
})
|
|
951
991
|
|
|
952
992
|
await exports.transactionChanged.call(void 0, {
|
|
993
|
+
walletId: walletInfo.id,
|
|
953
994
|
emitter,
|
|
954
995
|
walletTools,
|
|
955
996
|
processor,
|
|
@@ -977,6 +1018,7 @@ const updateTransactions = (
|
|
|
977
1018
|
args
|
|
978
1019
|
) => {
|
|
979
1020
|
const {
|
|
1021
|
+
walletInfo,
|
|
980
1022
|
emitter,
|
|
981
1023
|
walletTools,
|
|
982
1024
|
txId,
|
|
@@ -1012,6 +1054,7 @@ const updateTransactions = (
|
|
|
1012
1054
|
})
|
|
1013
1055
|
|
|
1014
1056
|
await exports.transactionChanged.call(void 0, {
|
|
1057
|
+
walletId: walletInfo.id,
|
|
1015
1058
|
emitter,
|
|
1016
1059
|
walletTools,
|
|
1017
1060
|
processor,
|
|
@@ -1098,10 +1141,19 @@ const internalDeriveScriptAddress = async ({
|
|
|
1098
1141
|
|
|
1099
1142
|
|
|
1100
1143
|
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
|
|
1101
1147
|
const internalGetFreshAddress = async (
|
|
1102
1148
|
args
|
|
1103
1149
|
) => {
|
|
1104
|
-
const {
|
|
1150
|
+
const {
|
|
1151
|
+
format,
|
|
1152
|
+
changeIndex: branch,
|
|
1153
|
+
walletTools,
|
|
1154
|
+
processor,
|
|
1155
|
+
forceIndex
|
|
1156
|
+
} = args
|
|
1105
1157
|
|
|
1106
1158
|
const numAddresses = processor.numAddressesByFormatPath({
|
|
1107
1159
|
format,
|
|
@@ -1117,16 +1169,33 @@ const internalGetFreshAddress = async (
|
|
|
1117
1169
|
0
|
|
1118
1170
|
)
|
|
1119
1171
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1172
|
+
if (forceIndex != null) {
|
|
1173
|
+
path.addressIndex = forceIndex
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
let nativeBalance = '0'
|
|
1177
|
+
let scriptPubkey
|
|
1178
|
+
const iAddress = await processor.fetchAddress(path)
|
|
1179
|
+
if (iAddress != null) {
|
|
1180
|
+
nativeBalance = iAddress.balance
|
|
1181
|
+
scriptPubkey = iAddress.scriptPubkey
|
|
1182
|
+
} else {
|
|
1183
|
+
const scriptPubKeyRet = await walletTools.getScriptPubkey(path)
|
|
1184
|
+
scriptPubkey = scriptPubKeyRet.scriptPubkey
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1123
1187
|
if (scriptPubkey == null) {
|
|
1124
1188
|
throw new Error('Unknown address path')
|
|
1125
1189
|
}
|
|
1126
|
-
|
|
1190
|
+
const address = walletTools.scriptPubkeyToAddress({
|
|
1127
1191
|
scriptPubkey,
|
|
1128
1192
|
format
|
|
1129
1193
|
})
|
|
1194
|
+
|
|
1195
|
+
return {
|
|
1196
|
+
...address,
|
|
1197
|
+
nativeBalance
|
|
1198
|
+
}
|
|
1130
1199
|
}
|
|
1131
1200
|
|
|
1132
1201
|
|
|
@@ -1140,6 +1209,7 @@ const processAddressTransactions = async (
|
|
|
1140
1209
|
args
|
|
1141
1210
|
) => {
|
|
1142
1211
|
const {
|
|
1212
|
+
walletInfo,
|
|
1143
1213
|
address,
|
|
1144
1214
|
addressTransactionState,
|
|
1145
1215
|
emitter,
|
|
@@ -1184,6 +1254,7 @@ const processAddressTransactions = async (
|
|
|
1184
1254
|
scriptPubkeys: [scriptPubkey]
|
|
1185
1255
|
})
|
|
1186
1256
|
await exports.transactionChanged.call(void 0, {
|
|
1257
|
+
walletId: walletInfo.id,
|
|
1187
1258
|
emitter,
|
|
1188
1259
|
walletTools,
|
|
1189
1260
|
processor,
|
|
@@ -5,6 +5,7 @@ import { Processor } from '../makeProcessor';
|
|
|
5
5
|
import { IProcessorTransaction } from '../types';
|
|
6
6
|
export declare const fromEdgeTransaction: (tx: EdgeTransaction) => IProcessorTransaction;
|
|
7
7
|
interface ToEdgeTransactionArgs {
|
|
8
|
+
walletId: string;
|
|
8
9
|
tx: IProcessorTransaction;
|
|
9
10
|
walletTools: UTXOPluginWalletTools;
|
|
10
11
|
processor: Processor;
|
|
@@ -14,7 +14,10 @@ export interface UtxoEngineState {
|
|
|
14
14
|
start: () => Promise<void>;
|
|
15
15
|
stop: () => Promise<void>;
|
|
16
16
|
deriveScriptAddress: (script: string) => Promise<EdgeFreshAddress>;
|
|
17
|
-
getFreshAddress: (
|
|
17
|
+
getFreshAddress: (params: {
|
|
18
|
+
branch?: number;
|
|
19
|
+
forceIndex?: number;
|
|
20
|
+
}) => Promise<EdgeFreshAddress>;
|
|
18
21
|
addGapLimitAddresses: (addresses: string[]) => Promise<void>;
|
|
19
22
|
broadcastTx: (transaction: EdgeTransaction) => Promise<string>;
|
|
20
23
|
refillServers: () => void;
|
|
@@ -101,6 +104,7 @@ interface AddressTransactionCache {
|
|
|
101
104
|
};
|
|
102
105
|
}
|
|
103
106
|
interface TransactionChangedArgs {
|
|
107
|
+
walletId: string;
|
|
104
108
|
tx: IProcessorTransaction;
|
|
105
109
|
emitter: EngineEmitter;
|
|
106
110
|
walletTools: UTXOPluginWalletTools;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edge-currency-plugins",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"bs58smartcheck": "^2.0.4",
|
|
49
49
|
"cleaners": "^0.3.12",
|
|
50
50
|
"disklet": "^0.4.5",
|
|
51
|
-
"edge-core-js": "^0.19.
|
|
51
|
+
"edge-core-js": "^0.19.33",
|
|
52
52
|
"edge-sync-client": "^0.2.7",
|
|
53
53
|
"memlet": "^0.1.6",
|
|
54
54
|
"uri-js": "^4.4.0",
|