From 3a5412313a7bbdbf2c5711874fc378e53f1e756f Mon Sep 17 00:00:00 2001 From: ruojunm <46366167+ruojunm@users.noreply.github.com> Date: Fri, 24 Nov 2023 16:58:34 +0800 Subject: [PATCH 1/3] feat: add xml marshal for Uint type (#364) * feat: add xml marshal for Uint type * feat: add ut for xml marshal for Uint type * fix: refine comments --------- Co-authored-by: dylanhuang Co-authored-by: Clyde --- math/uint.go | 16 ++++++++++++++++ math/uint_test.go | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/math/uint.go b/math/uint.go index 10cf749a99..597fe8e2e8 100644 --- a/math/uint.go +++ b/math/uint.go @@ -1,6 +1,7 @@ package math import ( + "encoding/xml" "errors" "fmt" "math/big" @@ -137,6 +138,21 @@ func MaxUint(u1, u2 Uint) Uint { return NewUintFromBigInt(max(u1.i, u2.i)) } // Human readable string func (u Uint) String() string { return u.i.String() } +// MarshalXML defines custom encoding for xml Marshaler +func (u Uint) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + return e.EncodeElement(u.String(), start) +} + +// UnmarshalXML defines custom decoding for xml Marshaler +func (u *Uint) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { + var s string + if err := d.DecodeElement(&s, &start); err != nil { + return err + } + *u = NewUintFromString(s) + return nil +} + // MarshalJSON defines custom encoding scheme func (u Uint) MarshalJSON() ([]byte, error) { if u.i == nil { // Necessary since default Uint initialization has i.i as nil diff --git a/math/uint_test.go b/math/uint_test.go index ceb3e87d72..dcb6e9ab86 100644 --- a/math/uint_test.go +++ b/math/uint_test.go @@ -1,6 +1,7 @@ package math_test import ( + "encoding/xml" "fmt" "math" "math/big" @@ -377,3 +378,11 @@ func (s *uintTestSuite) TestUintBigEndian() { s.Require().Equal(u1, u2) } + +func (s *uintTestSuite) TestUintXmlMarshalRoundTrip() { + u1 := sdkmath.NewUint(256) + marshalResult, _ := xml.Marshal(u1) + u2 := sdkmath.Uint{} + xml.Unmarshal(marshalResult, &u2) + s.Require().Equal(u1, u2) +} From 1e407f209b025d529f1cfc4f53edef4f38dbdff4 Mon Sep 17 00:00:00 2001 From: ruojunm <46366167+ruojunm@users.noreply.github.com> Date: Wed, 29 Nov 2023 09:32:57 +0800 Subject: [PATCH 2/3] feat: add xml marshal for Int type (#365) Co-authored-by: Clyde --- math/int.go | 15 +++++++++++++++ math/int_test.go | 9 +++++++++ 2 files changed, 24 insertions(+) diff --git a/math/int.go b/math/int.go index 6811893f7a..80b0733967 100644 --- a/math/int.go +++ b/math/int.go @@ -3,6 +3,7 @@ package math import ( "encoding" "encoding/json" + "encoding/xml" "fmt" "math/big" "strings" @@ -327,6 +328,20 @@ func (i Int) String() string { return i.i.String() } +// MarshalXML defines custom encoding for xml Marshaler +func (i Int) MarshalXML(e *xml.Encoder, start xml.StartElement) error { + return e.EncodeElement(i.String(), start) +} + +// UnmarshalXML defines custom decoding for xml Marshaler +func (i *Int) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { + var s string + if err := d.DecodeElement(&s, &start); err != nil { + return err + } + return i.Unmarshal([]byte(s)) +} + // MarshalJSON defines custom encoding scheme func (i Int) MarshalJSON() ([]byte, error) { if i.i == nil { // Necessary since default Uint initialization has i.i as nil diff --git a/math/int_test.go b/math/int_test.go index 5af450cb6c..3106734db5 100644 --- a/math/int_test.go +++ b/math/int_test.go @@ -2,6 +2,7 @@ package math_test import ( "encoding/json" + "encoding/xml" "fmt" "math/big" "math/rand" @@ -396,6 +397,14 @@ func (s *intTestSuite) TestIntEq() { s.Require().False(resp) } +func (s *intTestSuite) TestIntXmlMarshalRoundTrip() { + u1 := math.NewInt(256) + marshalResult, _ := xml.Marshal(u1) + u2 := math.Int{} + xml.Unmarshal(marshalResult, &u2) + s.Require().Equal(u1, u2) +} + func TestRoundTripMarshalToInt(t *testing.T) { values := []int64{ 0, From 3e7d502b3108d470b3db84f9d39d2f0a3e012cad Mon Sep 17 00:00:00 2001 From: zjubfd <296179868@qq.com> Date: Wed, 6 Dec 2023 12:09:21 +0800 Subject: [PATCH 3/3] docs: add change logs for v1.2.0 (#366) --- CHANGELOG.md | 7 +++++++ types/upgrade.go | 4 ++-- x/upgrade/types/upgrade_config.go | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fa12cd4ec..a622076210 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## V1.2.0 +This release introduce the Manchurian upgrade to the testnet. + +Chores: +* [#365](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/365) chore: add xml marshal for Int type +* [#364](https://github.com/bnb-chain/greenfield-cosmos-sdk/pull/364) chore: add xml marshal for UInt type + ## v1.1.1 This release introduces the Pampas upgrade to the mainnet. diff --git a/types/upgrade.go b/types/upgrade.go index 76e5afe479..fbeee19c58 100644 --- a/types/upgrade.go +++ b/types/upgrade.go @@ -10,6 +10,6 @@ const ( // Pampas is the upgrade name for Pampas upgrade Pampas = "Pampas" - // Eddystone is the upgrade name for Eddystone upgrade - Eddystone = "Eddystone" + // Manchurian is the upgrade name for Manchurian upgrade + Manchurian = "Manchurian" ) diff --git a/x/upgrade/types/upgrade_config.go b/x/upgrade/types/upgrade_config.go index 8bc6c4fa15..0f738ea3be 100644 --- a/x/upgrade/types/upgrade_config.go +++ b/x/upgrade/types/upgrade_config.go @@ -16,8 +16,8 @@ const ( // Pampas is the upgrade name for Pampas upgrade Pampas = types.Pampas - // Eddystone is the upgrade name for Eddystone upgrade - Eddystone = types.Eddystone + // Manchurian is the upgrade name for Manchurian upgrade + Manchurian = types.Manchurian ) // The default upgrade config for networks