2929import static org .tron .core .config .Parameter .DatabaseConstants .PROPOSAL_COUNT_LIMIT_MAX ;
3030import static org .tron .core .services .jsonrpc .JsonRpcApiUtil .parseEnergyFee ;
3131import static org .tron .core .services .jsonrpc .TronJsonRpcImpl .EARLIEST_STR ;
32+ import static org .tron .core .services .jsonrpc .TronJsonRpcImpl .FINALIZED_STR ;
33+ import static org .tron .core .services .jsonrpc .TronJsonRpcImpl .LATEST_STR ;
34+ import static org .tron .core .services .jsonrpc .TronJsonRpcImpl .PENDING_STR ;
35+ import static org .tron .core .services .jsonrpc .TronJsonRpcImpl .TAG_PENDING_SUPPORT_ERROR ;
3236import static org .tron .core .vm .utils .FreezeV2Util .getV2EnergyUsage ;
3337import static org .tron .core .vm .utils .FreezeV2Util .getV2NetUsage ;
3438import static org .tron .protos .contract .Common .ResourceCode ;
@@ -681,6 +685,16 @@ public Block getBlockByNum(long blockNum) {
681685 }
682686 }
683687
688+ public Block getFinalizedBlock () {
689+ try {
690+ long blockNum = chainBaseManager .getDynamicPropertiesStore ().getLatestSolidifiedBlockNum ();
691+ return chainBaseManager .getBlockByNum (blockNum ).getInstance ();
692+ } catch (StoreException e ) {
693+ logger .info (e .getMessage ());
694+ return null ;
695+ }
696+ }
697+
684698 public BlockCapsule getBlockCapsuleByNum (long blockNum ) {
685699 try {
686700 return chainBaseManager .getBlockByNum (blockNum );
@@ -706,10 +720,12 @@ public long getTransactionCountByBlockNum(long blockNum) {
706720 public Block getByJsonBlockId (String id ) throws JsonRpcInvalidParamsException {
707721 if (EARLIEST_STR .equalsIgnoreCase (id )) {
708722 return getBlockByNum (0 );
709- } else if ("latest" .equalsIgnoreCase (id )) {
723+ } else if (LATEST_STR .equalsIgnoreCase (id )) {
710724 return getNowBlock ();
711- } else if ("pending" .equalsIgnoreCase (id )) {
712- throw new JsonRpcInvalidParamsException ("TAG pending not supported" );
725+ } else if (FINALIZED_STR .equalsIgnoreCase (id )) {
726+ return getFinalizedBlock ();
727+ } else if (PENDING_STR .equalsIgnoreCase (id )) {
728+ throw new JsonRpcInvalidParamsException (TAG_PENDING_SUPPORT_ERROR );
713729 } else {
714730 long blockNumber ;
715731 try {
@@ -724,8 +740,8 @@ public Block getByJsonBlockId(String id) throws JsonRpcInvalidParamsException {
724740
725741 public List <Transaction > getTransactionsByJsonBlockId (String id )
726742 throws JsonRpcInvalidParamsException {
727- if ("pending" .equalsIgnoreCase (id )) {
728- throw new JsonRpcInvalidParamsException ("TAG pending not supported" );
743+ if (PENDING_STR .equalsIgnoreCase (id )) {
744+ throw new JsonRpcInvalidParamsException (TAG_PENDING_SUPPORT_ERROR );
729745 } else {
730746 Block block = getByJsonBlockId (id );
731747 return block != null ? block .getTransactionsList () : null ;
0 commit comments