-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add tx broadcast gRPC endpoint #7852
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
4d22fdf
WIP tx/broadcast grpc endpoint
aleem1314 6674921
fix lint
aleem1314 6134a9b
fix proto lint
aleem1314 0f09eb9
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into 73…
aleem1314 437b1bf
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into 73…
aleem1314 4871d32
Update service.proto
aleem1314 ccf6f0c
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into 73…
aleem1314 d65d3ee
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into 73…
aleem1314 abc49b8
resolve conflicts
aleem1314 05f6282
update service.proto
aleem1314 a0e5111
Update service.proto
aleem1314 dc8e1f3
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into 73…
aleem1314 c1d323e
review changes
aleem1314 1401b00
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into 73…
aleem1314 3ed9110
proto lint
aleem1314 75d7f8b
Merge branch 'master' into 7355-grpc-broadcast
aleem1314 c7031a6
Merge branch 'master' into 7355-grpc-broadcast
aleem1314 24030a4
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into 7355…
amaury1093 846946f
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into 7355…
amaury1093 52a9860
Switch to txraw
amaury1093 152022e
Add check breaking at the end
amaury1093 6e2c50d
Fix broadcast
amaury1093 c70daf7
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into 7355…
amaury1093 d2ec8f9
Send Msg on SetupSuite
amaury1093 4b323c4
Remove proto-check-breaking
amaury1093 48b8e4c
1 validator in test
amaury1093 41039b0
Add grpc server tests for broadcast
amaury1093 ce8f657
Fix grpc server tests
amaury1093 04cdc23
Merge branch 'master' into 7355-grpc-broadcast
amaury1093 4fb6f7f
Add some changes
amaury1093 d5152d8
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into 7355…
amaury1093 e2c75f1
Add ress comments
amaury1093 aade13d
Add table tests for tx service
amaury1093 00683e5
Add test for mode
amaury1093 b37c04c
Add simulate tests
amaury1093 8803107
Add build flag back
amaury1093 57cc0e8
Revert custom stringer for enum
amaury1093 3113060
Remove stray logs
amaury1093 64d4719
Merge branch 'master' into 7355-grpc-broadcast
alexanderbez 7c3ad41
Use /txs/{hash}
amaury1093 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package client | |
import ( | ||
gocontext "context" | ||
"fmt" | ||
"reflect" | ||
"strconv" | ||
|
||
gogogrpc "github.com/gogo/protobuf/grpc" | ||
|
@@ -12,18 +13,48 @@ import ( | |
"google.golang.org/grpc/encoding/proto" | ||
"google.golang.org/grpc/metadata" | ||
|
||
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" | ||
"github.com/cosmos/cosmos-sdk/types/tx" | ||
) | ||
|
||
var _ gogogrpc.ClientConn = Context{} | ||
|
||
var protoCodec = encoding.GetCodec(proto.Name) | ||
|
||
// Invoke implements the grpc ClientConn.Invoke method | ||
func (ctx Context) Invoke(grpcCtx gocontext.Context, method string, args, reply interface{}, opts ...grpc.CallOption) error { | ||
func (ctx Context) Invoke(grpcCtx gocontext.Context, method string, args, reply interface{}, opts ...grpc.CallOption) (err error) { | ||
// Two things can happen here: | ||
// 1. either we're broadcasting a Tx, in which call we call Tendermint's broadcast endpoint directly, | ||
// 2. or we are querying for state, in which case we call ABCI's Query. | ||
|
||
// In both cases, we don't allow empty request args (it will panic unexpectedly). | ||
if reflect.ValueOf(args).IsNil() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why Anyways, this works. |
||
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "request cannot be nil") | ||
} | ||
|
||
// Case 1. Broadcasting a Tx. | ||
if isBroadcast(method) { | ||
req, ok := args.(*tx.BroadcastTxRequest) | ||
if !ok { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "expected %T, got %T", (*tx.BroadcastTxRequest)(nil), args) | ||
} | ||
res, ok := reply.(*tx.BroadcastTxResponse) | ||
if !ok { | ||
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "expected %T, got %T", (*tx.BroadcastTxResponse)(nil), args) | ||
} | ||
|
||
broadcastRes, err := TxServiceBroadcast(grpcCtx, ctx, req) | ||
if err != nil { | ||
return err | ||
} | ||
*res = *broadcastRes | ||
|
||
return err | ||
} | ||
|
||
// Case 2. Querying state. | ||
reqBz, err := protoCodec.Marshal(args) | ||
if err != nil { | ||
return err | ||
|
@@ -86,3 +117,7 @@ func (ctx Context) Invoke(grpcCtx gocontext.Context, method string, args, reply | |
func (Context) NewStream(gocontext.Context, *grpc.StreamDesc, string, ...grpc.CallOption) (grpc.ClientStream, error) { | ||
return nil, fmt.Errorf("streaming rpc not supported") | ||
} | ||
|
||
func isBroadcast(method string) bool { | ||
return method == "/cosmos.tx.v1beta1.Service/BroadcastTx" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref: #8021