mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-19 11:48:18 -04:00
73 lines
2.2 KiB
Java
73 lines
2.2 KiB
Java
/*
|
|
* This file is part of Haveno.
|
|
*
|
|
* Haveno is free software: you can redistribute it and/or modify it
|
|
* under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or (at
|
|
* your option) any later version.
|
|
*
|
|
* Haveno is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
|
* License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with Haveno. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package haveno.asset;
|
|
|
|
/**
|
|
* Value object representing the result of validating an {@link Asset} address. Various
|
|
* factory methods are provided for typical use cases.
|
|
*
|
|
* @author Chris Beams
|
|
* @since 0.7.0
|
|
* @see Asset#validateAddress(String)
|
|
*/
|
|
public class AddressValidationResult {
|
|
|
|
private static final AddressValidationResult VALID_ADDRESS = new AddressValidationResult(true, "", "");
|
|
|
|
private final boolean isValid;
|
|
private final String message;
|
|
private final String i18nKey;
|
|
|
|
private AddressValidationResult(boolean isValid, String message, String i18nKey) {
|
|
this.isValid = isValid;
|
|
this.message = message;
|
|
this.i18nKey = i18nKey;
|
|
}
|
|
|
|
public boolean isValid() {
|
|
return isValid;
|
|
}
|
|
|
|
public String getI18nKey() {
|
|
return i18nKey;
|
|
}
|
|
|
|
public String getMessage() {
|
|
return message;
|
|
}
|
|
|
|
public static AddressValidationResult validAddress() {
|
|
return VALID_ADDRESS;
|
|
}
|
|
|
|
public static AddressValidationResult invalidAddress(Throwable cause) {
|
|
return invalidAddress(cause.getMessage());
|
|
}
|
|
|
|
public static AddressValidationResult invalidAddress(String cause) {
|
|
return invalidAddress(cause, "validation.crypto.invalidAddress");
|
|
}
|
|
|
|
public static AddressValidationResult invalidAddress(String cause, String i18nKey) {
|
|
return new AddressValidationResult(false, cause, i18nKey);
|
|
}
|
|
|
|
public static AddressValidationResult invalidStructure() {
|
|
return invalidAddress("", "validation.crypto.wrongStructure");
|
|
}
|
|
}
|