Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve exports txs to csv for contract addresses #537

Open
tdroxler opened this issue May 16, 2024 · 0 comments
Open

Improve exports txs to csv for contract addresses #537

tdroxler opened this issue May 16, 2024 · 0 comments

Comments

@tdroxler
Copy link
Member

For example when exporting from this address, if we take that transaction as an example, the toAddresses is wrong (empty):

fromAddresses, toAddresses, hintAmount
1BZ5nen4sNEgvGh7LDM7hn7rDkaA7jbzWHpBMT6j89U3G-2A7QeUr9z6qv8ywYX79jtYAnr8BtcYmFMCQ49ctVwL8z3,,,-50

Amount is correct, but the addresses are wrong because we are currently removing the change addresses, to make it nicer when filling taxes . It happens here:

def toCsv(address: Address): String = {
val dateTime = Instant.ofEpochMilli(timestamp.millis)
val fromAddresses = UtxoUtil.fromAddresses(inputs)
val fromAddressesStr = fromAddresses.mkString("-")
val toAddresses =
UtxoUtil.toAddressesWithoutChangeAddresses(outputs, fromAddresses).mkString("-")
val deltaAmount = UtxoUtil.deltaAmountForAddress(address, inputs, outputs)
val amount = deltaAmount.map(_.toString).getOrElse("")
val amountHint = deltaAmount
.map(delta =>
new java.math.BigDecimal(delta).divide(new java.math.BigDecimal(ALPH.oneAlph.v))
)
.map(_.toString)
.getOrElse("")
s"${hash.toHexString},${blockHash.toHexString},${timestamp.millis},$dateTime,$fromAddressesStr,$toAddresses,$amount,$amountHint\n"
}
and here
def toAddressesWithoutChangeAddresses(
outputs: ArraySeq[Output],
changeAddresses: ArraySeq[Address]
): ArraySeq[Address] = {
outputs.collect {
case output if !changeAddresses.contains(output.address) => output.address
}.distinct
}
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant