From d7acd8517cefc7335f795c7deb1a432b5e15f6a3 Mon Sep 17 00:00:00 2001 From: henry Date: Wed, 11 Oct 2017 23:37:05 -0400 Subject: [PATCH] - Added the subcription logic to grapheneApi --- .../apigenerator/GrapheneApiGenerator.java | 30 ++++++++++--------- .../manager/BitsharesAccountManager.java | 21 +++++++++++++ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java index f02022b..812abe1 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java @@ -1,5 +1,6 @@ package cy.agorise.crystalwallet.apigenerator; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -21,8 +22,10 @@ import cy.agorise.graphenej.api.TransactionBroadcastSequence; import cy.agorise.graphenej.interfaces.NodeErrorListener; import cy.agorise.graphenej.interfaces.SubscriptionListener; import cy.agorise.graphenej.interfaces.WitnessResponseListener; +import cy.agorise.graphenej.models.AccountBalanceUpdate; import cy.agorise.graphenej.models.AccountProperties; import cy.agorise.graphenej.models.BaseResponse; +import cy.agorise.graphenej.models.BroadcastedTransaction; import cy.agorise.graphenej.models.HistoricalTransfer; import cy.agorise.graphenej.models.SubscriptionResponse; import cy.agorise.graphenej.models.WitnessResponse; @@ -260,7 +263,7 @@ public class GrapheneApiGenerator { thread.start(); } - public static void subscribeBitsharesAccount(String accountId){ + public static void subscribeBitsharesAccount(final String accountId){ SubscriptionListener balanceListener = new SubscriptionListener() { @Override public ObjectType getInterestObjectType() { @@ -269,23 +272,22 @@ public class GrapheneApiGenerator { @Override public void onSubscriptionUpdate(SubscriptionResponse response) { - //TODO balance function + List updatedObjects = (List) response.params.get(1); + if(updatedObjects.size() > 0){ + for(Serializable update : updatedObjects){ + if(update instanceof AccountBalanceUpdate){ + AccountBalanceUpdate balanceUpdate = (AccountBalanceUpdate) update; + if(balanceUpdate.owner.equals(accountId)){ + //TODO balance function + //TODO refresh transactions + } + } + } + } } }; - SubscriptionListener transactionListener = new SubscriptionListener() { - @Override - public ObjectType getInterestObjectType() { - return ObjectType.TRANSACTION_OBJECT; - } - - @Override - public void onSubscriptionUpdate(SubscriptionResponse response) { - //TODO transaciton function - } - }; bitsharesSubscriptionHub.addSubscriptionListener(balanceListener); - bitsharesSubscriptionHub.addSubscriptionListener(transactionListener); if(!subscriptionThread.isConnected()){ subscriptionThread.start(); diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java index f5c979f..51a5f12 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -19,6 +19,7 @@ import cy.agorise.crystalwallet.cryptonetinforequests.ValidateImportBitsharesAcc import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.models.GrapheneAccount; import cy.agorise.graphenej.Address; import cy.agorise.graphenej.Asset; import cy.agorise.graphenej.AssetAmount; @@ -37,17 +38,37 @@ import cy.agorise.graphenej.operations.TransferOperationBuilder; public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetInfoRequestsListener { @Override public CryptoNetAccount createAccountFromSeed(CryptoNetAccount account) { + //TODO generate account keys + //TODO register account + //TODO save account on DB + //TODO subscribe account return null; } @Override public CryptoNetAccount importAccountFromSeed(CryptoNetAccount account) { + //TODO check account info + //TODO save account on DB + //TODO subscribe account + //TODO refresh account transaction + //TODO refresh account balance return null; } @Override public void loadAccountFromDB(CryptoNetAccount account) { + if(account instanceof GrapheneAccount){ + GrapheneAccount grapheneAccount = (GrapheneAccount) account; + if(grapheneAccount.getAccountId() == null){ + //TODO find account data by name + }else if(grapheneAccount.getName() == null){ + //TODO find account data by id + } + GrapheneApiGenerator.subscribeBitsharesAccount(grapheneAccount.getAccountId()); + //TODO refresh account transactions + //TODO refresh account balance + } } @Override