edge-currency-plugins 3.3.1 → 3.3.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.
|
@@ -128,9 +128,14 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
|
|
|
128
128
|
emitter,
|
|
129
129
|
log
|
|
130
130
|
})
|
|
131
|
+
|
|
131
132
|
const dataLayer = await _DataLayer.makeDataLayer.call(void 0, {
|
|
132
133
|
disklet: walletLocalDisklet
|
|
133
134
|
})
|
|
135
|
+
// This is a temporary data layer used only once (i.e. nonce) for sweeping
|
|
136
|
+
// private keys.
|
|
137
|
+
let nonceDataLayer
|
|
138
|
+
|
|
134
139
|
const engineProcessor = _UtxoEngineProcessor.makeUtxoEngineProcessor.call(void 0, {
|
|
135
140
|
...config,
|
|
136
141
|
walletTools,
|
|
@@ -509,6 +514,10 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
|
|
|
509
514
|
},
|
|
510
515
|
|
|
511
516
|
async makeSpend(edgeSpendInfo) {
|
|
517
|
+
// Define which DatLayer is used for the spend:
|
|
518
|
+
const makeSpendDataLayer = _nullishCoalesce(nonceDataLayer, () => ( dataLayer))
|
|
519
|
+
if (nonceDataLayer != null) nonceDataLayer = undefined
|
|
520
|
+
|
|
512
521
|
edgeSpendInfo = _upgradeMemos.upgradeMemos.call(void 0, edgeSpendInfo, currencyInfo)
|
|
513
522
|
const { memos = [], spendTargets } = edgeSpendInfo
|
|
514
523
|
const spendInfoOtherParams = _types7.asUtxoSpendInfoOtherParams.call(void 0,
|
|
@@ -537,7 +546,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
|
|
|
537
546
|
const utxos =
|
|
538
547
|
await _asyncNullishCoalesce(txOptions.utxos, async () => (
|
|
539
548
|
_filterUndefined.filterUndefined.call(void 0,
|
|
540
|
-
(await
|
|
549
|
+
(await makeSpendDataLayer.fetchUtxos({
|
|
541
550
|
scriptPubkey: utxoScriptPubkey,
|
|
542
551
|
utxoIds: []
|
|
543
552
|
}))
|
|
@@ -578,7 +587,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
|
|
|
578
587
|
const scriptPubkey = walletTools.addressToScriptPubkey(
|
|
579
588
|
target.publicAddress
|
|
580
589
|
)
|
|
581
|
-
if ((await
|
|
590
|
+
if ((await makeSpendDataLayer.fetchAddress(scriptPubkey)) != null) {
|
|
582
591
|
ourReceiveAddresses.push(target.publicAddress)
|
|
583
592
|
}
|
|
584
593
|
}
|
|
@@ -606,13 +615,15 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
|
|
|
606
615
|
|
|
607
616
|
let maxUtxo
|
|
608
617
|
if (txOptions.CPFP != null) {
|
|
609
|
-
const [childTx] = await
|
|
618
|
+
const [childTx] = await makeSpendDataLayer.fetchTransactions({
|
|
610
619
|
txId: txOptions.CPFP
|
|
611
620
|
})
|
|
612
621
|
if (childTx == null) throw new Error('transaction not found')
|
|
613
622
|
const utxos = []
|
|
614
623
|
for (const txid of childTx.ourOuts) {
|
|
615
|
-
const [output] = await
|
|
624
|
+
const [output] = await makeSpendDataLayer.fetchUtxos({
|
|
625
|
+
utxoIds: [txid]
|
|
626
|
+
})
|
|
616
627
|
if (output != null) utxos.push(output)
|
|
617
628
|
}
|
|
618
629
|
maxUtxo = utxos.reduce((a, b) => (bs.gt(a.value, b.value) ? a : b))
|
|
@@ -654,7 +665,7 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
|
|
|
654
665
|
)
|
|
655
666
|
for (const output of tx.outputs) {
|
|
656
667
|
const scriptPubkey = output.scriptPubkey.toString('hex')
|
|
657
|
-
const own = await
|
|
668
|
+
const own = await makeSpendDataLayer.fetchAddress(scriptPubkey)
|
|
658
669
|
if (own == null) {
|
|
659
670
|
// Not our output
|
|
660
671
|
nativeAmount = bs.sub(nativeAmount, output.value.toString())
|
|
@@ -896,16 +907,6 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
|
|
|
896
907
|
},
|
|
897
908
|
|
|
898
909
|
async sweepPrivateKeys(spendInfo) {
|
|
899
|
-
// Create the promise to return
|
|
900
|
-
let success
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
let failure
|
|
904
|
-
const end = new Promise((resolve, reject) => {
|
|
905
|
-
success = resolve
|
|
906
|
-
failure = reject
|
|
907
|
-
})
|
|
908
|
-
|
|
909
910
|
// The temporary wallet info should include all formats for the currency
|
|
910
911
|
const allFormats = engineInfo.formats
|
|
911
912
|
|
|
@@ -940,37 +941,47 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
|
|
|
940
941
|
publicKey: tmpWalletInfo.keys.publicKey
|
|
941
942
|
})
|
|
942
943
|
|
|
943
|
-
//
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
944
|
+
// Wait for the imported wallet to finish syncing then create an
|
|
945
|
+
// EdgeTransaction using the imported wallet's balance.
|
|
946
|
+
const sweepTxPromise = new Promise((resolve, reject) => {
|
|
947
|
+
// Max spend after imported wallet finishes sync
|
|
948
|
+
tmpEmitter.on(_EngineEmitter.EngineEvent.ADDRESSES_CHECKED, async (ratio) => {
|
|
949
|
+
if (ratio === 1) {
|
|
950
|
+
try {
|
|
951
|
+
await tmpEngineProcessor.stop()
|
|
952
|
+
|
|
953
|
+
const tmpUtxos = (await tmpDataLayer.fetchUtxos({
|
|
954
|
+
utxoIds: []
|
|
955
|
+
}))
|
|
956
|
+
if (tmpUtxos === null || tmpUtxos.length < 1) {
|
|
957
|
+
throw new Error('Private key has no funds')
|
|
958
|
+
}
|
|
959
|
+
const destAddress = await this.getFreshAddress({
|
|
960
|
+
tokenId: null
|
|
961
|
+
})
|
|
962
|
+
const nativeAmount = tmpMetadata.state.balance
|
|
963
|
+
const txOptions = {
|
|
964
|
+
utxos: tmpUtxos,
|
|
965
|
+
subtractFee: true
|
|
966
|
+
}
|
|
967
|
+
spendInfo.spendTargets = [
|
|
968
|
+
{ publicAddress: destAddress.publicAddress, nativeAmount }
|
|
969
|
+
]
|
|
970
|
+
spendInfo.otherParams = {
|
|
971
|
+
...spendInfo.otherParams,
|
|
972
|
+
txOptions
|
|
973
|
+
}
|
|
974
|
+
nonceDataLayer = tmpDataLayer
|
|
975
|
+
const tx = await engine.makeSpend(spendInfo)
|
|
976
|
+
resolve(tx)
|
|
977
|
+
} catch (e) {
|
|
978
|
+
reject(e)
|
|
964
979
|
}
|
|
965
|
-
const tx = await this.makeSpend(spendInfo)
|
|
966
|
-
success(tx)
|
|
967
|
-
} catch (e) {
|
|
968
|
-
failure(e)
|
|
969
980
|
}
|
|
970
|
-
}
|
|
981
|
+
})
|
|
971
982
|
})
|
|
972
983
|
|
|
973
|
-
const
|
|
984
|
+
const tmpEngineProcessor = _UtxoEngineProcessor.makeUtxoEngineProcessor.call(void 0, {
|
|
974
985
|
...config,
|
|
975
986
|
options: {
|
|
976
987
|
...config.options,
|
|
@@ -990,10 +1001,10 @@ var _UtxoWalletTools = require('./UtxoWalletTools');
|
|
|
990
1001
|
walletTools: tmpWalletTools,
|
|
991
1002
|
walletInfo: tmpWalletInfo
|
|
992
1003
|
})
|
|
993
|
-
await
|
|
994
|
-
await
|
|
1004
|
+
await tmpEngineProcessor.loadWifs(privateKeys)
|
|
1005
|
+
await tmpEngineProcessor.start()
|
|
995
1006
|
|
|
996
|
-
return await
|
|
1007
|
+
return await sweepTxPromise
|
|
997
1008
|
},
|
|
998
1009
|
|
|
999
1010
|
otherMethods: {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edge-currency-plugins",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.2",
|
|
4
4
|
"description": "Edge currency plugins to fetch and process wallet accounts, balances and transactions.",
|
|
5
5
|
"homepage": "https://edge.app/",
|
|
6
6
|
"repository": "https://github.com/EdgeApp/edge-currency-plugins",
|