Merge branch 'master' of https://github.com/Agorise/crystal-wallet-android
This commit is contained in:
commit
eb36492879
2 changed files with 40 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
package cy.agorise.crystalwallet.manager;
|
package cy.agorise.crystalwallet.manager;
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
@ -250,7 +251,6 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
|
||||||
for(PublicKey activeKey : prop.owner.getKeyAuthList()){
|
for(PublicKey activeKey : prop.owner.getKeyAuthList()){
|
||||||
if((new Address(activeKey.getKey(),"BTS")).toString().equals(bk.getPublicAddress("BTS").toString())){
|
if((new Address(activeKey.getKey(),"BTS")).toString().equals(bk.getPublicAddress("BTS").toString())){
|
||||||
importRequest.setMnemonicIsCorrect(true);
|
importRequest.setMnemonicIsCorrect(true);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
importRequest.setMnemonicIsCorrect(false);
|
importRequest.setMnemonicIsCorrect(false);
|
||||||
|
|
|
@ -14,15 +14,21 @@ import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import cy.agorise.crystalwallet.dao.AccountSeedDao;
|
||||||
import cy.agorise.crystalwallet.dao.CrystalDatabase;
|
import cy.agorise.crystalwallet.dao.CrystalDatabase;
|
||||||
import cy.agorise.crystalwallet.enums.CryptoNet;
|
import cy.agorise.crystalwallet.enums.CryptoNet;
|
||||||
|
import cy.agorise.crystalwallet.enums.SeedType;
|
||||||
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.crystalwallet.network.CryptoNetManager;
|
import cy.agorise.crystalwallet.network.CryptoNetManager;
|
||||||
import cy.agorise.crystalwallet.requestmanagers.CreateBackupRequest;
|
import cy.agorise.crystalwallet.requestmanagers.CreateBackupRequest;
|
||||||
|
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener;
|
||||||
|
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests;
|
||||||
import cy.agorise.crystalwallet.requestmanagers.FileServiceRequest;
|
import cy.agorise.crystalwallet.requestmanagers.FileServiceRequest;
|
||||||
import cy.agorise.crystalwallet.requestmanagers.FileServiceRequestsListener;
|
import cy.agorise.crystalwallet.requestmanagers.FileServiceRequestsListener;
|
||||||
import cy.agorise.crystalwallet.requestmanagers.ImportBackupRequest;
|
import cy.agorise.crystalwallet.requestmanagers.ImportBackupRequest;
|
||||||
|
import cy.agorise.crystalwallet.requestmanagers.ValidateImportBitsharesAccountRequest;
|
||||||
import cy.agorise.graphenej.Address;
|
import cy.agorise.graphenej.Address;
|
||||||
import cy.agorise.graphenej.BrainKey;
|
import cy.agorise.graphenej.BrainKey;
|
||||||
import cy.agorise.graphenej.FileBin;
|
import cy.agorise.graphenej.FileBin;
|
||||||
|
@ -158,7 +164,7 @@ public class FileBackupManager implements FileServiceRequestsListener {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readBinFile(ImportBackupRequest request){
|
private void readBinFile(final ImportBackupRequest request){
|
||||||
try {
|
try {
|
||||||
File file = new File(request.getFilePath());
|
File file = new File(request.getFilePath());
|
||||||
DataInputStream dis = new DataInputStream(new FileInputStream(file));
|
DataInputStream dis = new DataInputStream(new FileInputStream(file));
|
||||||
|
@ -193,10 +199,38 @@ public class FileBackupManager implements FileServiceRequestsListener {
|
||||||
String accountName = walletBackup.getWallet(i).getPrivateName();
|
String accountName = walletBackup.getWallet(i).getPrivateName();
|
||||||
seedNames.add(new BitsharesSeedName(accountName,brainKey));
|
seedNames.add(new BitsharesSeedName(accountName,brainKey));
|
||||||
}
|
}
|
||||||
//TODO handle the accounts
|
//TODO handle more than one account
|
||||||
request.setStatus(ImportBackupRequest.StatusCode.SUCCEEDED);
|
final CrystalDatabase db = CrystalDatabase.getAppDatabase(request.getContext());
|
||||||
|
final AccountSeedDao accountSeedDao = db.accountSeedDao();
|
||||||
|
for(BitsharesSeedName seedName : seedNames) {
|
||||||
|
final ValidateImportBitsharesAccountRequest validatorRequest =
|
||||||
|
new ValidateImportBitsharesAccountRequest(seedName.accountName, seedName.accountSeed);
|
||||||
|
validatorRequest.setListener(new CryptoNetInfoRequestListener() {
|
||||||
|
@Override
|
||||||
|
public void onCarryOut() {
|
||||||
|
if (!validatorRequest.getMnemonicIsCorrect()) {
|
||||||
|
request.setStatus(ImportBackupRequest.StatusCode.FAILED); // TODO reason bad seed
|
||||||
|
} else {
|
||||||
|
AccountSeed seed = new AccountSeed();
|
||||||
|
seed.setName(validatorRequest.getAccountName());
|
||||||
|
seed.setType(SeedType.BRAINKEY); // TODO change to use other types
|
||||||
|
seed.setMasterSeed(validatorRequest.getMnemonic());
|
||||||
|
long idSeed = accountSeedDao.insertAccountSeed(seed);
|
||||||
|
if(idSeed >= 0) {
|
||||||
|
GrapheneAccount account = new GrapheneAccount();
|
||||||
|
account.setSeedId(idSeed);
|
||||||
|
account.setName(validatorRequest.getAccountName());
|
||||||
|
BitsharesAccountManager bManger = new BitsharesAccountManager();
|
||||||
|
bManger.importAccountFromSeed(account,request.getContext());
|
||||||
|
request.setStatus(ImportBackupRequest.StatusCode.SUCCEEDED);
|
||||||
|
}else{
|
||||||
|
request.setStatus(ImportBackupRequest.StatusCode.FAILED); //TODO reason couldn't insert seed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
CryptoNetInfoRequests.getInstance().addRequest(validatorRequest);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
request.setStatus(ImportBackupRequest.StatusCode.FAILED);
|
request.setStatus(ImportBackupRequest.StatusCode.FAILED);
|
||||||
//TODO handle exception
|
//TODO handle exception
|
||||||
|
|
Loading…
Reference in a new issue