This commit is contained in:
Javier Varona 2017-10-12 22:07:12 -04:00
commit b15c5a4710
2 changed files with 37 additions and 14 deletions

View file

@ -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) {
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 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();

View file

@ -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