Skip to content

Commit

Permalink
Merge pull request #662 from WeBankFinTech/dev
Browse files Browse the repository at this point in the history
fix decode bytes output
  • Loading branch information
CodingCattwo authored Oct 8, 2021
2 parents 0bb6b05 + 1693915 commit c045a72
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.fisco.bcos.sdk.abi.datatypes.Type;
import org.fisco.bcos.sdk.abi.datatypes.generated.AbiTypes;
import org.fisco.bcos.sdk.abi.datatypes.generated.tuples.generated.Tuple2;
import org.fisco.bcos.sdk.abi.wrapper.ABICodecJsonWrapper;
import org.fisco.bcos.sdk.abi.wrapper.ABIDefinition;
import org.fisco.bcos.sdk.abi.wrapper.ABIDefinition.NamedType;
import org.fisco.bcos.sdk.abi.wrapper.ABIDefinitionFactory;
Expand Down Expand Up @@ -862,7 +863,8 @@ public List<String> handleCall(int groupId, String userAddress, String contractA
try {
List<String> res = abiCodec
.decodeMethodToString(abiStr, funcName, callOutput.getOutput());
// todo bytes类型转十六进制
log.info("call contract res before decode:{}", res);
// bytes类型转十六进制
this.handleFuncOutput(abiStr, funcName, res);
log.info("call contract res:{}", res);
return res;
Expand Down Expand Up @@ -1027,6 +1029,7 @@ private void validFuncParam(String contractAbiStr, String funcName, List<Object>
*/
private void handleFuncOutput(String abiStr, String funcName, List<String> outputValues) {
ABIDefinition abiDefinition = this.getABIDefinition(abiStr, funcName);
ABICodecJsonWrapper jsonWrapper = new ABICodecJsonWrapper();
List<NamedType> outputTypeList = abiDefinition.getOutputs();
for (int i = 0; i < outputTypeList.size(); i++) {
String type = outputTypeList.get(i).getType();
Expand All @@ -1038,8 +1041,11 @@ private void handleFuncOutput(String abiStr, String funcName, List<String> outpu
// if not bytes[], bytes or bytesN
if (!type.endsWith("[]")) {
// update funcParam
String bytesBase64 = outputValues.get(i);
byte[] inputArray = Base64.getDecoder().decode(bytesBase64);
String bytesBase64Str = outputValues.get(i);
if (bytesBase64Str.startsWith("base64://")) {
bytesBase64Str = bytesBase64Str.substring("base64://".length());
}
byte[] inputArray = Base64.getDecoder().decode(bytesBase64Str);
// replace hexString with array
outputValues.set(i, Numeric.toHexString(inputArray));
} else {
Expand All @@ -1048,6 +1054,9 @@ private void handleFuncOutput(String abiStr, String funcName, List<String> outpu
List<String> bytesArray = new ArrayList<>(base64StrArray.size());
for (int j = 0; j < base64StrArray.size(); j++) {
String bytesBase64Str = base64StrArray.get(j);
if (bytesBase64Str.startsWith("base64://")) {
bytesBase64Str = bytesBase64Str.substring("base64://".length());
}
byte[] inputArray = Base64.getDecoder().decode(bytesBase64Str);
bytesArray.add(Numeric.toHexString(inputArray));
}
Expand Down

0 comments on commit c045a72

Please sign in to comment.