/
key_attestation.go
48 lines (39 loc) · 1.32 KB
/
key_attestation.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
package types
import (
"encoding/binary"
"strings"
"github.com/router-protocol/sdk-go/routerchain/util"
)
var _ binary.ByteOrder
const (
// AttestationKeyPrefix is the prefix to retrieve all Attestation
AttestationKeyPrefix = "Attestation/value/"
)
var (
// PastEthSignatureCheckpointKey indexes eth signature checkpoints that have existed
// [0x1cbe0be407a979331b98e599eeedd09f]
PastEthSignatureCheckpointKey = util.HashString("PastEthSignatureCheckpointKey")
)
// AttestationKey returns the store key to retrieve a Attestation from the index fields
func AttestationKey(
chainId string,
contract string,
eventNonce uint64,
claimHash []byte,
) []byte {
return util.AppendBytes([]byte(chainId), []byte(contract), util.UInt64Bytes(eventNonce), claimHash)
}
// GetPastEthSignatureCheckpointKey returns the following key format
// prefix checkpoint
// [0x0][ checkpoint bytes ]
func GetPastEthSignatureCheckpointKey(checkpoint []byte) []byte {
return util.AppendBytes(PastEthSignatureCheckpointKey, []byte(convertByteArrToString(checkpoint)))
}
// This function is broken and it should not be used in other places except in GetPastEthSignatureCheckpointKey
func convertByteArrToString(value []byte) string {
var ret strings.Builder
for i := 0; i < len(value); i++ {
ret.WriteString(string(value[i]))
}
return ret.String()
}