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.
publicKey was added to the Wallet State on D10550