From f3f4f2ce3762031bcddf541d6852b733da0782b9 Mon Sep 17 00:00:00 2001 From: Magic Cat <37407870+MonikaCat@users.noreply.github.com> Date: Mon, 5 Jun 2023 21:34:40 +0700 Subject: [PATCH] fix: export Codec and LegacyAmino codec in Database wrapper (#96) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - [x] Targeted PR against correct branch. - [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work. - [ ] Wrote unit tests. - [x] Re-reviewed `Files changed` in the Github PR explorer. --- CHANGELOG.md | 7 +++++++ database/postgresql/postgresql.go | 26 +++++++++++++++----------- modules/messages/message_handler.go | 2 +- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1758d565..44a36b29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## v5.0.0 +### Changes +- Updated Cosmos SDK to `v0.47.2` + +### Database +- ([\#96](https://github.com/forbole/juno/pull/96)) Exported Codec and LegacyAmino codec inside Database wrapper + ## v4.2.0 ### Changes - ([\#93](https://github.com/forbole/juno/pull/93)) Decode IBC transfer data to JSON for `/ibc.core.channel.v1.MsgRecvPacket` message diff --git a/database/postgresql/postgresql.go b/database/postgresql/postgresql.go index 6c33db18..0fbecfcf 100644 --- a/database/postgresql/postgresql.go +++ b/database/postgresql/postgresql.go @@ -6,11 +6,11 @@ import ( "fmt" "strings" + "github.com/cosmos/cosmos-sdk/codec" "github.com/jmoiron/sqlx" "github.com/forbole/juno/v4/logging" - "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/lib/pq" "github.com/forbole/juno/v4/database" @@ -46,9 +46,11 @@ func Builder(ctx *database.Context) (database.Database, error) { postgresDb.SetMaxIdleConns(ctx.Cfg.MaxIdleConnections) return &Database{ - SQL: postgresDb, - EncodingConfig: ctx.EncodingConfig, - Logger: ctx.Logger, + Cdc: ctx.EncodingConfig.Marshaler, + Amino: ctx.EncodingConfig.Amino, + + SQL: postgresDb, + Logger: ctx.Logger, }, nil } @@ -58,9 +60,11 @@ var _ database.Database = &Database{} // Database defines a wrapper around a SQL database and implements functionality // for data aggregation and exporting. type Database struct { - SQL *sqlx.DB - EncodingConfig *params.EncodingConfig - Logger logging.Logger + Cdc codec.Codec + Amino *codec.LegacyAmino + + SQL *sqlx.DB + Logger logging.Logger } // createPartitionIfNotExists creates a new partition having the given partition id if not existing @@ -190,7 +194,7 @@ ON CONFLICT (hash, partition_id) DO UPDATE var msgs = make([]string, len(tx.Body.Messages)) for index, msg := range tx.Body.Messages { - bz, err := db.EncodingConfig.Marshaler.MarshalJSON(msg) + bz, err := db.Cdc.MarshalJSON(msg) if err != nil { return err } @@ -198,14 +202,14 @@ ON CONFLICT (hash, partition_id) DO UPDATE } msgsBz := fmt.Sprintf("[%s]", strings.Join(msgs, ",")) - feeBz, err := db.EncodingConfig.Marshaler.MarshalJSON(tx.AuthInfo.Fee) + feeBz, err := db.Cdc.MarshalJSON(tx.AuthInfo.Fee) if err != nil { return fmt.Errorf("failed to JSON encode tx fee: %s", err) } var sigInfos = make([]string, len(tx.AuthInfo.SignerInfos)) for index, info := range tx.AuthInfo.SignerInfos { - bz, err := db.EncodingConfig.Marshaler.MarshalJSON(info) + bz, err := db.Cdc.MarshalJSON(info) if err != nil { return err } @@ -213,7 +217,7 @@ ON CONFLICT (hash, partition_id) DO UPDATE } sigInfoBz := fmt.Sprintf("[%s]", strings.Join(sigInfos, ",")) - logsBz, err := db.EncodingConfig.Amino.MarshalJSON(tx.Logs) + logsBz, err := db.Amino.MarshalJSON(tx.Logs) if err != nil { return err } diff --git a/modules/messages/message_handler.go b/modules/messages/message_handler.go index f0699409..ac4a507b 100644 --- a/modules/messages/message_handler.go +++ b/modules/messages/message_handler.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" + channeltypes "github.com/cosmos/ibc-go/v4/modules/core/04-channel/types" "github.com/gogo/protobuf/proto" "github.com/forbole/juno/v4/database"