Page MenuHomePhabricator

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

Authored by hungsam on Nov 26 2021, 06:06.

Details

Reviewers
bytesofman
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Restricted Project
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

Diff Detail

Repository
rABC Bitcoin ABC
Branch
get-pubkey (branched from master)
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 17380
Build 34588: Build Diffcashtab-tests
Build 34587: arc lint + arc unit

Event Timeline

Owners added a reviewer: Restricted Owners Package.Nov 26 2021, 06:06
hungsam requested review of this revision.Nov 26 2021, 06:06

Failed tests logs:

====== CashTab Unit Tests:  Migrating legacy wallet on testnet ======
Error: expect(received).toStrictEqual(expected) // deep equality

- Expected  - 10
+ Received  + 13

  Object {
    "Path145": Object {
-     "cashAddress": "bitcoincash:qq47pcxfn8n7w7jy86njd7pvgsv39l9f9v0lgx569z",
-     "fundingAddress": "simpleledger:qq47pcxfn8n7w7jy86njd7pvgsv39l9f9vryrap6mu",
-     "fundingWif": "L2xvTe6CdNxroR6pbdpGWNjAa55AZX5Wm59W5TXMuH31ihNJdDjt",
-     "legacyAddress": "1511T3ynXKgCwXhFijCUWKuTfqbPxFV1AF",
-     "slpAddress": "simpleledger:qq47pcxfn8n7w7jy86njd7pvgsv39l9f9vryrap6mu",
+     "cashAddress": "bchtest:qq47pcxfn8n7w7jy86njd7pvgsv39l9f9vtdvpkdz7",
+     "fundingAddress": "slptest:qq47pcxfn8n7w7jy86njd7pvgsv39l9f9vset6v6sr",
+     "fundingWif": "cTKuvZ644Sf7xra5z3dPshEECJNaDyBCq7HyBsysQPh1ySSpxtQ1",
+     "legacyAddress": "mjWxk74mLM7TieAsSJArLF7nXqC6oc2mof",
+     "publicKey": "02fe5308d77bcce825068a9e46adc6f032dbbe39167a7b6d05ac563ac71d8b186e",
+     "slpAddress": "slptest:qq47pcxfn8n7w7jy86njd7pvgsv39l9f9vset6v6sr",
    },
    "Path1899": Object {
      "cashAddress": "bchtest:qzagy47mvh6qxkvcn3acjnz73rkhkc6y7c9ex06hrx",
      "fundingAddress": "slptest:qzagy47mvh6qxkvcn3acjnz73rkhkc6y7c7dp5qq3m",
      "fundingWif": "cNRFB6MmkNhyhAj1TpGhXdbHgzWg4BsdHbAkKjiz4vt4vwgpC44F",
      "legacyAddress": "mxX888y8yaPpTYh3WhrB9GEkT3cgumYwPw",
+     "publicKey": "02a06bb380cf180d703f6f80796a13555aefff817d1f6f842f1e5c555b15f0fa70",
      "slpAddress": "slptest:qzagy47mvh6qxkvcn3acjnz73rkhkc6y7c7dp5qq3m",
    },
    "Path245": Object {
-     "cashAddress": "bitcoincash:qztqe8k4v8ckn8cvfxt5659nhd7dcyvxy54hkry298",
-     "fundingAddress": "simpleledger:qztqe8k4v8ckn8cvfxt5659nhd7dcyvxy5evac32me",
-     "fundingWif": "KwgNkyijAaxFr5XQdnaYyNMXVSZobgHzSoKKfWiC3Q7Xr4n7iYMG",
-     "legacyAddress": "1EgPUfBgU7ekho3EjtGze87dRADnUE8ojP",
-     "slpAddress": "simpleledger:qztqe8k4v8ckn8cvfxt5659nhd7dcyvxy5evac32me",
+     "cashAddress": "bchtest:qztqe8k4v8ckn8cvfxt5659nhd7dcyvxy539jyxazm",
+     "fundingAddress": "slptest:qztqe8k4v8ckn8cvfxt5659nhd7dcyvxy5234lu2sx",
+     "fundingWif": "cN3NDtiabeeX1Wzg2CPgLgrb7fsDG8PgWqTnmwAhYWmY6osSta7Q",
+     "legacyAddress": "muCLmiGfH961UuWrTTFNU3KxH9pVQJJx6Z",
+     "publicKey": "03c4a69fd90c8b196683216cffd2943a7b13b0db0812e44a4ff156ac7e03fc4ed7",
+     "slpAddress": "slptest:qztqe8k4v8ckn8cvfxt5659nhd7dcyvxy5234lu2sx",
    },
    "mnemonic": "apart vacuum color cream drama kind foil history hurt alone ask census",
    "name": "MigrationTestAlpha",
  }
    at Object.<anonymous> (/work/web/cashtab/src/hooks/__tests__/useWallet.test.js:61:20)
====== CashTab Unit Tests:  Migrating legacy wallet on mainnet ======
Error: expect(received).toStrictEqual(expected) // deep equality

- Expected  - 0
+ Received  + 3

@@ -2,24 +2,27 @@
    "Path145": Object {
      "cashAddress": "bitcoincash:qq47pcxfn8n7w7jy86njd7pvgsv39l9f9v0lgx569z",
      "fundingAddress": "simpleledger:qq47pcxfn8n7w7jy86njd7pvgsv39l9f9vryrap6mu",
      "fundingWif": "L2xvTe6CdNxroR6pbdpGWNjAa55AZX5Wm59W5TXMuH31ihNJdDjt",
      "legacyAddress": "1511T3ynXKgCwXhFijCUWKuTfqbPxFV1AF",
+     "publicKey": "02fe5308d77bcce825068a9e46adc6f032dbbe39167a7b6d05ac563ac71d8b186e",
      "slpAddress": "simpleledger:qq47pcxfn8n7w7jy86njd7pvgsv39l9f9vryrap6mu",
    },
    "Path1899": Object {
      "cashAddress": "bitcoincash:qzagy47mvh6qxkvcn3acjnz73rkhkc6y7cptzgcqy6",
      "fundingAddress": "simpleledger:qzagy47mvh6qxkvcn3acjnz73rkhkc6y7cdsfndq6y",
      "fundingWif": "Kx4FiBMvKK1iXjFk5QTaAK6E4mDGPjmwDZ2HDKGUZpE4gCXMaPe9",
      "legacyAddress": "1J1Aq5tAAYxZgSDRo8soKM2Rb41z3xrYpm",
+     "publicKey": "02a06bb380cf180d703f6f80796a13555aefff817d1f6f842f1e5c555b15f0fa70",
      "slpAddress": "simpleledger:qzagy47mvh6qxkvcn3acjnz73rkhkc6y7cdsfndq6y",
    },
    "Path245": Object {
      "cashAddress": "bitcoincash:qztqe8k4v8ckn8cvfxt5659nhd7dcyvxy54hkry298",
      "fundingAddress": "simpleledger:qztqe8k4v8ckn8cvfxt5659nhd7dcyvxy5evac32me",
      "fundingWif": "KwgNkyijAaxFr5XQdnaYyNMXVSZobgHzSoKKfWiC3Q7Xr4n7iYMG",
      "legacyAddress": "1EgPUfBgU7ekho3EjtGze87dRADnUE8ojP",
+     "publicKey": "03c4a69fd90c8b196683216cffd2943a7b13b0db0812e44a4ff156ac7e03fc4ed7",
      "slpAddress": "simpleledger:qztqe8k4v8ckn8cvfxt5659nhd7dcyvxy5evac32me",
    },
    "mnemonic": "apart vacuum color cream drama kind foil history hurt alone ask census",
    "name": "MigrationTestAlpha",
  }
    at Object.<anonymous> (/work/web/cashtab/src/hooks/__tests__/useWallet.test.js:117:20)

Each failure log is accessible here:
CashTab Unit Tests: Migrating legacy wallet on testnet
CashTab Unit Tests: Migrating legacy wallet on mainnet