2017-09-27 02:48:34 +00:00
|
|
|
package cy.agorise.crystalwallet.manager;
|
|
|
|
|
2017-10-03 02:49:17 +00:00
|
|
|
import cy.agorise.crystalwallet.apigenerator.ApiRequest;
|
|
|
|
import cy.agorise.crystalwallet.apigenerator.ApiRequestListener;
|
|
|
|
import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator;
|
2017-10-02 02:18:56 +00:00
|
|
|
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequest;
|
|
|
|
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestsListener;
|
|
|
|
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateImportBitsharesAccountRequest;
|
2017-09-27 02:48:34 +00:00
|
|
|
import cy.agorise.crystalwallet.models.CryptoNetAccount;
|
2017-10-04 01:31:16 +00:00
|
|
|
import cy.agorise.graphenej.BrainKey;
|
|
|
|
import cy.agorise.graphenej.PublicKey;
|
|
|
|
import cy.agorise.graphenej.models.AccountProperties;
|
2017-09-27 02:48:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by henry on 26/9/2017.
|
|
|
|
*/
|
|
|
|
|
2017-10-02 02:18:56 +00:00
|
|
|
public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetInfoRequestsListener {
|
2017-09-27 02:48:34 +00:00
|
|
|
@Override
|
|
|
|
public CryptoNetAccount createAccountFromSeed(CryptoNetAccount account) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public CryptoNetAccount importAccountFromSeed(CryptoNetAccount account) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void loadAccountFromDB(CryptoNetAccount account) {
|
|
|
|
|
|
|
|
}
|
2017-10-02 02:18:56 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNewRequest(CryptoNetInfoRequest request) {
|
|
|
|
if (request instanceof ValidateImportBitsharesAccountRequest){
|
2017-10-05 02:04:42 +00:00
|
|
|
|
2017-10-03 02:49:17 +00:00
|
|
|
final ValidateImportBitsharesAccountRequest importRequest = (ValidateImportBitsharesAccountRequest) request;
|
|
|
|
ApiRequest checkAccountName = new ApiRequest(0, new ApiRequestListener() {
|
|
|
|
@Override
|
|
|
|
public void success(Object answer, int idPetition) {
|
2017-10-04 01:31:16 +00:00
|
|
|
importRequest.setAccountExists(true);
|
2017-10-03 02:49:17 +00:00
|
|
|
ApiRequest getAccountInfo = new ApiRequest(1,new ApiRequestListener(){
|
|
|
|
@Override
|
|
|
|
public void success(Object answer, int idPetition) {
|
2017-10-04 01:31:16 +00:00
|
|
|
if(answer != null && answer instanceof AccountProperties) {
|
|
|
|
AccountProperties prop = (AccountProperties) answer;
|
|
|
|
//TODO change the key to compare
|
|
|
|
BrainKey bk = new BrainKey(importRequest.getMnemonic(), 0);
|
|
|
|
for(PublicKey activeKey : prop.active.getKeyAuthList()){
|
|
|
|
if(activeKey.toBytes().equals(bk.getPublicKey())){
|
|
|
|
importRequest.setMnemonicIsCorrect(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
importRequest.setMnemonicIsCorrect(false);
|
|
|
|
}
|
|
|
|
|
2017-10-03 02:49:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fail(int idPetition) {
|
2017-10-05 00:54:24 +00:00
|
|
|
//
|
2017-10-03 02:49:17 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
GrapheneApiGenerator.getAccountById((String)answer,getAccountInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fail(int idPetition) {
|
2017-10-05 00:54:24 +00:00
|
|
|
//
|
2017-10-03 02:49:17 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
GrapheneApiGenerator.getAccountIdByName(importRequest.getAccountName(),checkAccountName);
|
2017-10-02 02:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-27 02:48:34 +00:00
|
|
|
}
|