diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/grapheneoperation/AccountUpgradeOperationBuilder.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/grapheneoperation/AccountUpgradeOperationBuilder.java new file mode 100644 index 0000000..97fdfa7 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/grapheneoperation/AccountUpgradeOperationBuilder.java @@ -0,0 +1,47 @@ +package cy.agorise.crystalwallet.apigenerator.grapheneoperation; + +import cy.agorise.graphenej.AssetAmount; +import cy.agorise.graphenej.UserAccount; +import cy.agorise.graphenej.errors.MalformedOperationException; +import cy.agorise.graphenej.operations.BaseOperationBuilder; + +/** + * Created by henry on 16/5/2018. + */ + +public class AccountUpgradeOperationBuilder extends BaseOperationBuilder { + + private UserAccount accountToUpgrade; + private AssetAmount fee; + private boolean isUpgrade = true; + + public AccountUpgradeOperationBuilder setAccountToUpgrade(UserAccount accountToUpgrade) { + this.accountToUpgrade = accountToUpgrade; + return this; + } + + public AccountUpgradeOperationBuilder setFee(AssetAmount fee) { + this.fee = fee; + return this; + } + + public AccountUpgradeOperationBuilder setIsUpgrade(Boolean isUpgrade) { + this.isUpgrade = isUpgrade; + return this; + } + + @Override + public AccountUpgradeOperation build(){ + AccountUpgradeOperation accountUpgrade; + if(accountToUpgrade == null ){ + throw new MalformedOperationException("Missing account to upgrade information"); + } + + if(fee != null){ + accountUpgrade = new AccountUpgradeOperation(accountToUpgrade, isUpgrade, fee); + }else{ + accountUpgrade = new AccountUpgradeOperation(accountToUpgrade, isUpgrade); + } + return accountUpgrade; + } +} 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 fff1580..7b4c6a8 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -18,6 +18,8 @@ import cy.agorise.crystalwallet.apigenerator.ApiRequest; import cy.agorise.crystalwallet.apigenerator.ApiRequestListener; import cy.agorise.crystalwallet.apigenerator.BitsharesFaucetApiGenerator; import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator; +import cy.agorise.crystalwallet.apigenerator.grapheneoperation.AccountUpgradeOperation; +import cy.agorise.crystalwallet.apigenerator.grapheneoperation.AccountUpgradeOperationBuilder; import cy.agorise.crystalwallet.application.constant.BitsharesConstant; import cy.agorise.crystalwallet.models.seed.BIP39; import cy.agorise.crystalwallet.requestmanagers.CryptoNetEquivalentRequest; @@ -444,8 +446,36 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI */ private void validateLTMAccountUpgrade(final ValidateBitsharesLTMUpgradeRequest sendRequest) { //TODO check internet, server connection - sendRequest.setStatus(ValidateBitsharesLTMUpgradeRequest.StatusCode.PETITION_FAILED); + Asset feeAsset = new Asset(sendRequest.getIdAsset()); + UserAccount fromUserAccount =new UserAccount(sendRequest.getSourceAccount().getAccountId()); + CrystalDatabase db = CrystalDatabase.getAppDatabase(sendRequest.getContext()); + + AccountUpgradeOperationBuilder builder = new AccountUpgradeOperationBuilder() + .setAccountToUpgrade(fromUserAccount) + .setFee(new AssetAmount(UnsignedLong.valueOf(0), feeAsset)); + ArrayList operationList = new ArrayList<>(); + operationList.add(builder.build()); + + ECKey privateKey = sendRequest.getSourceAccount().getActiveKey(sendRequest.getContext()); + + Transaction transaction = new Transaction(privateKey, null, operationList); + transaction.setChainId(CryptoNetManager.getChaindId(CryptoNet.BITSHARES)); + + + ApiRequest transactionRequest = new ApiRequest(0, new ApiRequestListener() { + @Override + public void success(Object answer, int idPetition) { + sendRequest.setStatus(ValidateBitsharesLTMUpgradeRequest.StatusCode.SUCCEEDED); + } + + @Override + public void fail(int idPetition) { + sendRequest.setStatus(ValidateBitsharesLTMUpgradeRequest.StatusCode.PETITION_FAILED); + } + }); + + GrapheneApiGenerator.broadcastTransaction(transaction,feeAsset, transactionRequest); } /** diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateBitsharesLTMUpgradeRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateBitsharesLTMUpgradeRequest.java index d0fe1b3..97b9bac 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateBitsharesLTMUpgradeRequest.java +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateBitsharesLTMUpgradeRequest.java @@ -33,6 +33,9 @@ public class ValidateBitsharesLTMUpgradeRequest extends CryptoNetInfoRequest { // The state of this request private StatusCode status = StatusCode.NOT_STARTED; + //TODO change asset + private String idAsset = "1.3.0"; //default to bTS + public ValidateBitsharesLTMUpgradeRequest(Context context, GrapheneAccount sourceAccount) { super(CryptoCoin.BITSHARES); this.mContext = context; @@ -48,6 +51,10 @@ public class ValidateBitsharesLTMUpgradeRequest extends CryptoNetInfoRequest { return mSourceAccount; } + public String getIdAsset() { + return idAsset; + } + public void validate(){ if ((this.status != StatusCode.NOT_STARTED)){ this._fireOnCarryOutEvent();