Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

keys.gno

0.75 Kb · 26 lines
 1package limit
 2
 3import (
 4	"gno.land/p/gnoswap/utils/v1"
 5)
 6
 7// OrderKey encodes an order ID so B+tree order matches numeric order.
 8func OrderKey(orderID uint64) string {
 9	return utils.EncodeUint64(orderID)
10}
11
12// OwnerOrderPrefix is the common prefix of an owner's index keys.
13func OwnerOrderPrefix(owner address) string {
14	return owner.String() + "/"
15}
16
17// OwnerOrderKey sorts an owner's orders by ID under OwnerOrderPrefix.
18func OwnerOrderKey(owner address, orderID uint64) string {
19	return OwnerOrderPrefix(owner) + utils.EncodeUint64(orderID)
20}
21
22// PrefixEnd is an exclusive upper bound for prefix + 8-byte encoded ID keys.
23// Nine 0xff bytes sort after every 8-byte suffix.
24func PrefixEnd(prefix string) string {
25	return prefix + "\xff\xff\xff\xff\xff\xff\xff\xff\xff"
26}