Skip to content

Commit

Permalink
fix: export Codec and LegacyAmino codec in Database wrapper (#96)
Browse files Browse the repository at this point in the history
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
v                               ✰  Thanks for creating a PR! ✰
v    Before smashing the submit button please review the checkboxes.
v If a checkbox is n/a - please still include it but + a little note why
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >  -->

<!-- Small description -->

- [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.
  • Loading branch information
MonikaCat committed Aug 31, 2023
1 parent dba3667 commit f3f4f2c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 15 additions & 11 deletions database/postgresql/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down Expand Up @@ -190,30 +194,30 @@ 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
}
msgs[index] = string(bz)
}
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
}
sigInfos[index] = string(bz)
}
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
}
Expand Down
2 changes: 1 addition & 1 deletion modules/messages/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f3f4f2c

Please sign in to comment.