Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump cosmos-sdk to v0.44.0 #551

Merged
merged 10 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ func (app *TerraApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIC
// RegisterTxService implements the Application.RegisterTxService method.
func (app *TerraApp) RegisterTxService(clientCtx client.Context) {
authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
customauthtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), app.TreasuryKeeper)
customauthtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.TreasuryKeeper)
}

// RegisterTendermintService implements the Application.RegisterTendermintService method.
Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

30 changes: 28 additions & 2 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -996,9 +996,22 @@ paths:
sequence:
type: string
example: '0'
required: true
mode:
required: true
type: string
example: block
sequences:
required: false
type: array
items:
type: string
example: '1'
fee_granter:
type: string
description: bech32 encoded address
example: terra1wg2mlrxdmnnkkykgqg4znky86nyrtc45q336yv
required: false
responses:
'200':
description: Tx broadcasting result
Expand Down Expand Up @@ -25371,11 +25384,18 @@ paths:
- Query
'/cosmos/upgrade/v1beta1/upgraded_consensus_state/{last_height}':
get:
summary: |-
summary: >-
UpgradedConsensusState queries the consensus state that will serve

as a trusted kernel for the next version of this chain. It will only be

stored at the last height of this chain.

UpgradedConsensusState RPC not supported with legacy querier

This rpc is deprecated now that IBC has its own replacement

(https://github.com/cosmos/ibc-go/blob/2c880a22e9f9cc75f62b527ca94aa75ce1106001/proto/ibc/core/client/v1/query.proto#L54)
operationId: UpgradedConsensusState
responses:
'200':
Expand Down Expand Up @@ -54882,7 +54902,13 @@ definitions:
properties:
tx:
$ref: '#/definitions/cosmos.tx.v1beta1.Tx'
description: tx is the transaction to simulate.
description: |-
tx is the transaction to simulate.
Deprecated. Send raw tx bytes instead.
tx_bytes:
type: string
format: byte
description: tx_bytes is the raw transaction.
description: |-
ComputeTaxRequest is the request type for the Service.ComputeTax
RPC method.
Expand Down
11 changes: 11 additions & 0 deletions client/docs/swagger_legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,21 @@ paths:
type: object
properties:
tx:
required: true
$ref: "#/definitions/StdTx"
mode:
required: true
type: string
example: block
sequences:
required: false
type: array
items:
type: string
example: "1"
fee_granter:
required: false
$ref: "#/definitions/Address"
responses:
200:
description: Tx broadcasting result
Expand Down
119 changes: 119 additions & 0 deletions custom/auth/client/rest/broadcast.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package rest

import (
"errors"
"fmt"
"io/ioutil"
"net/http"

"github.com/cosmos/cosmos-sdk/client"
clientrest "github.com/cosmos/cosmos-sdk/client/rest"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
)

// BroadcastReq defines a tx broadcasting request.
type BroadcastReq struct {
Tx legacytx.StdTx `json:"tx" yaml:"tx"`
Mode string `json:"mode" yaml:"mode"`
Sequences []uint64 `json:"sequences" yaml:"sequences"`
FeeGranter string `json:"fee_granter" yaml:"fee_granter"`
}

var _ codectypes.UnpackInterfacesMessage = BroadcastReq{}

// UnpackInterfaces implements the UnpackInterfacesMessage interface.
func (m BroadcastReq) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return m.Tx.UnpackInterfaces(unpacker)
}

// BroadcastTxRequest implements a tx broadcasting handler that is responsible
// for broadcasting a valid and signed tx to a full node. The tx can be
// broadcasted via a sync|async|block mechanism.
func BroadcastTxRequest(clientCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req BroadcastReq

body, err := ioutil.ReadAll(r.Body)
if rest.CheckBadRequestError(w, err) {
return
}

// NOTE: amino is used intentionally here, don't migrate it!
err = clientCtx.LegacyAmino.UnmarshalJSON(body, &req)
if err != nil {
err := fmt.Errorf("this transaction cannot be broadcasted via legacy REST endpoints, because it does not support"+
" Amino serialization. Please either use CLI, gRPC, gRPC-gateway, or directly query the Tendermint RPC"+
" endpoint to broadcast this transaction. The new REST endpoint (via gRPC-gateway) is POST /cosmos/tx/v1beta1/txs."+
" Please also see the REST endpoints migration guide at %s for more info", clientrest.DeprecationURL)
if rest.CheckBadRequestError(w, err) {
return
}
}

txBuilder := clientCtx.TxConfig.NewTxBuilder()
txBuilder.SetFeeAmount(req.Tx.GetFee())
txBuilder.SetGasLimit(req.Tx.GetGas())
txBuilder.SetMemo(req.Tx.GetMemo())
if err := txBuilder.SetMsgs(req.Tx.GetMsgs()...); rest.CheckBadRequestError(w, err) {
return
}

txBuilder.SetTimeoutHeight(req.Tx.GetTimeoutHeight())
if req.FeeGranter != "" {
addr, err := sdk.AccAddressFromBech32(req.FeeGranter)
if rest.CheckBadRequestError(w, err) {
return
}

txBuilder.SetFeeGranter(addr)
}

signatures, err := req.Tx.GetSignaturesV2()
if rest.CheckBadRequestError(w, err) {
return
}

// if sequence is not given, try fetch from the chain
if len(req.Sequences) == 0 {
for _, sig := range signatures {
_, seq, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, sdk.AccAddress(sig.PubKey.Address().Bytes()))
if rest.CheckBadRequestError(w, err) {
return
}
req.Sequences = append(req.Sequences, seq)
}
}

// check the sequence nubmer is equal with the signature nubmer
if len(signatures) != len(req.Sequences) {
rest.CheckBadRequestError(w, errors.New("Must provide each signers's sequence number"))
return
}

// fill sequence number to new signature
for i, seq := range req.Sequences {
signatures[i].Sequence = seq
}

if err := txBuilder.SetSignatures(signatures...); rest.CheckBadRequestError(w, err) {
return
}

// compute signature bytes
txBytes, err := clientCtx.TxConfig.TxEncoder()(txBuilder.GetTx())
if rest.CheckInternalServerError(w, err) {
return
}

clientCtx = clientCtx.WithBroadcastMode(req.Mode)
res, err := clientCtx.BroadcastTx(txBytes)
if rest.CheckInternalServerError(w, err) {
return
}

rest.PostProcessResponseBare(w, clientCtx, res)
}
}
1 change: 1 addition & 0 deletions custom/auth/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ import (
func RegisterTxRoutes(clientCtx client.Context, rtr *mux.Router) {
r := clientrest.WithHTTPDeprecationHeaders(rtr)
r.HandleFunc("/txs/estimate_fee", EstimateTxFeeRequestHandlerFn(clientCtx)).Methods("POST")
r.HandleFunc("/txs", BroadcastTxRequest(clientCtx)).Methods("POST")
}
30 changes: 26 additions & 4 deletions custom/auth/tx/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

customante "github.com/terra-money/core/custom/auth/ante"

"github.com/cosmos/cosmos-sdk/client"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand All @@ -18,12 +19,14 @@ var _ ServiceServer = txServer{}

// txServer is the server for the protobuf Tx service.
type txServer struct {
clientCtx client.Context
treasuryKeeper customante.TreasuryKeeper
}

// NewTxServer creates a new Tx service server.
func NewTxServer(treasuryKeeper customante.TreasuryKeeper) ServiceServer {
func NewTxServer(clientCtx client.Context, treasuryKeeper customante.TreasuryKeeper) ServiceServer {
return txServer{
clientCtx: clientCtx,
treasuryKeeper: treasuryKeeper,
}
}
Expand All @@ -35,7 +38,21 @@ func (ts txServer) ComputeTax(c context.Context, req *ComputeTaxRequest) (*Compu
return nil, status.Error(codes.InvalidArgument, "request cannot be nil")
}

taxAmount := customante.FilterMsgAndComputeTax(ctx, ts.treasuryKeeper, req.Tx.GetMsgs()...)
var msgs []sdk.Msg
if len(req.TxBytes) != 0 {
tx, err := ts.clientCtx.TxConfig.TxDecoder()(req.TxBytes)
if err != nil {
return nil, err
}

msgs = tx.GetMsgs()
} else if req.Tx != nil {
msgs = req.Tx.GetMsgs()
} else {
return nil, status.Errorf(codes.InvalidArgument, "empty txBytes is not allowed")
}

taxAmount := customante.FilterMsgAndComputeTax(ctx, ts.treasuryKeeper, msgs...)
return &ComputeTaxResponse{
TaxAmount: taxAmount,
}, nil
Expand All @@ -44,11 +61,12 @@ func (ts txServer) ComputeTax(c context.Context, req *ComputeTaxRequest) (*Compu
// RegisterTxService registers the tx service on the gRPC router.
func RegisterTxService(
qrt gogogrpc.Server,
clientCtx client.Context,
treasuryKeeper customante.TreasuryKeeper,
) {
RegisterServiceServer(
qrt,
NewTxServer(treasuryKeeper),
NewTxServer(clientCtx, treasuryKeeper),
)
}

Expand All @@ -62,5 +80,9 @@ var _ codectypes.UnpackInterfacesMessage = ComputeTaxRequest{}

// UnpackInterfaces implements the UnpackInterfacesMessage interface.
func (m ComputeTaxRequest) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
return m.Tx.UnpackInterfaces(unpacker)
if m.Tx != nil {
return m.Tx.UnpackInterfaces(unpacker)
}

return nil
}
Loading