66package validation
77
88import (
9+ "encoding/binary"
910 "math/big"
1011
1112 "github.com/pkg/errors"
@@ -24,18 +25,18 @@ type Repository struct {
2425 validations * solidity.Mapping [thor.Address , Validation ]
2526 rewards * solidity.Mapping [thor.Bytes32 , * big.Int ] // stores rewards per validator staking period
2627
27- exits * solidity.Mapping [* big. Int , thor.Address ] // exit block -> validator ID
28+ exits * solidity.Mapping [thor. Bytes32 , thor.Address ] // exit block -> validator ID
2829}
2930
3031func NewRepository (sctx * solidity.Context ) * Repository {
3132 return & Repository {
3233 validations : solidity .NewMapping [thor.Address , Validation ](sctx , slotValidations ),
3334 rewards : solidity .NewMapping [thor.Bytes32 , * big.Int ](sctx , slotRewards ),
34- exits : solidity .NewMapping [* big. Int , thor.Address ](sctx , slotExitEpochs ),
35+ exits : solidity .NewMapping [thor. Bytes32 , thor.Address ](sctx , slotExitEpochs ),
3536 }
3637}
3738
38- func (r * Repository ) GetValidation (validator thor.Address ) (* Validation , error ) {
39+ func (r * Repository ) getValidation (validator thor.Address ) (* Validation , error ) {
3940 v , err := r .validations .Get (validator )
4041 if err != nil {
4142 return nil , errors .Wrap (err , "failed to get validator" )
@@ -50,7 +51,7 @@ func (r *Repository) setValidation(validator thor.Address, entry *Validation, is
5051 return nil
5152}
5253
53- func (r * Repository ) GetReward (key thor.Bytes32 ) (* big.Int , error ) {
54+ func (r * Repository ) getReward (key thor.Bytes32 ) (* big.Int , error ) {
5455 reward , err := r .rewards .Get (key )
5556 if err != nil {
5657 return nil , errors .Wrap (err , "failed to get reward" )
@@ -61,18 +62,22 @@ func (r *Repository) GetReward(key thor.Bytes32) (*big.Int, error) {
6162 return reward , nil
6263}
6364
64- func (r * Repository ) SetReward (key thor.Bytes32 , val * big.Int , isNew bool ) error {
65+ func (r * Repository ) setReward (key thor.Bytes32 , val * big.Int , isNew bool ) error {
6566 return r .rewards .Set (key , val , isNew )
6667}
6768
68- func (r * Repository ) GetExit (block * big.Int ) (thor.Address , error ) {
69- return r .exits .Get (block )
69+ func (r * Repository ) getExit (block uint32 ) (thor.Address , error ) {
70+ var key thor.Bytes32
71+ binary .BigEndian .PutUint32 (key [:], block )
72+
73+ return r .exits .Get (key )
7074}
7175
72- func (r * Repository ) SetExit (block uint32 , validator thor.Address ) error {
73- bigBlock := big .NewInt (0 ).SetUint64 (uint64 (block ))
76+ func (r * Repository ) setExit (block uint32 , validator thor.Address ) error {
77+ var key thor.Bytes32
78+ binary .BigEndian .PutUint32 (key [:], block )
7479
75- if err := r .exits .Set (bigBlock , validator , true ); err != nil {
80+ if err := r .exits .Set (key , validator , true ); err != nil {
7681 return errors .Wrap (err , "failed to set exit epoch" )
7782 }
7883 return nil
0 commit comments