address format
package io.nuls.account.model;
+import io.nuls.core.tools.crypto.Base58;
+import io.nuls.core.tools.crypto.ECKey;
+import io.nuls.kernel.context.NulsContext;
+import io.nuls.kernel.utils.AddressTool;
+import io.nuls.kernel.utils.SerializeUtils;
import org.junit.Test;
/**
@@ -35,5 +40,41 @@ public class AddressTest {
@Test
public void test() {
+ final short chainId = 16402;
+ while (true) {
+ ECKey ecKey = new ECKey();
+ String address = getAddress(chainId, ecKey.getPubKey());
+// if (address.toUpperCase().startsWith("NS")) {
+ System.out.println(chainId + "::::::::::" + address);
+// } else if (address.toUpperCase().startsWith("N")) {
+// System.out.println(chainId + "::::::::::" + address);
+// }
+ }
+ }
+
+
+ private String getAddress(short chainId, byte[] publicKey) {
+ if (publicKey == null) {
+ return null;
+ }
+ byte[] hash160 = SerializeUtils.sha256hash160(publicKey);
+ byte[] body = new byte[22];
+ System.arraycopy(SerializeUtils.shortToBytes(chainId), 0, body, 0, 2);
+ System.arraycopy(hash160, 0, body, 2, hash160.length);
+ byte xor = getXor(body);
+ byte[] base58bytes = new byte[23];
+ System.arraycopy(body, 0, base58bytes, 0, body.length);
+ base58bytes[body.length] = xor;
+ return Base58.encode(base58bytes);
+ }
+
+
+ private byte getXor(byte[] body) {
+ byte xor = 0x00;
+ for (int i = 0; i < body.length; i++) {
+ xor ^= body[i];
+ }
+
+ return xor;
}
}
\ No newline at end of file
