github.com/line/ostracon@v1.0.10-0.20230328032236-7f20145f065d/rpc/grpc/api.go (about)

     1  package coregrpc
     2  
     3  import (
     4  	"context"
     5  
     6  	abci "github.com/tendermint/tendermint/abci/types"
     7  
     8  	ocabci "github.com/line/ostracon/abci/types"
     9  	core "github.com/line/ostracon/rpc/core"
    10  	rpctypes "github.com/line/ostracon/rpc/jsonrpc/types"
    11  )
    12  
    13  type broadcastAPI struct {
    14  }
    15  
    16  func (bapi *broadcastAPI) Ping(ctx context.Context, req *RequestPing) (*ResponsePing, error) {
    17  	// kvstore so we can check if the server is up
    18  	return &ResponsePing{}, nil
    19  }
    20  
    21  func (bapi *broadcastAPI) BroadcastTx(ctx context.Context, req *RequestBroadcastTx) (*ResponseBroadcastTx, error) {
    22  	// NOTE: there's no way to get client's remote address
    23  	// see https://stackoverflow.com/questions/33684570/session-and-remote-ip-address-in-grpc-go
    24  	res, err := core.BroadcastTxCommit(&rpctypes.Context{}, req.Tx)
    25  	if err != nil {
    26  		return nil, err
    27  	}
    28  
    29  	return &ResponseBroadcastTx{
    30  		CheckTx: &ocabci.ResponseCheckTx{
    31  			Code: res.CheckTx.Code,
    32  			Data: res.CheckTx.Data,
    33  			Log:  res.CheckTx.Log,
    34  		},
    35  		DeliverTx: &abci.ResponseDeliverTx{
    36  			Code: res.DeliverTx.Code,
    37  			Data: res.DeliverTx.Data,
    38  			Log:  res.DeliverTx.Log,
    39  		},
    40  	}, nil
    41  }