|
15 | 15 | import org.tron.protos.Protocol; |
16 | 16 | import org.tron.protos.Protocol.Transaction; |
17 | 17 | import org.tron.protos.Protocol.Transaction.Contract; |
| 18 | +import org.tron.protos.Protocol.Transaction.Contract.ContractType; |
| 19 | +import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract; |
18 | 20 |
|
19 | 21 | @JsonPropertyOrder(alphabetic = true) |
20 | 22 | @ToString |
@@ -75,6 +77,28 @@ private void parseSignature(Transaction tx) { |
75 | 77 | s = ByteArray.toJsonHex(sByte); |
76 | 78 | } |
77 | 79 |
|
| 80 | + private String parseInput(Transaction tx) { |
| 81 | + String data; |
| 82 | + if (tx.getRawData().getContractCount() == 0) { |
| 83 | + data = "0x"; |
| 84 | + } else { |
| 85 | + Contract contract = tx.getRawData().getContract(0); |
| 86 | + if (contract.getType() == ContractType.TriggerSmartContract) { |
| 87 | + try { |
| 88 | + TriggerSmartContract triggerSmartContract = contract.getParameter() |
| 89 | + .unpack(TriggerSmartContract.class); |
| 90 | + data = ByteArray.toJsonHex(triggerSmartContract.getData().toByteArray()); |
| 91 | + } catch (Exception e) { |
| 92 | + data = "0x"; |
| 93 | + } |
| 94 | + } else { |
| 95 | + data = "0x"; |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + return data; |
| 100 | + } |
| 101 | + |
78 | 102 | public TransactionResult(BlockCapsule blockCapsule, int index, Protocol.Transaction tx, |
79 | 103 | long energyUsageTotal, long energyFee, Wallet wallet) { |
80 | 104 | byte[] txId = new TransactionCapsule(tx).getTransactionId().getBytes(); |
@@ -105,7 +129,7 @@ public TransactionResult(BlockCapsule blockCapsule, int index, Protocol.Transact |
105 | 129 |
|
106 | 130 | gas = ByteArray.toJsonHex(energyUsageTotal); |
107 | 131 | gasPrice = ByteArray.toJsonHex(energyFee); |
108 | | - input = ByteArray.toJsonHex(tx.getRawData().getData().toByteArray()); |
| 132 | + input = parseInput(tx); |
109 | 133 |
|
110 | 134 | parseSignature(tx); |
111 | 135 | } |
@@ -133,7 +157,7 @@ public TransactionResult(Transaction tx, Wallet wallet) { |
133 | 157 |
|
134 | 158 | gas = "0x0"; |
135 | 159 | gasPrice = "0x"; |
136 | | - input = ByteArray.toJsonHex(tx.getRawData().getData().toByteArray()); |
| 160 | + input = parseInput(tx); |
137 | 161 |
|
138 | 162 | parseSignature(tx); |
139 | 163 | } |
|
0 commit comments