77import java .io .IOException ;
88import java .security .InvalidParameterException ;
99import java .util .ArrayList ;
10- import java .util .Base64 ;
1110import java .util .Iterator ;
1211import java .util .List ;
1312import org .fisco .bcos .sdk .codec .datatypes .*;
2120import org .slf4j .LoggerFactory ;
2221
2322public 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 }
0 commit comments