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 }