调用trx的api会生成两个地址:1:address
2:HexAddress
其中address用来展现给用户知道.
public static String bytes2HexStr(byte[] byteArr) {
String hexString = "0123456789ABCDEF";
StringBuilder sb = new StringBuilder(byteArr.length * 2);
for (int i = 0; i < byteArr.length; i++) {
sb.append(hexString.charAt((byteArr[i] & 0xf0) >> 4));
sb.append(hexString.charAt((byteArr[i] & 0x0f) >> 0));
}
return sb.toString();
}
public static byte[] decode(String input) {
if (input.length() == 0) {
return new byte[0];
}
byte[] input58 = new byte[input.length()];
for (int i = 0; i < input.length(); ++i) {
char c = input.charAt(i);
int digit58 = -1;
if (c >= 0 && c < 128) {
digit58 = INDEXES[c];
}
if (digit58 < 0) {
throw new RuntimeException("Not a Base58 input: " + input);
}
input58[i] = (byte) digit58;
}
int zeroCount = 0;
while (zeroCount < input58.length && input58[zeroCount] == 0) {
++zeroCount;
}
byte[] temp = new byte[input.length()];
int j = temp.length;
int startAt = zeroCount;
while (startAt < input58.length) {
byte mod = divmod256(input58, startAt);
if (input58[startAt] == 0) {
++startAt;
}
temp[--j] = mod;
}
while (j < temp.length && temp[j] == 0) {
++j;
}
return copyOfRange(temp, j - zeroCount, temp.length);
}
这个可以进行转换为交易地址。
private String address2Hex(String exchangeAccount) {
return Base58.bytes2HexStr(Base58.decode(exchangeAccount)).substring(0, 42);
}