-
Notifications
You must be signed in to change notification settings - Fork 206
/
badge.go
45 lines (36 loc) · 994 Bytes
/
badge.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
package types
import (
"strconv"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func CreateBadge(cuAllocation, epoch uint64, address sdk.AccAddress, lavaChainID string, sig []byte) *Badge {
badge := Badge{
CuAllocation: cuAllocation,
Epoch: epoch,
Address: address.String(),
LavaChainId: lavaChainID,
ProjectSig: sig,
}
return &badge
}
func CreateAddressEpochBadgeMapKey(address string, epoch uint64) string {
return address + "_" + strconv.FormatUint(epoch, 10)
}
// check badge's basic attributes compared to the same traits from the relay request
func (badge Badge) IsBadgeValid(clientAddr, lavaChainID string, epoch uint64) bool {
if badge.Address != clientAddr || badge.LavaChainId != lavaChainID ||
badge.Epoch != epoch {
return false
}
return true
}
func (b Badge) GetSignature() []byte {
return b.ProjectSig
}
func (b Badge) DataToSign() []byte {
b.ProjectSig = nil
return []byte(b.String())
}
func (b Badge) HashRounds() int {
return 1
}