MCPcopy Create free account
hub / github.com/akash-network/node / EncodePaginationKey

Function EncodePaginationKey

util/query/pagination.go:87–139  ·  view source on GitHub ↗
(states, prefix, key, unsolicited []byte)

Source from the content-addressed store, hash-verified

85}
86
87func EncodePaginationKey(states, prefix, key, unsolicited []byte) ([]byte, error) {
88 if len(states) == 0 {
89 return nil, fmt.Errorf("%w: states cannot be empty", ErrInvalidPaginationKey)
90 }
91
92 if len(prefix) == 0 {
93 return nil, fmt.Errorf("%w: prefix cannot be empty", ErrInvalidPaginationKey)
94 }
95
96 if len(key) == 0 {
97 return nil, fmt.Errorf("%w: key cannot be empty", ErrInvalidPaginationKey)
98 }
99
100 // 4 bytes for checksum
101 // 1 byte for states count
102 // len(states) bytes for states
103 // 1 byte for prefix length
104 // len(prefix) bytes for prefix
105 // 1 byte for key length
106 // len(key) bytes for key
107 encLen := 4 + 1 + len(states) + 1 + len(prefix) + 1 + len(key)
108
109 if len(unsolicited) > 0 {
110 encLen += 1 + len(unsolicited)
111 }
112
113 buf := make([]byte, encLen)
114
115 data := buf[4:]
116
117 tmp := validation.MustEncodeWithLengthPrefix(states)
118 copy(data, tmp)
119
120 offset := len(tmp)
121 tmp = validation.MustEncodeWithLengthPrefix(prefix)
122
123 copy(data[offset:], tmp)
124 offset += len(tmp)
125
126 tmp = validation.MustEncodeWithLengthPrefix(key)
127 copy(data[offset:], tmp)
128
129 if len(unsolicited) > 0 {
130 offset += len(tmp)
131 tmp = validation.MustEncodeWithLengthPrefix(unsolicited)
132 copy(data[offset:], tmp)
133 }
134
135 checksum := crc32.ChecksumIEEE(data)
136 binary.BigEndian.PutUint32(buf, checksum)
137
138 return buf, nil
139}

Callers 15

encodeLedgerNextKeyMethod · 0.92
CertificatesMethod · 0.92
AccountsMethod · 0.92
PaymentsMethod · 0.92
deploymentsOwnerPathMethod · 0.92
deploymentsStatePathMethod · 0.92
ordersOwnerPathMethod · 0.92
ordersStatePathMethod · 0.92
bidsOwnerPathMethod · 0.92
bidsProviderPathMethod · 0.92
bidsStatePathMethod · 0.92
leasesOwnerPathMethod · 0.92

Calls 1

Tested by 2

TestEncodePaginationKeyFunction · 0.68
makeTestKeyFunction · 0.68