dashpay / dash-wallet

Dash Wallet for Android
https://dash.org
175 stars 169 forks source link

feat: support dashpay sync txmetadata #1048

Closed HashEngineering closed 2 years ago

HashEngineering commented 2 years ago

Before this PR there was a single table called transaction_metadata that stored tx metadata.

With this PR, we are adding two more tables

  1. transaction_metadata_cache - this table contains changes that need to be synced with platform.
  2. transaction_metadata_platform - this table is synced with Platform

in theory transaction_metadata = latest(transaction_metadata_platform + transaction_metadata_cache).
In other words, the current state of the metadata that is displayed to the user is equal to the data stored on platform plus the data not yet pushed to platform.

Example:

  1. For transaction A, there is no memo
  2. User sets a memo "Alice Pizza Party" for transaction A.
  3. transaction_metadata is updated with this change.
  4. An entry is also added to transaction_metadata_cache which indicates that the memo on transaction A has changed.
  5. After a period of time (currently 15 seconds) or before Reset Wallet, all records (including transaction A) in transaction_metadata_cache are combined into a single list and published to Platform. transaction_metadata_cache is emptied.
  6. Shortly after 5), the app detects that there is a new information published on Platform and this will be added to the transaction_metadata_platform table.

Restoration of a Wallet

  1. Sync headers
  2. Sync masternode lists
  3. Sync Platform data (identity, username, contacts, profiles and tx_metadata). Tx Metadata is stored in the transaction_metadata_platform table. No transactions have been found.
  4. Sync blockchain and transactions.
  5. As each transaction is found, we search in transaction_metadata_platform for the latest data on a transaction. Then an entry with that information is added to transaction_metadata. For transaction A, it will find "Alice Pizza Party" as the memo.
  6. After blockchain sync is complete, transaction_metadata should be the same as it was before the Reset Wallet action.

Refactoring

Issue being fixed or feature implemented

Related PR's and Dependencies

1042

https://github.com/dashevo/android-dpp/pull/35 https://github.com/dashevo/android-dashpay/pull/67

Screenshots / Videos

How Has This Been Tested?

Checklist: