-
Notifications
You must be signed in to change notification settings - Fork 37
/
cellar.go
59 lines (45 loc) · 1.1 KB
/
cellar.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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/common"
)
func (c *Cellar) Address() common.Address {
return common.HexToAddress(c.Id)
}
//func (c *Cellar) InvalidationScope() tmbytes.HexBytes {
// return crypto.Keccak256Hash(c.ABIEncodedRebalanceBytes()).Bytes()
//}
func (c *Cellar) Equals(other Cellar) bool {
if c.Id != other.Id {
return false
}
if len(c.TickRanges) != len(other.TickRanges) {
return false
}
for _, tr := range c.TickRanges {
found := false
for _, otr := range other.TickRanges {
if tr.Equals(*otr) {
found = true
}
}
if !found {
return false
}
}
return true
}
func (c *Cellar) Hash(salt string, val sdk.ValAddress) ([]byte, error) {
databytes, err := c.Marshal()
if err != nil {
return nil, sdkerrors.Wrap(
sdkerrors.ErrJSONMarshal, "failed to marshal cellar",
)
}
hexbytes := hex.EncodeToString(databytes)
// calculate the vote hash on the server
commitHash := DataHash(salt, hexbytes, val)
return commitHash, nil
}