HomePhabricator

T1920 - fix excessive API Calls on Tx History Fetching

Description

T1920 - fix excessive API Calls on Tx History Fetching

Summary:
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

Test Plan:
On master branch

  • Npm start
  • Make sure you have 2 wallets with some XECs
  • Send some XECs from one wallet to another
  • Inspect the network traffic
  • Activate the receiving wallet
  • Confirm that the wallet retrieved more than 5 TXs
  • Note which Tx is marked as Sent / Received

On this diff

  • Repeat the steps as with master branch
  • Inspect the network traffic
  • Confirm that the wallet retrieved exactly 5 TXs
  • Confirm that the TXs are marked correctly as Sent / Receive
  • Better to load the same wallets on a phone and compare the Tx History

Reviewers: bytesofman, #bitcoin_abc

Reviewed By: bytesofman, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D10622

Details

Provenance
hungsamAuthored on Nov 26 2021, 02:53
hungsamPushed on Dec 13 2021, 22:35
Reviewer
Restricted Project
Differential Revision
D10622: T1920 - fix excessive API Calls on Tx History Fetching
Parents
rABCf513eb3feba4: [Cashtab] Full refactor of the OP_RETURN parsing logic to revolve around…
Branches
Unknown
Tags
Unknown