From fa952d9a3613d950c66f67e704217b4c3353651d Mon Sep 17 00:00:00 2001 From: hvarona Date: Tue, 6 Nov 2018 23:34:54 -0400 Subject: [PATCH] Added validate Address request --- .../manager/GeneralAccountManager.java | 14 +++++++ .../ValidateBitcoinAddressRequest.java | 42 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateBitcoinAddressRequest.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java index e47d8e6..9b49076 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/GeneralAccountManager.java @@ -3,6 +3,7 @@ package cy.agorise.crystalwallet.manager; import android.content.Context; import org.bitcoinj.core.Address; +import org.bitcoinj.core.AddressFormatException; import org.bitcoinj.core.Coin; import org.bitcoinj.core.ECKey; import org.bitcoinj.core.Sha256Hash; @@ -41,6 +42,7 @@ import cy.agorise.crystalwallet.requestmanagers.CreateBitcoinAccountRequest; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequest; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestsListener; import cy.agorise.crystalwallet.requestmanagers.NextBitcoinAccountAddressRequest; +import cy.agorise.crystalwallet.requestmanagers.ValidateBitcoinAddressRequest; import cy.agorise.graphenej.Util; public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInfoRequestsListener { @@ -149,6 +151,8 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf this.createGeneralAccount((CreateBitcoinAccountRequest) request); }else if(request instanceof NextBitcoinAccountAddressRequest){ this.getNextAddress((NextBitcoinAccountAddressRequest) request); + }else if(request instanceof ValidateBitcoinAddressRequest){ + this.validateAddress((ValidateBitcoinAddressRequest) request); }else{ System.out.println("Invalid " +this.cryptoCoin.getLabel() + " request "); } @@ -331,6 +335,16 @@ public class GeneralAccountManager implements CryptoAccountManager, CryptoNetInf db.cryptoCoinBalanceDao().insertCryptoCoinBalance(balance); } + private void validateAddress(ValidateBitcoinAddressRequest request){ + try{ + Address address = Address.fromBase58(this.cryptoCoin.getParameters(), request.getAddress()); + request.setAddressValid(true); + }catch(AddressFormatException ex){ + request.setAddressValid(false); + } + request.validate(); + } + public void send(final BitcoinSendRequest request){ //TODO check server connection //TODO validate to address diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateBitcoinAddressRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateBitcoinAddressRequest.java new file mode 100644 index 0000000..6bdea4b --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/ValidateBitcoinAddressRequest.java @@ -0,0 +1,42 @@ +package cy.agorise.crystalwallet.requestmanagers; + +import cy.agorise.crystalwallet.enums.CryptoCoin; + +/** + * This class validates that an account name exist, this can be used to verified the existing accounts + * or to verified if the name is available to create an Account + * + * Created by henry on 8/10/2017. + */ + +public class ValidateBitcoinAddressRequest extends CryptoNetInfoRequest { + // The account name to validate + private String address; + // The result of the validation, or null if there isn't a response + private Boolean addressValid; + + public ValidateBitcoinAddressRequest(CryptoCoin cryptoCoin, String address) { + super(cryptoCoin); + this.address = address; + } + + public boolean getAddressValid(){ + return this.addressValid; + } + + public void setAddressValid(boolean value){ + this.addressValid = value; + this.validate(); + } + + public void validate(){ + if ((this.addressValid != null)){ + this._fireOnCarryOutEvent(); + } + } + + public String getAddress() { + return address; + } + +}