Skip to content

Commit

Permalink
Client/CLI simplifications and improvements (#686)
Browse files Browse the repository at this point in the history
* use basic types and return grpc types

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

* update cli, output json most of the time, better json

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

* put back SendFil

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

* docs

Signed-off-by: Aaron Sutula <hi@asutula.com>
  • Loading branch information
asutula authored Oct 21, 2020
1 parent 393197e commit d363b94
Show file tree
Hide file tree
Showing 59 changed files with 417 additions and 1,349 deletions.
47 changes: 4 additions & 43 deletions api/client/asks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package client

import (
"context"
"time"

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

Expand All @@ -14,48 +12,11 @@ type Asks struct {
}

// Get returns the current index of available asks.
func (a *Asks) Get(ctx context.Context) (*ask.Index, error) {
reply, err := a.client.Get(ctx, &rpc.GetRequest{})
if err != nil {
return nil, err
}
lastUpdated := time.Unix(reply.GetIndex().GetLastUpdated(), 0)
storage := make(map[string]ask.StorageAsk, len(reply.GetIndex().GetStorage()))
for key, val := range reply.GetIndex().GetStorage() {
storage[key] = askFromPbAsk(val)
}
return &ask.Index{
LastUpdated: lastUpdated,
StorageMedianPrice: reply.GetIndex().StorageMedianPrice,
Storage: storage,
}, nil
func (a *Asks) Get(ctx context.Context) (*rpc.GetResponse, error) {
return a.client.Get(ctx, &rpc.GetRequest{})
}

// Query executes a query to retrieve active Asks.
func (a *Asks) Query(ctx context.Context, query ask.Query) ([]ask.StorageAsk, error) {
q := &rpc.Query{
MaxPrice: query.MaxPrice,
PieceSize: query.PieceSize,
Limit: int32(query.Limit),
Offset: int32(query.Offset),
}
reply, err := a.client.Query(ctx, &rpc.QueryRequest{Query: q})
if err != nil {
return nil, err
}
asks := make([]ask.StorageAsk, len(reply.GetAsks()))
for i, a := range reply.GetAsks() {
asks[i] = askFromPbAsk(a)
}
return asks, nil
}

func askFromPbAsk(a *rpc.StorageAsk) ask.StorageAsk {
return ask.StorageAsk{
Price: a.GetPrice(),
MinPieceSize: a.GetMinPieceSize(),
Miner: a.GetMiner(),
Timestamp: a.GetTimestamp(),
Expiry: a.GetExpiry(),
}
func (a *Asks) Query(ctx context.Context, query *rpc.Query) (*rpc.QueryResponse, error) {
return a.client.Query(ctx, &rpc.QueryRequest{Query: query})
}
3 changes: 1 addition & 2 deletions api/client/asks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"

"github.com/stretchr/testify/require"
"github.com/textileio/powergate/index/ask"
"github.com/textileio/powergate/index/ask/rpc"
)

Expand All @@ -20,7 +19,7 @@ func TestQuery(t *testing.T) {
a, done := setupAsks(t)
defer done()

_, err := a.Query(ctx, ask.Query{MaxPrice: 5})
_, err := a.Query(ctx, &rpc.Query{MaxPrice: 5})
require.NoError(t, err)
}

Expand Down
20 changes: 2 additions & 18 deletions api/client/faults.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"context"

"github.com/textileio/powergate/index/faults"
"github.com/textileio/powergate/index/faults/rpc"
)

Expand All @@ -13,21 +12,6 @@ type Faults struct {
}

// Get returns the current index of miner faults data.
func (s *Faults) Get(ctx context.Context) (*faults.IndexSnapshot, error) {
reply, err := s.client.Get(ctx, &rpc.GetRequest{})
if err != nil {
return nil, err
}

miners := make(map[string]faults.Faults, len(reply.GetIndex().GetMiners()))
for key, val := range reply.GetIndex().GetMiners() {
miners[key] = faults.Faults{Epochs: val.GetEpochs()}
}

index := &faults.IndexSnapshot{
TipSetKey: reply.GetIndex().GetTipsetkey(),
Miners: miners,
}

return index, nil
func (s *Faults) Get(ctx context.Context) (*rpc.GetResponse, error) {
return s.client.Get(ctx, &rpc.GetRequest{})
}
Loading

0 comments on commit d363b94

Please sign in to comment.