AlphaWallet / AlphaWallet/alpha-wallet-android
Refactor database token storage
- 主要言語
- Java
- スター
- 646
- フォーク
- 579
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Currently there's a huge amount of duplication of database info when it comes to storing tokens.
The static data for each token is stored for each wallet.
In this refactor, separate the static data from the dynamic wallet specific data like this:
```
public class RealmToken extends RealmObject {
@PrimaryKey
private String address; //static
private String name; //static
private String symbol; //static
private int decimals; //static
private long addedTime;
private long updatedTime;
private long lastTxTime;
private String balance;
private boolean isEnabled;
private int tokenId; // not used - don't migrate to RealmTokenInfo
private int interfaceSpec; //static
private String auxData; //static
private long lastBlockRead;
private int chainId; //static
private long earliestTxBlock;
private boolean visibilityChanged;
```
All the fields not marked static need to go into a new ```class RealmTokenWallet``` (obviously ```address``` needs to be duplicated for the primary key); all the static need to go into ```class RealmTokenInfo```.
There would only be one instance of RealmTokenInfo for each token, whereas there's a RealmTokenWallet per token for each wallet that holds it.
Luckily there's not many places that need to be changed for each. Fetching a token is only done in one place (```class TokensService```) so that method would need access to both the global ```RealmTokenInfo``` and the instance of ```RealmTokenWallet``` databases for the current wallet. This would work for everywhere (eg ```TokenHolder```) where we display balances.
There will be quite a few places where listeners need to be updated; now we'd be listening for changes to ```RealmTokenWallet```.
Also in TokensService when working out which token needs to be updated next, it's a small change there.
- [ ] Create RealmTokenInfo and RealmTokenWallet classes. (RealmToken maintains all members).
- [ ] Bump database version and add migration for AWRealmMigration; this is to create the two new schemas.
- [ ] Create the global RealmTokenInfo database instance.
- [ ] If RealmTokenWallet/RealmTokenInfo are empty for a wallet in ```class WalletFragment``` then perform full migration - this a function that will copy the static elements into ```RealmTokenInfo``` and wallet specific dynamic data into a new entry for ```RealmTokenWallet```. This will be performed once - pop up a waiting dialog to show database migration is happening and allow user to click on a 'continue migration in background' button. Once Migration is complete, delete all the RealmToken entries for the wallet. Perform this for all wallets.
- [ ] Update ```TokensService``` to use the new schemas.
- [ ] Update anywhere where RealmToken is accessed to use the appropriate database. Eg when waiting for a balance change it should be waiting for a change to ```RealmTokenWallet```.
- [ ] Check the database sizes in the data.data.io.stormbird.wallet.files area after the background migration process is complete to ensure the RealmToken databases are now empty (eg 0x123423423535234234234Address-db.realm)
It should be possible to go from a current installation to have the database upgraded without blanking existing data.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
評価
この issue はまだ評価されていません。