- Created the database structure for bitcoins alike coins
- Fixed "no balances" label appearing in the middle of the balance page when the user has one account.
This commit is contained in:
parent
e9a147e344
commit
f43c6aa1af
7 changed files with 273 additions and 5 deletions
|
@ -0,0 +1,17 @@
|
||||||
|
package cy.agorise.crystalwallet.dao;
|
||||||
|
|
||||||
|
import android.arch.lifecycle.LiveData;
|
||||||
|
import android.arch.persistence.room.Dao;
|
||||||
|
import android.arch.persistence.room.Query;
|
||||||
|
|
||||||
|
import cy.agorise.crystalwallet.models.BitcoinTransactionExtended;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Henry Varona on 10/02/2018.
|
||||||
|
*/
|
||||||
|
@Dao
|
||||||
|
public interface BitcoinTransactionDao {
|
||||||
|
|
||||||
|
@Query("SELECT * FROM crypto_coin_transaction cct, bitcoin_transaction bt WHERE bt.crypto_coin_transaction_id = cct.id")
|
||||||
|
LiveData<BitcoinTransactionExtended> getAll();
|
||||||
|
}
|
|
@ -10,6 +10,8 @@ import android.content.Context;
|
||||||
|
|
||||||
import cy.agorise.crystalwallet.dao.converters.Converters;
|
import cy.agorise.crystalwallet.dao.converters.Converters;
|
||||||
import cy.agorise.crystalwallet.models.AccountSeed;
|
import cy.agorise.crystalwallet.models.AccountSeed;
|
||||||
|
import cy.agorise.crystalwallet.models.BitcoinTransaction;
|
||||||
|
import cy.agorise.crystalwallet.models.BitcoinTransactionGTxIO;
|
||||||
import cy.agorise.crystalwallet.models.BitsharesAccountNameCache;
|
import cy.agorise.crystalwallet.models.BitsharesAccountNameCache;
|
||||||
import cy.agorise.crystalwallet.models.BitsharesAssetInfo;
|
import cy.agorise.crystalwallet.models.BitsharesAssetInfo;
|
||||||
import cy.agorise.crystalwallet.models.Contact;
|
import cy.agorise.crystalwallet.models.Contact;
|
||||||
|
@ -39,8 +41,10 @@ import cy.agorise.crystalwallet.models.GrapheneAccountInfo;
|
||||||
BitsharesAssetInfo.class,
|
BitsharesAssetInfo.class,
|
||||||
BitsharesAccountNameCache.class,
|
BitsharesAccountNameCache.class,
|
||||||
CryptoCurrencyEquivalence.class,
|
CryptoCurrencyEquivalence.class,
|
||||||
GeneralSetting.class
|
GeneralSetting.class,
|
||||||
}, version = 4, exportSchema = false)
|
BitcoinTransaction.class,
|
||||||
|
BitcoinTransactionGTxIO.class
|
||||||
|
}, version = 5, exportSchema = false)
|
||||||
@TypeConverters({Converters.class})
|
@TypeConverters({Converters.class})
|
||||||
public abstract class CrystalDatabase extends RoomDatabase {
|
public abstract class CrystalDatabase extends RoomDatabase {
|
||||||
|
|
||||||
|
@ -57,6 +61,7 @@ public abstract class CrystalDatabase extends RoomDatabase {
|
||||||
public abstract BitsharesAccountNameCacheDao bitsharesAccountNameCacheDao();
|
public abstract BitsharesAccountNameCacheDao bitsharesAccountNameCacheDao();
|
||||||
public abstract CryptoCurrencyEquivalenceDao cryptoCurrencyEquivalenceDao();
|
public abstract CryptoCurrencyEquivalenceDao cryptoCurrencyEquivalenceDao();
|
||||||
public abstract GeneralSettingDao generalSettingDao();
|
public abstract GeneralSettingDao generalSettingDao();
|
||||||
|
public abstract BitcoinTransactionDao bitcoinTransactionDao();
|
||||||
|
|
||||||
public static CrystalDatabase getAppDatabase(Context context) {
|
public static CrystalDatabase getAppDatabase(Context context) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
|
@ -66,6 +71,7 @@ public abstract class CrystalDatabase extends RoomDatabase {
|
||||||
.allowMainThreadQueries()
|
.allowMainThreadQueries()
|
||||||
.addMigrations(MIGRATION_2_3)
|
.addMigrations(MIGRATION_2_3)
|
||||||
.addMigrations(MIGRATION_3_4)
|
.addMigrations(MIGRATION_3_4)
|
||||||
|
.addMigrations(MIGRATION_4_5)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -91,4 +97,25 @@ public abstract class CrystalDatabase extends RoomDatabase {
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static final Migration MIGRATION_4_5 = new Migration(4, 5) {
|
||||||
|
@Override
|
||||||
|
public void migrate(SupportSQLiteDatabase database) {
|
||||||
|
database.execSQL("CREATE TABLE bitcoin_transaction ("
|
||||||
|
+"crypto_coin_transaction_id INTEGER PRIMARY KEY NOT NULL,"
|
||||||
|
+"tx_id TEXT NOT NULL,"
|
||||||
|
+"block INTEGER NOT NULL,"
|
||||||
|
+"fee INTEGER NOT NULL,"
|
||||||
|
+"confirmations INTEGER NOT NULL,"
|
||||||
|
+"FOREIGN KEY (crypto_coin_transaction_id) REFERENCES crypto_coin_transaction(id) ON DELETE CASCADE)");
|
||||||
|
|
||||||
|
database.execSQL("CREATE TABLE bitcoin_transaction_gt_io ("
|
||||||
|
+"bitcoin_transaction_id INTEGER NOT NULL,"
|
||||||
|
+"io_index INTEGER NOT NULL,"
|
||||||
|
+"address TEXT,"
|
||||||
|
+"is_output INTEGER NOT NULL,"
|
||||||
|
+"PRIMARY KEY (bitcoin_transaction_id, io_index, is_output),"
|
||||||
|
+"FOREIGN KEY (bitcoin_transaction_id) REFERENCES bitcoin_transaction(crypto_coin_transaction_id) ON DELETE CASCADE)");
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class BalanceFragment extends Fragment {
|
||||||
vCryptoNetBalanceListView.setData(cryptoNetBalances, fragment);
|
vCryptoNetBalanceListView.setData(cryptoNetBalances, fragment);
|
||||||
|
|
||||||
final int size = cryptoNetBalances.size();
|
final int size = cryptoNetBalances.size();
|
||||||
if(size==1){
|
if(size==0){
|
||||||
tvNobalances.setVisibility(View.VISIBLE);
|
tvNobalances.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
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.arch.persistence.room.Ignore;
|
||||||
|
import android.arch.persistence.room.Index;
|
||||||
|
import android.arch.persistence.room.PrimaryKey;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v7.util.DiffUtil;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a Bitcoin alike Transaction
|
||||||
|
*
|
||||||
|
* Created by Henry Varona on 10/2/2018.
|
||||||
|
*/
|
||||||
|
@Entity(
|
||||||
|
tableName="bitcoin_transaction",
|
||||||
|
primaryKeys = {"crypto_coin_transaction_id"},
|
||||||
|
foreignKeys = {
|
||||||
|
@ForeignKey(
|
||||||
|
entity = CryptoCoinTransaction.class,
|
||||||
|
parentColumns = "id",
|
||||||
|
childColumns = "crypto_coin_transaction_id",
|
||||||
|
onDelete = ForeignKey.CASCADE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public class BitcoinTransaction {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id of the base transaction
|
||||||
|
*/
|
||||||
|
@ColumnInfo(name="crypto_coin_transaction_id")
|
||||||
|
protected long cryptoCoinTransactionId;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The transaction id in the blockchain
|
||||||
|
*/
|
||||||
|
@ColumnInfo(name="tx_id")
|
||||||
|
@NonNull protected String txId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The block id in the blockchain
|
||||||
|
*/
|
||||||
|
@ColumnInfo(name="block")
|
||||||
|
protected long block;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The fee of the transaction
|
||||||
|
*/
|
||||||
|
@ColumnInfo(name="fee")
|
||||||
|
protected long fee;
|
||||||
|
/**
|
||||||
|
* The confirmations of the transaction in the blockchain
|
||||||
|
*/
|
||||||
|
@ColumnInfo(name="confirmations")
|
||||||
|
protected int confirmations;
|
||||||
|
|
||||||
|
public BitcoinTransaction(long cryptoCoinTransactionId, String txId, long block, long fee, int confirmations) {
|
||||||
|
this.cryptoCoinTransactionId = cryptoCoinTransactionId;
|
||||||
|
this.txId = txId;
|
||||||
|
this.block = block;
|
||||||
|
this.fee = fee;
|
||||||
|
this.confirmations = confirmations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCryptoCoinTransactionId() {
|
||||||
|
return cryptoCoinTransactionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCryptoCoinTransactionId(long cryptoCoinTransactionId) {
|
||||||
|
this.cryptoCoinTransactionId = cryptoCoinTransactionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTxId() {
|
||||||
|
return txId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTxId(String txId) {
|
||||||
|
this.txId = txId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getBlock() {
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlock(long block) {
|
||||||
|
this.block = block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getFee() {
|
||||||
|
return fee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFee(long fee) {
|
||||||
|
this.fee = fee;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getConfirmations() {
|
||||||
|
return confirmations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfirmations(int confirmations) {
|
||||||
|
this.confirmations = confirmations;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package cy.agorise.crystalwallet.models;
|
||||||
|
|
||||||
|
import android.arch.persistence.room.ColumnInfo;
|
||||||
|
import android.arch.persistence.room.Embedded;
|
||||||
|
import android.arch.persistence.room.Entity;
|
||||||
|
import android.arch.persistence.room.ForeignKey;
|
||||||
|
import android.arch.persistence.room.Relation;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a Bitcoin alike Transaction
|
||||||
|
*
|
||||||
|
* Created by Henry Varona on 10/2/2018.
|
||||||
|
*/
|
||||||
|
public class BitcoinTransactionExtended {
|
||||||
|
|
||||||
|
@Embedded
|
||||||
|
public CryptoCoinTransaction cryptoCoinTransaction;
|
||||||
|
|
||||||
|
@Embedded
|
||||||
|
public BitcoinTransaction bitcoinTransaction;
|
||||||
|
|
||||||
|
@Relation(parentColumn = "id", entityColumn = "bitcoin_transaction_id", entity = BitcoinTransactionGTxIO.class)
|
||||||
|
public List<BitcoinTransactionGTxIO> bitcoinTransactionGTxIOList;
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
package cy.agorise.crystalwallet.models;
|
||||||
|
|
||||||
|
import android.arch.persistence.room.ColumnInfo;
|
||||||
|
import android.arch.persistence.room.Entity;
|
||||||
|
import android.arch.persistence.room.ForeignKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a Bitcoin alike Transaction Inputs and Outputs
|
||||||
|
*
|
||||||
|
* Created by Henry Varona on 10/2/2018.
|
||||||
|
*/
|
||||||
|
@Entity(
|
||||||
|
tableName="bitcoin_transaction_gt_io",
|
||||||
|
primaryKeys = {"bitcoin_transaction_id", "io_index", "is_output"},
|
||||||
|
foreignKeys = {
|
||||||
|
@ForeignKey(
|
||||||
|
entity = BitcoinTransaction.class,
|
||||||
|
parentColumns = "crypto_coin_transaction_id",
|
||||||
|
childColumns = "bitcoin_transaction_id",
|
||||||
|
onDelete = ForeignKey.CASCADE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
public class BitcoinTransactionGTxIO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id of the bitcoin transaction
|
||||||
|
*/
|
||||||
|
@ColumnInfo(name="bitcoin_transaction_id")
|
||||||
|
protected long bitcoinTransactionId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The index in the transaction
|
||||||
|
*/
|
||||||
|
@ColumnInfo(name="io_index")
|
||||||
|
protected int index;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The address of the input or output
|
||||||
|
*/
|
||||||
|
@ColumnInfo(name="address")
|
||||||
|
protected String address;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* determines if this is an input or output
|
||||||
|
*/
|
||||||
|
@ColumnInfo(name="is_output")
|
||||||
|
protected boolean isOutput;
|
||||||
|
|
||||||
|
public BitcoinTransactionGTxIO(long bitcoinTransactionId, int index, String address, boolean isOutput) {
|
||||||
|
this.bitcoinTransactionId = bitcoinTransactionId;
|
||||||
|
this.index = index;
|
||||||
|
this.address = address;
|
||||||
|
this.isOutput = isOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getBitcoinTransactionId() {
|
||||||
|
return bitcoinTransactionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBitcoinTransactionId(long bitcoinTransactionId) {
|
||||||
|
this.bitcoinTransactionId = bitcoinTransactionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndex(int index) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddress() {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddress(String address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOutput() {
|
||||||
|
return isOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOutput(boolean output) {
|
||||||
|
isOutput = output;
|
||||||
|
}
|
||||||
|
}
|
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,6 +1,6 @@
|
||||||
#Thu Jun 07 09:09:01 CDT 2018
|
#Sat Sep 29 22:07:01 VET 2018
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
|
||||||
|
|
Loading…
Reference in a new issue