From 08630166eae3e3a11e1be59b293cee2afa8bf99d Mon Sep 17 00:00:00 2001 From: henry Date: Sun, 7 Jan 2018 21:31:52 -0400 Subject: [PATCH] create request for creation of account --- ...ValidateCreateBitsharesAccountRequest.java | 71 +++++++++++++++++++ .../manager/BitsharesAccountManager.java | 24 +++++++ 2 files changed, 95 insertions(+) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/ValidateCreateBitsharesAccountRequest.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/ValidateCreateBitsharesAccountRequest.java b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/ValidateCreateBitsharesAccountRequest.java new file mode 100644 index 0000000..823dd12 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/cryptonetinforequests/ValidateCreateBitsharesAccountRequest.java @@ -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; + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java index 59ceefd..76690c1 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -20,11 +20,14 @@ import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetEquivalentRequest import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequest; import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestsListener; import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest; +import cy.agorise.crystalwallet.cryptonetinforequests.ValidateCreateBitsharesAccountRequest; import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAccountRequest; import cy.agorise.crystalwallet.cryptonetinforequests.ValidateImportBitsharesAccountRequest; import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.dao.TransactionDao; 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.BitsharesAssetInfo; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; @@ -159,6 +162,8 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI this.validateSendRequest((ValidateBitsharesSendRequest) request); }else if (request instanceof CryptoNetEquivalentRequest){ this.getEquivalentValue((CryptoNetEquivalentRequest) request); + }else if (request instanceof ValidateCreateBitsharesAccountRequest){ + this.validateCreateAccount((ValidateCreateBitsharesAccountRequest) request); }else{ //TODO not implemented } @@ -209,6 +214,25 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI 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. *