@@ -295,6 +295,7 @@ public class Wallet {
295295 public static final String CONTRACT_VALIDATE_EXCEPTION = "ContractValidateException: {}" ;
296296 public static final String CONTRACT_VALIDATE_ERROR = "Contract validate error : " ;
297297
298+ private static int GET_WITNESS_LIST_MAX_LIMIT = 1000 ;
298299 /**
299300 * Creates a new Wallet with a random ECKey.
300301 */
@@ -774,17 +775,20 @@ public WitnessList getPaginatedNowWitnessList(long offset, long limit) {
774775 return null ;
775776 }
776777 // To control the maximum response size less than 40KB.
777- if (limit > 1000 ) {
778- limit = 1000 ;
778+ if (limit > GET_WITNESS_LIST_MAX_LIMIT ) {
779+ limit = GET_WITNESS_LIST_MAX_LIMIT ;
780+ }
781+
782+ // Get all witnesses from the store, it contains the final vote count at the end of the last epoch.
783+ List <WitnessCapsule > witnessCapsuleList = chainBaseManager .getWitnessStore ().getAllWitnesses ();
784+ if (offset >= witnessCapsuleList .size ()) {
785+ return null ;
779786 }
780787
781788 VotesStore votesStore = chainBaseManager .getVotesStore ();
782789 // Count the vote changes for each witness in the current epoch, it is maybe negative.
783790 Map <ByteString , Long > countWitness = countVote (votesStore );
784791
785- // Get all witnesses from the store, it contains the final vote count at the end of the last epoch.
786- List <WitnessCapsule > witnessCapsuleList = chainBaseManager .getWitnessStore ().getAllWitnesses ();
787-
788792 // Iterate through the witness list and apply the vote changes, it will be the realtime vote count.
789793 witnessCapsuleList .forEach ((witnessCapsule ) -> {
790794 long voteCount = countWitness .getOrDefault (witnessCapsule .getAddress (), 0L );
@@ -824,7 +828,6 @@ private Map<ByteString, Long> countVote(VotesStore votesStore) {
824828 // VotesStore is a key-value store, where the key is the address of the voter
825829 Iterator <Entry <byte [], VotesCapsule >> dbIterator = votesStore .iterator ();
826830
827- long sizeCount = 0 ;
828831 while (dbIterator .hasNext ()) {
829832 Entry <byte [], VotesCapsule > next = dbIterator .next ();
830833 VotesCapsule votes = next .getValue ();
@@ -848,9 +851,7 @@ private Map<ByteString, Long> countVote(VotesStore votesStore) {
848851 countWitness .put (voteAddress , voteCount );
849852 }
850853 });
851- sizeCount ++;
852854 }
853- logger .info ("There is {} votes in this request" , sizeCount );
854855 return countWitness ;
855856 }
856857
0 commit comments