refactor: remove store kv dependency (#14144)

This commit is contained in:
Marko 2022-12-07 20:57:47 +00:00 committed by GitHub
parent cdae85f28d
commit f3be41836f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 261 additions and 275 deletions

View File

@ -70,8 +70,8 @@ var (
)
func init() {
file_cosmos_base_kv_v1beta1_kv_proto_init()
md_Pairs = File_cosmos_base_kv_v1beta1_kv_proto.Messages().ByName("Pairs")
file_cosmos_base_store_internal_kv_v1beta1_kv_proto_init()
md_Pairs = File_cosmos_base_store_internal_kv_v1beta1_kv_proto.Messages().ByName("Pairs")
fd_Pairs_pairs = md_Pairs.Fields().ByName("pairs")
}
@ -84,7 +84,7 @@ func (x *Pairs) ProtoReflect() protoreflect.Message {
}
func (x *Pairs) slowProtoReflect() protoreflect.Message {
mi := &file_cosmos_base_kv_v1beta1_kv_proto_msgTypes[0]
mi := &file_cosmos_base_store_internal_kv_v1beta1_kv_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -161,13 +161,13 @@ func (x *fastReflection_Pairs) Range(f func(protoreflect.FieldDescriptor, protor
// a repeated field is populated if it is non-empty.
func (x *fastReflection_Pairs) Has(fd protoreflect.FieldDescriptor) bool {
switch fd.FullName() {
case "cosmos.base.kv.v1beta1.Pairs.pairs":
case "cosmos.base.store.internal.kv.v1beta1.Pairs.pairs":
return len(x.Pairs) != 0
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.kv.v1beta1.Pairs"))
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.store.internal.kv.v1beta1.Pairs"))
}
panic(fmt.Errorf("message cosmos.base.kv.v1beta1.Pairs does not contain field %s", fd.FullName()))
panic(fmt.Errorf("message cosmos.base.store.internal.kv.v1beta1.Pairs does not contain field %s", fd.FullName()))
}
}
@ -179,13 +179,13 @@ func (x *fastReflection_Pairs) Has(fd protoreflect.FieldDescriptor) bool {
// Clear is a mutating operation and unsafe for concurrent use.
func (x *fastReflection_Pairs) Clear(fd protoreflect.FieldDescriptor) {
switch fd.FullName() {
case "cosmos.base.kv.v1beta1.Pairs.pairs":
case "cosmos.base.store.internal.kv.v1beta1.Pairs.pairs":
x.Pairs = nil
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.kv.v1beta1.Pairs"))
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.store.internal.kv.v1beta1.Pairs"))
}
panic(fmt.Errorf("message cosmos.base.kv.v1beta1.Pairs does not contain field %s", fd.FullName()))
panic(fmt.Errorf("message cosmos.base.store.internal.kv.v1beta1.Pairs does not contain field %s", fd.FullName()))
}
}
@ -197,7 +197,7 @@ func (x *fastReflection_Pairs) Clear(fd protoreflect.FieldDescriptor) {
// of the value; to obtain a mutable reference, use Mutable.
func (x *fastReflection_Pairs) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value {
switch descriptor.FullName() {
case "cosmos.base.kv.v1beta1.Pairs.pairs":
case "cosmos.base.store.internal.kv.v1beta1.Pairs.pairs":
if len(x.Pairs) == 0 {
return protoreflect.ValueOfList(&_Pairs_1_list{})
}
@ -205,9 +205,9 @@ func (x *fastReflection_Pairs) Get(descriptor protoreflect.FieldDescriptor) prot
return protoreflect.ValueOfList(listValue)
default:
if descriptor.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.kv.v1beta1.Pairs"))
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.store.internal.kv.v1beta1.Pairs"))
}
panic(fmt.Errorf("message cosmos.base.kv.v1beta1.Pairs does not contain field %s", descriptor.FullName()))
panic(fmt.Errorf("message cosmos.base.store.internal.kv.v1beta1.Pairs does not contain field %s", descriptor.FullName()))
}
}
@ -223,15 +223,15 @@ func (x *fastReflection_Pairs) Get(descriptor protoreflect.FieldDescriptor) prot
// Set is a mutating operation and unsafe for concurrent use.
func (x *fastReflection_Pairs) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) {
switch fd.FullName() {
case "cosmos.base.kv.v1beta1.Pairs.pairs":
case "cosmos.base.store.internal.kv.v1beta1.Pairs.pairs":
lv := value.List()
clv := lv.(*_Pairs_1_list)
x.Pairs = *clv.list
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.kv.v1beta1.Pairs"))
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.store.internal.kv.v1beta1.Pairs"))
}
panic(fmt.Errorf("message cosmos.base.kv.v1beta1.Pairs does not contain field %s", fd.FullName()))
panic(fmt.Errorf("message cosmos.base.store.internal.kv.v1beta1.Pairs does not contain field %s", fd.FullName()))
}
}
@ -247,7 +247,7 @@ func (x *fastReflection_Pairs) Set(fd protoreflect.FieldDescriptor, value protor
// Mutable is a mutating operation and unsafe for concurrent use.
func (x *fastReflection_Pairs) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value {
switch fd.FullName() {
case "cosmos.base.kv.v1beta1.Pairs.pairs":
case "cosmos.base.store.internal.kv.v1beta1.Pairs.pairs":
if x.Pairs == nil {
x.Pairs = []*Pair{}
}
@ -255,9 +255,9 @@ func (x *fastReflection_Pairs) Mutable(fd protoreflect.FieldDescriptor) protoref
return protoreflect.ValueOfList(value)
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.kv.v1beta1.Pairs"))
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.store.internal.kv.v1beta1.Pairs"))
}
panic(fmt.Errorf("message cosmos.base.kv.v1beta1.Pairs does not contain field %s", fd.FullName()))
panic(fmt.Errorf("message cosmos.base.store.internal.kv.v1beta1.Pairs does not contain field %s", fd.FullName()))
}
}
@ -266,14 +266,14 @@ func (x *fastReflection_Pairs) Mutable(fd protoreflect.FieldDescriptor) protoref
// For lists, maps, and messages, this returns a new, empty, mutable value.
func (x *fastReflection_Pairs) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value {
switch fd.FullName() {
case "cosmos.base.kv.v1beta1.Pairs.pairs":
case "cosmos.base.store.internal.kv.v1beta1.Pairs.pairs":
list := []*Pair{}
return protoreflect.ValueOfList(&_Pairs_1_list{list: &list})
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.kv.v1beta1.Pairs"))
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.store.internal.kv.v1beta1.Pairs"))
}
panic(fmt.Errorf("message cosmos.base.kv.v1beta1.Pairs does not contain field %s", fd.FullName()))
panic(fmt.Errorf("message cosmos.base.store.internal.kv.v1beta1.Pairs does not contain field %s", fd.FullName()))
}
}
@ -283,7 +283,7 @@ func (x *fastReflection_Pairs) NewField(fd protoreflect.FieldDescriptor) protore
func (x *fastReflection_Pairs) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
switch d.FullName() {
default:
panic(fmt.Errorf("%s is not a oneof field in cosmos.base.kv.v1beta1.Pairs", d.FullName()))
panic(fmt.Errorf("%s is not a oneof field in cosmos.base.store.internal.kv.v1beta1.Pairs", d.FullName()))
}
panic("unreachable")
}
@ -514,8 +514,8 @@ var (
)
func init() {
file_cosmos_base_kv_v1beta1_kv_proto_init()
md_Pair = File_cosmos_base_kv_v1beta1_kv_proto.Messages().ByName("Pair")
file_cosmos_base_store_internal_kv_v1beta1_kv_proto_init()
md_Pair = File_cosmos_base_store_internal_kv_v1beta1_kv_proto.Messages().ByName("Pair")
fd_Pair_key = md_Pair.Fields().ByName("key")
fd_Pair_value = md_Pair.Fields().ByName("value")
}
@ -529,7 +529,7 @@ func (x *Pair) ProtoReflect() protoreflect.Message {
}
func (x *Pair) slowProtoReflect() protoreflect.Message {
mi := &file_cosmos_base_kv_v1beta1_kv_proto_msgTypes[1]
mi := &file_cosmos_base_store_internal_kv_v1beta1_kv_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -612,15 +612,15 @@ func (x *fastReflection_Pair) Range(f func(protoreflect.FieldDescriptor, protore
// a repeated field is populated if it is non-empty.
func (x *fastReflection_Pair) Has(fd protoreflect.FieldDescriptor) bool {
switch fd.FullName() {
case "cosmos.base.kv.v1beta1.Pair.key":
case "cosmos.base.store.internal.kv.v1beta1.Pair.key":
return len(x.Key) != 0
case "cosmos.base.kv.v1beta1.Pair.value":
case "cosmos.base.store.internal.kv.v1beta1.Pair.value":
return len(x.Value) != 0
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.kv.v1beta1.Pair"))
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.store.internal.kv.v1beta1.Pair"))
}
panic(fmt.Errorf("message cosmos.base.kv.v1beta1.Pair does not contain field %s", fd.FullName()))
panic(fmt.Errorf("message cosmos.base.store.internal.kv.v1beta1.Pair does not contain field %s", fd.FullName()))
}
}
@ -632,15 +632,15 @@ func (x *fastReflection_Pair) Has(fd protoreflect.FieldDescriptor) bool {
// Clear is a mutating operation and unsafe for concurrent use.
func (x *fastReflection_Pair) Clear(fd protoreflect.FieldDescriptor) {
switch fd.FullName() {
case "cosmos.base.kv.v1beta1.Pair.key":
case "cosmos.base.store.internal.kv.v1beta1.Pair.key":
x.Key = nil
case "cosmos.base.kv.v1beta1.Pair.value":
case "cosmos.base.store.internal.kv.v1beta1.Pair.value":
x.Value = nil
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.kv.v1beta1.Pair"))
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.store.internal.kv.v1beta1.Pair"))
}
panic(fmt.Errorf("message cosmos.base.kv.v1beta1.Pair does not contain field %s", fd.FullName()))
panic(fmt.Errorf("message cosmos.base.store.internal.kv.v1beta1.Pair does not contain field %s", fd.FullName()))
}
}
@ -652,17 +652,17 @@ func (x *fastReflection_Pair) Clear(fd protoreflect.FieldDescriptor) {
// of the value; to obtain a mutable reference, use Mutable.
func (x *fastReflection_Pair) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value {
switch descriptor.FullName() {
case "cosmos.base.kv.v1beta1.Pair.key":
case "cosmos.base.store.internal.kv.v1beta1.Pair.key":
value := x.Key
return protoreflect.ValueOfBytes(value)
case "cosmos.base.kv.v1beta1.Pair.value":
case "cosmos.base.store.internal.kv.v1beta1.Pair.value":
value := x.Value
return protoreflect.ValueOfBytes(value)
default:
if descriptor.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.kv.v1beta1.Pair"))
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.store.internal.kv.v1beta1.Pair"))
}
panic(fmt.Errorf("message cosmos.base.kv.v1beta1.Pair does not contain field %s", descriptor.FullName()))
panic(fmt.Errorf("message cosmos.base.store.internal.kv.v1beta1.Pair does not contain field %s", descriptor.FullName()))
}
}
@ -678,15 +678,15 @@ func (x *fastReflection_Pair) Get(descriptor protoreflect.FieldDescriptor) proto
// Set is a mutating operation and unsafe for concurrent use.
func (x *fastReflection_Pair) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) {
switch fd.FullName() {
case "cosmos.base.kv.v1beta1.Pair.key":
case "cosmos.base.store.internal.kv.v1beta1.Pair.key":
x.Key = value.Bytes()
case "cosmos.base.kv.v1beta1.Pair.value":
case "cosmos.base.store.internal.kv.v1beta1.Pair.value":
x.Value = value.Bytes()
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.kv.v1beta1.Pair"))
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.store.internal.kv.v1beta1.Pair"))
}
panic(fmt.Errorf("message cosmos.base.kv.v1beta1.Pair does not contain field %s", fd.FullName()))
panic(fmt.Errorf("message cosmos.base.store.internal.kv.v1beta1.Pair does not contain field %s", fd.FullName()))
}
}
@ -702,15 +702,15 @@ func (x *fastReflection_Pair) Set(fd protoreflect.FieldDescriptor, value protore
// Mutable is a mutating operation and unsafe for concurrent use.
func (x *fastReflection_Pair) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value {
switch fd.FullName() {
case "cosmos.base.kv.v1beta1.Pair.key":
panic(fmt.Errorf("field key of message cosmos.base.kv.v1beta1.Pair is not mutable"))
case "cosmos.base.kv.v1beta1.Pair.value":
panic(fmt.Errorf("field value of message cosmos.base.kv.v1beta1.Pair is not mutable"))
case "cosmos.base.store.internal.kv.v1beta1.Pair.key":
panic(fmt.Errorf("field key of message cosmos.base.store.internal.kv.v1beta1.Pair is not mutable"))
case "cosmos.base.store.internal.kv.v1beta1.Pair.value":
panic(fmt.Errorf("field value of message cosmos.base.store.internal.kv.v1beta1.Pair is not mutable"))
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.kv.v1beta1.Pair"))
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.store.internal.kv.v1beta1.Pair"))
}
panic(fmt.Errorf("message cosmos.base.kv.v1beta1.Pair does not contain field %s", fd.FullName()))
panic(fmt.Errorf("message cosmos.base.store.internal.kv.v1beta1.Pair does not contain field %s", fd.FullName()))
}
}
@ -719,15 +719,15 @@ func (x *fastReflection_Pair) Mutable(fd protoreflect.FieldDescriptor) protorefl
// For lists, maps, and messages, this returns a new, empty, mutable value.
func (x *fastReflection_Pair) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value {
switch fd.FullName() {
case "cosmos.base.kv.v1beta1.Pair.key":
case "cosmos.base.store.internal.kv.v1beta1.Pair.key":
return protoreflect.ValueOfBytes(nil)
case "cosmos.base.kv.v1beta1.Pair.value":
case "cosmos.base.store.internal.kv.v1beta1.Pair.value":
return protoreflect.ValueOfBytes(nil)
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.kv.v1beta1.Pair"))
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.base.store.internal.kv.v1beta1.Pair"))
}
panic(fmt.Errorf("message cosmos.base.kv.v1beta1.Pair does not contain field %s", fd.FullName()))
panic(fmt.Errorf("message cosmos.base.store.internal.kv.v1beta1.Pair does not contain field %s", fd.FullName()))
}
}
@ -737,7 +737,7 @@ func (x *fastReflection_Pair) NewField(fd protoreflect.FieldDescriptor) protoref
func (x *fastReflection_Pair) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
switch d.FullName() {
default:
panic(fmt.Errorf("%s is not a oneof field in cosmos.base.kv.v1beta1.Pair", d.FullName()))
panic(fmt.Errorf("%s is not a oneof field in cosmos.base.store.internal.kv.v1beta1.Pair", d.FullName()))
}
panic("unreachable")
}
@ -999,7 +999,7 @@ func (x *fastReflection_Pair) ProtoMethods() *protoiface.Methods {
// versions:
// protoc-gen-go v1.27.0
// protoc (unknown)
// source: cosmos/base/kv/v1beta1/kv.proto
// source: cosmos/base/store/internal/kv/v1beta1/kv.proto
const (
// Verify that this generated code is sufficiently up-to-date.
@ -1020,7 +1020,7 @@ type Pairs struct {
func (x *Pairs) Reset() {
*x = Pairs{}
if protoimpl.UnsafeEnabled {
mi := &file_cosmos_base_kv_v1beta1_kv_proto_msgTypes[0]
mi := &file_cosmos_base_store_internal_kv_v1beta1_kv_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -1034,7 +1034,7 @@ func (*Pairs) ProtoMessage() {}
// Deprecated: Use Pairs.ProtoReflect.Descriptor instead.
func (*Pairs) Descriptor() ([]byte, []int) {
return file_cosmos_base_kv_v1beta1_kv_proto_rawDescGZIP(), []int{0}
return file_cosmos_base_store_internal_kv_v1beta1_kv_proto_rawDescGZIP(), []int{0}
}
func (x *Pairs) GetPairs() []*Pair {
@ -1057,7 +1057,7 @@ type Pair struct {
func (x *Pair) Reset() {
*x = Pair{}
if protoimpl.UnsafeEnabled {
mi := &file_cosmos_base_kv_v1beta1_kv_proto_msgTypes[1]
mi := &file_cosmos_base_store_internal_kv_v1beta1_kv_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -1071,7 +1071,7 @@ func (*Pair) ProtoMessage() {}
// Deprecated: Use Pair.ProtoReflect.Descriptor instead.
func (*Pair) Descriptor() ([]byte, []int) {
return file_cosmos_base_kv_v1beta1_kv_proto_rawDescGZIP(), []int{1}
return file_cosmos_base_store_internal_kv_v1beta1_kv_proto_rawDescGZIP(), []int{1}
}
func (x *Pair) GetKey() []byte {
@ -1088,56 +1088,65 @@ func (x *Pair) GetValue() []byte {
return nil
}
var File_cosmos_base_kv_v1beta1_kv_proto protoreflect.FileDescriptor
var File_cosmos_base_store_internal_kv_v1beta1_kv_proto protoreflect.FileDescriptor
var file_cosmos_base_kv_v1beta1_kv_proto_rawDesc = []byte{
0x0a, 0x1f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, 0x6b, 0x76,
0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x6b, 0x76, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x12, 0x16, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x6b,
0x76, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x1a, 0x14, 0x67, 0x6f, 0x67, 0x6f, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22,
0x41, 0x0a, 0x05, 0x50, 0x61, 0x69, 0x72, 0x73, 0x12, 0x38, 0x0a, 0x05, 0x70, 0x61, 0x69, 0x72,
0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73,
0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x6b, 0x76, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31,
0x2e, 0x50, 0x61, 0x69, 0x72, 0x42, 0x04, 0xc8, 0xde, 0x1f, 0x00, 0x52, 0x05, 0x70, 0x61, 0x69,
0x72, 0x73, 0x22, 0x2e, 0x0a, 0x04, 0x50, 0x61, 0x69, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65,
0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05,
0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c,
0x75, 0x65, 0x42, 0xd3, 0x01, 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f,
0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x6b, 0x76, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61,
0x31, 0x42, 0x07, 0x4b, 0x76, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x31, 0x63, 0x6f,
0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63,
0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, 0x6b, 0x76, 0x2f, 0x76, 0x31,
0x62, 0x65, 0x74, 0x61, 0x31, 0x3b, 0x6b, 0x76, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xa2,
0x02, 0x03, 0x43, 0x42, 0x4b, 0xaa, 0x02, 0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x42,
0x61, 0x73, 0x65, 0x2e, 0x4b, 0x76, 0x2e, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xca, 0x02,
0x16, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x42, 0x61, 0x73, 0x65, 0x5c, 0x4b, 0x76, 0x5c,
0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xe2, 0x02, 0x22, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73,
0x5c, 0x42, 0x61, 0x73, 0x65, 0x5c, 0x4b, 0x76, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31,
0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x19, 0x43,
0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a, 0x3a, 0x42, 0x61, 0x73, 0x65, 0x3a, 0x3a, 0x4b, 0x76, 0x3a,
0x3a, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
var file_cosmos_base_store_internal_kv_v1beta1_kv_proto_rawDesc = []byte{
0x0a, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, 0x73, 0x74,
0x6f, 0x72, 0x65, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x6b, 0x76, 0x2f,
0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2f, 0x6b, 0x76, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x12, 0x25, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74,
0x6f, 0x72, 0x65, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e, 0x6b, 0x76, 0x2e,
0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x1a, 0x14, 0x67, 0x6f, 0x67, 0x6f, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x50, 0x0a,
0x05, 0x50, 0x61, 0x69, 0x72, 0x73, 0x12, 0x47, 0x0a, 0x05, 0x70, 0x61, 0x69, 0x72, 0x73, 0x18,
0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62,
0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e,
0x61, 0x6c, 0x2e, 0x6b, 0x76, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x2e, 0x50, 0x61,
0x69, 0x72, 0x42, 0x04, 0xc8, 0xde, 0x1f, 0x00, 0x52, 0x05, 0x70, 0x61, 0x69, 0x72, 0x73, 0x22,
0x2e, 0x0a, 0x04, 0x50, 0x61, 0x69, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01,
0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c,
0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42,
0xb1, 0x02, 0x0a, 0x29, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x62,
0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e,
0x61, 0x6c, 0x2e, 0x6b, 0x76, 0x2e, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x42, 0x07, 0x4b,
0x76, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x40, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73,
0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f,
0x73, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2f, 0x69, 0x6e, 0x74,
0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x6b, 0x76, 0x2f, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31,
0x3b, 0x6b, 0x76, 0x76, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xa2, 0x02, 0x05, 0x43, 0x42, 0x53,
0x49, 0x4b, 0xaa, 0x02, 0x25, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x42, 0x61, 0x73, 0x65,
0x2e, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2e,
0x4b, 0x76, 0x2e, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0xca, 0x02, 0x25, 0x43, 0x6f, 0x73,
0x6d, 0x6f, 0x73, 0x5c, 0x42, 0x61, 0x73, 0x65, 0x5c, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x5c, 0x49,
0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x5c, 0x4b, 0x76, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74,
0x61, 0x31, 0xe2, 0x02, 0x31, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5c, 0x42, 0x61, 0x73, 0x65,
0x5c, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x5c, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x5c,
0x4b, 0x76, 0x5c, 0x56, 0x31, 0x62, 0x65, 0x74, 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65,
0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x2a, 0x43, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x3a,
0x3a, 0x42, 0x61, 0x73, 0x65, 0x3a, 0x3a, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x3a, 0x3a, 0x49, 0x6e,
0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x3a, 0x3a, 0x4b, 0x76, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x65,
0x74, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_cosmos_base_kv_v1beta1_kv_proto_rawDescOnce sync.Once
file_cosmos_base_kv_v1beta1_kv_proto_rawDescData = file_cosmos_base_kv_v1beta1_kv_proto_rawDesc
file_cosmos_base_store_internal_kv_v1beta1_kv_proto_rawDescOnce sync.Once
file_cosmos_base_store_internal_kv_v1beta1_kv_proto_rawDescData = file_cosmos_base_store_internal_kv_v1beta1_kv_proto_rawDesc
)
func file_cosmos_base_kv_v1beta1_kv_proto_rawDescGZIP() []byte {
file_cosmos_base_kv_v1beta1_kv_proto_rawDescOnce.Do(func() {
file_cosmos_base_kv_v1beta1_kv_proto_rawDescData = protoimpl.X.CompressGZIP(file_cosmos_base_kv_v1beta1_kv_proto_rawDescData)
func file_cosmos_base_store_internal_kv_v1beta1_kv_proto_rawDescGZIP() []byte {
file_cosmos_base_store_internal_kv_v1beta1_kv_proto_rawDescOnce.Do(func() {
file_cosmos_base_store_internal_kv_v1beta1_kv_proto_rawDescData = protoimpl.X.CompressGZIP(file_cosmos_base_store_internal_kv_v1beta1_kv_proto_rawDescData)
})
return file_cosmos_base_kv_v1beta1_kv_proto_rawDescData
return file_cosmos_base_store_internal_kv_v1beta1_kv_proto_rawDescData
}
var file_cosmos_base_kv_v1beta1_kv_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_cosmos_base_kv_v1beta1_kv_proto_goTypes = []interface{}{
(*Pairs)(nil), // 0: cosmos.base.kv.v1beta1.Pairs
(*Pair)(nil), // 1: cosmos.base.kv.v1beta1.Pair
var file_cosmos_base_store_internal_kv_v1beta1_kv_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_cosmos_base_store_internal_kv_v1beta1_kv_proto_goTypes = []interface{}{
(*Pairs)(nil), // 0: cosmos.base.store.internal.kv.v1beta1.Pairs
(*Pair)(nil), // 1: cosmos.base.store.internal.kv.v1beta1.Pair
}
var file_cosmos_base_kv_v1beta1_kv_proto_depIdxs = []int32{
1, // 0: cosmos.base.kv.v1beta1.Pairs.pairs:type_name -> cosmos.base.kv.v1beta1.Pair
var file_cosmos_base_store_internal_kv_v1beta1_kv_proto_depIdxs = []int32{
1, // 0: cosmos.base.store.internal.kv.v1beta1.Pairs.pairs:type_name -> cosmos.base.store.internal.kv.v1beta1.Pair
1, // [1:1] is the sub-list for method output_type
1, // [1:1] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
@ -1145,13 +1154,13 @@ var file_cosmos_base_kv_v1beta1_kv_proto_depIdxs = []int32{
0, // [0:1] is the sub-list for field type_name
}
func init() { file_cosmos_base_kv_v1beta1_kv_proto_init() }
func file_cosmos_base_kv_v1beta1_kv_proto_init() {
if File_cosmos_base_kv_v1beta1_kv_proto != nil {
func init() { file_cosmos_base_store_internal_kv_v1beta1_kv_proto_init() }
func file_cosmos_base_store_internal_kv_v1beta1_kv_proto_init() {
if File_cosmos_base_store_internal_kv_v1beta1_kv_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_cosmos_base_kv_v1beta1_kv_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
file_cosmos_base_store_internal_kv_v1beta1_kv_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Pairs); i {
case 0:
return &v.state
@ -1163,7 +1172,7 @@ func file_cosmos_base_kv_v1beta1_kv_proto_init() {
return nil
}
}
file_cosmos_base_kv_v1beta1_kv_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
file_cosmos_base_store_internal_kv_v1beta1_kv_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Pair); i {
case 0:
return &v.state
@ -1180,18 +1189,18 @@ func file_cosmos_base_kv_v1beta1_kv_proto_init() {
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_cosmos_base_kv_v1beta1_kv_proto_rawDesc,
RawDescriptor: file_cosmos_base_store_internal_kv_v1beta1_kv_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_cosmos_base_kv_v1beta1_kv_proto_goTypes,
DependencyIndexes: file_cosmos_base_kv_v1beta1_kv_proto_depIdxs,
MessageInfos: file_cosmos_base_kv_v1beta1_kv_proto_msgTypes,
GoTypes: file_cosmos_base_store_internal_kv_v1beta1_kv_proto_goTypes,
DependencyIndexes: file_cosmos_base_store_internal_kv_v1beta1_kv_proto_depIdxs,
MessageInfos: file_cosmos_base_store_internal_kv_v1beta1_kv_proto_msgTypes,
}.Build()
File_cosmos_base_kv_v1beta1_kv_proto = out.File
file_cosmos_base_kv_v1beta1_kv_proto_rawDesc = nil
file_cosmos_base_kv_v1beta1_kv_proto_goTypes = nil
file_cosmos_base_kv_v1beta1_kv_proto_depIdxs = nil
File_cosmos_base_store_internal_kv_v1beta1_kv_proto = out.File
file_cosmos_base_store_internal_kv_v1beta1_kv_proto_rawDesc = nil
file_cosmos_base_store_internal_kv_v1beta1_kv_proto_goTypes = nil
file_cosmos_base_store_internal_kv_v1beta1_kv_proto_depIdxs = nil
}

View File

@ -1,9 +1,11 @@
syntax = "proto3";
package cosmos.base.kv.v1beta1;
package cosmos.base.store.internal.kv.v1beta1;
import "gogoproto/gogo.proto";
option go_package = "github.com/cosmos/cosmos-sdk/types/kv";
option go_package = "github.com/cosmos/cosmos-sdk/store/internal/kv";
// This is duplicated from the base kv directory to avoid a circular dependency with the cosmos-sdk
// Pairs defines a repeated slice of Pair objects.
message Pairs {

View File

@ -17,10 +17,10 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
@ -222,6 +222,7 @@ func TestAppImportExport(t *testing.T) {
require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare")
fmt.Printf("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), skp.A, skp.B)
require.Equal(t, 0, len(failedKVAs), simtestutil.GetSimulationLog(skp.A.Name(), app.SimulationManager().StoreDecoders, failedKVAs, failedKVBs))
}
}

View File

@ -10,9 +10,9 @@ import (
dbm "github.com/tendermint/tm-db"
"github.com/cosmos/cosmos-sdk/internal/conv"
"github.com/cosmos/cosmos-sdk/store/internal/kv"
"github.com/cosmos/cosmos-sdk/store/tracekv"
"github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/types/kv"
)
// cValue represents a cached value.

View File

@ -15,11 +15,11 @@ import (
sdkerrors "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/store/cachekv"
"github.com/cosmos/cosmos-sdk/store/internal/kv"
pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types"
"github.com/cosmos/cosmos-sdk/store/tracekv"
"github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/telemetry"
"github.com/cosmos/cosmos-sdk/types/kv"
)
const (

View File

@ -5,16 +5,15 @@ import (
"fmt"
"testing"
"github.com/cosmos/cosmos-sdk/store/cachekv"
"github.com/cosmos/iavl"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
"github.com/cosmos/cosmos-sdk/store/cachekv"
"github.com/cosmos/cosmos-sdk/store/internal/kv"
"github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/types/kv"
)
var (

View File

@ -0,0 +1,17 @@
package kv
import "fmt"
// AssertKeyAtLeastLength panics when store key length is less than the given length.
func AssertKeyAtLeastLength(bz []byte, length int) {
if len(bz) < length {
panic(fmt.Sprintf("expected key of length at least %d, got %d", length, len(bz)))
}
}
// AssertKeyLength panics when store key length is not equal to the given length.
func AssertKeyLength(bz []byte, length int) {
if len(bz) != length {
panic(fmt.Sprintf("unexpected key length; got: %d, expected: %d", len(bz), length))
}
}

28
store/internal/kv/kv.go Normal file
View File

@ -0,0 +1,28 @@
package kv
import (
"bytes"
"sort"
)
func (kvs Pairs) Len() int { return len(kvs.Pairs) }
func (kvs Pairs) Less(i, j int) bool {
switch bytes.Compare(kvs.Pairs[i].Key, kvs.Pairs[j].Key) {
case -1:
return true
case 0:
return bytes.Compare(kvs.Pairs[i].Value, kvs.Pairs[j].Value) < 0
case 1:
return false
default:
panic("invalid comparison result")
}
}
func (kvs Pairs) Swap(i, j int) { kvs.Pairs[i], kvs.Pairs[j] = kvs.Pairs[j], kvs.Pairs[i] }
// Sort invokes sort.Sort on kvs.
func (kvs Pairs) Sort() { sort.Sort(kvs) }

View File

@ -1,5 +1,5 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: cosmos/base/kv/v1beta1/kv.proto
// source: cosmos/base/store/internal/kv/v1beta1/kv.proto
package kv
@ -32,7 +32,7 @@ func (m *Pairs) Reset() { *m = Pairs{} }
func (m *Pairs) String() string { return proto.CompactTextString(m) }
func (*Pairs) ProtoMessage() {}
func (*Pairs) Descriptor() ([]byte, []int) {
return fileDescriptor_a44e87fe7182bb73, []int{0}
return fileDescriptor_6f21adefebb93202, []int{0}
}
func (m *Pairs) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@ -78,7 +78,7 @@ func (m *Pair) Reset() { *m = Pair{} }
func (m *Pair) String() string { return proto.CompactTextString(m) }
func (*Pair) ProtoMessage() {}
func (*Pair) Descriptor() ([]byte, []int) {
return fileDescriptor_a44e87fe7182bb73, []int{1}
return fileDescriptor_6f21adefebb93202, []int{1}
}
func (m *Pair) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@ -122,28 +122,31 @@ func (m *Pair) GetValue() []byte {
}
func init() {
proto.RegisterType((*Pairs)(nil), "cosmos.base.kv.v1beta1.Pairs")
proto.RegisterType((*Pair)(nil), "cosmos.base.kv.v1beta1.Pair")
proto.RegisterType((*Pairs)(nil), "cosmos.base.store.internal.kv.v1beta1.Pairs")
proto.RegisterType((*Pair)(nil), "cosmos.base.store.internal.kv.v1beta1.Pair")
}
func init() { proto.RegisterFile("cosmos/base/kv/v1beta1/kv.proto", fileDescriptor_a44e87fe7182bb73) }
func init() {
proto.RegisterFile("cosmos/base/store/internal/kv/v1beta1/kv.proto", fileDescriptor_6f21adefebb93202)
}
var fileDescriptor_a44e87fe7182bb73 = []byte{
// 221 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4f, 0xce, 0x2f, 0xce,
0xcd, 0x2f, 0xd6, 0x4f, 0x4a, 0x2c, 0x4e, 0xd5, 0xcf, 0x2e, 0xd3, 0x2f, 0x33, 0x4c, 0x4a, 0x2d,
0x49, 0x34, 0xd4, 0xcf, 0x2e, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x83, 0x28, 0xd0,
0x03, 0x29, 0xd0, 0xcb, 0x2e, 0xd3, 0x83, 0x2a, 0x90, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x2b,
0xd1, 0x07, 0xb1, 0x20, 0xaa, 0x95, 0x1c, 0xb9, 0x58, 0x03, 0x12, 0x33, 0x8b, 0x8a, 0x85, 0x2c,
0xb8, 0x58, 0x0b, 0x40, 0x0c, 0x09, 0x46, 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x19, 0x3d, 0xec, 0xc6,
0xe8, 0x81, 0x54, 0x3b, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x04, 0xd1, 0xa0, 0xa4, 0xc7, 0xc5,
0x02, 0x12, 0x14, 0x12, 0xe0, 0x62, 0xce, 0x4e, 0xad, 0x94, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x09,
0x02, 0x31, 0x85, 0x44, 0xb8, 0x58, 0xcb, 0x12, 0x73, 0x4a, 0x53, 0x25, 0x98, 0xc0, 0x62, 0x10,
0x8e, 0x93, 0xfd, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38,
0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xa9, 0xa6, 0x67,
0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x43, 0xbd, 0x09, 0xa1, 0x74, 0x8b, 0x53,
0xb2, 0xf5, 0x4b, 0x2a, 0x0b, 0x52, 0x8b, 0xf5, 0xb3, 0xcb, 0x92, 0xd8, 0xc0, 0x4e, 0x37, 0x06,
0x04, 0x00, 0x00, 0xff, 0xff, 0x15, 0x18, 0x16, 0xcf, 0x0b, 0x01, 0x00, 0x00,
var fileDescriptor_6f21adefebb93202 = []byte{
// 236 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4b, 0xce, 0x2f, 0xce,
0xcd, 0x2f, 0xd6, 0x4f, 0x4a, 0x2c, 0x4e, 0xd5, 0x2f, 0x2e, 0xc9, 0x2f, 0x4a, 0xd5, 0xcf, 0xcc,
0x2b, 0x49, 0x2d, 0xca, 0x4b, 0xcc, 0xd1, 0xcf, 0x2e, 0xd3, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49,
0x34, 0xd4, 0xcf, 0x2e, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x85, 0xa8, 0xd7, 0x03,
0xa9, 0xd7, 0x03, 0xab, 0xd7, 0x83, 0xa9, 0xd7, 0xcb, 0x2e, 0xd3, 0x83, 0xaa, 0x97, 0x12, 0x49,
0xcf, 0x4f, 0xcf, 0x07, 0xeb, 0xd0, 0x07, 0xb1, 0x20, 0x9a, 0x95, 0x02, 0xb8, 0x58, 0x03, 0x12,
0x33, 0x8b, 0x8a, 0x85, 0xdc, 0xb9, 0x58, 0x0b, 0x40, 0x0c, 0x09, 0x46, 0x05, 0x66, 0x0d, 0x6e,
0x23, 0x6d, 0x3d, 0xa2, 0x4c, 0xd5, 0x03, 0x69, 0x76, 0x62, 0x39, 0x71, 0x4f, 0x9e, 0x21, 0x08,
0xa2, 0x5f, 0x49, 0x8f, 0x8b, 0x05, 0x24, 0x28, 0x24, 0xc0, 0xc5, 0x9c, 0x9d, 0x5a, 0x29, 0xc1,
0xa8, 0xc0, 0xa8, 0xc1, 0x13, 0x04, 0x62, 0x0a, 0x89, 0x70, 0xb1, 0x96, 0x25, 0xe6, 0x94, 0xa6,
0x4a, 0x30, 0x81, 0xc5, 0x20, 0x1c, 0x27, 0x8f, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63,
0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96,
0x63, 0x88, 0xd2, 0x4b, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x87, 0x86,
0x09, 0x84, 0xd2, 0x2d, 0x4e, 0xc9, 0xc6, 0x0c, 0x99, 0x24, 0x36, 0xb0, 0x97, 0x8c, 0x01, 0x01,
0x00, 0x00, 0xff, 0xff, 0x5d, 0x1a, 0x9a, 0x0b, 0x41, 0x01, 0x00, 0x00,
}
func (m *Pairs) Marshal() (dAtA []byte, err error) {

View File

@ -7,7 +7,7 @@ import (
"github.com/tendermint/tendermint/crypto/tmhash"
tmcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/cosmos/cosmos-sdk/store/internal/kv"
)
// merkleMap defines a merkle-ized tree from a map. Leave values are treated as

View File

@ -1,12 +1,9 @@
package types
import (
"bytes"
"fmt"
"sort"
"strings"
"github.com/cosmos/cosmos-sdk/types/kv"
)
// KVStorePrefixIterator iterates over all the keys with a certain prefix in ascending order
@ -19,62 +16,6 @@ func KVStoreReversePrefixIterator(kvs KVStore, prefix []byte) Iterator {
return kvs.ReverseIterator(prefix, PrefixEndBytes(prefix))
}
// DiffKVStores compares two KVstores and returns all the key/value pairs
// that differ from one another. It also skips value comparison for a set of provided prefixes.
func DiffKVStores(a KVStore, b KVStore, prefixesToSkip [][]byte) (kvAs, kvBs []kv.Pair) {
iterA := a.Iterator(nil, nil)
defer iterA.Close()
iterB := b.Iterator(nil, nil)
defer iterB.Close()
for {
if !iterA.Valid() && !iterB.Valid() {
return kvAs, kvBs
}
var kvA, kvB kv.Pair
if iterA.Valid() {
kvA = kv.Pair{Key: iterA.Key(), Value: iterA.Value()}
iterA.Next()
}
if iterB.Valid() {
kvB = kv.Pair{Key: iterB.Key(), Value: iterB.Value()}
}
compareValue := true
for _, prefix := range prefixesToSkip {
// Skip value comparison if we matched a prefix
if bytes.HasPrefix(kvA.Key, prefix) {
compareValue = false
break
}
}
if !compareValue {
// We're skipping this key due to an exclusion prefix. If it's present in B, iterate past it. If it's
// absent don't iterate.
if bytes.Equal(kvA.Key, kvB.Key) {
iterB.Next()
}
continue
}
// always iterate B when comparing
iterB.Next()
if !bytes.Equal(kvA.Key, kvB.Key) || !bytes.Equal(kvA.Value, kvB.Value) {
kvAs = append(kvAs, kvA)
kvBs = append(kvBs, kvB)
}
}
}
// PrefixEndBytes returns the []byte that would end a
// range query for all []byte with a certain prefix
// Deals with last byte of prefix being FF without overflowing

View File

@ -24,53 +24,6 @@ func initTestStores(t *testing.T) (types.KVStore, types.KVStore) {
return ms.GetKVStore(key1), ms.GetKVStore(key2)
}
func TestDiffKVStores(t *testing.T) {
t.Parallel()
store1, store2 := initTestStores(t)
// Two equal stores
k1, v1 := []byte("k1"), []byte("v1")
store1.Set(k1, v1)
store2.Set(k1, v1)
kvAs, kvBs := types.DiffKVStores(store1, store2, nil)
require.Equal(t, 0, len(kvAs))
require.Equal(t, len(kvAs), len(kvBs))
// delete k1 from store2, which is now empty
store2.Delete(k1)
kvAs, kvBs = types.DiffKVStores(store1, store2, nil)
require.Equal(t, 1, len(kvAs))
require.Equal(t, len(kvAs), len(kvBs))
// set k1 in store2, different value than what store1 holds for k1
v2 := []byte("v2")
store2.Set(k1, v2)
kvAs, kvBs = types.DiffKVStores(store1, store2, nil)
require.Equal(t, 1, len(kvAs))
require.Equal(t, len(kvAs), len(kvBs))
// add k2 to store2
k2 := []byte("k2")
store2.Set(k2, v2)
kvAs, kvBs = types.DiffKVStores(store1, store2, nil)
require.Equal(t, 2, len(kvAs))
require.Equal(t, len(kvAs), len(kvBs))
// Reset stores
store1.Delete(k1)
store2.Delete(k1)
store2.Delete(k2)
// Same keys, different value. Comparisons will be nil as prefixes are skipped.
prefix := []byte("prefix:")
k1Prefixed := append(prefix, k1...)
store1.Set(k1Prefixed, v1)
store2.Set(k1Prefixed, v2)
kvAs, kvBs = types.DiffKVStores(store1, store2, [][]byte{prefix})
require.Equal(t, 0, len(kvAs))
require.Equal(t, len(kvAs), len(kvBs))
}
func TestPrefixEndBytes(t *testing.T) {
t.Parallel()
bs1 := []byte{0x23, 0xA5, 0x06}

View File

@ -1,28 +1,10 @@
package kv
import (
"bytes"
"sort"
)
func (kvs Pairs) Len() int { return len(kvs.Pairs) }
func (kvs Pairs) Less(i, j int) bool {
switch bytes.Compare(kvs.Pairs[i].Key, kvs.Pairs[j].Key) {
case -1:
return true
case 0:
return bytes.Compare(kvs.Pairs[i].Value, kvs.Pairs[j].Value) < 0
case 1:
return false
default:
panic("invalid comparison result")
}
type Pair struct {
Key []byte
Value []byte
}
func (kvs Pairs) Swap(i, j int) { kvs.Pairs[i], kvs.Pairs[j] = kvs.Pairs[j], kvs.Pairs[i] }
// Sort invokes sort.Sort on kvs.
func (kvs Pairs) Sort() { sort.Sort(kvs) }
type Pairs struct {
Pairs []Pair
}

View File

@ -1,6 +1,7 @@
package types
import (
"bytes"
fmt "fmt"
"sort"
"strings"
@ -49,9 +50,59 @@ func KVStoreReversePrefixIteratorPaginated(kvs KVStore, prefix []byte, page, lim
}
// DiffKVStores compares two KVstores and returns all the key/value pairs
// that differ from one another. It also skips value comparison for a set of provided prefixes
// that differ from one another. It also skips value comparison for a set of provided prefixes.
func DiffKVStores(a KVStore, b KVStore, prefixesToSkip [][]byte) (kvAs, kvBs []kv.Pair) {
return types.DiffKVStores(a, b, prefixesToSkip)
iterA := a.Iterator(nil, nil)
defer iterA.Close()
iterB := b.Iterator(nil, nil)
defer iterB.Close()
for {
if !iterA.Valid() && !iterB.Valid() {
return kvAs, kvBs
}
var kvA, kvB kv.Pair
if iterA.Valid() {
kvA = kv.Pair{Key: iterA.Key(), Value: iterA.Value()}
iterA.Next()
}
if iterB.Valid() {
kvB = kv.Pair{Key: iterB.Key(), Value: iterB.Value()}
}
compareValue := true
for _, prefix := range prefixesToSkip {
// Skip value comparison if we matched a prefix
if bytes.HasPrefix(kvA.Key, prefix) {
compareValue = false
break
}
}
if !compareValue {
// We're skipping this key due to an exclusion prefix. If it's present in B, iterate past it. If it's
// absent don't iterate.
if bytes.Equal(kvA.Key, kvB.Key) {
iterB.Next()
}
continue
}
// always iterate B when comparing
iterB.Next()
if !bytes.Equal(kvA.Key, kvB.Key) || !bytes.Equal(kvA.Value, kvB.Value) {
kvAs = append(kvAs, kvA)
kvBs = append(kvBs, kvB)
}
}
}
// assertNoCommonPrefix will panic if there are two keys: k1 and k2 in keys, such that

View File

@ -120,8 +120,8 @@ func (s *storeTestSuite) initTestStores() (types.KVStore, types.KVStore) {
}
func (s *storeTestSuite) checkDiffResults(store1, store2 types.KVStore) {
kvAs1, kvBs1 := types.DiffKVStores(store1, store2, nil)
kvAs2, kvBs2 := types.DiffKVStores(store1, store2, nil)
kvAs1, kvBs1 := sdk.DiffKVStores(store1, store2, nil)
kvAs2, kvBs2 := sdk.DiffKVStores(store1, store2, nil)
s.Require().Equal(kvAs1, kvAs2)
s.Require().Equal(kvBs1, kvBs2)
}