Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ TransactionResult getTransactionByBlockNumberAndIndex(String blockNumOrTag, Stri
@JsonRpcError(exception = JsonRpcInvalidParamsException.class, code = -32602, data = "{}"),
@JsonRpcError(exception = JsonRpcInternalException.class, code = -32000, data = "{}")
})
List<TransactionReceipt> getBlockReceipts(String blockNumOrTag)
List<TransactionReceipt> getBlockReceipts(String blockNumOrHashOrTag)
throws JsonRpcInvalidParamsException, JsonRpcInternalException;

@JsonRpcMethod("eth_call")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,25 +839,35 @@ private TransactionContext findTransactionContext(TransactionInfoList infoList,

/**
* Get all transaction receipts for a specific block
* @param blockNumOrTag the block number or tag (latest, earliest, pending, finalized)
* @param blockNumOrHashOrTag blockNumber or blockHash or tag,
* tag includes: latest, earliest, pending, finalized
* @return List of TransactionReceipt objects for all transactions in the block,
* null if block not found
* @throws JsonRpcInvalidParamsException if the parameter format is invalid
* @throws JsonRpcInternalException if there's an internal error
*/
@Override
public List<TransactionReceipt> getBlockReceipts(String blockNumOrTag)
public List<TransactionReceipt> getBlockReceipts(String blockNumOrHashOrTag)
throws JsonRpcInvalidParamsException, JsonRpcInternalException {
Block block = wallet.getByJsonBlockId(blockNumOrTag);
if (block == null) {

Block block = null;

if (Pattern.matches(HASH_REGEX, blockNumOrHashOrTag)) {
block = getBlockByJsonHash(blockNumOrHashOrTag);
} else {
block = wallet.getByJsonBlockId(blockNumOrHashOrTag);
}

Comment thread
0xbigapple marked this conversation as resolved.
// block receipts not available: block is genesis, not produced yet, or pruned in light node
if (block == null || block.getBlockHeader().getRawData().getNumber() == 0) {
Comment thread
0xbigapple marked this conversation as resolved.
return null;
}

BlockCapsule blockCapsule = new BlockCapsule(block);
long blockNum = blockCapsule.getNum();
TransactionInfoList transactionInfoList = wallet.getTransactionInfoByBlockNum(blockNum);

//energy price at the block timestamp
// energy price at the block timestamp
long energyFee = wallet.getEnergyFee(blockCapsule.getTimeStamp());

// Validate transaction list size consistency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,6 @@ public void init() {
dbManager.getTransactionStore()
.put(transactionCapsule3.getTransactionId().getBytes(), transactionCapsule3);

blockCapsule0.getTransactions().forEach(tx -> {
TransactionCapsule transactionCapsule = new TransactionCapsule(tx.getInstance());
transactionCapsule.setBlockNum(blockCapsule0.getNum());
dbManager.getTransactionStore()
.put(transactionCapsule.getTransactionId().getBytes(), transactionCapsule);
});

TransactionRetCapsule transactionRetCapsule0 = new TransactionRetCapsule();
blockCapsule0.getTransactions().forEach(tx -> {
TransactionInfoCapsule transactionInfoCapsule = new TransactionInfoCapsule();
transactionInfoCapsule.setId(tx.getTransactionId().getBytes());
transactionInfoCapsule.setBlockNumber(blockCapsule0.getNum());
transactionRetCapsule0.addTransactionInfo(transactionInfoCapsule.getInstance());
});
dbManager.getTransactionRetStore().put(
ByteArray.fromLong(blockCapsule0.getNum()), transactionRetCapsule0);

List<Protocol.TransactionInfo.Log> logs = new ArrayList<>();
logs.add(Protocol.TransactionInfo.Log.newBuilder()
.setAddress(ByteString.copyFrom("address1".getBytes()))
Expand Down Expand Up @@ -340,6 +323,8 @@ public void testGetBlockByNumber() {
}
Assert.assertEquals(ByteArray.toJsonHex(0L), blockResult.getNumber());
Assert.assertEquals(ByteArray.toJsonHex(blockCapsule0.getNum()), blockResult.getNumber());
Assert.assertEquals(blockResult.getTransactions().length,
blockCapsule0.getTransactions().size());

// latest
try {
Expand Down Expand Up @@ -1048,7 +1033,7 @@ public void testGetBlockReceipts() {

try {
List<TransactionReceipt> transactionReceiptList = tronJsonRpc.getBlockReceipts("earliest");
Assert.assertFalse(transactionReceiptList.isEmpty());
Assert.assertNull(transactionReceiptList);
} catch (JsonRpcInvalidParamsException | JsonRpcInternalException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -1088,6 +1073,20 @@ public void testGetBlockReceipts() {
throw new RuntimeException(e);
}

try {
String blockHash = blockCapsule1.getBlockId().toString();
List<TransactionReceipt> transactionReceiptList
= tronJsonRpc.getBlockReceipts(blockHash);
List<TransactionReceipt> transactionReceiptList2
= tronJsonRpc.getBlockReceipts("0x" + blockHash);

Assert.assertFalse(transactionReceiptList.isEmpty());
Assert.assertEquals(JSON.toJSONString(transactionReceiptList),
JSON.toJSONString(transactionReceiptList2));
} catch (JsonRpcInvalidParamsException | JsonRpcInternalException e) {
throw new RuntimeException(e);
}

}

@Test
Expand Down