Skip to content

Commit

Permalink
Gen js grpc lib + proto cleanup (#408)
Browse files Browse the repository at this point in the history
* scritp for generating js bindings, update protos for consistency

Signed-off-by: Aaron Sutula <hi@asutula.com>

* move reputation module to latest rpc style

Signed-off-by: Aaron Sutula <hi@asutula.com>

* update health, net, ffs to latest rpc patterns

Signed-off-by: Aaron Sutula <hi@asutula.com>

* move deals to latest rpc patterns

Signed-off-by: Aaron Sutula <hi@asutula.com>

* updating proto package

Signed-off-by: Aaron Sutula <hi@asutula.com>

* removing unused proto options

Signed-off-by: Aaron Sutula <hi@asutula.com>

* move wallet to latest rpc patterns

Signed-off-by: Aaron Sutula <hi@asutula.com>

* move asks to latest rpc patterns

Signed-off-by: Aaron Sutula <hi@asutula.com>

* move slashing to latest rpc patterns

Signed-off-by: Aaron Sutula <hi@asutula.com>

* mover miner to latest rpc patterns

Signed-off-by: Aaron Sutula <hi@asutula.com>

* top level Makefile commands for generating go protos

Signed-off-by: Aaron Sutula <hi@asutula.com>

* update ask rpc patterns

Signed-off-by: Aaron Sutula <hi@asutula.com>

* bash compatible clean-protos command

Signed-off-by: Aaron Sutula <hi@asutula.com>

* updated rpc naming

Signed-off-by: Aaron Sutula <hi@asutula.com>
  • Loading branch information
asutula authored May 18, 2020
1 parent 3e24606 commit 66beee9
Show file tree
Hide file tree
Showing 63 changed files with 1,659 additions and 1,672 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/publish-grpc-libs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Publish JS gRPC bindings
on:
release:
types: [published]
jobs:

publish_grpc_lib:
name: Publish JS gRPC bindings
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v1
- name: Get latest tag
id: latesttag
uses: "WyriHaximus/github-action-get-previous-tag@master"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Install build tools
run: |
sudo apt-get update
sudo apt-get install -y build-essential
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://registry.npmjs.org'
- name: Install protoc
uses: arduino/setup-protoc@master
with:
version: '3.11.2'
- name: Generate JS gRPC bindings
run: |
./scripts/gen-js-protos.sh ("${{ steps.latesttag.outputs.tag }}").replace("v", "") . ./js-grpc
- name: Publish JS gRPC bindings
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: |
npm publish --access=public
working-directory: ./js-grpc
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ build: build-cli build-server build-bench
test:
go test -short -p 4 -race ./...
.PHONY: test

clean-protos:
find . -type f -name '*.pb.go' -delete
find . -type f -name '*pb_test.go' -delete
.PHONY: clean-protos

protos: clean-protos
./scripts/protoc_gen_plugin.bash --proto_path=. --plugin_name=go --plugin_out=. --plugin_opt=plugins=grpc
.PHONY: protos
12 changes: 6 additions & 6 deletions api/client/asks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import (
"time"

"github.com/textileio/powergate/index/ask"
pb "github.com/textileio/powergate/index/ask/pb"
"github.com/textileio/powergate/index/ask/rpc"
"github.com/textileio/powergate/index/ask/runner"
)

// Asks provides an API for viewing asks data
type Asks struct {
client pb.APIClient
client rpc.RPCClient
}

// Get returns the current index of available asks
func (a *Asks) Get(ctx context.Context) (*ask.Index, error) {
reply, err := a.client.Get(ctx, &pb.GetRequest{})
reply, err := a.client.Get(ctx, &rpc.GetRequest{})
if err != nil {
return nil, err
}
Expand All @@ -34,13 +34,13 @@ func (a *Asks) Get(ctx context.Context) (*ask.Index, error) {

// Query executes a query to retrieve active Asks
func (a *Asks) Query(ctx context.Context, query runner.Query) ([]ask.StorageAsk, error) {
q := &pb.Query{
q := &rpc.Query{
MaxPrice: query.MaxPrice,
PieceSize: query.PieceSize,
Limit: int32(query.Limit),
Offset: int32(query.Offset),
}
reply, err := a.client.Query(ctx, &pb.QueryRequest{Query: q})
reply, err := a.client.Query(ctx, &rpc.QueryRequest{Query: q})
if err != nil {
return nil, err
}
Expand All @@ -51,7 +51,7 @@ func (a *Asks) Query(ctx context.Context, query runner.Query) ([]ask.StorageAsk,
return asks, nil
}

func askFromPbAsk(a *pb.StorageAsk) ask.StorageAsk {
func askFromPbAsk(a *rpc.StorageAsk) ask.StorageAsk {
return ask.StorageAsk{
Price: a.GetPrice(),
MinPieceSize: a.GetMinPieceSize(),
Expand Down
4 changes: 2 additions & 2 deletions api/client/asks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package client
import (
"testing"

pb "github.com/textileio/powergate/index/ask/pb"
"github.com/textileio/powergate/index/ask/rpc"
"github.com/textileio/powergate/index/ask/runner"
)

Expand Down Expand Up @@ -32,7 +32,7 @@ func TestQuery(t *testing.T) {
func setupAsks(t *testing.T) (*Asks, func()) {
serverDone := setupServer(t)
conn, done := setupConnection(t)
return &Asks{client: pb.NewAPIClient(conn)}, func() {
return &Asks{client: rpc.NewRPCClient(conn)}, func() {
done()
serverDone()
}
Expand Down
30 changes: 15 additions & 15 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import (
"context"

"github.com/multiformats/go-multiaddr"
dealsPb "github.com/textileio/powergate/deals/pb"
dealsRpc "github.com/textileio/powergate/deals/rpc"
ffsRpc "github.com/textileio/powergate/ffs/rpc"
healthRpc "github.com/textileio/powergate/health/rpc"
asksPb "github.com/textileio/powergate/index/ask/pb"
minerPb "github.com/textileio/powergate/index/miner/pb"
slashingPb "github.com/textileio/powergate/index/slashing/pb"
askRpc "github.com/textileio/powergate/index/ask/rpc"
minerRpc "github.com/textileio/powergate/index/miner/rpc"
slashingRpc "github.com/textileio/powergate/index/slashing/rpc"
netRpc "github.com/textileio/powergate/net/rpc"
reputationPb "github.com/textileio/powergate/reputation/pb"
reputationRpc "github.com/textileio/powergate/reputation/rpc"
"github.com/textileio/powergate/util"
walletPb "github.com/textileio/powergate/wallet/pb"
walletRpc "github.com/textileio/powergate/wallet/rpc"
"google.golang.org/grpc"
)

Expand Down Expand Up @@ -67,15 +67,15 @@ func NewClient(ma multiaddr.Multiaddr, opts ...grpc.DialOption) (*Client, error)
return nil, err
}
client := &Client{
Asks: &Asks{client: asksPb.NewAPIClient(conn)},
Miners: &Miners{client: minerPb.NewAPIClient(conn)},
Slashing: &Slashing{client: slashingPb.NewAPIClient(conn)},
Deals: &Deals{client: dealsPb.NewAPIClient(conn)},
Wallet: &Wallet{client: walletPb.NewAPIClient(conn)},
Reputation: &Reputation{client: reputationPb.NewAPIClient(conn)},
FFS: &FFS{client: ffsRpc.NewFFSClient(conn)},
Health: &Health{client: healthRpc.NewHealthClient(conn)},
Net: &Net{client: netRpc.NewNetClient(conn)},
Asks: &Asks{client: askRpc.NewRPCClient(conn)},
Miners: &Miners{client: minerRpc.NewRPCClient(conn)},
Slashing: &Slashing{client: slashingRpc.NewRPCClient(conn)},
Deals: &Deals{client: dealsRpc.NewRPCClient(conn)},
Wallet: &Wallet{client: walletRpc.NewRPCClient(conn)},
Reputation: &Reputation{client: reputationRpc.NewRPCClient(conn)},
FFS: &FFS{client: ffsRpc.NewRPCClient(conn)},
Health: &Health{client: healthRpc.NewRPCClient(conn)},
Net: &Net{client: netRpc.NewRPCClient(conn)},
conn: conn,
}
return client, nil
Expand Down
20 changes: 10 additions & 10 deletions api/client/deals.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"github.com/filecoin-project/go-address"
cid "github.com/ipfs/go-cid"
"github.com/textileio/powergate/deals"
pb "github.com/textileio/powergate/deals/pb"
"github.com/textileio/powergate/deals/rpc"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

// Deals provides an API for managing deals and storing data
type Deals struct {
client pb.APIClient
client rpc.RPCClient
}

// WatchEvent is used to send data or error values for Watch
Expand All @@ -32,21 +32,21 @@ func (d *Deals) Store(ctx context.Context, addr string, data io.Reader, dealConf
return nil, nil, err
}

reqDealConfigs := make([]*pb.DealConfig, len(dealConfigs))
reqDealConfigs := make([]*rpc.DealConfig, len(dealConfigs))
for i, dealConfig := range dealConfigs {
reqDealConfigs[i] = &pb.DealConfig{
reqDealConfigs[i] = &rpc.DealConfig{
Miner: dealConfig.Miner,
EpochPrice: dealConfig.EpochPrice,
}
}
storeParams := &pb.StoreParams{
storeParams := &rpc.StoreParams{
Address: addr,
DealConfigs: reqDealConfigs,
Duration: duration,
}
innerReq := &pb.StoreRequest_StoreParams{StoreParams: storeParams}
innerReq := &rpc.StoreRequest_StoreParams{StoreParams: storeParams}

if err = stream.Send(&pb.StoreRequest{Payload: innerReq}); err != nil {
if err = stream.Send(&rpc.StoreRequest{Payload: innerReq}); err != nil {
return nil, nil, err
}

Expand All @@ -56,7 +56,7 @@ func (d *Deals) Store(ctx context.Context, addr string, data io.Reader, dealConf
if err != nil && err != io.EOF {
return nil, nil, err
}
sendErr := stream.Send(&pb.StoreRequest{Payload: &pb.StoreRequest_Chunk{Chunk: buffer[:bytesRead]}})
sendErr := stream.Send(&rpc.StoreRequest{Payload: &rpc.StoreRequest_Chunk{Chunk: buffer[:bytesRead]}})
if sendErr != nil {
return nil, nil, sendErr
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func (d *Deals) Watch(ctx context.Context, proposals []cid.Cid) (<-chan WatchEve
for i, proposal := range proposals {
proposalStrings[i] = proposal.String()
}
stream, err := d.client.Watch(ctx, &pb.WatchRequest{Proposals: proposalStrings})
stream, err := d.client.Watch(ctx, &rpc.WatchRequest{Proposals: proposalStrings})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func (d *Deals) Watch(ctx context.Context, proposals []cid.Cid) (<-chan WatchEve

// Retrieve is used to fetch data from filecoin
func (d *Deals) Retrieve(ctx context.Context, waddr string, cid cid.Cid) (io.Reader, error) {
req := &pb.RetrieveRequest{
req := &rpc.RetrieveRequest{
Address: waddr,
Cid: cid.String(),
}
Expand Down
4 changes: 2 additions & 2 deletions api/client/deals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/ipfs/go-cid"
"github.com/textileio/powergate/deals"
pb "github.com/textileio/powergate/deals/pb"
"github.com/textileio/powergate/deals/rpc"
)

func TestStore(t *testing.T) {
Expand Down Expand Up @@ -48,7 +48,7 @@ func TestRetrieve(t *testing.T) {
func setupDeals(t *testing.T) (*Deals, func()) {
serverDone := setupServer(t)
conn, done := setupConnection(t)
return &Deals{client: pb.NewAPIClient(conn)}, func() {
return &Deals{client: rpc.NewRPCClient(conn)}, func() {
done()
serverDone()
}
Expand Down
2 changes: 1 addition & 1 deletion api/client/ffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

// FFS provides the API to create and interact with an FFS instance
type FFS struct {
client rpc.FFSClient
client rpc.RPCClient
}

// JobEvent represents an event for Watching a job
Expand Down
2 changes: 1 addition & 1 deletion api/client/ffs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestCreate(t *testing.T) {
func setupFfs(t *testing.T) (*FFS, func()) {
serverDone := setupServer(t)
conn, done := setupConnection(t)
return &FFS{client: rpc.NewFFSClient(conn)}, func() {
return &FFS{client: rpc.NewRPCClient(conn)}, func() {
done()
serverDone()
}
Expand Down
2 changes: 1 addition & 1 deletion api/client/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// Health provides an API for checking node Health
type Health struct {
client rpc.HealthClient
client rpc.RPCClient
}

// Check returns the node health status and any related messages
Expand Down
2 changes: 1 addition & 1 deletion api/client/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestCheck(t *testing.T) {
func setupHealth(t *testing.T) (*Health, func()) {
serverDone := setupServer(t)
conn, done := setupConnection(t)
return &Health{client: rpc.NewHealthClient(conn)}, func() {
return &Health{client: rpc.NewRPCClient(conn)}, func() {
done()
serverDone()
}
Expand Down
6 changes: 3 additions & 3 deletions api/client/miners.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import (
"time"

"github.com/textileio/powergate/index/miner"
pb "github.com/textileio/powergate/index/miner/pb"
"github.com/textileio/powergate/index/miner/rpc"
)

// Miners provides an API for viewing miner data
type Miners struct {
client pb.APIClient
client rpc.RPCClient
}

// Get returns the current index of available asks
func (a *Miners) Get(ctx context.Context) (*miner.IndexSnapshot, error) {
reply, err := a.client.Get(ctx, &pb.GetRequest{})
reply, err := a.client.Get(ctx, &rpc.GetRequest{})
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions api/client/miners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package client
import (
"testing"

pb "github.com/textileio/powergate/index/miner/pb"
"github.com/textileio/powergate/index/miner/rpc"
)

func TestGetMiners(t *testing.T) {
Expand All @@ -20,7 +20,7 @@ func TestGetMiners(t *testing.T) {
func setupMiners(t *testing.T) (*Miners, func()) {
serverDone := setupServer(t)
conn, done := setupConnection(t)
return &Miners{client: pb.NewAPIClient(conn)}, func() {
return &Miners{client: rpc.NewRPCClient(conn)}, func() {
done()
serverDone()
}
Expand Down
2 changes: 1 addition & 1 deletion api/client/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// Net provides the Net API
type Net struct {
client rpc.NetClient
client rpc.RPCClient
}

// ListenAddr returns listener address info for the local node
Expand Down
2 changes: 1 addition & 1 deletion api/client/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestConnectedness(t *testing.T) {
func setupNet(t *testing.T) (*Net, func()) {
serverDone := setupServer(t)
conn, done := setupConnection(t)
return &Net{client: rpc.NewNetClient(conn)}, func() {
return &Net{client: rpc.NewRPCClient(conn)}, func() {
done()
serverDone()
}
Expand Down
8 changes: 4 additions & 4 deletions api/client/reputation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import (

ma "github.com/multiformats/go-multiaddr"
"github.com/textileio/powergate/reputation"
pb "github.com/textileio/powergate/reputation/pb"
"github.com/textileio/powergate/reputation/rpc"
)

// Reputation provides an API for viewing reputation data
type Reputation struct {
client pb.APIClient
client rpc.RPCClient
}

// AddSource adds a new external Source to be considered for reputation generation
func (r *Reputation) AddSource(ctx context.Context, id string, maddr ma.Multiaddr) error {
req := &pb.AddSourceRequest{
req := &rpc.AddSourceRequest{
Id: id,
Maddr: maddr.String(),
}
Expand All @@ -25,7 +25,7 @@ func (r *Reputation) AddSource(ctx context.Context, id string, maddr ma.Multiadd

// GetTopMiners gets the top n miners with best score
func (r *Reputation) GetTopMiners(ctx context.Context, limit int) ([]reputation.MinerScore, error) {
req := &pb.GetTopMinersRequest{Limit: int32(limit)}
req := &rpc.GetTopMinersRequest{Limit: int32(limit)}
reply, err := r.client.GetTopMiners(ctx, req)
if err != nil {
return []reputation.MinerScore{}, err
Expand Down
4 changes: 2 additions & 2 deletions api/client/reputation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

ma "github.com/multiformats/go-multiaddr"
pb "github.com/textileio/powergate/reputation/pb"
"github.com/textileio/powergate/reputation/rpc"
)

func TestAddSource(t *testing.T) {
Expand Down Expand Up @@ -35,7 +35,7 @@ func TestGetTopMiners(t *testing.T) {
func setupReputation(t *testing.T) (*Reputation, func()) {
serverDone := setupServer(t)
conn, done := setupConnection(t)
return &Reputation{client: pb.NewAPIClient(conn)}, func() {
return &Reputation{client: rpc.NewRPCClient(conn)}, func() {
done()
serverDone()
}
Expand Down
Loading

0 comments on commit 66beee9

Please sign in to comment.