Skip to content

Commit 11db78c

Browse files
committed
feat(jsonrpc): add blockTimestamp to logs and receipts
1 parent 039821c commit 11db78c

4 files changed

Lines changed: 8 additions & 1 deletion

File tree

framework/src/main/java/org/tron/core/services/jsonrpc/filters/LogMatch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public static List<LogFilterElement> matchBlock(LogFilter logFilter, long blockN
6666
topicList,
6767
ByteArray.toHexString(log.getData().toByteArray()),
6868
logIndexInBlock,
69-
removed
69+
removed,
70+
transactionInfo.getBlockTimeStamp()
7071
);
7172
matchedLog.add(logFilterElement);
7273
}

framework/src/main/java/org/tron/core/services/jsonrpc/types/TransactionReceipt.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static class TransactionLog {
3535
private String data;
3636
private String[] topics;
3737
private boolean removed = false;
38+
private String blockTimestamp;
3839

3940
public TransactionLog() {}
4041
}
@@ -116,6 +117,7 @@ public TransactionReceipt(
116117
transactionLog.setTransactionIndex(this.transactionIndex);
117118
transactionLog.setBlockHash(this.blockHash);
118119
transactionLog.setBlockNumber(this.blockNumber);
120+
transactionLog.setBlockTimestamp(ByteArray.toJsonHex(txInfo.getBlockTimeStamp() / 1000));
119121

120122
byte[] addressByte = convertToTronAddress(log.getAddress().toByteArray());
121123
transactionLog.setAddress(ByteArray.toJsonHexAddress(addressByte));

framework/src/test/java/org/tron/core/jsonrpc/LogMatchExactlyTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ private TransactionInfo createTransactionInfo(byte[] address, byte[][] topicArra
3737
LogInfo logInfo = new LogInfo(address, topics, data);
3838
logList.add(LogInfo.buildLog(logInfo));
3939
builder.addAllLog(logList);
40+
builder.setBlockTimeStamp(1000000L);
4041

4142
return builder.build();
4243
}
@@ -230,6 +231,7 @@ public void testMatchBlock() {
230231
LogFilterElement logFilterElement1 = elementList.get(0);
231232
LogFilterElement logFilterElement2 = elementList2.get(0);
232233

234+
Assert.assertEquals("0x3e8", logFilterElement1.getBlockTimestamp());
233235
Assert.assertEquals(logFilterElement1.hashCode(), logFilterElement2.hashCode());
234236
Assert.assertEquals(logFilterElement1, logFilterElement2);
235237

framework/src/test/java/org/tron/core/services/jsonrpc/TransactionReceiptTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public void testTransactionReceipt() throws JsonRpcInternalException {
3232
Protocol.TransactionInfo transactionInfo = Protocol.TransactionInfo.newBuilder()
3333
.setId(ByteString.copyFrom("1".getBytes()))
3434
.setContractAddress(ByteString.copyFrom("address1".getBytes()))
35+
.setBlockTimeStamp(1000000L)
3536
.setReceipt(Protocol.ResourceReceipt.newBuilder()
3637
.setEnergyUsageTotal(100L)
3738
.setResult(Protocol.Transaction.Result.contractResult.DEFAULT)
@@ -90,6 +91,7 @@ public void testTransactionReceipt() throws JsonRpcInternalException {
9091
Assert.assertEquals(transactionReceipt.getLogs()[0].getBlockNumber(), "0x1");
9192
Assert.assertEquals(transactionReceipt.getLogs()[0].getTransactionHash(), "0x31");
9293
Assert.assertEquals(transactionReceipt.getLogs()[0].getTransactionIndex(), "0x0");
94+
Assert.assertEquals(transactionReceipt.getLogs()[0].getBlockTimestamp(), "0x3e8");
9395

9496
// assert default fields
9597
Assert.assertNull(transactionReceipt.getRoot());

0 commit comments

Comments
 (0)