-
Notifications
You must be signed in to change notification settings - Fork 41
/
rebalance_vote.go
43 lines (32 loc) · 962 Bytes
/
rebalance_vote.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package types
import (
"encoding/hex"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/crypto"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
)
func (rv *RebalanceVote) InvalidationScope() tmbytes.HexBytes {
return crypto.Keccak256Hash(rv.ABIEncodedRebalanceBytes()).Bytes()
}
func (rv *RebalanceVote) Equals(other RebalanceVote) bool {
if !rv.Cellar.Equals(*other.Cellar) {
return false
}
if rv.CurrentPrice != other.CurrentPrice {
return false
}
return true
}
func (rv *RebalanceVote) Hash(salt string, val sdk.ValAddress) ([]byte, error) {
databytes, err := rv.Marshal()
if err != nil {
return nil, sdkerrors.Wrap(
sdkerrors.ErrJSONMarshal, "failed to marshal rebalance vote",
)
}
hexbytes := hex.EncodeToString(databytes)
// calculate the vote hash on the server
commitHash := DataHash(salt, hexbytes, val)
return commitHash, nil
}