Open b0tm1nd opened 1 year ago
This is because the exchange in question consumed 2 offers. You can pass extractExchanges(tx, { collapse: true })
to have the expected output, but note that you will lose information about the individual offers, such as maker
, hash
and sequence
.
PS. I respect your courage to use this library in alpha without any documentation whatsoever 😄
PS. I respect your courage to use this library in alpha without any documentation whatsoever smile
Do you mean like using your library? I've started working on a ready made project and there happened an issue with improper calculation of exchange rates for OfferCreate type of transactions. So I've started digging the code and documentation.. For some reason could not find any documentation for PreviousFields and FinalFields, TakerPays, TakerGets.. Then searched gitHub for those keywords and found that it's actually using some files and functions from your lib.
Wondering how have you figured out to calculate a transaction balance by subtracting (previousTakerPays.value - finalTakerPays.value) as this is not in documentation? I've seen similar libs use (FinalFields.Balance - PreviousFields.Balance) for the goal.
previousTakerPays.value - finalTakerPays.value
represents the change in the offer size, thus allows for derivation of the amount consumed by the taker, and by extension, in aggregate, the actual exchange rate of the trade.
A transaction of this kind when doing a token-token exchange will return 2 separate transactions with parseExchanges() with absolutely wrong exchange rates. From what I have discovered, there is only documentation for a transaction metadata at https://xrpl.org/transaction-metadata.html but nothing really about what is inside of PreviousFields and FinalFields. That's why I'm wondering where the logic from parseExchanges() comes from? Thanks
PS. I have found an abandoned project at https://www.npmjs.com/package/ripple-lib-transactionparser and also ripple-lib which are closed in flavor of the official https://github.com/XRPLF/xrpl.js But can't really find how can you parse a transaction with it.