Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调用 invokeEVMContract 时候,argss 需要传递 evmaddress ,没找到对应的 XchainToEVMAddress 方法 #36

Open
LKCoinOne opened this issue Mar 10, 2022 · 2 comments

Comments

@LKCoinOne
Copy link

调用 invokeEVMContract 时候,argss 需要传递 evmaddress ,没找到对应的 XchainToEVMAddress 方法

@superlitian
Copy link

Java sdk 目前还没有地址转换功能,可以使用go sdk 或 xchain-cli 进行转换,java sdk 的地址转换在不久后会上线

@LKCoinOne
Copy link
Author

目前解决方法,从sdk分支中找到(搬砖)

/**
 * AKAddress 转 EVMAddress
 *
 * @return
 * @throws Exception
 */
public static String getAkToEVMAddress(String akAddress) {
    if (akAddress == null) {
        throw new RuntimeException("getAKAddress() is null");
    }
    byte[] rawAddr = new byte[0];
    try {
        rawAddr = Base58.decode(akAddress);
    } catch (Exception e) {
        throw new RuntimeException("getAKAddress() Base58 Error");
    }

    if (rawAddr.length < 21) {
        throw new RuntimeException("bad address");
    }

    byte[] ripemd160Hash = Arrays.copyOfRange(rawAddr, 1, 21);
    StringBuilder result = new StringBuilder();
    for (int index = 0, len = ripemd160Hash.length; index <= len - 1; index += 1) {
        String invalue1 = Integer.toHexString((ripemd160Hash[index] >> 4) & 0xF);
        String intValue2 = Integer.toHexString(ripemd160Hash[index] & 0xF);
        result.append(invalue1);
        result.append(intValue2);
    }
    return result.toString().toUpperCase(Locale.ROOT);
}

/**
 * 使用方法
 */
public static void main(String[] args) {
   Account account = Account.create(1,2);
// getAkToEVMAddress(account.getAddress());
   getAkToEVMAddress(account.getAKAddress());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants