From 5ceffbec2fb66ce3ccafade7f87387ec7a614df0 Mon Sep 17 00:00:00 2001 From: hvarona Date: Thu, 22 Nov 2018 22:36:45 -0400 Subject: [PATCH] added send request to manager --- .../insightapi/BroadcastTransaction.java | 11 ++++++++--- .../manager/GeneralAccountManager.java | 19 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/insightapi/BroadcastTransaction.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/insightapi/BroadcastTransaction.java index c4fa9cc..75910d6 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/insightapi/BroadcastTransaction.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/insightapi/BroadcastTransaction.java @@ -65,9 +65,14 @@ public class BroadcastTransaction extends Thread implements Callback { */ @Override public void run() { - InsightApiService service = this.mServiceGenerator.getService(InsightApiService.class); - Call broadcastTransaction = service.broadcastTransaction(this.mPath,this.mRawTx); - broadcastTransaction.enqueue(this); + try { + + InsightApiService service = this.mServiceGenerator.getService(InsightApiService.class); + Call broadcastTransaction = service.broadcastTransaction(this.mPath, this.mRawTx); + broadcastTransaction.enqueue(this); + }catch(Exception e){ + e.printStackTrace(); + } } public interface BroadCastTransactionListener{ diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java index 84c8165..b802316 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java @@ -98,7 +98,19 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf new ChildNumber(1, false)); CryptoCoinBalance balance = new CryptoCoinBalance(); - balance.setBalance(0); + long amount = 0; + List trransactions = db.transactionDao().getByIdAccount(account.getId()); + for(CryptoCoinTransaction transaction : trransactions){ + if(transaction.isConfirmed()){ + if(transaction.getInput()){ + amount += transaction.getAmount(); + }else{ + amount -= transaction.getAmount(); + } + + } + } + balance.setBalance(amount); balance.setCryptoCurrencyId(db.cryptoCurrencyDao().getByName(cryptoCoin.getLabel(),cryptoCoin.name()).getId()); balance.setAccountId(account.getId()); db.cryptoCoinBalanceDao().insertCryptoCoinBalance(balance); @@ -115,7 +127,7 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf address.setChange(false); address.setAccountId(account.getId()); address.setIndex(0); - String addressString =externalAddrKey.toAddress(this.cryptoCoin.getParameters()).toString(); + String addressString = externalAddrKey.toAddress(this.cryptoCoin.getParameters()).toString(); address.setAddress(addressString); db.bitcoinAddressDao().insertBitcoinAddresses(address); InsightApiGenerator.getTransactionFromAddress(cryptoCoin,addressString,true, @@ -149,6 +161,7 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf //if(Arrays.asList(SUPPORTED_COINS).contains(request.getCoin())){ if(request.getCoin().equals(this.cryptoCoin)){ if(request instanceof BitcoinSendRequest) { + this.send((BitcoinSendRequest) request); }else if(request instanceof CreateBitcoinAccountRequest){ this.createGeneralAccount((CreateBitcoinAccountRequest) request); }else if(request instanceof NextBitcoinAccountAddressRequest){ @@ -360,12 +373,10 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf public void send(final BitcoinSendRequest request){ //TODO check server connection //TODO validate to address - System.out.println("GeneralAccountManager sending " + request.getAmount()); InsightApiGenerator.getEstimateFee(this.cryptoCoin,new ApiRequest(1, new ApiRequestListener() { @Override public void success(Object answer, int idPetition) { - System.out.println("GeneralAccountManager estimateFee response " + answer); Transaction tx = new Transaction(cryptoCoin.getParameters()); long currentAmount = 0; long fee = -1;