- Added the subcription logic to grapheneApi
This commit is contained in:
parent
697c2406fd
commit
d7acd8517c
2 changed files with 37 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
||||||
package cy.agorise.crystalwallet.apigenerator;
|
package cy.agorise.crystalwallet.apigenerator;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.NodeErrorListener;
|
||||||
import cy.agorise.graphenej.interfaces.SubscriptionListener;
|
import cy.agorise.graphenej.interfaces.SubscriptionListener;
|
||||||
import cy.agorise.graphenej.interfaces.WitnessResponseListener;
|
import cy.agorise.graphenej.interfaces.WitnessResponseListener;
|
||||||
|
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;
|
||||||
|
@ -260,7 +263,7 @@ public class GrapheneApiGenerator {
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void subscribeBitsharesAccount(String accountId){
|
public static void subscribeBitsharesAccount(final String accountId){
|
||||||
SubscriptionListener balanceListener = new SubscriptionListener() {
|
SubscriptionListener balanceListener = new SubscriptionListener() {
|
||||||
@Override
|
@Override
|
||||||
public ObjectType getInterestObjectType() {
|
public ObjectType getInterestObjectType() {
|
||||||
|
@ -269,23 +272,22 @@ public class GrapheneApiGenerator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSubscriptionUpdate(SubscriptionResponse response) {
|
public void onSubscriptionUpdate(SubscriptionResponse response) {
|
||||||
|
List<Serializable> updatedObjects = (List<Serializable>) 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 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(balanceListener);
|
||||||
bitsharesSubscriptionHub.addSubscriptionListener(transactionListener);
|
|
||||||
|
|
||||||
if(!subscriptionThread.isConnected()){
|
if(!subscriptionThread.isConnected()){
|
||||||
subscriptionThread.start();
|
subscriptionThread.start();
|
||||||
|
|
|
@ -19,6 +19,7 @@ import cy.agorise.crystalwallet.cryptonetinforequests.ValidateImportBitsharesAcc
|
||||||
import cy.agorise.crystalwallet.dao.CrystalDatabase;
|
import cy.agorise.crystalwallet.dao.CrystalDatabase;
|
||||||
import cy.agorise.crystalwallet.models.AccountSeed;
|
import cy.agorise.crystalwallet.models.AccountSeed;
|
||||||
import cy.agorise.crystalwallet.models.CryptoNetAccount;
|
import cy.agorise.crystalwallet.models.CryptoNetAccount;
|
||||||
|
import cy.agorise.crystalwallet.models.GrapheneAccount;
|
||||||
import cy.agorise.graphenej.Address;
|
import cy.agorise.graphenej.Address;
|
||||||
import cy.agorise.graphenej.Asset;
|
import cy.agorise.graphenej.Asset;
|
||||||
import cy.agorise.graphenej.AssetAmount;
|
import cy.agorise.graphenej.AssetAmount;
|
||||||
|
@ -37,17 +38,37 @@ import cy.agorise.graphenej.operations.TransferOperationBuilder;
|
||||||
public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetInfoRequestsListener {
|
public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetInfoRequestsListener {
|
||||||
@Override
|
@Override
|
||||||
public CryptoNetAccount createAccountFromSeed(CryptoNetAccount account) {
|
public CryptoNetAccount createAccountFromSeed(CryptoNetAccount account) {
|
||||||
|
//TODO generate account keys
|
||||||
|
//TODO register account
|
||||||
|
//TODO save account on DB
|
||||||
|
//TODO subscribe account
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CryptoNetAccount importAccountFromSeed(CryptoNetAccount account) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadAccountFromDB(CryptoNetAccount account) {
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue