-
Notifications
You must be signed in to change notification settings - Fork 1
/
tx_service.go
83 lines (67 loc) · 2.5 KB
/
tx_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package types
import (
"context"
gogogrpc "github.com/cosmos/gogoproto/grpc" // nolint: staticcheck
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/cosmos/cosmos-sdk/client"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
// nolint: staticcheck
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)
// txServer is the server for the protobuf Tx service.
type routerTxServer struct {
clientCtx client.Context
simulate baseAppSimulateFn
interfaceRegistry codectypes.InterfaceRegistry
}
// NewRouterTxServer creates a new Router Tx service server.
func NewRouterTxServer(clientCtx client.Context, simulate baseAppSimulateFn, interfaceRegistry codectypes.InterfaceRegistry) RouterTxRpcServer {
return routerTxServer{
clientCtx: clientCtx,
simulate: simulate,
interfaceRegistry: interfaceRegistry,
}
}
var _ RouterTxRpcServer = routerTxServer{}
// TxsByEvents implements the ServiceServer.TxsByEvents RPC method.
func (s routerTxServer) GetTx(ctx context.Context, req *GetTxRequest) (*GetTxResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "request cannot be nil")
}
return &GetTxResponse{}, nil
}
func (s routerTxServer) PrepareTx(ctx context.Context, req *PrepareTxRequest) (*PrepareTxResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "request cannot be nil")
}
return &PrepareTxResponse{
Data: "{venky:sdf}",
}, nil
}
func (s routerTxServer) BroadcastTx(ctx context.Context, req *BroadcastTxRequest) (*BroadcastTxResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "request cannot be nil")
}
return &BroadcastTxResponse{}, nil
}
// RegisterRouterTxService registers the router tx service on the gRPC router.
func RegisterRouterTxService(
qrt gogogrpc.Server,
clientCtx client.Context,
simulateFn baseAppSimulateFn,
interfaceRegistry codectypes.InterfaceRegistry,
) {
RegisterRouterTxRpcServer(
qrt,
NewRouterTxServer(clientCtx, simulateFn, interfaceRegistry),
)
}
// RegisterGRPCGatewayRoutes mounts the tx service's GRPC-gateway routes on the
// given Mux.
func RegisterGRPCGatewayRoutes(clientConn gogogrpc.ClientConn, mux *runtime.ServeMux) {
_ = RegisterRouterTxRpcHandlerClient(context.Background(), mux, NewRouterTxRpcClient(clientConn))
}