Skip to content

Commit 374654f

Browse files
committed
Merge branch 'feature/addTransactioninfo' of https://github.com/tronprotocol/java-tron into feature/addTransactioninfo
2 parents 511677f + 3f12113 commit 374654f

4 files changed

Lines changed: 81 additions & 48 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class BlockLogTriggerCapsule extends TriggerCapsule {
1414
public BlockLogTriggerCapsule(BlockCapsule block) {
1515
blockLogTrigger = new BlockLogTrigger();
1616
blockLogTrigger.setBlockHash(block.getBlockId().toString());
17-
blockLogTrigger.setTimeStamp(System.currentTimeMillis());
17+
blockLogTrigger.setTimeStamp(block.getTimeStamp());
1818
blockLogTrigger.setBlockNumber(block.getNum());
1919
blockLogTrigger.setTransactionSize(block.getTransactions().size());
2020
block.getTransactions().forEach(trx ->

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

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
package org.tron.common.logsfilter.capsule;
22

3+
import static org.tron.protos.Protocol.Transaction.Contract.ContractType.TransferAssetContract;
4+
import static org.tron.protos.Protocol.Transaction.Contract.ContractType.TransferContract;
5+
6+
import com.google.protobuf.Any;
7+
import com.google.protobuf.InvalidProtocolBufferException;
38
import java.util.Objects;
49

510
import com.google.protobuf.ByteString;
611
import lombok.Getter;
712
import lombok.Setter;
13+
import lombok.extern.slf4j.Slf4j;
14+
import org.spongycastle.util.encoders.Hex;
815
import org.tron.common.logsfilter.EventPluginLoader;
916
import org.tron.common.logsfilter.trigger.TransactionLogTrigger;
1017
import org.tron.common.runtime.vm.program.ProgramResult;
11-
import org.tron.common.utils.TypeConversion;
18+
import org.tron.common.utils.ByteArray;
19+
import org.tron.core.Wallet;
1220
import org.tron.core.capsule.BlockCapsule;
1321
import org.tron.core.capsule.TransactionCapsule;
1422
import org.tron.core.db.TransactionTrace;
23+
import org.tron.protos.Contract.TransferAssetContract;
24+
import org.tron.protos.Contract.TransferContract;
25+
import org.tron.protos.Protocol;
1526

27+
@Slf4j
1628
public class TransactionLogTriggerCapsule extends TriggerCapsule {
1729

1830
@Getter
@@ -30,6 +42,52 @@ public TransactionLogTriggerCapsule(TransactionCapsule trxCasule, BlockCapsule b
3042

3143
TransactionTrace trxTrace = trxCasule.getTrxTrace();
3244

45+
//result
46+
if (Objects.nonNull(trxCasule.getContractRet())){
47+
transactionLogTrigger.setResult(trxCasule.getContractRet().toString());
48+
}
49+
50+
if (Objects.nonNull(trxCasule.getInstance().getRawData())){
51+
// feelimit
52+
transactionLogTrigger.setFeeLimit(trxCasule.getInstance().getRawData().getFeeLimit());
53+
54+
Protocol.Transaction.Contract contract = trxCasule.getInstance().getRawData().getContract(0);
55+
Any contractParameter = contract.getParameter();
56+
// contract type
57+
if (Objects.nonNull(contract)){
58+
Protocol.Transaction.Contract.ContractType contractType = contract.getType();
59+
if (Objects.nonNull(contractType)){
60+
transactionLogTrigger.setContractType(contractType.toString());
61+
}
62+
63+
transactionLogTrigger.setContractCallValue(TransactionCapsule.getCallValue(contract));
64+
}
65+
66+
if (Objects.nonNull(contractParameter)) {
67+
if (contract.getType() == TransferContract) {
68+
try {
69+
TransferContract contractTransfer = contractParameter.unpack(TransferContract.class);
70+
transactionLogTrigger.setAssetName("TRX");
71+
transactionLogTrigger.setFromAddress(Wallet.encode58Check(contractTransfer.getOwnerAddress().toByteArray()));
72+
transactionLogTrigger.setToAddress(Wallet.encode58Check(contractTransfer.getToAddress().toByteArray()));
73+
transactionLogTrigger.setAssetAmount(contractTransfer.getAmount());
74+
} catch (InvalidProtocolBufferException e) {
75+
logger.error("failed to load transferContract, error '{}'", e);
76+
}
77+
} else if (contract.getType() == TransferAssetContract) {
78+
try {
79+
TransferAssetContract contractTransfer = contractParameter.unpack(TransferAssetContract.class);
80+
transactionLogTrigger.setAssetName(ByteArray.toStr(contractTransfer.getAssetName().toByteArray()));
81+
transactionLogTrigger.setFromAddress(Wallet.encode58Check(contractTransfer.getOwnerAddress().toByteArray()));
82+
transactionLogTrigger.setToAddress(Wallet.encode58Check(contractTransfer.getToAddress().toByteArray()));
83+
transactionLogTrigger.setAssetAmount(contractTransfer.getAmount());
84+
} catch (InvalidProtocolBufferException e) {
85+
logger.error("failed to load transferAssetContract, error'{}'", e);
86+
}
87+
}
88+
}
89+
}
90+
3391
// receipt
3492
if (Objects.nonNull(trxTrace) && Objects.nonNull(trxTrace.getReceipt())) {
3593
transactionLogTrigger.setEnergyFee(trxTrace.getReceipt().getEnergyFee());
@@ -47,22 +105,11 @@ public TransactionLogTriggerCapsule(TransactionCapsule trxCasule, BlockCapsule b
47105
ByteString contractAddress = ByteString.copyFrom(programResult.getContractAddress());
48106

49107
if (Objects.nonNull(contractResult) && contractResult.size() > 0){
50-
transactionLogTrigger.setContractResult(TypeConversion.bytesToHexString(contractResult.toByteArray()));
108+
transactionLogTrigger.setContractResult(Hex.toHexString(contractResult.toByteArray()));
51109
}
52110

53111
if (Objects.nonNull(contractAddress) && contractAddress.size() > 0){
54-
transactionLogTrigger.setContractAddress(TypeConversion.bytesToHexString(contractAddress.toByteArray()));
55-
}
56-
57-
if (Objects.nonNull(programResult.getRet())){
58-
transactionLogTrigger.setContractFee(programResult.getRet().getFee());
59-
transactionLogTrigger.setUnfreezeAmount(programResult.getRet().getUnfreezeAmount());
60-
transactionLogTrigger.setAssetIssueID(programResult.getRet().getAssetIssueID());
61-
transactionLogTrigger.setExchangeId(programResult.getRet().getExchangeId());
62-
transactionLogTrigger.setWithdrawAmount(programResult.getRet().getWithdrawAmount());
63-
transactionLogTrigger.setExchangeReceivedAmount(programResult.getRet().getExchangeReceivedAmount());
64-
transactionLogTrigger.setExchangeInjectAnotherAmount(programResult.getRet().getExchangeInjectAnotherAmount());
65-
transactionLogTrigger.setExchangeWithdrawAnotherAmount(programResult.getRet().getExchangeWithdrawAnotherAmount());
112+
transactionLogTrigger.setContractAddress(Wallet.encode58Check((contractAddress.toByteArray())));
66113
}
67114

68115
// internal transaction

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

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,44 @@
55
import lombok.Getter;
66
import org.spongycastle.util.encoders.Hex;
77
import org.tron.common.runtime.vm.program.InternalTransaction;
8-
import org.tron.common.utils.Base58;
98

109
public class InternalTransactionPojo {
1110

1211
@Getter
1312
private String hash;
1413
@Getter
15-
private String parentHash;
16-
@Getter
1714
/* the amount of trx to transfer (calculated as sun) */
18-
private long value;
15+
private long callValue;
1916
@Getter
2017
private Map<String, Long> tokenInfo = new HashMap<>();
2118

2219
/* the address of the destination account (for message)
2320
* In creation transaction the receive address is - 0 */
2421
@Getter
25-
private String receiveAddress;
22+
private String transferTo_address;
2623

2724
/* An unlimited size byte array specifying
2825
* input [data] of the message call or
2926
* Initialization code for a new contract */
3027
@Getter
3128
private String data;
32-
@Getter
33-
private long nonce;
34-
@Getter
35-
private String transferToAddress;
3629

3730
/* Message sender address */
3831
@Getter
39-
private String sendAddress;
40-
@Getter
41-
private int deep;
42-
@Getter
43-
private int index;
32+
private String caller_address;
4433
@Getter
4534
private boolean rejected;
4635
@Getter
4736
private String note;
4837

4938
public InternalTransactionPojo(InternalTransaction internalTransaction) {
5039
this.hash = Hex.toHexString(internalTransaction.getHash());
51-
this.value = internalTransaction.getValue();
40+
this.callValue = internalTransaction.getValue();
5241
this.tokenInfo = internalTransaction.getTokenInfo();
53-
this.sendAddress = Base58.encode(internalTransaction.getSender());
54-
this.receiveAddress = Base58.encode(internalTransaction.getReceiveAddress());
55-
this.parentHash = Hex.toHexString(internalTransaction.getParentHash());
42+
43+
this.caller_address = Hex.toHexString(internalTransaction.getSender());
44+
this.transferTo_address = Hex.toHexString(internalTransaction.getReceiveAddress());
5645
this.data = Hex.toHexString(internalTransaction.getData());
57-
this.nonce = internalTransaction.getNonce();
58-
this.deep = internalTransaction.getDeep();
59-
this.index = internalTransaction.getIndex();
6046
this.rejected = internalTransaction.isRejected();
6147
this.note = internalTransaction.getNote();
6248
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,51 +49,51 @@ public void setTimeStamp(long ts) {
4949
@Setter
5050
private long netFee;
5151

52-
// program result
52+
//contract
5353
@Getter
5454
@Setter
55-
private String contractResult;
55+
private String result;
5656

5757
@Getter
5858
@Setter
5959
private String contractAddress;
6060

6161
@Getter
6262
@Setter
63-
private long contractFee;
63+
private String contractType;
6464

6565
@Getter
6666
@Setter
67-
private long unfreezeAmount;
67+
private long feeLimit;
6868

6969
@Getter
7070
@Setter
71-
private String assetIssueID;
71+
private long contractCallValue;
7272

7373
@Getter
7474
@Setter
75-
private long exchangeId;
75+
private String contractResult;
7676

77+
//internal transaction
7778
@Getter
7879
@Setter
79-
private long withdrawAmount;
80+
private List<InternalTransactionPojo> internalTrananctionList;
8081

8182
@Getter
8283
@Setter
83-
private long exchangeReceivedAmount;
84+
private String fromAddress;
8485

8586
@Getter
8687
@Setter
87-
private long exchangeInjectAnotherAmount;
88+
private String toAddress;
8889

8990
@Getter
9091
@Setter
91-
private long exchangeWithdrawAnotherAmount;
92+
private String assetName;
9293

93-
// internal transaction
9494
@Getter
9595
@Setter
96-
private List<InternalTransactionPojo> internalTrananctionList;
96+
private long assetAmount;
9797

9898
public TransactionLogTrigger() {
9999
setTriggerName(Trigger.TRANSACTION_TRIGGER_NAME);

0 commit comments

Comments
 (0)