Skip to content

Commit

Permalink
refactor!: rm usages of .GetSignBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
kocubinski committed May 8, 2023
1 parent 2f21cb5 commit 025d165
Show file tree
Hide file tree
Showing 33 changed files with 435 additions and 796 deletions.
317 changes: 161 additions & 156 deletions api/cosmos/tx/v1beta1/tx.pulsar.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ require (

// Below are the long-lived replace of the Cosmos SDK
replace (
// TODO remove after cosmossdk.io/api release
cosmossdk.io/api => ./api
cosmossdk.io/core => ./core
cosmossdk.io/store => ./store
// TODO: remove after 0.7.0 release
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
cosmossdk.io/api v0.4.1 h1:0ikaYM6GyxTYYcfBiyR8YnLCfhNnhKpEFnaSepCTmqg=
cosmossdk.io/api v0.4.1/go.mod h1:jR7k5ok90LxW2lFUXvd8Vpo/dr4PpiyVegxdm7b1ZdE=
cosmossdk.io/collections v0.1.0 h1:nzJGeiq32KnZroSrhB6rPifw4I85Cgmzw/YAmr4luv8=
cosmossdk.io/collections v0.1.0/go.mod h1:xbauc0YsbUF8qKMVeBZl0pFCunxBIhKN/WlxpZ3lBuo=
cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw=
Expand Down
17 changes: 13 additions & 4 deletions proto/cosmos/tx/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
syntax = "proto3";
package cosmos.tx.v1beta1;

import "amino/amino.proto";
import "gogoproto/gogo.proto";
import "cosmos/crypto/multisig/v1beta1/multisig.proto";
import "cosmos/base/v1beta1/coin.proto";
Expand Down Expand Up @@ -205,8 +206,12 @@ message ModeInfo {
// which must be above some miminum to be accepted into the mempool.
message Fee {
// amount is the amount of coins to be paid as a fee
repeated cosmos.base.v1beta1.Coin amount = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
repeated cosmos.base.v1beta1.Coin amount = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(amino.dont_omitempty) = true,
(amino.encoding) = "legacy_coins"
];

// gas_limit is the maximum gas that can be used in transaction processing
// before an out of gas error occurs
Expand All @@ -228,8 +233,12 @@ message Fee {
// Since: cosmos-sdk 0.46
message Tip {
// amount is the amount of the tip
repeated cosmos.base.v1beta1.Coin amount = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
repeated cosmos.base.v1beta1.Coin amount = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(amino.dont_omitempty) = true,
(amino.encoding) = "legacy_coins"
];
// tipper is the address of the account paying for the tip
string tipper = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}
Expand Down
4 changes: 0 additions & 4 deletions server/mock/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ func (msg *KVStoreTx) GetMsgs() []sdk.Msg {
return []sdk.Msg{msg}
}

func (msg *KVStoreTx) GetSignBytes() []byte {
return msg.bytes
}

// Should the app be calling this? Or only handlers?
func (msg *KVStoreTx) ValidateBasic() error {
return nil
Expand Down
9 changes: 0 additions & 9 deletions testutil/testdata/tx.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package testdata

import (
"encoding/json"
"testing"

"gotest.tools/v3/assert"
Expand Down Expand Up @@ -78,14 +77,6 @@ func NewTestMsg(addrs ...sdk.AccAddress) *TestMsg {

var _ sdk.Msg = (*TestMsg)(nil)

func (msg *TestMsg) GetSignBytes() []byte {
bz, err := json.Marshal(msg.Signers)
if err != nil {
panic(err)
}
return sdk.MustSortJSON(bz)
}

func (msg *TestMsg) GetSigners() []sdk.AccAddress {
signers := make([]sdk.AccAddress, 0, len(msg.Signers))
for _, addr := range msg.Signers {
Expand Down
133 changes: 68 additions & 65 deletions types/tx/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions x/auth/migrations/legacytx/stdsign.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ type StdSignDoc struct {
Tip *StdTip `json:"tip,omitempty" yaml:"tip"`
}

var RegressionTestingAminoCodec *codec.LegacyAmino

// StdSignBytes returns the bytes to sign for a transaction.
// Deprecated: Only used in regression tests.
func StdSignBytes(chainID string, accnum, sequence, timeout uint64, fee StdFee, msgs []sdk.Msg, memo string, tip *tx.Tip) []byte {
if RegressionTestingAminoCodec == nil {
panic(fmt.Errorf("must set RegressionTestingAminoCodec before calling StdSignBytes"))
}
msgsBytes := make([]json.RawMessage, 0, len(msgs))
for _, msg := range msgs {
legacyMsg, ok := msg.(LegacyMsg)
if !ok {
panic(fmt.Errorf("expected %T when using amino JSON", (*LegacyMsg)(nil)))
}

msgsBytes = append(msgsBytes, json.RawMessage(legacyMsg.GetSignBytes()))
bz := RegressionTestingAminoCodec.MustMarshalJSON(msg)
msgsBytes = append(msgsBytes, sdk.MustSortJSON(bz))
}

var stdTip *StdTip
Expand Down
5 changes: 0 additions & 5 deletions x/auth/migrations/legacytx/stdsignmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ type StdSignMsg struct {
Memo string `json:"memo" yaml:"memo"`
}

// get message bytes
func (msg StdSignMsg) Bytes() []byte {
return StdSignBytes(msg.ChainID, msg.AccountNumber, msg.Sequence, msg.TimeoutHeight, msg.Fee, msg.Msgs, msg.Memo, nil)
}

func (msg StdSignMsg) UnpackInterfaces(unpacker types.AnyUnpacker) error {
for _, m := range msg.Msgs {
err := types.UnpackInterfaces(m, unpacker)
Expand Down
Loading

0 comments on commit 025d165

Please sign in to comment.