* Handle nil any in UnpackAny * Add test * Add flag back * Update runTx signature * Update Simulate signature * Update calls to Simulate * Add txEncoder in baseapp * Fix TestTxWithoutPublicKey * Wrap errors * Use amino in baseapp tests * Add txEncoder arg to Check & Deliver * Fix gas in test * Fix remaining base app tests * Rename to amionTxEncoder * Update codec/types/interface_registry.go Co-authored-by: Aaron Craelius <aaron@regen.network> * golangci-lint fix Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: Cory Levinson <cjlevinson@gmail.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package simulate
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
|
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
// BaseAppSimulateFn is the signature of the Baseapp#Simulate function.
|
|
type BaseAppSimulateFn func(txBytes []byte) (sdk.GasInfo, *sdk.Result, error)
|
|
|
|
type simulateServer struct {
|
|
simulate BaseAppSimulateFn
|
|
interfaceRegistry codectypes.InterfaceRegistry
|
|
}
|
|
|
|
// NewSimulateServer creates a new SimulateServer.
|
|
func NewSimulateServer(simulate BaseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry) SimulateServiceServer {
|
|
return simulateServer{
|
|
simulate: simulate,
|
|
interfaceRegistry: interfaceRegistry,
|
|
}
|
|
}
|
|
|
|
var _ SimulateServiceServer = simulateServer{}
|
|
|
|
// Simulate implements the SimulateService.Simulate RPC method.
|
|
func (s simulateServer) Simulate(ctx context.Context, req *SimulateRequest) (*SimulateResponse, error) {
|
|
if req.Tx == nil {
|
|
return nil, status.Error(codes.InvalidArgument, "invalid empty tx")
|
|
}
|
|
|
|
err := req.Tx.UnpackInterfaces(s.interfaceRegistry)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
txBytes, err := req.Tx.Marshal()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
gasInfo, result, err := s.simulate(txBytes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &SimulateResponse{
|
|
GasInfo: &gasInfo,
|
|
Result: result,
|
|
}, nil
|
|
}
|