From b1ad81b6ad657adeb12ebd0d1dbdf875e0b9e9b4 Mon Sep 17 00:00:00 2001 From: hamburger <1210062377@qq.com> Date: Wed, 24 Apr 2024 02:17:51 +0800 Subject: [PATCH] modify encodePacked Utf8String Signed-off-by: hamburger <1210062377@qq.com> --- abi/src/main/java/org/web3j/abi/TypeEncoder.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/abi/src/main/java/org/web3j/abi/TypeEncoder.java b/abi/src/main/java/org/web3j/abi/TypeEncoder.java index 959921f89..c0fbe1bc4 100644 --- a/abi/src/main/java/org/web3j/abi/TypeEncoder.java +++ b/abi/src/main/java/org/web3j/abi/TypeEncoder.java @@ -101,8 +101,10 @@ public static String encode(Type parameter) { */ public static String encodePacked(Type parameter) { if (parameter instanceof Utf8String) { - return removePadding(encode(parameter), parameter); + //removePadding can also be used, but is not necessary + return Numeric.toHexStringNoPrefix(((Utf8String) parameter).getValue().getBytes(StandardCharsets.UTF_8)); } else if (parameter instanceof DynamicBytes) { + //removePadding can also be used, but is not necessary return Numeric.toHexStringNoPrefix(((DynamicBytes) parameter).getValue()); } else if (parameter instanceof DynamicArray) { return arrayEncodePacked((DynamicArray) parameter); @@ -140,6 +142,9 @@ static String removePadding(String encodedValue, Type parameter) { int length = ((Utf8String) parameter).getValue().getBytes(StandardCharsets.UTF_8).length; return encodedValue.substring(64, 64 + length * 2); + } + if (parameter instanceof DynamicBytes) { + return encodedValue.substring(64, 64 + ((DynamicBytes) parameter).getValue().length * 2); } else { throw new UnsupportedOperationException( "Type cannot be encoded: " + parameter.getClass());