Skip to content

Commit

Permalink
refactor keys
Browse files Browse the repository at this point in the history
  • Loading branch information
danwt committed Aug 7, 2024
1 parent c01bce4 commit a39538f
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions x/rollapp/types/liveness.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,28 @@ func LivenessEventQueueKey(e LivenessEvent) []byte {
if e.IsJail {
v = LivenessEventQueueJail
}
return createLivenessEventQueueKey(&e.HubHeight, v, &e.RollappId)
}

func LivenessEventQueueIterKey(height *int64) []byte {
return createLivenessEventQueueKey(height, nil, nil)
ret := LivenessEventQueueIterKey(&e.HubHeight)
ret = append(ret, []byte("/")...)
ret = append(ret, v...)
ret = append(ret, []byte("/")...)
ret = append(ret, e.RollappId...)
return ret
}

// can be called with no arguments to retrieve all items
// can be called with only a height, to iterate all events for a height
// otherwise must have all three arguments, for put/del ops
func createLivenessEventQueueKey(height *int64, kind []byte, rollappID *string) []byte {
if height == nil && (0 < len(kind) || rollappID != nil) {
panic("must provide a height")
}
var key []byte
key = append(key, LivenessEventQueueKeyPrefix...)
// LivenessEventQueueIterKey returns a key to iterate items
// If height is nil then all items
// Otherwise, only for heights greater than or equal to the passed height
func LivenessEventQueueIterKey(height *int64) []byte {
var ret []byte
ret = append(ret, LivenessEventQueueKeyPrefix...)
if height != nil {
key = append(key, []byte("/")...)
ret = append(ret, []byte("/")...)
hBz := make([]byte, 8)
binary.BigEndian.PutUint64(hBz, uint64(*height))
key = append(key, hBz...)
}
if len(kind) != 0 {
key = append(key, []byte("/")...)
key = append(key, kind...)
ret = append(ret, hBz...)
}
if rollappID != nil {
key = append(key, []byte("/")...)
key = append(key, []byte(*rollappID)...)
}
return key
return ret
}

// LivenessEventQueueKeyToEvent converts store key to LivenessEvent
Expand Down

0 comments on commit a39538f

Please sign in to comment.