@@ -96,7 +96,7 @@ def balance_of(self, snapshot: storage.Snapshot, account: types.UInt160) -> vm.B
96
96
97
97
Note: The returned value is still in internal format. Divide the results by the contract's `decimals`
98
98
"""
99
- storage_item = snapshot .storages .try_get (self .key_account + account )
99
+ storage_item = snapshot .storages .try_get (self .key_account + account , read_only = True )
100
100
if storage_item is None :
101
101
return vm .BigInteger .zero ()
102
102
else :
@@ -641,17 +641,11 @@ def vote(self,
641
641
return True
642
642
643
643
@register ("getCandidates" , contracts .CallFlags .READ_STATES , cpu_price = 1 << 22 )
644
- def get_candidates (self , engine : contracts .ApplicationEngine ) -> None :
644
+ def get_candidates (self , engine : contracts .ApplicationEngine ) -> List [ Tuple [ cryptography . ECPoint , vm . BigInteger ]] :
645
645
"""
646
646
Fetch all registered candidates, convert them to a StackItem and push them onto the evaluation stack.
647
647
"""
648
- array = vm .ArrayStackItem (engine .reference_counter )
649
- for k , v in self ._get_candidates (engine .snapshot ):
650
- struct = vm .StructStackItem (engine .reference_counter )
651
- struct .append (vm .ByteStringStackItem (k .to_array ()))
652
- struct .append (vm .IntegerStackItem (v ))
653
- array .append (struct )
654
- engine .push (array )
648
+ return self ._get_candidates (engine .snapshot )
655
649
656
650
@register ("getNextBlockValidators" , contracts .CallFlags .READ_STATES , cpu_price = 1 << 16 )
657
651
def get_next_block_validators (self , snapshot : storage .Snapshot ) -> List [cryptography .ECPoint ]:
@@ -915,16 +909,14 @@ def _compute_committee_members(self, snapshot: storage.Snapshot) -> Dict[cryptog
915
909
def _get_candidates (self ,
916
910
snapshot : storage .Snapshot ) -> \
917
911
List [Tuple [cryptography .ECPoint , vm .BigInteger ]]:
918
- if self ._candidates_dirty :
919
- self ._candidates = []
920
- for k , v in snapshot .storages .find (self .key_candidate .to_array ()):
921
- candidate = _CandidateState .deserialize_from_bytes (v .value )
922
- if candidate .registered :
923
- # take of the CANDIDATE prefix
924
- point = cryptography .ECPoint .deserialize_from_bytes (k .key [1 :])
925
- self ._candidates .append ((point , candidate .votes ))
926
- self ._candidates_dirty = False
927
-
912
+ self ._candidates = []
913
+ for k , v in snapshot .storages .find (self .key_candidate .to_array ()):
914
+ candidate = _CandidateState .deserialize_from_bytes (v .value )
915
+ if candidate .registered :
916
+ # take of the CANDIDATE prefix
917
+ point = cryptography .ECPoint .deserialize_from_bytes (k .key [1 :])
918
+ self ._candidates .append ((point , candidate .votes ))
919
+ self ._candidates_dirty = False
928
920
return self ._candidates
929
921
930
922
def _should_refresh_committee (self , height : int ) -> bool :
0 commit comments