forked from tendermint/tendermint
-
Notifications
You must be signed in to change notification settings - Fork 2
/
api.go
39 lines (33 loc) · 1.04 KB
/
api.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
package core_grpc
import (
"context"
abci "github.com/tendermint/tendermint/abci/types"
core "github.com/tendermint/tendermint/rpc/core"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
)
type broadcastAPI struct {
}
func (bapi *broadcastAPI) Ping(ctx context.Context, req *RequestPing) (*ResponsePing, error) {
// kvstore so we can check if the server is up
return &ResponsePing{}, nil
}
func (bapi *broadcastAPI) BroadcastTx(ctx context.Context, req *RequestBroadcastTx) (*ResponseBroadcastTx, error) {
// NOTE: there's no way to get client's remote address
// see https://stackoverflow.com/questions/33684570/session-and-remote-ip-address-in-grpc-go
res, err := core.BroadcastTxCommit(&rpctypes.Context{}, req.Tx)
if err != nil {
return nil, err
}
return &ResponseBroadcastTx{
CheckTx: &abci.ResponseCheckTx{
Code: res.CheckTx.Code,
Data: res.CheckTx.Data,
Log: res.CheckTx.Log,
},
DeliverTx: &abci.ResponseDeliverTx{
Code: res.DeliverTx.Code,
Data: res.DeliverTx.Data,
Log: res.DeliverTx.Log,
},
}, nil
}