22
33import com .google .protobuf .ByteString ;
44import java .io .IOException ;
5+ import java .util .ArrayList ;
6+ import java .util .List ;
57import java .util .stream .Collectors ;
68import javax .servlet .http .HttpServlet ;
79import javax .servlet .http .HttpServletRequest ;
1012import org .springframework .beans .factory .annotation .Autowired ;
1113import org .springframework .stereotype .Component ;
1214import org .tron .api .GrpcAPI .BytesMessage ;
15+ import org .tron .common .runtime .utils .MUtil ;
1316import org .tron .common .utils .ByteArray ;
1417import org .tron .core .Wallet ;
1518import org .tron .protos .Protocol .TransactionInfo ;
19+ import org .tron .protos .Protocol .TransactionInfo .Log ;
1620
1721
1822@ Component
@@ -29,7 +33,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) {
2933 TransactionInfo reply = wallet
3034 .getTransactionInfoById (ByteString .copyFrom (ByteArray .fromHexString (input )));
3135 if (reply != null ) {
32- response .getWriter ().println (JsonFormat . printToString (reply , visible ));
36+ response .getWriter ().println (convertLogAddressToTronAddress (reply , visible ));
3337 } else {
3438 response .getWriter ().println ("{}" );
3539 }
@@ -53,7 +57,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
5357 JsonFormat .merge (input , build , visible );
5458 TransactionInfo reply = wallet .getTransactionInfoById (build .getValue ());
5559 if (reply != null ) {
56- response .getWriter ().println (JsonFormat . printToString (reply , visible ));
60+ response .getWriter ().println (convertLogAddressToTronAddress (reply , visible ));
5761 } else {
5862 response .getWriter ().println ("{}" );
5963 }
@@ -66,4 +70,30 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
6670 }
6771 }
6872 }
73+
74+ private static String convertLogAddressToTronAddress (TransactionInfo transactionInfo ,
75+ boolean visible ) {
76+ if (visible ) {
77+ List <Log > newLogList = new ArrayList <>();
78+ for (Log log : transactionInfo .getLogList ()) {
79+ Log .Builder logBuilder = Log .newBuilder ();
80+ logBuilder .setData (log .getData ());
81+ logBuilder .addAllTopics (log .getTopicsList ());
82+
83+ byte [] oldAddress = log .getAddress ().toByteArray ();
84+ if (oldAddress .length == 0 || oldAddress .length > 20 ) {
85+ logBuilder .setAddress (log .getAddress ());
86+ } else {
87+ byte [] newAddress = new byte [20 ];
88+
89+ int start = 20 - oldAddress .length ;
90+ System .arraycopy (oldAddress , 0 , newAddress , start , oldAddress .length );
91+ logBuilder .setAddress (ByteString .copyFrom (MUtil .convertToTronAddress (newAddress )));
92+ }
93+ newLogList .add (logBuilder .build ());
94+ }
95+ transactionInfo = transactionInfo .toBuilder ().clearLog ().addAllLog (newLogList ).build ();
96+ }
97+ return JsonFormat .printToString (transactionInfo , visible );
98+ }
6999}
0 commit comments