Skip to content

Commit ba07f7d

Browse files
committed
code refactor for low dependency
1 parent e535233 commit ba07f7d

3 files changed

Lines changed: 40 additions & 29 deletions

File tree

‎src/main/java/org/tron/common/logsfilter/capsule/TransactionLogTriggerCapsule.java‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
import com.google.protobuf.Any;
77
import com.google.protobuf.InvalidProtocolBufferException;
8+
9+
import java.util.ArrayList;
10+
import java.util.List;
811
import java.util.Objects;
912

1013
import com.google.protobuf.ByteString;
@@ -13,7 +16,9 @@
1316
import lombok.extern.slf4j.Slf4j;
1417
import org.spongycastle.util.encoders.Hex;
1518
import org.tron.common.logsfilter.EventPluginLoader;
19+
import org.tron.common.logsfilter.trigger.InternalTransactionPojo;
1620
import org.tron.common.logsfilter.trigger.TransactionLogTrigger;
21+
import org.tron.common.runtime.vm.program.InternalTransaction;
1722
import org.tron.common.runtime.vm.program.ProgramResult;
1823
import org.tron.core.Wallet;
1924
import org.tron.core.capsule.BlockCapsule;
@@ -134,10 +139,31 @@ public TransactionLogTriggerCapsule(TransactionCapsule trxCasule, BlockCapsule b
134139
}
135140

136141
// internal transaction
137-
transactionLogTrigger.setInternalTransactionPojoList(programResult.getInternalTransactions());
142+
transactionLogTrigger.setInternalTrananctionList(getInternalTransactionList(programResult.getInternalTransactions()));
138143
}
139144
}
140145

146+
private List<InternalTransactionPojo> getInternalTransactionList(List<InternalTransaction> internalTransactionList){
147+
List<InternalTransactionPojo> pojoList = new ArrayList<>();
148+
149+
internalTransactionList.forEach(internalTransaction -> {
150+
InternalTransactionPojo item = new InternalTransactionPojo();
151+
152+
item.setHash(Hex.toHexString(internalTransaction.getHash()));
153+
item.setCallValue(internalTransaction.getValue());
154+
item.setTokenInfo(internalTransaction.getTokenInfo());
155+
item.setCaller_address(Hex.toHexString(internalTransaction.getSender()));
156+
item.setTransferTo_address(Hex.toHexString(internalTransaction.getReceiveAddress()));
157+
item.setData(Hex.toHexString(internalTransaction.getData()));
158+
item.setRejected(internalTransaction.isRejected());
159+
item.setNote(internalTransaction.getNote());
160+
161+
pojoList.add(item);
162+
});
163+
164+
return pojoList;
165+
}
166+
141167
@Override
142168
public void processTrigger() {
143169
EventPluginLoader.getInstance().postTransactionTrigger(transactionLogTrigger);

‎src/main/java/org/tron/common/logsfilter/trigger/InternalTransactionPojo.java‎

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,46 @@
33
import java.util.HashMap;
44
import java.util.Map;
55
import lombok.Getter;
6-
import org.spongycastle.util.encoders.Hex;
7-
import org.tron.common.runtime.vm.program.InternalTransaction;
6+
import lombok.Setter;
87

98
public class InternalTransactionPojo {
109

1110
@Getter
11+
@Setter
1212
private String hash;
13+
1314
@Getter
15+
@Setter
1416
/* the amount of trx to transfer (calculated as sun) */
1517
private long callValue;
18+
1619
@Getter
20+
@Setter
1721
private Map<String, Long> tokenInfo = new HashMap<>();
1822

1923
/* the address of the destination account (for message)
2024
* In creation transaction the receive address is - 0 */
2125
@Getter
26+
@Setter
2227
private String transferTo_address;
2328

2429
/* An unlimited size byte array specifying
2530
* input [data] of the message call or
2631
* Initialization code for a new contract */
2732
@Getter
33+
@Setter
2834
private String data;
2935

3036
/* Message sender address */
3137
@Getter
38+
@Setter
3239
private String caller_address;
40+
3341
@Getter
42+
@Setter
3443
private boolean rejected;
44+
3545
@Getter
46+
@Setter
3647
private String note;
37-
38-
public InternalTransactionPojo(InternalTransaction internalTransaction) {
39-
this.hash = Hex.toHexString(internalTransaction.getHash());
40-
this.callValue = internalTransaction.getValue();
41-
this.tokenInfo = internalTransaction.getTokenInfo();
42-
43-
this.caller_address = Hex.toHexString(internalTransaction.getSender());
44-
this.transferTo_address = Hex.toHexString(internalTransaction.getReceiveAddress());
45-
this.data = Hex.toHexString(internalTransaction.getData());
46-
this.rejected = internalTransaction.isRejected();
47-
this.note = internalTransaction.getNote();
48-
}
49-
50-
@Override
51-
public String toString() {
52-
return super.toString();
53-
}
5448
}

‎src/main/java/org/tron/common/logsfilter/trigger/TransactionLogTrigger.java‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.List;
55
import lombok.Getter;
66
import lombok.Setter;
7-
import org.tron.common.runtime.vm.program.InternalTransaction;
87

98
public class TransactionLogTrigger extends Trigger {
109

@@ -98,13 +97,5 @@ public void setTimeStamp(long ts) {
9897

9998
public TransactionLogTrigger() {
10099
setTriggerName(Trigger.TRANSACTION_TRIGGER_NAME);
101-
internalTrananctionList = new ArrayList<>();
102-
}
103-
104-
public void setInternalTransactionPojoList(List<InternalTransaction> internalTransactionList) {
105-
internalTransactionList.forEach(internalTransaction -> {
106-
this.internalTrananctionList.add(new InternalTransactionPojo(internalTransaction));
107-
});
108-
109100
}
110101
}

0 commit comments

Comments
 (0)