From 8c605b4420978eccc0e8b1c82e5f842148c2b814 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 | 3 +++ database/postgresql/postgresql.go | 26 +++++++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98a99f17..74402998 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ### 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 bca5076f..20f22d55 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/v5/logging" - "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/lib/pq" "github.com/forbole/juno/v5/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.Codec, + 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 }