Skip to content
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

Client/CLI simplifications and improvements #686

Merged
merged 6 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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