edge-currency-monero 0.4.2 → 0.5.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.
- package/CHANGELOG.md +14 -2
- package/README.md +1 -2
- package/lib/MyMoneroApi.js +272 -0
- package/lib/mymonero-utils/ResponseParser.js +204 -0
- package/lib/mymonero-utils/mymonero-keyimage-cache.js +37 -0
- package/lib/react-native/edge-currency-monero.js +3944 -5687
- package/lib/react-native/edge-currency-monero.js.map +1 -1
- package/lib/react-native-io.js +4 -7
- package/lib/utils.js +0 -21
- package/lib/xmrEngine.js +71 -234
- package/lib/xmrPlugin.js +18 -25
- package/package.json +10 -9
- package/lib/mymonero/HostedMoneroAPIClient/BackgroundResponseParser.web.js +0 -119
- package/lib/mymonero/HostedMoneroAPIClient/HostedMoneroAPIClient.Lite.js +0 -42
- package/lib/mymonero/HostedMoneroAPIClient/HostedMoneroAPIClient_Base.js +0 -489
- package/lib/mymonero/MyMoneroApi.js +0 -306
- package/lib/mymonero/hostAPI/net_service_utils.js +0 -157
- package/lib/mymonero/hostAPI/response_parser_utils.js +0 -511
- package/lib/mymonero/monero_utils/monero_keyImage_cache_utils.js +0 -100
- package/lib/mymonero/monero_utils/monero_paymentID_utils.js +0 -76
- package/lib/mymonero/monero_utils/monero_sendingFunds_utils.js +0 -324
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
# edge-currency-monero
|
|
2
2
|
|
|
3
|
+
# 0.5.2 (2022-08-13)
|
|
4
|
+
|
|
5
|
+
- fixed: incorrect amounts after spend
|
|
6
|
+
|
|
7
|
+
# 0.5.1 (2022-08-13)
|
|
8
|
+
|
|
9
|
+
- fixed: Stop randomly crashing while sending funds.
|
|
10
|
+
|
|
11
|
+
# 0.5.0 (2022-08-11)
|
|
12
|
+
|
|
13
|
+
- changed: Upgrade to react-native-mymonero-core v0.2.0, with its new API.
|
|
14
|
+
|
|
3
15
|
# 0.4.2 (2022-08-03)
|
|
4
16
|
|
|
5
|
-
- Set `addressesChecked` to `false` on resync
|
|
17
|
+
- fixed: Set `addressesChecked` to `false` on resync
|
|
6
18
|
|
|
7
19
|
# 0.4.1 (2022-05-11)
|
|
8
20
|
|
|
9
|
-
- Fix syncing when the user settings are empty
|
|
21
|
+
- fixed: Fix syncing when the user settings are empty
|
|
10
22
|
|
|
11
23
|
# 0.4.0 (2022-01-11)
|
|
12
24
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# Edge Monero Currency Plugin
|
|
2
|
-
[![Build Status][travis-image]][travis-url] [![NPM version][npm-image]][npm-url] [![Dependency Status][daviddm-image]][daviddm-url]
|
|
3
2
|
|
|
4
|
-
[](https://app.travis-ci.com/EdgeApp/edge-currency-monero)
|
|
5
4
|
|
|
6
5
|
Implements Monero send/receive functionality per the spec for crypto currency plugins for [edge-core-js](https://github.com/EdgeApp/edge-core-js)
|
|
7
6
|
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const parserUtils = require('./mymonero-utils/ResponseParser.js')
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Brings together the mymonero server, JavaScript utilities,
|
|
54
|
+
* and native C++ methods into a coherent API.
|
|
55
|
+
*/
|
|
56
|
+
export class MyMoneroApi {
|
|
57
|
+
// Network options:
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
// Dependency injection:
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
// Maps from key identifiers (a bunch of concatenated stuff) to key images:
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
constructor(cppBridge, options) {
|
|
70
|
+
this.apiKey = options.apiKey
|
|
71
|
+
this.apiUrl = options.apiServer
|
|
72
|
+
this.nettype = _nullishCoalesce(options.nettype, () => ( 'MAINNET'))
|
|
73
|
+
|
|
74
|
+
this.fetch = options.fetch
|
|
75
|
+
this.cppBridge = cppBridge
|
|
76
|
+
|
|
77
|
+
this.keyImageCache = {}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async decodeAddress(address) {
|
|
81
|
+
return await this.cppBridge.decodeAddress(address, this.nettype)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async generateWallet(language = 'english') {
|
|
85
|
+
return await this.cppBridge.generateWallet(language, this.nettype)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async seedAndKeysFromMnemonic(mnemonic) {
|
|
89
|
+
return await this.cppBridge.seedAndKeysFromMnemonic(mnemonic, this.nettype)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Authenticates with the MyMonero light-wallet server.
|
|
94
|
+
*/
|
|
95
|
+
async login(keys) {
|
|
96
|
+
const { address, privateViewKey } = keys
|
|
97
|
+
const result = await this.fetchPostMyMonero('login', {
|
|
98
|
+
address: address,
|
|
99
|
+
api_key: this.apiKey,
|
|
100
|
+
create_account: true,
|
|
101
|
+
view_key: privateViewKey
|
|
102
|
+
})
|
|
103
|
+
// const asLogin = asObject({
|
|
104
|
+
// new_address: asBoolean,
|
|
105
|
+
// start_height: asNumber
|
|
106
|
+
// })
|
|
107
|
+
|
|
108
|
+
return result // TODO: Clean this
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async getTransactions(keys) {
|
|
112
|
+
const { address, privateSpendKey, privateViewKey, publicSpendKey } = keys
|
|
113
|
+
const result = await this.fetchPostMyMonero('get_address_txs', {
|
|
114
|
+
address,
|
|
115
|
+
api_key: this.apiKey,
|
|
116
|
+
view_key: privateViewKey
|
|
117
|
+
})
|
|
118
|
+
// asGetAddressTxs = asObject({
|
|
119
|
+
// blockchain_height: asNumber,
|
|
120
|
+
// scanned_block_height: asNumber,
|
|
121
|
+
// scanned_height: asNumber,
|
|
122
|
+
// start_height: asNumber,
|
|
123
|
+
// total_received: asString,
|
|
124
|
+
// transaction_height: asNumber,
|
|
125
|
+
// transactions: asArray(asObject({
|
|
126
|
+
// coinbase: asBoolean,
|
|
127
|
+
// hash: asString,
|
|
128
|
+
// height: asNumber,
|
|
129
|
+
// id: asNumber,
|
|
130
|
+
// mempool: asBoolean,
|
|
131
|
+
// mixin: asNumber,
|
|
132
|
+
// timestamp: asDate,
|
|
133
|
+
// total_received: asString,
|
|
134
|
+
// total_sent: asString,
|
|
135
|
+
// unlock_time: asNumber
|
|
136
|
+
// }))
|
|
137
|
+
// })
|
|
138
|
+
|
|
139
|
+
const parsed = await parserUtils.Parsed_AddressTransactions__async(
|
|
140
|
+
this.keyImageCache,
|
|
141
|
+
result,
|
|
142
|
+
address,
|
|
143
|
+
privateViewKey,
|
|
144
|
+
publicSpendKey,
|
|
145
|
+
privateSpendKey,
|
|
146
|
+
this.cppBridge
|
|
147
|
+
)
|
|
148
|
+
return parsed.serialized_transactions
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async getAddressInfo(keys) {
|
|
152
|
+
const { address, privateSpendKey, privateViewKey, publicSpendKey } = keys
|
|
153
|
+
const result = await this.fetchPostMyMonero('get_address_info', {
|
|
154
|
+
address,
|
|
155
|
+
api_key: this.apiKey,
|
|
156
|
+
view_key: privateViewKey
|
|
157
|
+
})
|
|
158
|
+
// const asAddressInfo = asObject({
|
|
159
|
+
// blockchain_height: asNumber,
|
|
160
|
+
// locked_funds: asString,
|
|
161
|
+
// rates: asObject(asNumber),
|
|
162
|
+
// scanned_block_height: asNumber,
|
|
163
|
+
// scanned_height: asNumber,
|
|
164
|
+
// spent_outputs: asArray(
|
|
165
|
+
// asObject({
|
|
166
|
+
// amount: asString,
|
|
167
|
+
// key_image: asString,
|
|
168
|
+
// mixin: asNumber,
|
|
169
|
+
// out_index: asNumber,
|
|
170
|
+
// tx_pub_key: asString
|
|
171
|
+
// })
|
|
172
|
+
// ),
|
|
173
|
+
// start_height: asNumber,
|
|
174
|
+
// total_received: asString,
|
|
175
|
+
// total_sent: asString,
|
|
176
|
+
// transaction_height: asNumber
|
|
177
|
+
// })
|
|
178
|
+
|
|
179
|
+
const parsed = await parserUtils.Parsed_AddressInfo__async(
|
|
180
|
+
this.keyImageCache,
|
|
181
|
+
result,
|
|
182
|
+
address,
|
|
183
|
+
privateViewKey,
|
|
184
|
+
publicSpendKey,
|
|
185
|
+
privateSpendKey,
|
|
186
|
+
this.cppBridge
|
|
187
|
+
)
|
|
188
|
+
return {
|
|
189
|
+
blockHeight: parsed.blockchain_height,
|
|
190
|
+
totalReceived: parsed.total_received_String,
|
|
191
|
+
lockedBalance: parsed.locked_balance_String,
|
|
192
|
+
totalSent: parsed.total_sent_String
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async createTransaction(
|
|
197
|
+
keys,
|
|
198
|
+
opts
|
|
199
|
+
) {
|
|
200
|
+
const { address, privateSpendKey, privateViewKey, publicSpendKey } = keys
|
|
201
|
+
const { amount, isSweepTx = false, priority = 1, targetAddress } = opts
|
|
202
|
+
|
|
203
|
+
// Grab the UTXO set:
|
|
204
|
+
const unspentOuts = await this.fetchPostMyMonero('get_unspent_outs', {
|
|
205
|
+
address,
|
|
206
|
+
amount: '0',
|
|
207
|
+
api_key: this.apiKey,
|
|
208
|
+
dust_threshold: '2000000000',
|
|
209
|
+
mixin: 10,
|
|
210
|
+
use_dust: true,
|
|
211
|
+
view_key: privateViewKey
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
// Grab some random outputs to mix in:
|
|
215
|
+
const randomOutsCb = async (count) => {
|
|
216
|
+
const amounts = []
|
|
217
|
+
for (let i = 0; i < count; ++i) amounts.push('0')
|
|
218
|
+
return await this.fetchPostMyMonero('get_random_outs', {
|
|
219
|
+
amounts,
|
|
220
|
+
api_key: this.apiKey,
|
|
221
|
+
count: 11
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Make the transaction:
|
|
226
|
+
return await this.cppBridge.createTransaction({
|
|
227
|
+
destinations: [
|
|
228
|
+
{
|
|
229
|
+
send_amount: amount,
|
|
230
|
+
to_address: targetAddress
|
|
231
|
+
}
|
|
232
|
+
],
|
|
233
|
+
priority,
|
|
234
|
+
address,
|
|
235
|
+
privateViewKey,
|
|
236
|
+
publicSpendKey,
|
|
237
|
+
privateSpendKey,
|
|
238
|
+
shouldSweep: isSweepTx,
|
|
239
|
+
nettype: this.nettype,
|
|
240
|
+
unspentOuts,
|
|
241
|
+
randomOutsCb
|
|
242
|
+
})
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async broadcastTransaction(tx) {
|
|
246
|
+
await this.fetchPostMyMonero('submit_raw_tx', {
|
|
247
|
+
api_key: this.apiKey,
|
|
248
|
+
tx
|
|
249
|
+
})
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Private routines
|
|
253
|
+
// ----------------
|
|
254
|
+
|
|
255
|
+
async fetchPostMyMonero(cmd, params) {
|
|
256
|
+
const url = `${this.apiUrl}/${cmd}`
|
|
257
|
+
const response = await this.fetch(url, {
|
|
258
|
+
body: JSON.stringify(params),
|
|
259
|
+
headers: {
|
|
260
|
+
'Content-Type': 'application/json',
|
|
261
|
+
Accept: 'application/json'
|
|
262
|
+
},
|
|
263
|
+
method: 'POST'
|
|
264
|
+
})
|
|
265
|
+
if (!response.ok) {
|
|
266
|
+
throw new Error(
|
|
267
|
+
`The server returned error code ${response.status} for ${url}`
|
|
268
|
+
)
|
|
269
|
+
}
|
|
270
|
+
return response.json()
|
|
271
|
+
}
|
|
272
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// This has been taken from @mymonero/mymonero-response-parser-utils v2.0.0
|
|
2
|
+
// We have made the "__sync" methods async and deleted the rest.
|
|
3
|
+
|
|
4
|
+
// Copyright (c) 2014-2019, MyMonero.com
|
|
5
|
+
//
|
|
6
|
+
// All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
// Redistribution and use in source and binary forms, with or without modification, are
|
|
9
|
+
// permitted provided that the following conditions are met:
|
|
10
|
+
//
|
|
11
|
+
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
12
|
+
// conditions and the following disclaimer.
|
|
13
|
+
//
|
|
14
|
+
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
15
|
+
// of conditions and the following disclaimer in the documentation and/or other
|
|
16
|
+
// materials provided with the distribution.
|
|
17
|
+
//
|
|
18
|
+
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
19
|
+
// used to endorse or promote products derived from this software without specific
|
|
20
|
+
// prior written permission.
|
|
21
|
+
//
|
|
22
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
23
|
+
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
24
|
+
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
25
|
+
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
26
|
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
27
|
+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
28
|
+
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
29
|
+
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
30
|
+
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
+
//
|
|
32
|
+
'use strict'
|
|
33
|
+
//
|
|
34
|
+
const JSBigInt = require('@mymonero/mymonero-bigint').BigInteger
|
|
35
|
+
const monero_amount_format_utils = require('@mymonero/mymonero-money-format')
|
|
36
|
+
const monero_keyImage_cache_utils = require("./mymonero-keyimage-cache.js")
|
|
37
|
+
//
|
|
38
|
+
async function Parsed_AddressInfo__async (
|
|
39
|
+
keyImage_cache,
|
|
40
|
+
data,
|
|
41
|
+
address,
|
|
42
|
+
view_key__private,
|
|
43
|
+
spend_key__public,
|
|
44
|
+
spend_key__private,
|
|
45
|
+
coreBridge_instance
|
|
46
|
+
) {
|
|
47
|
+
// -> returnValuesByKey
|
|
48
|
+
const total_received = new JSBigInt(data.total_received || 0)
|
|
49
|
+
const locked_balance = new JSBigInt(data.locked_funds || 0)
|
|
50
|
+
var total_sent = new JSBigInt(data.total_sent || 0) // will be modified in place
|
|
51
|
+
//
|
|
52
|
+
const account_scanned_tx_height = data.scanned_height || 0
|
|
53
|
+
const account_scanned_block_height = data.scanned_block_height || 0
|
|
54
|
+
const account_scan_start_height = data.start_height || 0
|
|
55
|
+
const transaction_height = data.transaction_height || 0
|
|
56
|
+
const blockchain_height = data.blockchain_height || 0
|
|
57
|
+
const spent_outputs = data.spent_outputs || []
|
|
58
|
+
//
|
|
59
|
+
for (let spent_output of spent_outputs) {
|
|
60
|
+
var key_image = await monero_keyImage_cache_utils.Lazy_KeyImage(
|
|
61
|
+
keyImage_cache,
|
|
62
|
+
spent_output.tx_pub_key,
|
|
63
|
+
spent_output.out_index,
|
|
64
|
+
address,
|
|
65
|
+
view_key__private,
|
|
66
|
+
spend_key__public,
|
|
67
|
+
spend_key__private,
|
|
68
|
+
coreBridge_instance
|
|
69
|
+
)
|
|
70
|
+
if (spent_output.key_image !== key_image) {
|
|
71
|
+
// console.log('💬 Output used as mixin (' + spent_output.key_image + '/' + key_image + ')')
|
|
72
|
+
total_sent = new JSBigInt(total_sent).subtract(spent_output.amount)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//
|
|
76
|
+
const ratesBySymbol = data.rates || {} // jic it's not there
|
|
77
|
+
//
|
|
78
|
+
const returnValuesByKey = {
|
|
79
|
+
total_received_String: total_received
|
|
80
|
+
? total_received.toString()
|
|
81
|
+
: null,
|
|
82
|
+
locked_balance_String: locked_balance
|
|
83
|
+
? locked_balance.toString()
|
|
84
|
+
: null,
|
|
85
|
+
total_sent_String: total_sent ? total_sent.toString() : null,
|
|
86
|
+
// ^serialized JSBigInt
|
|
87
|
+
spent_outputs: spent_outputs,
|
|
88
|
+
account_scanned_tx_height: account_scanned_tx_height,
|
|
89
|
+
account_scanned_block_height: account_scanned_block_height,
|
|
90
|
+
account_scan_start_height: account_scan_start_height,
|
|
91
|
+
transaction_height: transaction_height,
|
|
92
|
+
blockchain_height: blockchain_height,
|
|
93
|
+
//
|
|
94
|
+
ratesBySymbol: ratesBySymbol
|
|
95
|
+
}
|
|
96
|
+
return returnValuesByKey
|
|
97
|
+
}
|
|
98
|
+
exports.Parsed_AddressInfo__async = Parsed_AddressInfo__async
|
|
99
|
+
//
|
|
100
|
+
async function Parsed_AddressTransactions__async (
|
|
101
|
+
keyImage_cache,
|
|
102
|
+
data,
|
|
103
|
+
address,
|
|
104
|
+
view_key__private,
|
|
105
|
+
spend_key__public,
|
|
106
|
+
spend_key__private,
|
|
107
|
+
coreBridge_instance
|
|
108
|
+
) {
|
|
109
|
+
const account_scanned_height = data.scanned_height || 0
|
|
110
|
+
const account_scanned_block_height = data.scanned_block_height || 0
|
|
111
|
+
const account_scan_start_height = data.start_height || 0
|
|
112
|
+
const transaction_height = data.transaction_height || 0
|
|
113
|
+
const blockchain_height = data.blockchain_height || 0
|
|
114
|
+
//
|
|
115
|
+
const transactions = data.transactions || []
|
|
116
|
+
//
|
|
117
|
+
// TODO: rewrite this with more clarity if possible
|
|
118
|
+
for (let i = 0; i < transactions.length; ++i) {
|
|
119
|
+
if ((transactions[i].spent_outputs || []).length > 0) {
|
|
120
|
+
for (var j = 0; j < transactions[i].spent_outputs.length; ++j) {
|
|
121
|
+
var key_image = await monero_keyImage_cache_utils.Lazy_KeyImage(
|
|
122
|
+
keyImage_cache,
|
|
123
|
+
transactions[i].spent_outputs[j].tx_pub_key,
|
|
124
|
+
transactions[i].spent_outputs[j].out_index,
|
|
125
|
+
address,
|
|
126
|
+
view_key__private,
|
|
127
|
+
spend_key__public,
|
|
128
|
+
spend_key__private,
|
|
129
|
+
coreBridge_instance
|
|
130
|
+
)
|
|
131
|
+
if (transactions[i].spent_outputs[j].key_image !== key_image) {
|
|
132
|
+
// console.log('Output used as mixin, ignoring (' + transactions[i].spent_outputs[j].key_image + '/' + key_image + ')')
|
|
133
|
+
transactions[i].total_sent = new JSBigInt(
|
|
134
|
+
transactions[i].total_sent
|
|
135
|
+
)
|
|
136
|
+
.subtract(transactions[i].spent_outputs[j].amount)
|
|
137
|
+
.toString()
|
|
138
|
+
transactions[i].spent_outputs.splice(j, 1)
|
|
139
|
+
j--
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (
|
|
144
|
+
new JSBigInt(transactions[i].total_received || 0)
|
|
145
|
+
.add(transactions[i].total_sent || 0)
|
|
146
|
+
.compare(0) <= 0
|
|
147
|
+
) {
|
|
148
|
+
transactions.splice(i, 1)
|
|
149
|
+
i--
|
|
150
|
+
continue
|
|
151
|
+
}
|
|
152
|
+
transactions[i].amount = new JSBigInt(
|
|
153
|
+
transactions[i].total_received || 0
|
|
154
|
+
)
|
|
155
|
+
.subtract(transactions[i].total_sent || 0)
|
|
156
|
+
.toString()
|
|
157
|
+
transactions[i].approx_float_amount = parseFloat(
|
|
158
|
+
monero_amount_format_utils.formatMoney(transactions[i].amount)
|
|
159
|
+
)
|
|
160
|
+
transactions[i].timestamp = transactions[i].timestamp
|
|
161
|
+
const record__payment_id = transactions[i].payment_id
|
|
162
|
+
if (typeof record__payment_id !== 'undefined' && record__payment_id) {
|
|
163
|
+
if (record__payment_id.length == 16) {
|
|
164
|
+
// short (encrypted) pid
|
|
165
|
+
if (transactions[i].approx_float_amount < 0) {
|
|
166
|
+
// outgoing
|
|
167
|
+
delete transactions[i]['payment_id'] // need to filter these out .. because the server can't filter out short (encrypted) pids on outgoing txs
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
transactions.sort(function (a, b) {
|
|
173
|
+
if (a.mempool == true) {
|
|
174
|
+
if (b.mempool != true) {
|
|
175
|
+
return -1 // a first
|
|
176
|
+
}
|
|
177
|
+
// both mempool - fall back to .id compare
|
|
178
|
+
} else if (b.mempool == true) {
|
|
179
|
+
return 1 // b first
|
|
180
|
+
}
|
|
181
|
+
return b.id - a.id
|
|
182
|
+
})
|
|
183
|
+
// prepare transactions to be serialized
|
|
184
|
+
for (let transaction of transactions) {
|
|
185
|
+
transaction.amount = transaction.amount.toString() // JSBigInt -> String
|
|
186
|
+
if (
|
|
187
|
+
typeof transaction.total_sent !== 'undefined' &&
|
|
188
|
+
transaction.total_sent !== null
|
|
189
|
+
) {
|
|
190
|
+
transaction.total_sent = transaction.total_sent.toString()
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// on the other side, we convert transactions timestamp to Date obj
|
|
194
|
+
const returnValuesByKey = {
|
|
195
|
+
account_scanned_height: account_scanned_height,
|
|
196
|
+
account_scanned_block_height: account_scanned_block_height,
|
|
197
|
+
account_scan_start_height: account_scan_start_height,
|
|
198
|
+
transaction_height: transaction_height,
|
|
199
|
+
blockchain_height: blockchain_height,
|
|
200
|
+
serialized_transactions: transactions
|
|
201
|
+
}
|
|
202
|
+
return returnValuesByKey
|
|
203
|
+
}
|
|
204
|
+
exports.Parsed_AddressTransactions__async = Parsed_AddressTransactions__async
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// This has been taken from @mymonero/mymonero-keyimage-cache v2.0.0
|
|
2
|
+
// We have made `Lazy_KeyImage` async and deleted the rest.
|
|
3
|
+
// We have also renamed generate_key_image to generateKeyImage.
|
|
4
|
+
|
|
5
|
+
'use strict'
|
|
6
|
+
|
|
7
|
+
const Lazy_KeyImage = async function (
|
|
8
|
+
mutable_keyImagesByCacheKey, // pass a mutable JS dictionary
|
|
9
|
+
tx_pub_key,
|
|
10
|
+
out_index,
|
|
11
|
+
public_address,
|
|
12
|
+
view_key__private,
|
|
13
|
+
spend_key__public,
|
|
14
|
+
spend_key__private,
|
|
15
|
+
coreBridge_instance // must pass this so this fn can remain synchronous
|
|
16
|
+
) {
|
|
17
|
+
var cache_index = tx_pub_key + ':' + public_address + ':' + out_index
|
|
18
|
+
const cached__key_image = mutable_keyImagesByCacheKey[cache_index]
|
|
19
|
+
if (
|
|
20
|
+
typeof cached__key_image !== 'undefined' &&
|
|
21
|
+
cached__key_image !== null
|
|
22
|
+
) {
|
|
23
|
+
return cached__key_image
|
|
24
|
+
}
|
|
25
|
+
var key_image = await coreBridge_instance.generateKeyImage(
|
|
26
|
+
tx_pub_key,
|
|
27
|
+
view_key__private,
|
|
28
|
+
spend_key__public,
|
|
29
|
+
spend_key__private,
|
|
30
|
+
out_index
|
|
31
|
+
)
|
|
32
|
+
// cache:
|
|
33
|
+
mutable_keyImagesByCacheKey[cache_index] = key_image
|
|
34
|
+
//
|
|
35
|
+
return key_image
|
|
36
|
+
}
|
|
37
|
+
exports.Lazy_KeyImage = Lazy_KeyImage
|