cosmos-sdk/store/changeset.go
Aleksandr Bezobchuk 03bca7b791
feat(store/v2): Merge Feature Branch (#18150)
Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>
Co-authored-by: yihuang <huang@crypto.com>
2023-10-18 18:03:43 +00:00

40 lines
865 B
Go

package store
// KVPair defines a key-value pair with additional metadata that is used to
// track writes. Deletion can be denoted by a nil value or explicitly by the
// Delete field.
type KVPair struct {
Key []byte
Value []byte
StoreKey string // optional
}
// Changeset defines a set of KVPair entries.
type Changeset struct {
Pairs []KVPair
}
func NewChangeset(pairs ...KVPair) *Changeset {
return &Changeset{
Pairs: pairs,
}
}
// Size returns the number of key-value pairs in the batch.
func (cs *Changeset) Size() int {
return len(cs.Pairs)
}
// Add adds a key-value pair to the ChangeSet.
func (cs *Changeset) Add(key, value []byte) {
cs.Pairs = append(cs.Pairs, KVPair{
Key: key,
Value: value,
})
}
// AddKVPair adds a KVPair to the ChangeSet.
func (cs *Changeset) AddKVPair(pair KVPair) {
cs.Pairs = append(cs.Pairs, pair)
}