@@ -70,6 +70,8 @@ public class Wallet {
7070 private Application app ;
7171 private Node p2pnode ;
7272 private Manager dbManager ;
73+ private static String addressPreFixString = Constant .ADD_PRE_FIX_STRING_TESTNET ; //default testnet
74+ private static byte addressPreFixByte = Constant .ADD_PRE_FIX_BYTE_TESTNET ;
7375
7476 /**
7577 * Creates a new Wallet with a random ECKey.
@@ -102,6 +104,66 @@ public byte[] getAddress() {
102104 return ecKey .getAddress ();
103105 }
104106
107+ public static String getAddressPreFixString () {
108+ return addressPreFixString ;
109+ }
110+
111+ public static void setAddressPreFixString (String addressPreFixString ) {
112+ Wallet .addressPreFixString = addressPreFixString ;
113+ }
114+
115+ public static byte getAddressPreFixByte () {
116+ return addressPreFixByte ;
117+ }
118+
119+ public static void setAddressPreFixByte (byte addressPreFixByte ) {
120+ Wallet .addressPreFixByte = addressPreFixByte ;
121+ }
122+
123+ public static boolean addressValid (ByteString bsAddress ) {
124+
125+ if (bsAddress == null || bsAddress .size () == 0 ) {
126+ logger .warn ("Warning: Address is empty !!" );
127+ return false ;
128+ }
129+ byte [] address = bsAddress .toByteArray ();
130+ return addressValid (address );
131+ }
132+
133+ public static boolean addressValid (byte [] address ) {
134+ if (address == null || address .length == 0 ) {
135+ logger .warn ("Warning: Address is empty !!" );
136+ return false ;
137+ }
138+ if (address .length != Constant .ADDRESS_SIZE / 2 ) {
139+ logger .warn (
140+ "Warning: Address length need " + Constant .ADDRESS_SIZE + " but " + address .length
141+ + " !!" );
142+ return false ;
143+ }
144+ if (address [0 ] != addressPreFixByte ) {
145+ logger .warn ("Warning: Address need prefix with " + addressPreFixByte + " but "
146+ + address [0 ] + " !!" );
147+ return false ;
148+ }
149+ //Other rule;
150+ return true ;
151+ }
152+
153+ public static boolean addressValid (String addressStr ) {
154+ if (addressStr == null || "" .equals (addressStr )) {
155+ logger .warn ("Warning: Address is empty !!" );
156+ return false ;
157+ }
158+ try {
159+ byte [] address = ByteArray .fromHexString (addressStr );
160+ return addressValid (address );
161+ } catch (Exception e ) {
162+ logger .error (e .getMessage ());
163+ return false ;
164+ }
165+ }
166+
105167 /**
106168 * Get balance by address.
107169 */
0 commit comments