Bitshares petition fix

This commit is contained in:
henry 2017-10-23 23:25:09 -04:00
parent efb6820b9e
commit e3629f5c5b
3 changed files with 133 additions and 65 deletions

View file

@ -1,6 +1,5 @@
package cy.agorise.crystalwallet.apigenerator; package cy.agorise.crystalwallet.apigenerator;
import android.app.Application;
import android.arch.lifecycle.LiveData; import android.arch.lifecycle.LiveData;
import android.content.Context; import android.content.Context;
@ -17,7 +16,7 @@ import cy.agorise.crystalwallet.manager.BitsharesAccountManager;
import cy.agorise.crystalwallet.models.BitsharesAsset; import cy.agorise.crystalwallet.models.BitsharesAsset;
import cy.agorise.crystalwallet.models.BitsharesAssetInfo; import cy.agorise.crystalwallet.models.BitsharesAssetInfo;
import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCoinBalance;
import cy.agorise.crystalwallet.models.CryptoNetBalance; import cy.agorise.crystalwallet.models.CryptoCurrency;
import cy.agorise.crystalwallet.network.WebSocketThread; import cy.agorise.crystalwallet.network.WebSocketThread;
import cy.agorise.graphenej.Address; import cy.agorise.graphenej.Address;
import cy.agorise.graphenej.Asset; import cy.agorise.graphenej.Asset;
@ -28,6 +27,7 @@ import cy.agorise.graphenej.UserAccount;
import cy.agorise.graphenej.api.GetAccountBalances; import cy.agorise.graphenej.api.GetAccountBalances;
import cy.agorise.graphenej.api.GetAccountByName; import cy.agorise.graphenej.api.GetAccountByName;
import cy.agorise.graphenej.api.GetAccounts; import cy.agorise.graphenej.api.GetAccounts;
import cy.agorise.graphenej.api.GetBlockHeader;
import cy.agorise.graphenej.api.GetKeyReferences; import cy.agorise.graphenej.api.GetKeyReferences;
import cy.agorise.graphenej.api.GetRelativeAccountHistory; import cy.agorise.graphenej.api.GetRelativeAccountHistory;
import cy.agorise.graphenej.api.ListAssets; import cy.agorise.graphenej.api.ListAssets;
@ -40,7 +40,6 @@ import cy.agorise.graphenej.interfaces.WitnessResponseListener;
import cy.agorise.graphenej.models.AccountBalanceUpdate; import cy.agorise.graphenej.models.AccountBalanceUpdate;
import cy.agorise.graphenej.models.AccountProperties; import cy.agorise.graphenej.models.AccountProperties;
import cy.agorise.graphenej.models.BaseResponse; import cy.agorise.graphenej.models.BaseResponse;
import cy.agorise.graphenej.models.BroadcastedTransaction;
import cy.agorise.graphenej.models.HistoricalTransfer; import cy.agorise.graphenej.models.HistoricalTransfer;
import cy.agorise.graphenej.models.SubscriptionResponse; import cy.agorise.graphenej.models.SubscriptionResponse;
import cy.agorise.graphenej.models.WitnessResponse; import cy.agorise.graphenej.models.WitnessResponse;
@ -237,8 +236,8 @@ public abstract class GrapheneApiGenerator {
}else{ }else{
ArrayList<BitsharesAsset> responseAssets = new ArrayList<>(); ArrayList<BitsharesAsset> responseAssets = new ArrayList<>();
for(Asset asset: assets){ for(Asset asset: assets){
BitsharesAsset.Type assetType = null; BitsharesAsset.Type assetType = BitsharesAsset.Type.UIA;
if(asset.getAssetType().equals(Asset.AssetType.CORE_ASSET)){ /*if(asset.getAssetType().equals(Asset.AssetType.CORE_ASSET)){
assetType = BitsharesAsset.Type.CORE; assetType = BitsharesAsset.Type.CORE;
}else if(asset.getAssetType().equals(Asset.AssetType.SMART_COIN)){ }else if(asset.getAssetType().equals(Asset.AssetType.SMART_COIN)){
assetType = BitsharesAsset.Type.SMART_COIN; assetType = BitsharesAsset.Type.SMART_COIN;
@ -246,7 +245,7 @@ public abstract class GrapheneApiGenerator {
assetType = BitsharesAsset.Type.UIA; assetType = BitsharesAsset.Type.UIA;
}else if(asset.getAssetType().equals(Asset.AssetType.PREDICTION_MARKET)){ }else if(asset.getAssetType().equals(Asset.AssetType.PREDICTION_MARKET)){
assetType = BitsharesAsset.Type.PREDICTION_MARKET; assetType = BitsharesAsset.Type.PREDICTION_MARKET;
} }*/
BitsharesAsset responseAsset = new BitsharesAsset(asset.getSymbol(),asset.getPrecision(),asset.getObjectId(),assetType); BitsharesAsset responseAsset = new BitsharesAsset(asset.getSymbol(),asset.getPrecision(),asset.getObjectId(),assetType);
responseAssets.add(responseAsset); responseAssets.add(responseAsset);
} }
@ -278,8 +277,8 @@ public abstract class GrapheneApiGenerator {
}else{ }else{
ArrayList<BitsharesAsset> responseAssets = new ArrayList<>(); ArrayList<BitsharesAsset> responseAssets = new ArrayList<>();
for(Asset asset: assets){ for(Asset asset: assets){
BitsharesAsset.Type assetType = null; BitsharesAsset.Type assetType = BitsharesAsset.Type.UIA;
if(asset.getAssetType().equals(Asset.AssetType.CORE_ASSET)){ /*if(asset.getAssetType().equals(Asset.AssetType.CORE_ASSET)){
assetType = BitsharesAsset.Type.CORE; assetType = BitsharesAsset.Type.CORE;
}else if(asset.getAssetType().equals(Asset.AssetType.SMART_COIN)){ }else if(asset.getAssetType().equals(Asset.AssetType.SMART_COIN)){
assetType = BitsharesAsset.Type.SMART_COIN; assetType = BitsharesAsset.Type.SMART_COIN;
@ -287,7 +286,7 @@ public abstract class GrapheneApiGenerator {
assetType = BitsharesAsset.Type.UIA; assetType = BitsharesAsset.Type.UIA;
}else if(asset.getAssetType().equals(Asset.AssetType.PREDICTION_MARKET)){ }else if(asset.getAssetType().equals(Asset.AssetType.PREDICTION_MARKET)){
assetType = BitsharesAsset.Type.PREDICTION_MARKET; assetType = BitsharesAsset.Type.PREDICTION_MARKET;
} }*/
BitsharesAsset responseAsset = new BitsharesAsset(asset.getSymbol(),asset.getPrecision(),asset.getObjectId(),assetType); BitsharesAsset responseAsset = new BitsharesAsset(asset.getSymbol(),asset.getPrecision(),asset.getObjectId(),assetType);
responseAssets.add(responseAsset); responseAssets.add(responseAsset);
} }
@ -323,35 +322,40 @@ public abstract class GrapheneApiGenerator {
if(update instanceof AccountBalanceUpdate){ if(update instanceof AccountBalanceUpdate){
AccountBalanceUpdate balanceUpdate = (AccountBalanceUpdate) update; AccountBalanceUpdate balanceUpdate = (AccountBalanceUpdate) update;
if(balanceUpdate.owner.equals(accountBitsharesId)){ if(balanceUpdate.owner.equals(accountBitsharesId)){
CryptoCoinBalance balance = new CryptoCoinBalance(); final CryptoCoinBalance balance = new CryptoCoinBalance();
balance.setAccountId(accountId); balance.setAccountId(accountId);
balance.setBalance(((AccountBalanceUpdate) update).balance); balance.setBalance(((AccountBalanceUpdate) update).balance);
/*LiveData<BitsharesAssetInfo> assetInfo = bitsharesAssetDao.getBitsharesAssetInfoById(((AccountBalanceUpdate) update).asset_type); LiveData<BitsharesAssetInfo> assetInfo = bitsharesAssetDao.getBitsharesAssetInfoById(((AccountBalanceUpdate) update).asset_type);
if(assetInfo == null || assetInfo.getValue() == null){ if(assetInfo == null || assetInfo.getValue() == null){
BitsharesAsset.Type assetType; final String assetType = ((AccountBalanceUpdate) update).asset_type;
Asset asset = balance.getAsset(); ArrayList<String> idAssets = new ArrayList<>();
if(asset.getAssetType().equals(Asset.AssetType.CORE_ASSET)){ idAssets.add(assetType);
assetType = BitsharesAsset.Type.CORE; ApiRequest getAssetRequest = new ApiRequest(1, new ApiRequestListener() {
}else if(asset.getAssetType().equals(Asset.AssetType.SMART_COIN)){ @Override
assetType = BitsharesAsset.Type.SMART_COIN; public void success(Object answer, int idPetition) {
}else if(asset.getAssetType().equals(Asset.AssetType.UIA)){ if(answer instanceof BitsharesAsset){
assetType = BitsharesAsset.Type.UIA; BitsharesAssetInfo info = new BitsharesAssetInfo((BitsharesAsset) answer);
}else if(asset.getAssetType().equals(Asset.AssetType.PREDICTION_MARKET)){ cryptoCurrencyDao.insertCryptoCurrency((CryptoCurrency)answer );
assetType = BitsharesAsset.Type.PREDICTION_MARKET; bitsharesAssetDao.insertBitsharesAssetInfo(info);
} balance.setCryptoCurrencyId(bitsharesAssetDao.getBitsharesAssetInfoById(assetType).getValue().getCryptoCurrencyId());
balanceDao.insertCryptoCoinBalance(balance);
}
}
BitsharesAsset newAsset = new BitsharesAsset(asset.getSymbol(),asset.getPrecision(),asset.getObjectId(),assetType); @Override
BitsharesAssetInfo info = new BitsharesAssetInfo(newAsset); public void fail(int idPetition) {
cryptoCurrencyDao.insertCryptoCurrency(newAsset);
bitsharesAssetDao.insertBitsharesAssetInfo(info); }
assetInfo = bitsharesAssetDao.getBitsharesAssetInfoById(balance.getAsset().getObjectId()); });
getAssetById(idAssets,getAssetRequest);
}else {
balance.setCryptoCurrencyId(assetInfo.getValue().getCryptoCurrencyId());
balanceDao.insertCryptoCoinBalance(balance);
//TODO balance function
} }
balance.setCryptoCurrency(assetInfo.getValue().getCryptoCurrencyId());
balanceDao.insertCryptoCoinBalance(balance);*/
//TODO balance function
BitsharesAccountManager.refreshAccountTransactions(accountId,context); BitsharesAccountManager.refreshAccountTransactions(accountId,context);
} }
} }
} }
@ -381,37 +385,42 @@ public abstract class GrapheneApiGenerator {
final CryptoCoinBalanceDao balanceDao = db.cryptoCoinBalanceDao(); final CryptoCoinBalanceDao balanceDao = db.cryptoCoinBalanceDao();
final BitsharesAssetDao bitsharesAssetDao = db.bitsharesAssetDao(); final BitsharesAssetDao bitsharesAssetDao = db.bitsharesAssetDao();
final CryptoCurrencyDao cryptoCurrencyDao = db.cryptoCurrencyDao(); final CryptoCurrencyDao cryptoCurrencyDao = db.cryptoCurrencyDao();
WebSocketThread thread = new WebSocketThread(new GetAccountBalances(new UserAccount(accountGrapheneId), null, new WitnessResponseListener() { WebSocketThread thread = new WebSocketThread(new GetAccountBalances(new UserAccount(accountGrapheneId), new ArrayList<Asset>(), new WitnessResponseListener() {
@Override @Override
public void onSuccess(WitnessResponse response) { public void onSuccess(WitnessResponse response) {
List<AssetAmount> balances = (List<AssetAmount>) response.result; List<AssetAmount> balances = (List<AssetAmount>) response.result;
for(AssetAmount balance : balances){ for(final AssetAmount balance : balances){
CryptoCoinBalance ccBalance = new CryptoCoinBalance(); final CryptoCoinBalance ccBalance = new CryptoCoinBalance();
ccBalance.setAccountId(accountId); ccBalance.setAccountId(accountId);
ccBalance.setBalance(balance.getAmount().longValue()); ccBalance.setBalance(balance.getAmount().longValue());
LiveData<BitsharesAssetInfo> assetInfo = bitsharesAssetDao.getBitsharesAssetInfoById(balance.getAsset().getObjectId()); LiveData<BitsharesAssetInfo> assetInfo = bitsharesAssetDao.getBitsharesAssetInfoById(balance.getAsset().getObjectId());
if(assetInfo == null || assetInfo.getValue() == null){ if(assetInfo == null || assetInfo.getValue() == null){
BitsharesAsset.Type assetType = null; ArrayList<String> idAssets = new ArrayList<>();
Asset asset = balance.getAsset(); idAssets.add(balance.getAsset().getObjectId());
if(asset.getAssetType().equals(Asset.AssetType.CORE_ASSET)){ ApiRequest getAssetRequest = new ApiRequest(1, new ApiRequestListener() {
assetType = BitsharesAsset.Type.CORE; @Override
}else if(asset.getAssetType().equals(Asset.AssetType.SMART_COIN)){ public void success(Object answer, int idPetition) {
assetType = BitsharesAsset.Type.SMART_COIN; if(answer instanceof BitsharesAsset){
}else if(asset.getAssetType().equals(Asset.AssetType.UIA)){ BitsharesAssetInfo info = new BitsharesAssetInfo((BitsharesAsset) answer);
assetType = BitsharesAsset.Type.UIA; cryptoCurrencyDao.insertCryptoCurrency((CryptoCurrency)answer );
}else if(asset.getAssetType().equals(Asset.AssetType.PREDICTION_MARKET)){ bitsharesAssetDao.insertBitsharesAssetInfo(info);
assetType = BitsharesAsset.Type.PREDICTION_MARKET; ccBalance.setCryptoCurrencyId(bitsharesAssetDao.getBitsharesAssetInfoById(balance.getAsset().getObjectId()).getValue().getCryptoCurrencyId());
} balanceDao.insertCryptoCoinBalance(ccBalance);
}
}
BitsharesAsset newAsset = new BitsharesAsset(asset.getSymbol(),asset.getPrecision(),asset.getObjectId(),assetType); @Override
BitsharesAssetInfo info = new BitsharesAssetInfo(newAsset); public void fail(int idPetition) {
cryptoCurrencyDao.insertCryptoCurrency(newAsset);
bitsharesAssetDao.insertBitsharesAssetInfo(info); }
assetInfo = bitsharesAssetDao.getBitsharesAssetInfoById(balance.getAsset().getObjectId()); });
getAssetById(idAssets,getAssetRequest);
}else {
ccBalance.setCryptoCurrencyId(assetInfo.getValue().getCryptoCurrencyId());
balanceDao.insertCryptoCoinBalance(ccBalance);
} }
ccBalance.setCryptoCurrencyId(assetInfo.getValue().getCryptoCurrencyId());
balanceDao.insertCryptoCoinBalance(ccBalance);
} }
} }
@ -425,4 +434,24 @@ public abstract class GrapheneApiGenerator {
} }
public static void getBlockHeaderTime(long blockHeader, final ApiRequest request){
WebSocketThread thread = new WebSocketThread(new GetBlockHeader(blockHeader, new WitnessResponseListener() {
@Override
public void onSuccess(WitnessResponse response) {
if(response == null){
request.getListener().fail(request.getId());
}else {
request.getListener().success(response.result, request.getId());
}
}
@Override
public void onError(BaseResponse.Error error) {
request.getListener().fail(request.getId());
}
}),url);
thread.start();
}
} }

View file

@ -22,6 +22,9 @@ public interface CryptoCurrencyDao {
@Query("SELECT * FROM crypto_currency WHERE id = :id") @Query("SELECT * FROM crypto_currency WHERE id = :id")
CryptoCurrency getById(int id); CryptoCurrency getById(int id);
@Query("SELECT * FROM crypto_currency WHERE name = :name")
CryptoCurrency getByName(String name);
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
public long[] insertCryptoCurrency(CryptoCurrency... currencies); public long[] insertCryptoCurrency(CryptoCurrency... currencies);

View file

@ -5,11 +5,15 @@ import android.content.Context;
import com.google.common.primitives.UnsignedLong; import com.google.common.primitives.UnsignedLong;
import org.bitcoinj.core.Block;
import org.bitcoinj.core.ECKey; import org.bitcoinj.core.ECKey;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.TimeZone;
import cy.agorise.crystalwallet.apigenerator.ApiRequest; import cy.agorise.crystalwallet.apigenerator.ApiRequest;
import cy.agorise.crystalwallet.apigenerator.ApiRequestListener; import cy.agorise.crystalwallet.apigenerator.ApiRequestListener;
@ -21,9 +25,11 @@ import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendReque
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAccountRequest; import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAccountRequest;
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateImportBitsharesAccountRequest; import cy.agorise.crystalwallet.cryptonetinforequests.ValidateImportBitsharesAccountRequest;
import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.dao.TransactionDao;
import cy.agorise.crystalwallet.enums.CryptoNet; import cy.agorise.crystalwallet.enums.CryptoNet;
import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.AccountSeed;
import cy.agorise.crystalwallet.models.BitsharesAsset; import cy.agorise.crystalwallet.models.BitsharesAsset;
import cy.agorise.crystalwallet.models.BitsharesAssetInfo;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoCurrency; import cy.agorise.crystalwallet.models.CryptoCurrency;
import cy.agorise.crystalwallet.models.CryptoNetAccount; import cy.agorise.crystalwallet.models.CryptoNetAccount;
@ -38,6 +44,7 @@ import cy.agorise.graphenej.PublicKey;
import cy.agorise.graphenej.Transaction; import cy.agorise.graphenej.Transaction;
import cy.agorise.graphenej.UserAccount; import cy.agorise.graphenej.UserAccount;
import cy.agorise.graphenej.models.AccountProperties; import cy.agorise.graphenej.models.AccountProperties;
import cy.agorise.graphenej.models.BlockHeader;
import cy.agorise.graphenej.models.HistoricalTransfer; import cy.agorise.graphenej.models.HistoricalTransfer;
import cy.agorise.graphenej.objects.Memo; import cy.agorise.graphenej.objects.Memo;
import cy.agorise.graphenej.operations.TransferOperationBuilder; import cy.agorise.graphenej.operations.TransferOperationBuilder;
@ -77,14 +84,17 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
GrapheneAccount grapheneAccount = (GrapheneAccount) account; GrapheneAccount grapheneAccount = (GrapheneAccount) account;
if(grapheneAccount.getAccountId() == null){ if(grapheneAccount.getAccountId() == null){
System.out.println("Importing without accountid");
grapheneAccount = this.getAccountInfoByName(grapheneAccount.getName()); grapheneAccount = this.getAccountInfoByName(grapheneAccount.getName());
}else if(grapheneAccount.getName() == null){ }else if(grapheneAccount.getName() == null){
System.out.println("Importing without accountname");
grapheneAccount = this.getAccountInfoById(grapheneAccount.getAccountId()); grapheneAccount = this.getAccountInfoById(grapheneAccount.getAccountId());
} }
if(grapheneAccount == null) { if(grapheneAccount == null) {
//TODO grapaheneAccount null, error fetching //TODO grapaheneAccount null, error fetching
return null; return null;
} }
System.out.println("Importing not null " + ((GrapheneAccount) account).getName() + " " + ((GrapheneAccount) account).getAccountId());
CrystalDatabase db = CrystalDatabase.getAppDatabase(context); CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount); db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount);
@ -268,23 +278,20 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
} }
public static void refreshAccountTransactions(long idAccount, Context context){ public static void refreshAccountTransactions(long idAccount, Context context){
System.out.println("Call refresh Account transactions from " + idAccount);
CrystalDatabase db = CrystalDatabase.getAppDatabase(context); CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
List<CryptoCoinTransaction> transactions = db.transactionDao().getByIdAccount(idAccount); List<CryptoCoinTransaction> transactions = db.transactionDao().getByIdAccount(idAccount);
CryptoNetAccount account = db.cryptoNetAccountDao().getById(idAccount); CryptoNetAccount account = db.cryptoNetAccountDao().getById(idAccount);
if(account.getCryptoNet() == CryptoNet.BITSHARES) { if(account.getCryptoNet() == CryptoNet.BITSHARES) {
GrapheneAccount grapheneAccount = new GrapheneAccount(account); GrapheneAccount grapheneAccount = new GrapheneAccount(account);
grapheneAccount.loadInfo(db.grapheneAccountInfoDao().getByAccountId(idAccount)); grapheneAccount.loadInfo(db.grapheneAccountInfoDao().getByAccountId(idAccount));
int start = transactions.size(); int start = transactions.size();
int limit = 50; int limit = 50;
int stop = start + limit; int stop = start + limit;
ApiRequest transactionRequest = new ApiRequest(0, new TransactionRequestListener(start, stop, limit, grapheneAccount, db)); ApiRequest transactionRequest = new ApiRequest(0, new TransactionRequestListener(start, stop, limit, grapheneAccount, db));
GrapheneApiGenerator.getAccountTransaction(grapheneAccount.getName(), start, stop, limit, transactionRequest); GrapheneApiGenerator.getAccountTransaction(grapheneAccount.getName(), start, stop, limit, transactionRequest);
} }
} }
@ -312,13 +319,12 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
CryptoCoinTransaction transaction = new CryptoCoinTransaction(); CryptoCoinTransaction transaction = new CryptoCoinTransaction();
transaction.setAccountId(account.getId()); transaction.setAccountId(account.getId());
transaction.setAmount(transfer.getOperation().getAssetAmount().getAmount().longValue()); transaction.setAmount(transfer.getOperation().getAssetAmount().getAmount().longValue());
BitsharesAsset currency = null; CryptoCurrency currency = db.cryptoCurrencyDao().getByName(transfer.getOperation().getAssetAmount().getAsset().getSymbol());
//TODO find currency by symbol db.cryptoCurrencyDao().getBySymbol(transfer.getOperation().getAssetAmount().getAsset().getSymbol())
if(currency == null){ if(currency == null){
//CryptoCurrency not in database //CryptoCurrency not in database
Asset asset = transfer.getOperation().getAssetAmount().getAsset(); Asset asset = transfer.getOperation().getAssetAmount().getAsset();
BitsharesAsset.Type assetType = null; BitsharesAsset.Type assetType = BitsharesAsset.Type.UIA;
if(asset.getAssetType() == Asset.AssetType.CORE_ASSET){ /*if(asset.getAssetType() == Asset.AssetType.CORE_ASSET){
assetType = BitsharesAsset.Type.CORE; assetType = BitsharesAsset.Type.CORE;
}else if(asset.getAssetType() == Asset.AssetType.SMART_COIN){ }else if(asset.getAssetType() == Asset.AssetType.SMART_COIN){
assetType = BitsharesAsset.Type.SMART_COIN; assetType = BitsharesAsset.Type.SMART_COIN;
@ -326,18 +332,19 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
assetType = BitsharesAsset.Type.PREDICTION_MARKET; assetType = BitsharesAsset.Type.PREDICTION_MARKET;
}else if(asset.getAssetType() == Asset.AssetType.UIA){ }else if(asset.getAssetType() == Asset.AssetType.UIA){
assetType = BitsharesAsset.Type.UIA; assetType = BitsharesAsset.Type.UIA;
} }*/
currency = new BitsharesAsset(asset.getSymbol(),asset.getPrecision(),asset.getObjectId(), assetType); currency = new BitsharesAsset(asset.getSymbol(),asset.getPrecision(),asset.getObjectId(), assetType);
db.cryptoCurrencyDao().insertCryptoCurrency(currency); db.cryptoCurrencyDao().insertCryptoCurrency(currency);
db.bitsharesAssetDao().insertBitsharesAssetInfo(new BitsharesAssetInfo((BitsharesAsset)currency));
} }
transaction.setIdCurrency(currency.getId()); transaction.setIdCurrency(currency.getId());
transaction.setConfirmed(true); //graphene transaction are always confirmed transaction.setConfirmed(true); //graphene transaction are always confirmed
//TODO date of the transaction transaction.setDate(transfer.);
transaction.setFrom(transfer.getOperation().getFrom().getName()); transaction.setFrom(transfer.getOperation().getFrom().getName());
transaction.setInput(!transfer.getOperation().getFrom().getName().equals(account.getName())); transaction.setInput(!transfer.getOperation().getFrom().getName().equals(account.getName()));
transaction.setTo(transfer.getOperation().getTo().getName()); transaction.setTo(transfer.getOperation().getTo().getName());
db.transactionDao().insertTransaction(transaction);
GrapheneApiGenerator.getBlockHeaderTime(transfer.getBlockNum(),new ApiRequest(0,new GetTransactionDate(transaction,db.transactionDao())));
} }
if(transfers.size()>= limit){ if(transfers.size()>= limit){
int newStart= start + limit; int newStart= start + limit;
@ -387,4 +394,33 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
} }
} }
private static class GetTransactionDate implements ApiRequestListener{
private CryptoCoinTransaction transaction;
TransactionDao transactionDao;
public GetTransactionDate(CryptoCoinTransaction transaction, TransactionDao transactionDao) {
this.transaction = transaction;
this.transactionDao = transactionDao;
}
@Override
public void success(Object answer, int idPetition) {
if(answer instanceof BlockHeader){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
try {
transaction.setDate(dateFormat.parse(((BlockHeader) answer).timestamp));
transactionDao.insertTransaction(transaction);
} catch (ParseException e) {
e.printStackTrace();
}
}
}
@Override
public void fail(int idPetition) {
}
}
} }