This commit is contained in:
Javier Varona 2018-01-07 21:32:21 -04:00
commit 2587ceb068
2 changed files with 95 additions and 0 deletions

View file

@ -0,0 +1,71 @@
package cy.agorise.crystalwallet.cryptonetinforequests;
import android.content.Context;
import cy.agorise.crystalwallet.enums.CryptoCoin;
/**
* Imports a bitsahres accounts,
*
* return true if the account exist, and the mnemonic (brainkey provide is for that account
* Created by Henry Varona on 1/10/2017.
*/
public class ValidateCreateBitsharesAccountRequest extends CryptoNetInfoRequest {
/**
* The name of the account
*/
private String accountName;
/**
* Indicates if the account exist
*/
private Boolean accountExists;
private Boolean creationComplete;
private Context context;
public ValidateCreateBitsharesAccountRequest(String accountName, String mnemonic, Context context){
super(CryptoCoin.BITSHARES);
this.accountName = accountName;
this.context = context;
}
public void setAccountExists(boolean value){
this.accountExists = value;
this.validate();
}
public void setCreationComple(boolean value){
this.creationComplete = value;
this.validate();
}
public boolean getAccountExists(){
return this.accountExists;
}
public Boolean getCreationComplete() {
return creationComplete;
}
public void validate(){
if ((this.accountExists != null) && (this.creationComplete != null)){
this._fireOnCarryOutEvent();
}
}
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public Context getContext() {
return context;
}
}

View file

@ -20,11 +20,14 @@ import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetEquivalentRequest
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequest; import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequest;
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestsListener; import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestsListener;
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest; import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest;
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateCreateBitsharesAccountRequest;
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAccountRequest; import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAccountRequest;
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateImportBitsharesAccountRequest; import cy.agorise.crystalwallet.cryptonetinforequests.ValidateImportBitsharesAccountRequest;
import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.dao.TransactionDao; import cy.agorise.crystalwallet.dao.TransactionDao;
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.BitsharesAsset; import cy.agorise.crystalwallet.models.BitsharesAsset;
import cy.agorise.crystalwallet.models.BitsharesAssetInfo; import cy.agorise.crystalwallet.models.BitsharesAssetInfo;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
@ -159,6 +162,8 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
this.validateSendRequest((ValidateBitsharesSendRequest) request); this.validateSendRequest((ValidateBitsharesSendRequest) request);
}else if (request instanceof CryptoNetEquivalentRequest){ }else if (request instanceof CryptoNetEquivalentRequest){
this.getEquivalentValue((CryptoNetEquivalentRequest) request); this.getEquivalentValue((CryptoNetEquivalentRequest) request);
}else if (request instanceof ValidateCreateBitsharesAccountRequest){
this.validateCreateAccount((ValidateCreateBitsharesAccountRequest) request);
}else{ }else{
//TODO not implemented //TODO not implemented
} }
@ -209,6 +214,25 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI
GrapheneApiGenerator.getAccountIdByName(importRequest.getAccountName(),checkAccountName); GrapheneApiGenerator.getAccountIdByName(importRequest.getAccountName(),checkAccountName);
} }
private void validateCreateAccount(ValidateCreateBitsharesAccountRequest createRequest){
// Generate seed or find key
Context context = createRequest.getContext();
AccountSeed seed = AccountSeed.getAccountSeed(SeedType.BIP39, context);
CrystalDatabase db = CrystalDatabase.getAppDatabase(context);
long idSeed = db.accountSeedDao().insertAccountSeed(seed);
seed.setId(idSeed);
GrapheneAccount account = new GrapheneAccount();
account.setName(createRequest.getAccountName());
account.setSeedId(idSeed);
account.setAccountIndex(0);
account.setCryptoNet(CryptoNet.BITSHARES);
if (this.createAccountFromSeed(account,context) != null){
createRequest.setAccountExists(false);
createRequest.setCreationComple(true);
}
}
/** /**
* Process the account exist request, it consults the bitshares api for the account name. * Process the account exist request, it consults the bitshares api for the account name.
* *