Added Bitshares subscription hub manager in grapheneapigenerator, this will be used for real time updatess
This commit is contained in:
parent
557a3e9202
commit
81669160a9
2 changed files with 58 additions and 5 deletions
|
@ -1,10 +1,5 @@
|
||||||
package cy.agorise.crystalwallet.apigenerator;
|
package cy.agorise.crystalwallet.apigenerator;
|
||||||
|
|
||||||
import com.neovisionaries.ws.client.WebSocket;
|
|
||||||
import com.neovisionaries.ws.client.WebSocketException;
|
|
||||||
import com.neovisionaries.ws.client.WebSocketFactory;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -12,6 +7,7 @@ import cy.agorise.crystalwallet.models.BitsharesAsset;
|
||||||
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;
|
||||||
|
import cy.agorise.graphenej.ObjectType;
|
||||||
import cy.agorise.graphenej.Transaction;
|
import cy.agorise.graphenej.Transaction;
|
||||||
import cy.agorise.graphenej.UserAccount;
|
import cy.agorise.graphenej.UserAccount;
|
||||||
import cy.agorise.graphenej.api.GetAccountByName;
|
import cy.agorise.graphenej.api.GetAccountByName;
|
||||||
|
@ -20,11 +16,15 @@ 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;
|
||||||
import cy.agorise.graphenej.api.LookupAssetSymbols;
|
import cy.agorise.graphenej.api.LookupAssetSymbols;
|
||||||
|
import cy.agorise.graphenej.api.SubscriptionMessagesHub;
|
||||||
import cy.agorise.graphenej.api.TransactionBroadcastSequence;
|
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.interfaces.WitnessResponseListener;
|
||||||
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.HistoricalTransfer;
|
import cy.agorise.graphenej.models.HistoricalTransfer;
|
||||||
|
import cy.agorise.graphenej.models.SubscriptionResponse;
|
||||||
import cy.agorise.graphenej.models.WitnessResponse;
|
import cy.agorise.graphenej.models.WitnessResponse;
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,6 +39,16 @@ public class GrapheneApiGenerator {
|
||||||
//TODO make to work with all Graphene stype, not only bitshares
|
//TODO make to work with all Graphene stype, not only bitshares
|
||||||
private static String url = "http://128.0.69.157:8090";
|
private static String url = "http://128.0.69.157:8090";
|
||||||
|
|
||||||
|
// The meesage broker for bitshares
|
||||||
|
private static SubscriptionMessagesHub bitsharesSubscriptionHub = new SubscriptionMessagesHub("", "", true, new NodeErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void onError(BaseResponse.Error error) {
|
||||||
|
//TODO subcription hub error
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
private static WebSocketThread subscriptionThread = new WebSocketThread(bitsharesSubscriptionHub,url);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the data of an account searching by it's id
|
* Retrieves the data of an account searching by it's id
|
||||||
*
|
*
|
||||||
|
@ -249,4 +259,43 @@ public class GrapheneApiGenerator {
|
||||||
}),url);
|
}),url);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void subscribeBitsharesAccount(String accountId){
|
||||||
|
SubscriptionListener balanceListener = new SubscriptionListener() {
|
||||||
|
@Override
|
||||||
|
public ObjectType getInterestObjectType() {
|
||||||
|
return ObjectType.BALANCE_OBJECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSubscriptionUpdate(SubscriptionResponse response) {
|
||||||
|
//TODO balance function
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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();
|
||||||
|
}else if(!bitsharesSubscriptionHub.isSubscribed()){
|
||||||
|
bitsharesSubscriptionHub.resubscribe();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void cancelBitsharesAccountSubcriptions(){
|
||||||
|
bitsharesSubscriptionHub.cancelSubscriptions();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,4 +123,8 @@ public class WebSocketThread extends Thread {
|
||||||
}
|
}
|
||||||
WebSocketThread.currentThreads.remove(this.getId());
|
WebSocketThread.currentThreads.remove(this.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isConnected(){
|
||||||
|
return mWebSocket.isOpen();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue