-
Notifications
You must be signed in to change notification settings - Fork 326
/
keys.go
60 lines (49 loc) · 1.71 KB
/
keys.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
60
package types
import (
"encoding/binary"
fmt "fmt"
commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
)
var _ binary.ByteOrder
const (
// ModuleName defines the module name
ModuleName = "eibc"
// KeySeparator defines the separator for keys
KeySeparator = "/"
// StoreKey defines the primary module store key
StoreKey = ModuleName
// RouterKey defines the module's message routing key
RouterKey = ModuleName
// MemStoreKey defines the in-memory store key
MemStoreKey = "mem_eibc"
)
// Store Key Prefixes
var (
// AllDemandOrdersKeyPrefix is the prefix for all demand orders
AllDemandOrdersKeyPrefix = []byte{0x00}
// PendingDemandOrderKeyPrefix is the prefix for pending demand orders
PendingDemandOrderKeyPrefix = []byte{0x00, 0x01}
// FinalizedDemandOrderKeyPrefix is the prefix for finalized demand orders
FinalizedDemandOrderKeyPrefix = []byte{0x00, 0x02}
// RevertedDemandOrderKeyPrefix is the prefix for reverted demand orders
RevertedDemandOrderKeyPrefix = []byte{0x00, 0x03}
)
func KeyPrefix(p string) []byte {
return []byte(p)
}
// GetDemandOrderKey constructs a key for a specific DemandOrder.
func GetDemandOrderKey(packetStatus commontypes.Status, orderId string) ([]byte, error) {
// Get the relevant key prefix based on the packet status
var prefix []byte
switch packetStatus {
case commontypes.Status_PENDING:
prefix = PendingDemandOrderKeyPrefix
case commontypes.Status_FINALIZED:
prefix = FinalizedDemandOrderKeyPrefix
case commontypes.Status_REVERTED:
prefix = RevertedDemandOrderKeyPrefix
default:
return nil, fmt.Errorf("invalid packet status: %s", packetStatus)
}
return []byte(fmt.Sprintf("%s%s%s%s%s", prefix, KeySeparator, packetStatus, KeySeparator, orderId)), nil
}