mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
Prevent 'amount' from being misinterpreted (#924)
The 'amount' field should almost never be used. With partial payments, the field can show an amount that is significantly less than the amount that the transaction actually delivered. This change sets amount to 0 XRP when it may be misleading. This change omits the `amount` when parsing payment transactions. See `HISTORY.md` for recommended alternatives.
This commit is contained in:
@@ -29,7 +29,7 @@ function parseTransactionWrapper(ledgerVersion, tx) {
|
||||
meta: tx.metaData,
|
||||
ledger_index: ledgerVersion
|
||||
})
|
||||
const result = parseTransaction(transaction)
|
||||
const result = parseTransaction(transaction, false)
|
||||
if (!result.outcome.ledgerVersion) {
|
||||
result.outcome.ledgerVersion = ledgerVersion
|
||||
}
|
||||
@@ -62,19 +62,20 @@ function parseState(state) {
|
||||
|
||||
export function parseLedger(ledger: Ledger): FormattedLedger {
|
||||
const ledgerVersion = parseInt(ledger.ledger_index || ledger.seqNum, 10)
|
||||
return removeUndefined(Object.assign({
|
||||
stateHash: ledger.account_hash,
|
||||
closeTime: rippleTimeToISO8601(ledger.close_time),
|
||||
closeTimeResolution: ledger.close_time_resolution,
|
||||
closeFlags: ledger.close_flags,
|
||||
ledgerHash: ledger.hash || ledger.ledger_hash,
|
||||
ledgerVersion: ledgerVersion,
|
||||
parentLedgerHash: ledger.parent_hash,
|
||||
parentCloseTime: rippleTimeToISO8601(ledger.parent_close_time),
|
||||
totalDrops: ledger.total_coins || ledger.totalCoins,
|
||||
transactionHash: ledger.transaction_hash
|
||||
},
|
||||
parseTransactions(ledger.transactions, ledgerVersion),
|
||||
parseState(ledger.accountState)
|
||||
return removeUndefined(Object.assign(
|
||||
{
|
||||
stateHash: ledger.account_hash,
|
||||
closeTime: rippleTimeToISO8601(ledger.close_time),
|
||||
closeTimeResolution: ledger.close_time_resolution,
|
||||
closeFlags: ledger.close_flags,
|
||||
ledgerHash: ledger.hash || ledger.ledger_hash,
|
||||
ledgerVersion: ledgerVersion,
|
||||
parentLedgerHash: ledger.parent_hash,
|
||||
parentCloseTime: rippleTimeToISO8601(ledger.parent_close_time),
|
||||
totalDrops: ledger.total_coins || ledger.totalCoins,
|
||||
transactionHash: ledger.transaction_hash
|
||||
},
|
||||
parseTransactions(ledger.transactions, ledgerVersion),
|
||||
parseState(ledger.accountState)
|
||||
))
|
||||
}
|
||||
|
||||
@@ -28,10 +28,13 @@ function parsePayment(tx: any): Object {
|
||||
tag: tx.SourceTag
|
||||
}
|
||||
|
||||
const destination = {
|
||||
const destination: {
|
||||
address: string,
|
||||
tag: number | undefined
|
||||
} = {
|
||||
address: tx.Destination,
|
||||
amount: removeGenericCounterparty(parseAmount(tx.Amount), tx.Destination),
|
||||
tag: tx.DestinationTag
|
||||
// Notice that `amount` is omitted to prevent misinterpretation
|
||||
}
|
||||
|
||||
return removeUndefined({
|
||||
|
||||
@@ -42,7 +42,7 @@ function parseTransactionType(type) {
|
||||
return mapping[type] || null
|
||||
}
|
||||
|
||||
function parseTransaction(tx: any): any {
|
||||
function parseTransaction(tx: any, includeRawTransaction: boolean): any {
|
||||
const type = parseTransactionType(tx.TransactionType)
|
||||
const mapping = {
|
||||
'payment': parsePayment,
|
||||
@@ -72,7 +72,8 @@ function parseTransaction(tx: any): any {
|
||||
sequence: tx.Sequence,
|
||||
id: tx.hash,
|
||||
specification: removeUndefined(specification),
|
||||
outcome: outcome ? removeUndefined(outcome) : undefined
|
||||
outcome: outcome ? removeUndefined(outcome) : undefined,
|
||||
rawTransaction: includeRawTransaction ? JSON.stringify(tx) : undefined
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user