Skip to content

Commit

Permalink
feat(types/collections): add LegacyDec collection value (#21693)
Browse files Browse the repository at this point in the history
Co-authored-by: Luca Graziotti <[email protected]>
(cherry picked from commit 3bc707a)

# Conflicts:
#	types/collections.go
  • Loading branch information
johnletey authored and mergify[bot] committed Sep 13, 2024
1 parent f78ed49 commit d7aa3d3
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions types/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,41 @@ var (
// IntValue represents a collections.ValueCodec to work with Int.
IntValue collcodec.ValueCodec[math.Int] = intValueCodec{}

<<<<<<< HEAD

Check failure on line 35 in types/collections.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected 'IDENT', found '<<'

Check failure on line 35 in types/collections.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected type, found '<<'

Check failure on line 35 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected <<, expected name

Check failure on line 35 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expected name

Check failure on line 35 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expected name

Check failure on line 35 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expected name

Check failure on line 35 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expected name

Check failure on line 35 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expected name
=======

Check failure on line 36 in types/collections.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected 'IDENT', found '=='

Check failure on line 36 in types/collections.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected type, found '=='

Check failure on line 36 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected ==, expected name

Check failure on line 36 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ==, expected name

Check failure on line 36 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ==, expected name

Check failure on line 36 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ==, expected name

Check failure on line 36 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ==, expected name

Check failure on line 36 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ==, expected name
// UintValue represents a collections.ValueCodec to work with Uint.
UintValue collcodec.ValueCodec[math.Uint] = uintValueCodec{}

Check failure on line 38 in types/collections.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected ';', found ']'

Check failure on line 38 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected ] in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 38 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ] in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 38 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ] in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 38 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ] in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 38 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ] in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 38 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ] in grouped declaration; possibly missing semicolon or newline or )

// LegacyDecValue represents a collections.ValueCodec to work with LegacyDec.
LegacyDecValue collcodec.ValueCodec[math.LegacyDec] = legacyDecValueCodec{}

>>>>>>> 3bc707a5a (feat(types/collections): add `LegacyDec` collection value (#21693))

Check failure on line 43 in types/collections.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'

Check failure on line 43 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (02)

invalid character U+0023 '#'

Check failure on line 43 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 43 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 43 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 43 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'

Check failure on line 43 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'
// TimeKey represents a collections.KeyCodec to work with time.Time
// Deprecated: exists only for state compatibility reasons, should not
// be used for new storage keys using time. Please use the time KeyCodec
// provided in the collections package.
TimeKey collcodec.KeyCodec[time.Time] = timeKeyCodec{}
<<<<<<< HEAD
=======
// LEUint64Key is a collections KeyCodec that encodes uint64 using little endian.
// NOTE: it MUST NOT be used by other modules, distribution relies on this only for
// state backwards compatibility.
// Deprecated: use collections.Uint64Key instead.
LEUint64Key collcodec.KeyCodec[uint64] = leUint64Key{}
// LengthPrefixedBytesKey is a collections KeyCodec to work with []byte.
// Deprecated: exists only for state compatibility reasons, should not be
// used for new storage keys using []byte. Please use the BytesKey provided
// in the collections package.
LengthPrefixedBytesKey collcodec.KeyCodec[[]byte] = lengthPrefixedBytesKey{collections.BytesKey}
)
const (

Check failure on line 65 in types/collections.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected 'IDENT', found 'const'
Int string = "math.Int"

Check failure on line 66 in types/collections.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected ')', found string
Uint string = "math.Uint"
LegacyDec string = "math.LegacyDec"
>>>>>>> 3bc707a5a (feat(types/collections): add `LegacyDec` collection value (#21693))

Check failure on line 69 in types/collections.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected 'IDENT', found '>>'

Check failure on line 69 in types/collections.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected type, found '>>'

Check failure on line 69 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected >>, expected name

Check failure on line 69 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (02)

invalid character U+0023 '#'

Check failure on line 69 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected >>, expected name

Check failure on line 69 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 69 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected >>, expected name

Check failure on line 69 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 69 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected >>, expected name

Check failure on line 69 in types/collections.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'
)
type addressUnion interface {
Expand Down Expand Up @@ -166,6 +196,42 @@ func (i intValueCodec) ValueType() string {
return "math.Int"
}

type legacyDecValueCodec struct{}

func (i legacyDecValueCodec) Encode(value math.LegacyDec) ([]byte, error) {
return value.Marshal()
}

func (i legacyDecValueCodec) Decode(b []byte) (math.LegacyDec, error) {
v := new(math.LegacyDec)
err := v.Unmarshal(b)
if err != nil {
return math.LegacyDec{}, err
}
return *v, nil
}

func (i legacyDecValueCodec) EncodeJSON(value math.LegacyDec) ([]byte, error) {
return value.MarshalJSON()
}

func (i legacyDecValueCodec) DecodeJSON(b []byte) (math.LegacyDec, error) {
v := new(math.LegacyDec)
err := v.UnmarshalJSON(b)
if err != nil {
return math.LegacyDec{}, err
}
return *v, nil
}

func (i legacyDecValueCodec) Stringify(value math.LegacyDec) string {
return value.String()
}

func (i legacyDecValueCodec) ValueType() string {
return LegacyDec
}

type timeKeyCodec struct{}

func (timeKeyCodec) Encode(buffer []byte, key time.Time) (int, error) {
Expand Down

0 comments on commit d7aa3d3

Please sign in to comment.