import org.fisco.bcos.sdk.jni.common.JniLibLoader; import org.fisco.bcos.sdk.jni.utilities.tx.TransactionStructBuilderJniObj; import org.fisco.bcos.sdk.jni.utilities.tx.Transaction; /** * 用官方 JNI 解码我构造的交易 TARS 字节,输出官方视角的 JSON。 * * 用法: java -cp bcos-sdk-jni.jar Decode */ public class Decode { public static void main(String[] args) throws Exception { JniLibLoader.loadJniLibrary(); String hex = new String(java.nio.file.Files.readAllBytes( java.nio.file.Paths.get(args[0])), "utf-8").trim(); if (hex.startsWith("0x")) hex = hex.substring(2); Transaction tx = TransactionStructBuilderJniObj.decodeTransactionStruct(hex); String json = TransactionStructBuilderJniObj.encodeTransactionStructToJson(tx); System.out.println("OFFICIAL_JSON=" + json); byte[] dh = tx.getDataHash(); StringBuilder sb = new StringBuilder(); for (byte b : dh) sb.append(String.format("%02x", b)); System.out.println("OFFICIAL_DECODED_HASH=" + sb); byte[] sg = tx.getSignature(); StringBuilder sb2 = new StringBuilder(); for (byte b : sg) sb2.append(String.format("%02x", b)); System.out.println("OFFICIAL_DECODED_SIG=" + sb2); } }