Currently, to determine if a transaction is incoming or outgoing, the wallet
- retrieves the transaction data by calling BCH.RawTransactions.getTxData(txid)
- looks through the returned transaction data’s “vin” to see if it contains the address of the current wallet
- If it does, the transaction is outgoing,
- Else, the transaction is incoming
There is a performance problem with BCH.RawTransactions.getTxData(txid).
It populates the address property of each “vin” by making a separate api call
to retrieve the data of the transaction that generates this input.
If a transaction has hundreds of inputs,
retrieving the data for that transaction will generate hundreds of api calls instead of just one.
This problem can be solved by calling BCH.RawTransaction.getRawTransaction(txid,true),
instead of BCH.RawTransaction.getTxData().
getRawTransaction() only makes one api call, however,
the returned data does not contain a wallet address in the “vin”.
We will not be able to determine if a transaction is incoming or outgoing
by comparing the vin’s address with the current wallet address.
Instead, we have the extract the public key in the scriptSig of each "vin",
and compare it with the public key of this wallet.
If they are the same, the transaction is outgoing.
Hence, we need to retrieve and store public key for each address of this wallet
see
https://bchjs.fullstack.cash/#api-RawTransactions-getRawTransaction
https://bchjs.fullstack.cash/#api-RawTransactions-getTxData