- Fixing inconsistent loading of transactions

This commit is contained in:
Javier Varona 2018-09-21 00:43:29 -04:00
parent d549e3af8d
commit 270f2d40b6
4 changed files with 66 additions and 28 deletions

View file

@ -1,6 +1,7 @@
package cy.agorise.crystalwallet.apigenerator; package cy.agorise.crystalwallet.apigenerator;
import android.content.Context; import android.content.Context;
import android.util.Log;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
@ -380,10 +381,20 @@ public abstract class GrapheneApiGenerator {
public void success(Object answer, int idPetition) { public void success(Object answer, int idPetition) {
ArrayList<BitsharesAsset> assets = (ArrayList<BitsharesAsset>) answer; ArrayList<BitsharesAsset> assets = (ArrayList<BitsharesAsset>) answer;
for(BitsharesAsset asset : assets){ for(BitsharesAsset asset : assets){
long idCryptoCurrency = cryptoCurrencyDao.insertCryptoCurrency(asset)[0];
long currencyId = -1;
CryptoCurrency cryptoCurrencyDb = cryptoCurrencyDao.getByNameAndCryptoNet(((BitsharesAsset) answer).getName(),((BitsharesAsset) answer).getCryptoNet().name());
if (cryptoCurrencyDb != null){
currencyId = cryptoCurrencyDb.getId();
} else {
long idCryptoCurrency = cryptoCurrencyDao.insertCryptoCurrency(asset)[0];
currencyId = idCryptoCurrency;
}
BitsharesAssetInfo info = new BitsharesAssetInfo(asset); BitsharesAssetInfo info = new BitsharesAssetInfo(asset);
info.setCryptoCurrencyId(idCryptoCurrency); info.setCryptoCurrencyId(currencyId);
asset.setId((int)idCryptoCurrency); asset.setId((int)currencyId);
bitsharesAssetDao.insertBitsharesAssetInfo(info); bitsharesAssetDao.insertBitsharesAssetInfo(info);
saveTransaction(transaction,cryptoCurrencyDao.getById(info.getCryptoCurrencyId()),accountBitsharesId,tOperation,context); saveTransaction(transaction,cryptoCurrencyDao.getById(info.getCryptoCurrencyId()),accountBitsharesId,tOperation,context);
} }
@ -484,10 +495,19 @@ public abstract class GrapheneApiGenerator {
List<BitsharesAsset> assets = (List<BitsharesAsset>) answer; List<BitsharesAsset> assets = (List<BitsharesAsset>) answer;
for(BitsharesAsset asset : assets) { for(BitsharesAsset asset : assets) {
BitsharesAssetInfo info = new BitsharesAssetInfo(asset); BitsharesAssetInfo info = new BitsharesAssetInfo(asset);
long[] cryptoCurrencyId = cryptoCurrencyDao.insertCryptoCurrency((CryptoCurrency) asset);
info.setCryptoCurrencyId(cryptoCurrencyId[0]); long currencyId = -1;
CryptoCurrency cryptoCurrencyDb = cryptoCurrencyDao.getByNameAndCryptoNet(asset.getName(),asset.getCryptoNet().name());
if (cryptoCurrencyDb != null){
currencyId = cryptoCurrencyDb.getId();
} else {
long[] cryptoCurrencyId = cryptoCurrencyDao.insertCryptoCurrency((CryptoCurrency) asset);
currencyId = cryptoCurrencyId[0];
}
info.setCryptoCurrencyId(currencyId);
bitsharesAssetDao.insertBitsharesAssetInfo(info); bitsharesAssetDao.insertBitsharesAssetInfo(info);
ccBalance.setCryptoCurrencyId(cryptoCurrencyId[0]); ccBalance.setCryptoCurrencyId(currencyId);
balanceDao.insertCryptoCoinBalance(ccBalance); balanceDao.insertCryptoCoinBalance(ccBalance);
} }
} }
@ -616,8 +636,18 @@ public abstract class GrapheneApiGenerator {
public void success(Object answer, int idPetition) { public void success(Object answer, int idPetition) {
if(answer instanceof BitsharesAsset){ if(answer instanceof BitsharesAsset){
BitsharesAssetInfo info = new BitsharesAssetInfo((BitsharesAsset) answer); BitsharesAssetInfo info = new BitsharesAssetInfo((BitsharesAsset) answer);
long cryptoCurrencyId = cryptoCurrencyDao.insertCryptoCurrency((CryptoCurrency)answer )[0];
info.setCryptoCurrencyId(cryptoCurrencyId); long currencyId = -1;
CryptoCurrency cryptoCurrencyDb = cryptoCurrencyDao.getByNameAndCryptoNet(((BitsharesAsset) answer).getName(),((BitsharesAsset) answer).getCryptoNet().name());
if (cryptoCurrencyDb != null){
currencyId = cryptoCurrencyDb.getId();
} else {
long cryptoCurrencyId = cryptoCurrencyDao.insertCryptoCurrency((CryptoCurrency)answer )[0];
currencyId = cryptoCurrencyId;
}
info.setCryptoCurrencyId(currencyId);
bitsharesAssetDao.insertBitsharesAssetInfo(info); bitsharesAssetDao.insertBitsharesAssetInfo(info);
GrapheneApiGenerator.getEquivalentValue((BitsharesAsset) answer, quoteAssets, context); GrapheneApiGenerator.getEquivalentValue((BitsharesAsset) answer, quoteAssets, context);
} }

View file

@ -28,6 +28,6 @@ public interface BitsharesAssetDao {
@Query("SELECT * FROM bitshares_asset WHERE bitshares_id = :bitsharesId") @Query("SELECT * FROM bitshares_asset WHERE bitshares_id = :bitsharesId")
BitsharesAssetInfo getBitsharesAssetInfoById(String bitsharesId); BitsharesAssetInfo getBitsharesAssetInfoById(String bitsharesId);
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.IGNORE)
public long[] insertBitsharesAssetInfo(BitsharesAssetInfo... accounts); public long[] insertBitsharesAssetInfo(BitsharesAssetInfo... accounts);
} }

View file

@ -35,7 +35,7 @@ public interface CryptoCurrencyDao {
@Query("SELECT * FROM crypto_currency WHERE name = :name") @Query("SELECT * FROM crypto_currency WHERE name = :name")
CryptoCurrency getByName(String name); CryptoCurrency getByName(String name);
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.IGNORE)
public long[] insertCryptoCurrency(CryptoCurrency... currencies); public long[] insertCryptoCurrency(CryptoCurrency... currencies);
} }

View file

@ -333,23 +333,21 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
GrapheneAccount account = new GrapheneAccount(); GrapheneAccount account = new GrapheneAccount();
account.setName(createRequest.getAccountName()); account.setName(createRequest.getAccountName());
account.setSeedId(idSeed); account.setSeedId(idSeed);
account.setAccountIndex(0); account.setAccountIndex(0);
account.setCryptoNet(CryptoNet.BITSHARES); account.setCryptoNet(CryptoNet.BITSHARES);
this.createAccountFromSeed(account, new ManagerRequest() { this.createAccountFromSeed(account, new ManagerRequest() {
@Override
public void success(Object answer) {
createRequest.setAccount((GrapheneAccount) answer);
createRequest.setStatus(ValidateCreateBitsharesAccountRequest.StatusCode.SUCCEEDED);
}
@Override
public void fail() {
createRequest.setStatus(ValidateCreateBitsharesAccountRequest.StatusCode.ACCOUNT_EXIST);
}
}, context);
@Override
public void success(Object answer) {
createRequest.setAccount((GrapheneAccount) answer);
createRequest.setStatus(ValidateCreateBitsharesAccountRequest.StatusCode.SUCCEEDED);
}
@Override
public void fail() {
createRequest.setStatus(ValidateCreateBitsharesAccountRequest.StatusCode.ACCOUNT_EXIST);
}
}, context);
} }
/** /**
@ -681,10 +679,20 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
public void success(Object answer, int idPetition) { public void success(Object answer, int idPetition) {
ArrayList<BitsharesAsset> assets = (ArrayList<BitsharesAsset>) answer; ArrayList<BitsharesAsset> assets = (ArrayList<BitsharesAsset>) answer;
for(BitsharesAsset asset : assets){ for(BitsharesAsset asset : assets){
long idCryptoCurrency = db.cryptoCurrencyDao().insertCryptoCurrency(asset)[0]; long currencyId = -1;
CryptoCurrency cryptoCurrencyDb = db.cryptoCurrencyDao().getByNameAndCryptoNet(asset.getName(),asset.getCryptoNet().name());
if (cryptoCurrencyDb != null){
currencyId = cryptoCurrencyDb.getId();
} else {
long idCryptoCurrency = db.cryptoCurrencyDao().insertCryptoCurrency(asset)[0];
currencyId = idCryptoCurrency;
}
BitsharesAssetInfo info = new BitsharesAssetInfo(asset); BitsharesAssetInfo info = new BitsharesAssetInfo(asset);
info.setCryptoCurrencyId(idCryptoCurrency); info.setCryptoCurrencyId(currencyId);
asset.setId((int)idCryptoCurrency); asset.setId((int)currencyId);
db.bitsharesAssetDao().insertBitsharesAssetInfo(info); db.bitsharesAssetDao().insertBitsharesAssetInfo(info);
saveTransaction(transaction,info,transfer); saveTransaction(transaction,info,transfer);
} }