Added validate Address request

This commit is contained in:
hvarona 2018-11-06 23:34:54 -04:00
parent dc6114bb10
commit fa952d9a36
2 changed files with 56 additions and 0 deletions

View file

@ -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

View file

@ -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;
}
}