Merge branch 'develop' of https://github.com/Agorise/crystal-wallet-android into develop
This commit is contained in:
commit
3c0e2058bb
3 changed files with 139 additions and 2 deletions
|
@ -0,0 +1,30 @@
|
|||
package cy.agorise.crystalwallet.dao;
|
||||
|
||||
import android.arch.lifecycle.LiveData;
|
||||
import android.arch.persistence.room.Dao;
|
||||
import android.arch.persistence.room.Insert;
|
||||
import android.arch.persistence.room.OnConflictStrategy;
|
||||
import android.arch.persistence.room.Query;
|
||||
|
||||
import cy.agorise.crystalwallet.models.BitcoinAddress;
|
||||
import cy.agorise.crystalwallet.models.BitcoinTransaction;
|
||||
import cy.agorise.crystalwallet.models.BitcoinTransactionExtended;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 10/17/2018.
|
||||
*/
|
||||
@Dao
|
||||
public interface BitcoinAddressDao {
|
||||
|
||||
@Query("SELECT * FROM bitcoin_address")
|
||||
LiveData<BitcoinAddress> getAll();
|
||||
|
||||
@Query("SELECT COUNT(*) FROM bitcoin_address ba WHERE ba.address = :address")
|
||||
Boolean addressExists(String address);
|
||||
|
||||
@Query("SELECT * FROM bitcoin_address ba WHERE ba.address = :address")
|
||||
BitcoinAddress getdadress(String address);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
public long[] insertBitcoinAddresses(BitcoinAddress... addresses);
|
||||
}
|
|
@ -10,6 +10,7 @@ import android.content.Context;
|
|||
|
||||
import cy.agorise.crystalwallet.dao.converters.Converters;
|
||||
import cy.agorise.crystalwallet.models.AccountSeed;
|
||||
import cy.agorise.crystalwallet.models.BitcoinAddress;
|
||||
import cy.agorise.crystalwallet.models.BitcoinTransaction;
|
||||
import cy.agorise.crystalwallet.models.BitcoinTransactionGTxIO;
|
||||
import cy.agorise.crystalwallet.models.BitsharesAccountNameCache;
|
||||
|
@ -43,8 +44,9 @@ import cy.agorise.crystalwallet.models.GrapheneAccountInfo;
|
|||
CryptoCurrencyEquivalence.class,
|
||||
GeneralSetting.class,
|
||||
BitcoinTransaction.class,
|
||||
BitcoinTransactionGTxIO.class
|
||||
}, version = 5, exportSchema = false)
|
||||
BitcoinTransactionGTxIO.class,
|
||||
BitcoinAddress.class
|
||||
}, version = 6, exportSchema = false)
|
||||
@TypeConverters({Converters.class})
|
||||
public abstract class CrystalDatabase extends RoomDatabase {
|
||||
|
||||
|
@ -62,6 +64,7 @@ public abstract class CrystalDatabase extends RoomDatabase {
|
|||
public abstract CryptoCurrencyEquivalenceDao cryptoCurrencyEquivalenceDao();
|
||||
public abstract GeneralSettingDao generalSettingDao();
|
||||
public abstract BitcoinTransactionDao bitcoinTransactionDao();
|
||||
public abstract BitcoinAddressDao bitcoinAddressDao();
|
||||
|
||||
public static CrystalDatabase getAppDatabase(Context context) {
|
||||
if (instance == null) {
|
||||
|
@ -72,6 +75,7 @@ public abstract class CrystalDatabase extends RoomDatabase {
|
|||
.addMigrations(MIGRATION_2_3)
|
||||
.addMigrations(MIGRATION_3_4)
|
||||
.addMigrations(MIGRATION_4_5)
|
||||
.addMigrations(MIGRATION_5_6)
|
||||
.build();
|
||||
}
|
||||
return instance;
|
||||
|
@ -118,4 +122,17 @@ public abstract class CrystalDatabase extends RoomDatabase {
|
|||
+"FOREIGN KEY (bitcoin_transaction_id) REFERENCES bitcoin_transaction(crypto_coin_transaction_id) ON DELETE CASCADE)");
|
||||
}
|
||||
};
|
||||
|
||||
static final Migration MIGRATION_5_6 = new Migration(5, 6) {
|
||||
@Override
|
||||
public void migrate(SupportSQLiteDatabase database) {
|
||||
database.execSQL("CREATE TABLE bitcoin_address ("
|
||||
+"account_id INTEGER NOT NULL,"
|
||||
+"address_index INTEGER NOT NULL,"
|
||||
+"is_change INTEGER NOT NULL,"
|
||||
+"address TEXT NOT NULL,"
|
||||
+"PRIMARY KEY (account_id, address_index),"
|
||||
+"FOREIGN KEY (account_id) REFERENCES crypto_net_account(id) ON DELETE CASCADE)");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
package cy.agorise.crystalwallet.models;
|
||||
|
||||
import android.arch.persistence.room.ColumnInfo;
|
||||
import android.arch.persistence.room.Entity;
|
||||
import android.arch.persistence.room.ForeignKey;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* Represents a Bitcoin derivated address
|
||||
*
|
||||
* Created by Henry Varona on 10/17/2018.
|
||||
*/
|
||||
@Entity(
|
||||
tableName="bitcoin_address",
|
||||
primaryKeys = {"account_id","address_index"},
|
||||
foreignKeys = {
|
||||
@ForeignKey(
|
||||
entity = CryptoNetAccount.class,
|
||||
parentColumns = "id",
|
||||
childColumns = "account_id",
|
||||
onDelete = ForeignKey.CASCADE
|
||||
)
|
||||
}
|
||||
)
|
||||
public class BitcoinAddress {
|
||||
|
||||
/**
|
||||
* The id of the account associated
|
||||
*/
|
||||
@ColumnInfo(name="account_id")
|
||||
protected long accountId;
|
||||
|
||||
/**
|
||||
* The index of this address
|
||||
*/
|
||||
@ColumnInfo(name="address_index")
|
||||
@NonNull protected long index;
|
||||
|
||||
/**
|
||||
* Whether or not this address is a change one
|
||||
*/
|
||||
@ColumnInfo(name="is_change")
|
||||
@NonNull protected boolean isChange;
|
||||
|
||||
/**
|
||||
* Address
|
||||
*/
|
||||
@ColumnInfo(name="address")
|
||||
@NonNull protected String address;
|
||||
|
||||
public BitcoinAddress(long accountId, @NonNull long index, boolean isChange, String address) {
|
||||
this.accountId = accountId;
|
||||
this.index = index;
|
||||
this.isChange = isChange;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public long getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(long accountId) {
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public long getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(@NonNull long index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public boolean isChange() {
|
||||
return isChange;
|
||||
}
|
||||
|
||||
public void setChange(boolean change) {
|
||||
isChange = change;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue