edge-currency-monero 1.4.2 → 1.5.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/CHANGELOG.md +3 -1
- package/lib/MoneroEngine.js +37 -27
- package/lib/MyMoneroApi.js +9 -13
- package/lib/react-native/edge-currency-monero.ts +54 -38
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/lib/MoneroEngine.js
CHANGED
|
@@ -601,10 +601,14 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
|
|
|
601
601
|
}
|
|
602
602
|
|
|
603
603
|
const options = {
|
|
604
|
-
amount: '0',
|
|
605
604
|
isSweepTx: true,
|
|
606
605
|
priority: translateFee(edgeSpendInfo.networkFeeOption),
|
|
607
|
-
|
|
606
|
+
targets: [
|
|
607
|
+
{
|
|
608
|
+
amount: '0',
|
|
609
|
+
targetAddress: publicAddress
|
|
610
|
+
}
|
|
611
|
+
]
|
|
608
612
|
}
|
|
609
613
|
|
|
610
614
|
const result = await this.createMyMoneroTransaction(options, privateKeys)
|
|
@@ -642,39 +646,45 @@ const PRIMARY_CURRENCY_TOKEN_ID = null
|
|
|
642
646
|
const { memos = [] } = edgeSpendInfo
|
|
643
647
|
const privateKeys = _moneroTypes.asPrivateKeys.call(void 0, _optionalChain([opts, 'optionalAccess', _7 => _7.privateKeys]))
|
|
644
648
|
|
|
645
|
-
|
|
646
|
-
// TODO: The new SDK fixes this!
|
|
647
|
-
if (edgeSpendInfo.spendTargets.length !== 1) {
|
|
648
|
-
throw new Error('Error: only one output allowed')
|
|
649
|
-
}
|
|
649
|
+
const { spendTargets } = edgeSpendInfo
|
|
650
650
|
|
|
651
|
-
|
|
652
|
-
const
|
|
653
|
-
if (publicAddress == null) {
|
|
654
|
-
throw new TypeError('Missing destination address')
|
|
655
|
-
}
|
|
656
|
-
if (nativeAmount == null || _biggystring.eq.call(void 0, nativeAmount, '0')) {
|
|
657
|
-
throw new (0, _types.NoAmountSpecifiedError)()
|
|
658
|
-
}
|
|
651
|
+
let totalAmount = '0'
|
|
652
|
+
const targets = []
|
|
659
653
|
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
throw new (0, _types.PendingFundsError)()
|
|
668
|
-
} else {
|
|
669
|
-
throw new (0, _types.InsufficientFundsError)({ tokenId: PRIMARY_CURRENCY_TOKEN_ID })
|
|
654
|
+
for (const spendTarget of spendTargets) {
|
|
655
|
+
const { publicAddress, nativeAmount } = spendTarget
|
|
656
|
+
if (publicAddress == null) {
|
|
657
|
+
throw new TypeError('Missing destination address')
|
|
658
|
+
}
|
|
659
|
+
if (nativeAmount == null || _biggystring.eq.call(void 0, nativeAmount, '0')) {
|
|
660
|
+
throw new (0, _types.NoAmountSpecifiedError)()
|
|
670
661
|
}
|
|
662
|
+
totalAmount = _biggystring.add.call(void 0, totalAmount, nativeAmount)
|
|
663
|
+
if (
|
|
664
|
+
_biggystring.gte.call(void 0,
|
|
665
|
+
totalAmount,
|
|
666
|
+
_nullishCoalesce(this.walletLocalData.totalBalances.get(PRIMARY_CURRENCY_TOKEN_ID), () => (
|
|
667
|
+
'0'))
|
|
668
|
+
)
|
|
669
|
+
) {
|
|
670
|
+
if (_biggystring.gte.call(void 0, this.walletLocalData.lockedXmrBalance, totalAmount)) {
|
|
671
|
+
throw new (0, _types.PendingFundsError)()
|
|
672
|
+
} else {
|
|
673
|
+
throw new (0, _types.InsufficientFundsError)({
|
|
674
|
+
tokenId: PRIMARY_CURRENCY_TOKEN_ID
|
|
675
|
+
})
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
targets.push({
|
|
679
|
+
amount: _biggystring.div.call(void 0, nativeAmount, '1000000000000', 12),
|
|
680
|
+
targetAddress: publicAddress
|
|
681
|
+
})
|
|
671
682
|
}
|
|
672
683
|
|
|
673
684
|
const options = {
|
|
674
|
-
amount: _biggystring.div.call(void 0, nativeAmount, '1000000000000', 12),
|
|
675
685
|
isSweepTx: false,
|
|
676
686
|
priority: translateFee(edgeSpendInfo.networkFeeOption),
|
|
677
|
-
|
|
687
|
+
targets
|
|
678
688
|
}
|
|
679
689
|
this.log(`Creating transaction: ${JSON.stringify(options, null, 1)}`)
|
|
680
690
|
|
package/lib/MyMoneroApi.js
CHANGED
|
@@ -48,6 +48,8 @@ var _ResponseParser = require('./mymonero-utils/ResponseParser'); var _ResponseP
|
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
|
|
51
|
+
|
|
52
|
+
|
|
51
53
|
|
|
52
54
|
|
|
53
55
|
|
|
@@ -238,13 +240,7 @@ const asGetAddressTxsResponse = _cleaners.asObject.call(void 0, {
|
|
|
238
240
|
opts
|
|
239
241
|
) {
|
|
240
242
|
const { address, privateSpendKey, privateViewKey, publicSpendKey } = keys
|
|
241
|
-
const {
|
|
242
|
-
amount,
|
|
243
|
-
isSweepTx = false,
|
|
244
|
-
paymentId,
|
|
245
|
-
priority = 1,
|
|
246
|
-
targetAddress
|
|
247
|
-
} = opts
|
|
243
|
+
const { isSweepTx = false, paymentId, priority = 1, targets } = opts
|
|
248
244
|
|
|
249
245
|
// Grab the UTXO set:
|
|
250
246
|
const unspentOuts = await this.fetchPostMyMonero('get_unspent_outs', {
|
|
@@ -268,14 +264,14 @@ const asGetAddressTxsResponse = _cleaners.asObject.call(void 0, {
|
|
|
268
264
|
})
|
|
269
265
|
}
|
|
270
266
|
|
|
267
|
+
const destinations = targets.map(t => ({
|
|
268
|
+
send_amount: t.amount,
|
|
269
|
+
to_address: t.targetAddress
|
|
270
|
+
}))
|
|
271
|
+
|
|
271
272
|
// Make the transaction:
|
|
272
273
|
return await this.cppBridge.createTransaction({
|
|
273
|
-
destinations
|
|
274
|
-
{
|
|
275
|
-
send_amount: amount,
|
|
276
|
-
to_address: targetAddress
|
|
277
|
-
}
|
|
278
|
-
],
|
|
274
|
+
destinations,
|
|
279
275
|
priority,
|
|
280
276
|
address,
|
|
281
277
|
paymentId,
|
|
@@ -2836,10 +2836,12 @@ var MoneroEngine = /*#__PURE__*/function () {
|
|
|
2836
2836
|
|
|
2837
2837
|
case 5:
|
|
2838
2838
|
options = {
|
|
2839
|
-
amount: '0',
|
|
2840
2839
|
isSweepTx: true,
|
|
2841
2840
|
priority: translateFee(edgeSpendInfo.networkFeeOption),
|
|
2842
|
-
|
|
2841
|
+
targets: [{
|
|
2842
|
+
amount: '0',
|
|
2843
|
+
targetAddress: publicAddress
|
|
2844
|
+
}]
|
|
2843
2845
|
};
|
|
2844
2846
|
_context20.next = 8;
|
|
2845
2847
|
return this.createMyMoneroTransaction(options, privateKeys);
|
|
@@ -2911,74 +2913,85 @@ var MoneroEngine = /*#__PURE__*/function () {
|
|
|
2911
2913
|
key: "makeSpend",
|
|
2912
2914
|
value: function () {
|
|
2913
2915
|
var _makeSpend = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee22(edgeSpendInfo, opts) {
|
|
2914
|
-
var _this$walletLocalData8;
|
|
2915
|
-
|
|
2916
|
-
var _edgeSpendInfo$memos, memos, privateKeys, _edgeSpendInfo$spendT2, spendTarget, publicAddress, nativeAmount, options, result, date, edgeTransaction;
|
|
2916
|
+
var _edgeSpendInfo$memos, memos, privateKeys, spendTargets, totalAmount, targets, _i4, _this$walletLocalData8, spendTarget, publicAddress, nativeAmount, options, result, date, edgeTransaction;
|
|
2917
2917
|
|
|
2918
2918
|
return regeneratorRuntime.wrap(function _callee22$(_context22) {
|
|
2919
2919
|
while (1) {
|
|
2920
2920
|
switch (_context22.prev = _context22.next) {
|
|
2921
2921
|
case 0:
|
|
2922
2922
|
_edgeSpendInfo$memos = edgeSpendInfo.memos, memos = _edgeSpendInfo$memos === void 0 ? [] : _edgeSpendInfo$memos;
|
|
2923
|
-
privateKeys = (0,_moneroTypes__WEBPACK_IMPORTED_MODULE_4__.asPrivateKeys)(opts === null || opts === void 0 ? void 0 : opts.privateKeys);
|
|
2924
|
-
|
|
2923
|
+
privateKeys = (0,_moneroTypes__WEBPACK_IMPORTED_MODULE_4__.asPrivateKeys)(opts === null || opts === void 0 ? void 0 : opts.privateKeys);
|
|
2924
|
+
spendTargets = edgeSpendInfo.spendTargets;
|
|
2925
|
+
totalAmount = '0';
|
|
2926
|
+
targets = [];
|
|
2927
|
+
_i4 = 0;
|
|
2925
2928
|
|
|
2926
|
-
|
|
2927
|
-
|
|
2929
|
+
case 6:
|
|
2930
|
+
if (!(_i4 < spendTargets.length)) {
|
|
2931
|
+
_context22.next = 24;
|
|
2928
2932
|
break;
|
|
2929
2933
|
}
|
|
2930
2934
|
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
case 4:
|
|
2934
|
-
_edgeSpendInfo$spendT2 = _slicedToArray(edgeSpendInfo.spendTargets, 1), spendTarget = _edgeSpendInfo$spendT2[0];
|
|
2935
|
+
spendTarget = spendTargets[_i4];
|
|
2935
2936
|
publicAddress = spendTarget.publicAddress, nativeAmount = spendTarget.nativeAmount;
|
|
2936
2937
|
|
|
2937
2938
|
if (!(publicAddress == null)) {
|
|
2938
|
-
_context22.next =
|
|
2939
|
+
_context22.next = 11;
|
|
2939
2940
|
break;
|
|
2940
2941
|
}
|
|
2941
2942
|
|
|
2942
2943
|
throw new TypeError('Missing destination address');
|
|
2943
2944
|
|
|
2944
|
-
case
|
|
2945
|
+
case 11:
|
|
2945
2946
|
if (!(nativeAmount == null || (0,biggystring__WEBPACK_IMPORTED_MODULE_0__.eq)(nativeAmount, '0'))) {
|
|
2946
|
-
_context22.next =
|
|
2947
|
+
_context22.next = 13;
|
|
2947
2948
|
break;
|
|
2948
2949
|
}
|
|
2949
2950
|
|
|
2950
2951
|
throw new edge_core_js_types__WEBPACK_IMPORTED_MODULE_1__.NoAmountSpecifiedError();
|
|
2951
2952
|
|
|
2952
|
-
case
|
|
2953
|
-
|
|
2954
|
-
|
|
2953
|
+
case 13:
|
|
2954
|
+
totalAmount = (0,biggystring__WEBPACK_IMPORTED_MODULE_0__.add)(totalAmount, nativeAmount);
|
|
2955
|
+
|
|
2956
|
+
if (!(0,biggystring__WEBPACK_IMPORTED_MODULE_0__.gte)(totalAmount, (_this$walletLocalData8 = this.walletLocalData.totalBalances.get(PRIMARY_CURRENCY_TOKEN_ID)) !== null && _this$walletLocalData8 !== void 0 ? _this$walletLocalData8 : '0')) {
|
|
2957
|
+
_context22.next = 20;
|
|
2955
2958
|
break;
|
|
2956
2959
|
}
|
|
2957
2960
|
|
|
2958
|
-
if (!(0,biggystring__WEBPACK_IMPORTED_MODULE_0__.gte)(this.walletLocalData.lockedXmrBalance,
|
|
2959
|
-
_context22.next =
|
|
2961
|
+
if (!(0,biggystring__WEBPACK_IMPORTED_MODULE_0__.gte)(this.walletLocalData.lockedXmrBalance, totalAmount)) {
|
|
2962
|
+
_context22.next = 19;
|
|
2960
2963
|
break;
|
|
2961
2964
|
}
|
|
2962
2965
|
|
|
2963
2966
|
throw new edge_core_js_types__WEBPACK_IMPORTED_MODULE_1__.PendingFundsError();
|
|
2964
2967
|
|
|
2965
|
-
case
|
|
2968
|
+
case 19:
|
|
2966
2969
|
throw new edge_core_js_types__WEBPACK_IMPORTED_MODULE_1__.InsufficientFundsError({
|
|
2967
2970
|
tokenId: PRIMARY_CURRENCY_TOKEN_ID
|
|
2968
2971
|
});
|
|
2969
2972
|
|
|
2970
|
-
case
|
|
2971
|
-
|
|
2973
|
+
case 20:
|
|
2974
|
+
targets.push({
|
|
2972
2975
|
amount: (0,biggystring__WEBPACK_IMPORTED_MODULE_0__.div)(nativeAmount, '1000000000000', 12),
|
|
2976
|
+
targetAddress: publicAddress
|
|
2977
|
+
});
|
|
2978
|
+
|
|
2979
|
+
case 21:
|
|
2980
|
+
_i4++;
|
|
2981
|
+
_context22.next = 6;
|
|
2982
|
+
break;
|
|
2983
|
+
|
|
2984
|
+
case 24:
|
|
2985
|
+
options = {
|
|
2973
2986
|
isSweepTx: false,
|
|
2974
2987
|
priority: translateFee(edgeSpendInfo.networkFeeOption),
|
|
2975
|
-
|
|
2988
|
+
targets: targets
|
|
2976
2989
|
};
|
|
2977
2990
|
this.log("Creating transaction: ".concat(JSON.stringify(options, null, 1)));
|
|
2978
|
-
_context22.next =
|
|
2991
|
+
_context22.next = 28;
|
|
2979
2992
|
return this.createMyMoneroTransaction(options, privateKeys);
|
|
2980
2993
|
|
|
2981
|
-
case
|
|
2994
|
+
case 28:
|
|
2982
2995
|
result = _context22.sent;
|
|
2983
2996
|
date = Date.now() / 1000;
|
|
2984
2997
|
this.log("Total sent: ".concat(result.total_sent, ", Fee: ").concat(result.used_fee));
|
|
@@ -3007,7 +3020,7 @@ var MoneroEngine = /*#__PURE__*/function () {
|
|
|
3007
3020
|
this.log.warn("makeSpend edgeTransaction ".concat((0,_utils__WEBPACK_IMPORTED_MODULE_6__.cleanTxLogs)(edgeTransaction)));
|
|
3008
3021
|
return _context22.abrupt("return", edgeTransaction);
|
|
3009
3022
|
|
|
3010
|
-
case
|
|
3023
|
+
case 34:
|
|
3011
3024
|
case "end":
|
|
3012
3025
|
return _context22.stop();
|
|
3013
3026
|
}
|
|
@@ -3969,14 +3982,14 @@ var MyMoneroApi = /*#__PURE__*/function () {
|
|
|
3969
3982
|
var _createTransaction = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(keys, opts) {
|
|
3970
3983
|
var _this = this;
|
|
3971
3984
|
|
|
3972
|
-
var address, privateSpendKey, privateViewKey, publicSpendKey,
|
|
3985
|
+
var address, privateSpendKey, privateViewKey, publicSpendKey, _opts$isSweepTx, isSweepTx, paymentId, _opts$priority, priority, targets, unspentOuts, randomOutsCb, destinations;
|
|
3973
3986
|
|
|
3974
3987
|
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
3975
3988
|
while (1) {
|
|
3976
3989
|
switch (_context5.prev = _context5.next) {
|
|
3977
3990
|
case 0:
|
|
3978
3991
|
address = keys.address, privateSpendKey = keys.privateSpendKey, privateViewKey = keys.privateViewKey, publicSpendKey = keys.publicSpendKey;
|
|
3979
|
-
|
|
3992
|
+
_opts$isSweepTx = opts.isSweepTx, isSweepTx = _opts$isSweepTx === void 0 ? false : _opts$isSweepTx, paymentId = opts.paymentId, _opts$priority = opts.priority, priority = _opts$priority === void 0 ? 1 : _opts$priority, targets = opts.targets; // Grab the UTXO set:
|
|
3980
3993
|
|
|
3981
3994
|
_context5.next = 4;
|
|
3982
3995
|
return this.fetchPostMyMonero('get_unspent_outs', {
|
|
@@ -4027,15 +4040,18 @@ var MyMoneroApi = /*#__PURE__*/function () {
|
|
|
4027
4040
|
return function randomOutsCb(_x6) {
|
|
4028
4041
|
return _ref.apply(this, arguments);
|
|
4029
4042
|
};
|
|
4030
|
-
}();
|
|
4043
|
+
}();
|
|
4031
4044
|
|
|
4045
|
+
destinations = targets.map(function (t) {
|
|
4046
|
+
return {
|
|
4047
|
+
send_amount: t.amount,
|
|
4048
|
+
to_address: t.targetAddress
|
|
4049
|
+
};
|
|
4050
|
+
}); // Make the transaction:
|
|
4032
4051
|
|
|
4033
|
-
_context5.next =
|
|
4052
|
+
_context5.next = 9;
|
|
4034
4053
|
return this.cppBridge.createTransaction({
|
|
4035
|
-
destinations:
|
|
4036
|
-
send_amount: amount,
|
|
4037
|
-
to_address: targetAddress
|
|
4038
|
-
}],
|
|
4054
|
+
destinations: destinations,
|
|
4039
4055
|
priority: priority,
|
|
4040
4056
|
address: address,
|
|
4041
4057
|
paymentId: paymentId,
|
|
@@ -4048,10 +4064,10 @@ var MyMoneroApi = /*#__PURE__*/function () {
|
|
|
4048
4064
|
randomOutsCb: randomOutsCb
|
|
4049
4065
|
});
|
|
4050
4066
|
|
|
4051
|
-
case
|
|
4067
|
+
case 9:
|
|
4052
4068
|
return _context5.abrupt("return", _context5.sent);
|
|
4053
4069
|
|
|
4054
|
-
case
|
|
4070
|
+
case 10:
|
|
4055
4071
|
case "end":
|
|
4056
4072
|
return _context5.stop();
|
|
4057
4073
|
}
|