HomePhabricator

[Cashtab] add publicKey property for each of the Path in the wallet

Description

[Cashtab] add publicKey property for each of the Path in the wallet

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.

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

Test Plan:

  • make sure there are multiple existing wallets on the local storage
  • npm start
  • make sure the currently active wallet is migrated to include the public key
  • make sure all operations perform as normal
  • switch to another wallet
  • make sure the previously active wallet is saved and includes the public key
  • make sure the currently active wallet is migrated and includes the public key
  • make sure all operations perform as normal

Reviewers: O1 Bitcoin ABC, #bitcoin_abc, bytesofman

Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, bytesofman

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

Details

Provenance
hungsamAuthored on Nov 26 2021, 02:53
hungsamPushed on Dec 2 2021, 22:07
Reviewer
Restricted Owners Package
Differential Revision
D10550: [Cashtab] add publicKey property for each of the Path in the wallet
Parents
rABC8d77b112ed06: [Cashtab] update "Migrate legacy wallet on testnet" unit test
Branches
Unknown
Tags
Unknown