fix(indexer): the issues during simapp v1 integration (#22413)

This commit is contained in:
cool-developer
2024-11-06 23:26:57 +00:00
committed by GitHub
parent fdccc8455e
commit 2290c5ee55
17 changed files with 154 additions and 26 deletions
+7 -7
View File
@@ -65,7 +65,7 @@ func ValueSchemaCodec[V any](cdc ValueCodec[V]) (SchemaCodec[V], error) {
// FallbackSchemaCodec returns a fallback schema codec for T when one isn't explicitly
// specified with HasSchemaCodec. It maps all simple types directly to schema kinds
// and converts everything else to JSON.
// and converts everything else to JSON String.
func FallbackSchemaCodec[T any]() SchemaCodec[T] {
var t T
kind := schema.KindForGoValue(t)
@@ -81,20 +81,20 @@ func FallbackSchemaCodec[T any]() SchemaCodec[T] {
FromSchemaType: nil,
}
} else {
// we default to encoding everything to JSON
// we default to encoding everything to JSON String
return SchemaCodec[T]{
Fields: []schema.Field{{Kind: schema.JSONKind}},
Fields: []schema.Field{{Kind: schema.StringKind}},
ToSchemaType: func(t T) (any, error) {
bz, err := json.Marshal(t)
return json.RawMessage(bz), err
return string(json.RawMessage(bz)), err
},
FromSchemaType: func(a any) (T, error) {
var t T
bz, ok := a.(json.RawMessage)
sz, ok := a.(string)
if !ok {
return t, fmt.Errorf("expected json.RawMessage, got %T", a)
return t, fmt.Errorf("expected string, got %T", a)
}
err := json.Unmarshal(bz, &t)
err := json.Unmarshal([]byte(sz), &t)
return t, err
},
}