Skip to content

Commit 496df21

Browse files
authored
Merge pull request #432 from kyonRay/release-3.1.0
<fix>(codec): rm bytes base64 encode decode.
2 parents 196920c + ee01ca4 commit 496df21

File tree

9 files changed

+308
-290
lines changed

9 files changed

+308
-290
lines changed

sdk-codec/src/main/java/org/fisco/bcos/sdk/codec/datatypes/DynamicArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public int bytes32PaddedLength() {
5353
@Override
5454
public String getTypeAsString() {
5555
String type;
56-
if (StructType.class.isAssignableFrom(value.get(0).getClass())) {
56+
if (!value.isEmpty() && StructType.class.isAssignableFrom(value.get(0).getClass())) {
5757
type = value.get(0).getTypeAsString();
5858
} else {
5959
type = AbiTypes.getTypeAString(getComponentType());

sdk-codec/src/main/java/org/fisco/bcos/sdk/codec/wrapper/ABICodecJsonWrapper.java

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.io.IOException;
88
import java.security.InvalidParameterException;
99
import java.util.ArrayList;
10-
import java.util.Base64;
1110
import java.util.Iterator;
1211
import java.util.List;
1312
import org.fisco.bcos.sdk.codec.datatypes.*;
@@ -21,7 +20,6 @@
2120
import org.slf4j.LoggerFactory;
2221

2322
public class ABICodecJsonWrapper {
24-
public static final String Base64EncodedDataPrefix = "base64://";
2523
public static final String HexEncodedDataPrefix = "hex://";
2624

2725
private static final Logger logger = LoggerFactory.getLogger(ABICodecJsonWrapper.class);
@@ -280,10 +278,7 @@ private ABIObject encodeNode(String path, ABIObject template, JsonNode node) {
280278
}
281279

282280
public static byte[] tryDecodeInputData(String inputData) {
283-
if (inputData.startsWith(Base64EncodedDataPrefix)) {
284-
return Base64.getDecoder()
285-
.decode(inputData.substring(Base64EncodedDataPrefix.length()));
286-
} else if (inputData.startsWith(HexEncodedDataPrefix)) {
281+
if (inputData.startsWith(HexEncodedDataPrefix)) {
287282
String hexString = inputData.substring(HexEncodedDataPrefix.length());
288283
if (hexString.startsWith("0x")) {
289284
return Hex.decode(hexString.substring(2));
@@ -340,7 +335,7 @@ public ABIObject encode(ABIObject template, List<String> inputs) throws IOExcept
340335
}
341336
case BYTES:
342337
{
343-
// Binary data requires base64 encoding
338+
// Binary data hex encoding
344339
byte[] bytesValue = tryDecodeInputData(value);
345340
if (bytesValue == null) {
346341
bytesValue = value.getBytes();
@@ -360,7 +355,7 @@ public ABIObject encode(ABIObject template, List<String> inputs) throws IOExcept
360355
}
361356
case DBYTES:
362357
{
363-
// Binary data requires base64 encoding
358+
// Binary data requires hex encoding
364359
byte[] bytesValue = tryDecodeInputData(value);
365360
if (bytesValue == null) {
366361
bytesValue = value.getBytes();
@@ -432,13 +427,14 @@ public JsonNode decode(ABIObject abiObject) {
432427
}
433428
case BYTES:
434429
{
435-
return jsonNodeFactory.binaryNode(
436-
abiObject.getBytesValue().getValue());
430+
return jsonNodeFactory.textNode(
431+
Hex.toHexString(abiObject.getBytesValue().getValue()));
437432
}
438433
case DBYTES:
439434
{
440-
return jsonNodeFactory.binaryNode(
441-
abiObject.getDynamicBytesValue().getValue());
435+
return jsonNodeFactory.textNode(
436+
Hex.toHexString(
437+
abiObject.getDynamicBytesValue().getValue()));
442438
}
443439
case STRING:
444440
{
@@ -511,19 +507,15 @@ public List<String> decode(ABIObject template, byte[] buffer) {
511507
case BYTES:
512508
{
513509
byte[] value = ABICodecObject.formatBytesN(argObject);
514-
byte[] base64Bytes = Base64.getEncoder().encode(value);
515-
result.add(Base64EncodedDataPrefix + new String(base64Bytes));
510+
byte[] hexBytes = Hex.encode(value);
511+
result.add(HexEncodedDataPrefix + new String(hexBytes));
516512
break;
517513
}
518514
case DBYTES:
519515
{
520-
byte[] base64Bytes =
521-
Base64.getEncoder()
522-
.encode(
523-
argObject
524-
.getDynamicBytesValue()
525-
.getValue());
526-
result.add(Base64EncodedDataPrefix + new String(base64Bytes));
516+
byte[] hexBytes =
517+
Hex.encode(argObject.getDynamicBytesValue().getValue());
518+
result.add(HexEncodedDataPrefix + new String(hexBytes));
527519
break;
528520
}
529521
case STRING:
@@ -545,7 +537,7 @@ public List<String> decode(ABIObject template, byte[] buffer) {
545537
{
546538
// Note: when the argNode is text data, toPrettyString output the text data
547539
// if the argNode is binary data, toPrettyString output the
548-
// base64-encoded data
540+
// hex-encoded data
549541
result.add(argNode.toPrettyString());
550542
break;
551543
}

sdk-codec/src/main/java/org/fisco/bcos/sdk/codec/wrapper/ABIDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public String getMethodSignatureAsString() {
9898
result.append("(");
9999
String params =
100100
this.getInputs().stream()
101-
.map(abi -> abi.getTypeAsString())
101+
.map(NamedType::getTypeAsString)
102102
.collect(Collectors.joining(","));
103103
result.append(params);
104104
result.append(")");

0 commit comments

Comments
 (0)