Cosmos-sdk: Overriding Encoder and Decoder Tx doesn't work

Created on 18 Oct 2019  Â·  3Comments  Â·  Source: cosmos/cosmos-sdk

Summary of Bug

I override Encoder and Decoder for Tx, but I caught problems:
1) get Tx by the CLI (./cli q tx {hash})
https://github.com/cosmos/cosmos-sdk/blob/master/x/auth/client/utils/query.go#L174
2) When happened first init blockchain (genesis step ./node start) because Tx encoded hardcoded here
https://github.com/cosmos/cosmos-sdk/blob/master/x/genutil/gentx.go#L99

Version

sdk v0.37

Steps to Reproduce

Set up your Tx encoder via config

// Read in the configuration file for the sdk
    config := sdk.GetConfig()
    config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
    config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
    config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
    config.SetTxEncoder(func(tx sdk.Tx) ([]byte, error) {
        return cdc.MarshalJSON(tx)
    })
    config.Seal()

Setup your Tx decoder like this

// BaseApp handles interactions with Tendermint through the ABCI protocol
    bApp := bam.NewBaseApp(appName, logger, db, func(txBytes []byte) (sdk.Tx, sdk.Error) {
        var tx auth.StdTx

        if err := cdc.UnmarshalJSON(txBytes, &tx); err != nil {
            return nil, sdk.NewError(sdk.CodespaceRoot, sdk.CodeTxDecode, err.Error())
        }
        return tx, nil
    }, baseAppOptions...)

For Admin Use

  • [ ] Not duplicate issue
  • [ ] Appropriate labels applied
  • [ ] Appropriate contributors tagged
  • [ ] Contributor assigned/self-assigned
bug stale

Most helpful comment

Thanks @tochka. We need to support Tx ideally and use the tx encoder specified by the client.

All 3 comments

Thanks @tochka. We need to support Tx ideally and use the tx encoder specified by the client.

Seems like the problem is centered on the sdk client assuming transaction is auth.StdTx? Fixing this should help #5207 as well

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adrianbrink picture adrianbrink  Â·  3Comments

ValarDragon picture ValarDragon  Â·  3Comments

rigelrozanski picture rigelrozanski  Â·  3Comments

ValarDragon picture ValarDragon  Â·  3Comments

ValarDragon picture ValarDragon  Â·  3Comments