Skip to content

Commit

Permalink
Merge pull request #86 from EdgeApp/william/upgrade-core
Browse files Browse the repository at this point in the history
Upgrade core
  • Loading branch information
swansontec authored Mar 20, 2024
2 parents 32de3d2 + e6f911b commit fce6fb3
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 352 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

# Unreleased

- added: Report legacy payment ID's using the new core `memo` transaction property.
- removed: Only bundle the package in CJS-format, and drop the ESM output.
- removed: Stop supporting undocumented `getTransaction` options.

# 1.1.1 (2023-08-15)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"babel-eslint": "^10.1.0",
"babel-loader": "^9.1.3",
"chai": "^4.1.2",
"edge-core-js": "^0.19.48",
"edge-core-js": "^1.14.0",
"eslint": "^7.14.0",
"eslint-config-standard-kit": "0.15.1",
"eslint-plugin-flowtype": "^5.2.0",
Expand Down
68 changes: 30 additions & 38 deletions src/MoneroEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
// @flow

import { div, eq, gte, sub } from 'biggystring'
import { div, eq, gte, lt, sub } from 'biggystring'
import type { Disklet } from 'disklet'
import {
type EdgeCorePluginOptions,
Expand All @@ -16,9 +16,9 @@ import {
type EdgeEnginePrivateKeyOptions,
type EdgeFreshAddress,
type EdgeGetReceiveAddressOptions,
type EdgeGetTransactionsOptions,
type EdgeIo,
type EdgeLog,
type EdgeMemo,
type EdgeMetaToken,
type EdgeSpendInfo,
type EdgeToken,
Expand Down Expand Up @@ -229,16 +229,30 @@ export class MoneroEngine {

const date = Date.parse(tx.timestamp) / 1000

// Expose legacy payment ID's to the GUI. This only applies
// to really old transactions, before integrated addresses:
const memos: EdgeMemo[] = []
if (tx.payment_id != null) {
memos.push({
memoName: 'payment id',
type: 'hex',
value: tx.payment_id
})
}

let edgeTransaction: EdgeTransaction = {
txid: tx.hash,
date,
currencyCode: 'XMR',
blockHeight,
currencyCode: 'XMR',
date,
isSend: lt(netNativeAmount, '0'),
memos,
nativeAmount: netNativeAmount,
networkFee: nativeNetworkFee,
otherParams: {},
ourReceiveAddresses,
signedTx: '',
otherParams: {},
tokenId: null,
txid: tx.hash,
walletId: this.walletId
}

Expand Down Expand Up @@ -527,41 +541,15 @@ export class MoneroEngine {
}

async getTransactions(
options: EdgeGetTransactionsOptions = {}
options: EdgeCurrencyCodeOptions = {}
): Promise<EdgeTransaction[]> {
let { currencyCode = PRIMARY_CURRENCY, startIndex = 0 } = options
// $FlowFixMe This does not exist in the core types:
let numEntries: number = options.numEntries ?? 0
const { currencyCode = PRIMARY_CURRENCY } = options

if (this.walletLocalData.transactionsObj[currencyCode] == null) {
return []
}

if (
startIndex >= this.walletLocalData.transactionsObj[currencyCode].length
) {
startIndex = this.walletLocalData.transactionsObj[currencyCode].length - 1
}
if (
numEntries + startIndex >
this.walletLocalData.transactionsObj[currencyCode].length
) {
// Don't read past the end of the transactionsObj
numEntries =
this.walletLocalData.transactionsObj[currencyCode].length - startIndex
}

// Copy the appropriate entries from the arrayTransactions:
if (numEntries > 0) {
return this.walletLocalData.transactionsObj[currencyCode].slice(
startIndex,
numEntries + startIndex
)
} else {
return this.walletLocalData.transactionsObj[currencyCode].slice(
startIndex
)
}
return this.walletLocalData.transactionsObj[currencyCode].slice(0)
}

async getFreshAddress(
Expand Down Expand Up @@ -626,6 +614,7 @@ export class MoneroEngine {
edgeSpendInfo: EdgeSpendInfo,
opts?: EdgeEnginePrivateKeyOptions
): Promise<EdgeTransaction> {
const { memos = [] } = edgeSpendInfo
const privateKeys = asPrivateKeys(opts?.privateKeys)

// Monero can only have one output
Expand Down Expand Up @@ -668,14 +657,17 @@ export class MoneroEngine {

this.log(`Total sent: ${result.total_sent}, Fee: ${result.used_fee}`)
const edgeTransaction: EdgeTransaction = {
txid: result.tx_hash,
date,
currencyCode: 'XMR', // currencyCode
blockHeight: 0, // blockHeight
currencyCode: 'XMR', // currencyCode
date,
isSend: true,
memos,
nativeAmount: '-' + result.total_sent,
networkFee: result.used_fee,
ourReceiveAddresses: [], // ourReceiveAddresses
signedTx: result.serialized_signed_tx,
tokenId: null,
txid: result.tx_hash,
txSecret: result.tx_key,
walletId: this.walletId
}
Expand Down
4 changes: 3 additions & 1 deletion test/engine/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type EdgeCurrencyPlugin,
type EdgeCurrencyTools,
type EdgeIo,
type EdgeTokenId,
type EdgeWalletInfo,
closeEdge,
makeFakeIo
Expand Down Expand Up @@ -63,8 +64,9 @@ for (const fixture of fixtures) {
// console.log('onBlockHeightChange:', height)
emitter.emit('onBlockHeightChange', height)
},
onNewTokens(tokenIds: string[]) {},
onTokenBalanceChanged(tokenId: EdgeTokenId, balance: string) {},
onTransactionsChanged(transactionList) {
// console.log('onTransactionsChanged:', transactionList)
emitter.emit('onTransactionsChanged', transactionList)
},
onUnactivatedTokenIdsChanged() {},
Expand Down
Loading

0 comments on commit fce6fb3

Please sign in to comment.