diff --git a/api/client/asks.go b/api/client/asks.go index 710a8a5ac..2144ae1aa 100644 --- a/api/client/asks.go +++ b/api/client/asks.go @@ -2,9 +2,7 @@ package client import ( "context" - "time" - "github.com/textileio/powergate/index/ask" "github.com/textileio/powergate/index/ask/rpc" ) @@ -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}) } diff --git a/api/client/asks_test.go b/api/client/asks_test.go index a56473346..6e81b58af 100644 --- a/api/client/asks_test.go +++ b/api/client/asks_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/textileio/powergate/index/ask" "github.com/textileio/powergate/index/ask/rpc" ) @@ -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) } diff --git a/api/client/faults.go b/api/client/faults.go index f5d40466c..cca205be2 100644 --- a/api/client/faults.go +++ b/api/client/faults.go @@ -3,7 +3,6 @@ package client import ( "context" - "github.com/textileio/powergate/index/faults" "github.com/textileio/powergate/index/faults/rpc" ) @@ -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{}) } diff --git a/api/client/ffs.go b/api/client/ffs.go index 51ec09904..5ab51ea87 100644 --- a/api/client/ffs.go +++ b/api/client/ffs.go @@ -7,16 +7,12 @@ import ( "net/http" "os" "strings" - "time" - cid "github.com/ipfs/go-cid" files "github.com/ipfs/go-ipfs-files" httpapi "github.com/ipfs/go-ipfs-http-client" "github.com/ipfs/interface-go-ipfs-core/options" ipfspath "github.com/ipfs/interface-go-ipfs-core/path" "github.com/multiformats/go-multiaddr" - "github.com/textileio/powergate/deals" - "github.com/textileio/powergate/ffs" "github.com/textileio/powergate/ffs/rpc" "github.com/textileio/powergate/util" "google.golang.org/grpc/codes" @@ -28,9 +24,9 @@ type FFS struct { client rpc.RPCServiceClient } -// JobEvent represents an event for Watching a job. -type JobEvent struct { - Job ffs.StorageJob +// WatchJobsEvent represents an event for Watching a job. +type WatchJobsEvent struct { + Res *rpc.WatchJobsResponse Err error } @@ -55,14 +51,10 @@ func WithAddressType(addressType string) NewAddressOption { type PushStorageConfigOption func(r *rpc.PushStorageConfigRequest) // WithStorageConfig overrides the Api default Cid configuration. -func WithStorageConfig(c ffs.StorageConfig) PushStorageConfigOption { +func WithStorageConfig(c *rpc.StorageConfig) PushStorageConfigOption { return func(r *rpc.PushStorageConfigRequest) { r.HasConfig = true - r.Config = &rpc.StorageConfig{ - Repairable: c.Repairable, - Hot: toRPCHotConfig(c.Hot), - Cold: toRPCColdConfig(c.Cold), - } + r.Config = c } } @@ -80,9 +72,9 @@ type WatchLogsOption func(r *rpc.WatchLogsRequest) // WithJidFilter filters only log messages of a Cid related to // the Job with id jid. -func WithJidFilter(jid ffs.JobID) WatchLogsOption { +func WithJidFilter(jid string) WatchLogsOption { return func(r *rpc.WatchLogsRequest) { - r.Jid = jid.String() + r.Jid = jid } } @@ -94,10 +86,10 @@ func WithHistory(enabled bool) WatchLogsOption { } } -// LogEvent represents an event for watching cid logs. -type LogEvent struct { - LogEntry ffs.LogEntry - Err error +// WatchLogsEvent represents an event for watching cid logs. +type WatchLogsEvent struct { + Res *rpc.WatchLogsResponse + Err error } // ListDealRecordsOption updates a ListDealRecordsConfig. @@ -144,12 +136,8 @@ func WithAscending(ascending bool) ListDealRecordsOption { } // ID returns the FFS instance ID. -func (f *FFS) ID(ctx context.Context) (ffs.APIID, error) { - resp, err := f.client.ID(ctx, &rpc.IDRequest{}) - if err != nil { - return ffs.EmptyInstanceID, err - } - return ffs.APIID(resp.Id), nil +func (f *FFS) ID(ctx context.Context) (*rpc.IDResponse, error) { + return f.client.ID(ctx, &rpc.IDRequest{}) } // Addrs returns a list of addresses managed by the FFS instance. @@ -158,52 +146,37 @@ func (f *FFS) Addrs(ctx context.Context) (*rpc.AddrsResponse, error) { } // DefaultStorageConfig returns the default storage config. -func (f *FFS) DefaultStorageConfig(ctx context.Context) (ffs.StorageConfig, error) { - resp, err := f.client.DefaultStorageConfig(ctx, &rpc.DefaultStorageConfigRequest{}) - if err != nil { - return ffs.StorageConfig{}, err - } - return fromRPCStorageConfig(resp.DefaultStorageConfig), nil +func (f *FFS) DefaultStorageConfig(ctx context.Context) (*rpc.DefaultStorageConfigResponse, error) { + return f.client.DefaultStorageConfig(ctx, &rpc.DefaultStorageConfigRequest{}) } // SignMessage signs a message with a FFS managed wallet address. -func (f *FFS) SignMessage(ctx context.Context, addr string, message []byte) ([]byte, error) { +func (f *FFS) SignMessage(ctx context.Context, addr string, message []byte) (*rpc.SignMessageResponse, error) { r := &rpc.SignMessageRequest{Addr: addr, Msg: message} - resp, err := f.client.SignMessage(ctx, r) - return resp.Signature, err + return f.client.SignMessage(ctx, r) } // VerifyMessage verifies a message signature from a wallet address. -func (f *FFS) VerifyMessage(ctx context.Context, addr string, message, signature []byte) (bool, error) { +func (f *FFS) VerifyMessage(ctx context.Context, addr string, message, signature []byte) (*rpc.VerifyMessageResponse, error) { r := &rpc.VerifyMessageRequest{Addr: addr, Msg: message, Signature: signature} - resp, err := f.client.VerifyMessage(ctx, r) - if err != nil { - return false, err - } - return resp.Ok, nil + return f.client.VerifyMessage(ctx, r) } // NewAddr created a new wallet address managed by the FFS instance. -func (f *FFS) NewAddr(ctx context.Context, name string, options ...NewAddressOption) (string, error) { +func (f *FFS) NewAddr(ctx context.Context, name string, options ...NewAddressOption) (*rpc.NewAddrResponse, error) { r := &rpc.NewAddrRequest{Name: name} for _, opt := range options { opt(r) } - resp, err := f.client.NewAddr(ctx, r) - return resp.Addr, err + return f.client.NewAddr(ctx, r) } // SetDefaultStorageConfig sets the default storage config. -func (f *FFS) SetDefaultStorageConfig(ctx context.Context, config ffs.StorageConfig) error { +func (f *FFS) SetDefaultStorageConfig(ctx context.Context, config *rpc.StorageConfig) (*rpc.SetDefaultStorageConfigResponse, error) { req := &rpc.SetDefaultStorageConfigRequest{ - Config: &rpc.StorageConfig{ - Hot: toRPCHotConfig(config.Hot), - Cold: toRPCColdConfig(config.Cold), - Repairable: config.Repairable, - }, + Config: config, } - _, err := f.client.SetDefaultStorageConfig(ctx, req) - return err + return f.client.SetDefaultStorageConfig(ctx, req) } // CidData returns information about cids managed by the FFS instance. @@ -213,14 +186,13 @@ func (f *FFS) CidData(ctx context.Context, cids ...string) (*rpc.CidDataResponse // CancelJob signals that the executing Job with JobID jid should be // canceled. -func (f *FFS) CancelJob(ctx context.Context, jid ffs.JobID) error { - _, err := f.client.CancelJob(ctx, &rpc.CancelJobRequest{Jid: jid.String()}) - return err +func (f *FFS) CancelJob(ctx context.Context, jid string) (*rpc.CancelJobResponse, error) { + return f.client.CancelJob(ctx, &rpc.CancelJobRequest{Jid: jid}) } // StorageJob returns the current state of the specified job. -func (f *FFS) StorageJob(ctx context.Context, jid ffs.JobID) (*rpc.StorageJobResponse, error) { - return f.client.StorageJob(ctx, &rpc.StorageJobRequest{Jid: jid.String()}) +func (f *FFS) StorageJob(ctx context.Context, jid string) (*rpc.StorageJobResponse, error) { + return f.client.StorageJob(ctx, &rpc.StorageJobRequest{Jid: jid}) } // QueuedStorageJobs returns a list of queued storage jobs. @@ -267,37 +239,24 @@ func (f *FFS) StorageJobsSummary(ctx context.Context, cids ...string) (*rpc.Stor // by the client after the call, so it shouldn't be closed by the client. To stop receiving // events, the provided ctx should be canceled. If an error occurs, it will be returned // in the Err field of JobEvent and the channel will be closed. -func (f *FFS) WatchJobs(ctx context.Context, ch chan<- JobEvent, jids ...ffs.JobID) error { - jidStrings := make([]string, len(jids)) - for i, jid := range jids { - jidStrings[i] = jid.String() - } - - stream, err := f.client.WatchJobs(ctx, &rpc.WatchJobsRequest{Jids: jidStrings}) +func (f *FFS) WatchJobs(ctx context.Context, ch chan<- WatchJobsEvent, jids ...string) error { + stream, err := f.client.WatchJobs(ctx, &rpc.WatchJobsRequest{Jids: jids}) if err != nil { return err } go func() { for { - reply, err := stream.Recv() + res, err := stream.Recv() if err == io.EOF || status.Code(err) == codes.Canceled { close(ch) break } if err != nil { - ch <- JobEvent{Err: err} - close(ch) - break - } - - job, err := fromRPCJob(reply.Job) - if err != nil { - ch <- JobEvent{Err: err} + ch <- WatchJobsEvent{Err: err} close(ch) break } - - ch <- JobEvent{Job: job} + ch <- WatchJobsEvent{Res: res} } }() return nil @@ -305,43 +264,36 @@ func (f *FFS) WatchJobs(ctx context.Context, ch chan<- JobEvent, jids ...ffs.Job // Replace pushes a StorageConfig for c2 equal to that of c1, and removes c1. This operation // is more efficient than manually removing and adding in two separate operations. -func (f *FFS) Replace(ctx context.Context, c1 cid.Cid, c2 cid.Cid) (ffs.JobID, error) { - resp, err := f.client.Replace(ctx, &rpc.ReplaceRequest{Cid1: util.CidToString(c1), Cid2: util.CidToString(c2)}) - if err != nil { - return ffs.EmptyJobID, err - } - return ffs.JobID(resp.JobId), nil +func (f *FFS) Replace(ctx context.Context, cid1, cid2 string) (*rpc.ReplaceResponse, error) { + return f.client.Replace(ctx, &rpc.ReplaceRequest{Cid1: cid1, Cid2: cid2}) } // PushStorageConfig push a new configuration for the Cid in the Hot and Cold layers. -func (f *FFS) PushStorageConfig(ctx context.Context, c cid.Cid, opts ...PushStorageConfigOption) (ffs.JobID, error) { - req := &rpc.PushStorageConfigRequest{Cid: util.CidToString(c)} +func (f *FFS) PushStorageConfig(ctx context.Context, cid string, opts ...PushStorageConfigOption) (*rpc.PushStorageConfigResponse, error) { + req := &rpc.PushStorageConfigRequest{Cid: cid} for _, opt := range opts { opt(req) } - - resp, err := f.client.PushStorageConfig(ctx, req) - if err != nil { - return ffs.EmptyJobID, err - } - - return ffs.JobID(resp.JobId), nil + return f.client.PushStorageConfig(ctx, req) } // Remove removes a Cid from being tracked as an active storage. The Cid should have // both Hot and Cold storage disabled, if that isn't the case it will return ErrActiveInStorage. -func (f *FFS) Remove(ctx context.Context, c cid.Cid) error { - _, err := f.client.Remove(ctx, &rpc.RemoveRequest{Cid: util.CidToString(c)}) - return err +func (f *FFS) Remove(ctx context.Context, cid string) (*rpc.RemoveResponse, error) { + return f.client.Remove(ctx, &rpc.RemoveRequest{Cid: cid}) } // GetFolder retrieves to outputDir a Cid which corresponds to a folder. -func (f *FFS) GetFolder(ctx context.Context, ipfsRevProxyAddr string, c cid.Cid, outputDir string) error { +func (f *FFS) GetFolder(ctx context.Context, ipfsRevProxyAddr, cid, outputDir string) error { token := ctx.Value(AuthKey).(string) ipfs, err := newDecoratedIPFSAPI(ipfsRevProxyAddr, token) if err != nil { return fmt.Errorf("creating decorated IPFS client: %s", err) } + c, err := util.CidFromString(cid) + if err != nil { + return fmt.Errorf("decoding cid: %s", err) + } n, err := ipfs.Unixfs().Get(ctx, ipfspath.IpfsPath(c)) if err != nil { return fmt.Errorf("getting folder DAG from IPFS: %s", err) @@ -354,9 +306,9 @@ func (f *FFS) GetFolder(ctx context.Context, ipfsRevProxyAddr string, c cid.Cid, } // Get returns an io.Reader for reading a stored Cid from the Hot Storage. -func (f *FFS) Get(ctx context.Context, c cid.Cid) (io.Reader, error) { +func (f *FFS) Get(ctx context.Context, cid string) (io.Reader, error) { stream, err := f.client.Get(ctx, &rpc.GetRequest{ - Cid: util.CidToString(c), + Cid: cid, }) if err != nil { return nil, err @@ -364,7 +316,7 @@ func (f *FFS) Get(ctx context.Context, c cid.Cid) (io.Reader, error) { reader, writer := io.Pipe() go func() { for { - reply, err := stream.Recv() + res, err := stream.Recv() if err == io.EOF { _ = writer.Close() break @@ -372,7 +324,7 @@ func (f *FFS) Get(ctx context.Context, c cid.Cid) (io.Reader, error) { _ = writer.CloseWithError(err) break } - _, err = writer.Write(reply.GetChunk()) + _, err = writer.Write(res.GetChunk()) if err != nil { _ = writer.CloseWithError(err) break @@ -386,61 +338,45 @@ func (f *FFS) Get(ctx context.Context, c cid.Cid) (io.Reader, error) { // WatchLogs pushes human-friendly messages about Cid executions. The method is blocking // and will continue to send messages until the context is canceled. The provided channel // is owned by the method and must not be closed. -func (f *FFS) WatchLogs(ctx context.Context, ch chan<- LogEvent, c cid.Cid, opts ...WatchLogsOption) error { - r := &rpc.WatchLogsRequest{Cid: util.CidToString(c)} +func (f *FFS) WatchLogs(ctx context.Context, ch chan<- WatchLogsEvent, cid string, opts ...WatchLogsOption) error { + r := &rpc.WatchLogsRequest{Cid: cid} for _, opt := range opts { opt(r) } - stream, err := f.client.WatchLogs(ctx, r) if err != nil { return err } go func() { for { - reply, err := stream.Recv() + res, err := stream.Recv() if err == io.EOF || status.Code(err) == codes.Canceled { close(ch) break } if err != nil { - ch <- LogEvent{Err: err} - close(ch) - break - } - - cid, err := util.CidFromString(reply.LogEntry.Cid) - if err != nil { - ch <- LogEvent{Err: err} + ch <- WatchLogsEvent{Err: err} close(ch) break } - - entry := ffs.LogEntry{ - Cid: cid, - Timestamp: time.Unix(reply.LogEntry.Time, 0), - Jid: ffs.JobID(reply.LogEntry.Jid), - Msg: reply.LogEntry.Msg, - } - ch <- LogEvent{LogEntry: entry} + ch <- WatchLogsEvent{Res: res} } }() return nil } // SendFil sends fil from a managed address to any another address, returns immediately but funds are sent asynchronously. -func (f *FFS) SendFil(ctx context.Context, from string, to string, amount int64) error { +func (f *FFS) SendFil(ctx context.Context, from string, to string, amount int64) (*rpc.SendFilResponse, error) { req := &rpc.SendFilRequest{ From: from, To: to, Amount: amount, } - _, err := f.client.SendFil(ctx, req) - return err + return f.client.SendFil(ctx, req) } // Stage allows to temporarily stage data in the Hot Storage in preparation for pushing a cid storage config. -func (f *FFS) Stage(ctx context.Context, data io.Reader) (*cid.Cid, error) { +func (f *FFS) Stage(ctx context.Context, data io.Reader) (*rpc.StageResponse, error) { stream, err := f.client.Stage(ctx) if err != nil { return nil, err @@ -464,34 +400,25 @@ func (f *FFS) Stage(ctx context.Context, data io.Reader) (*cid.Cid, error) { break } } - reply, err := stream.CloseAndRecv() - if err != nil { - return nil, err - } - - cid, err := util.CidFromString(reply.GetCid()) - if err != nil { - return nil, err - } - return &cid, nil + return stream.CloseAndRecv() } // StageFolder allows to temporarily stage a folder in the Hot Storage in preparation for pushing a cid storage config. -func (f *FFS) StageFolder(ctx context.Context, ipfsRevProxyAddr string, folderPath string) (cid.Cid, error) { +func (f *FFS) StageFolder(ctx context.Context, ipfsRevProxyAddr string, folderPath string) (string, error) { ffsToken := ctx.Value(AuthKey).(string) ipfs, err := newDecoratedIPFSAPI(ipfsRevProxyAddr, ffsToken) if err != nil { - return cid.Undef, fmt.Errorf("creating IPFS HTTP client: %s", err) + return "", fmt.Errorf("creating IPFS HTTP client: %s", err) } stat, err := os.Lstat(folderPath) if err != nil { - return cid.Undef, err + return "", err } ff, err := files.NewSerialFile(folderPath, false, stat) if err != nil { - return cid.Undef, err + return "", err } defer func() { _ = ff.Close() }() opts := []options.UnixfsAddOption{ @@ -500,333 +427,49 @@ func (f *FFS) StageFolder(ctx context.Context, ipfsRevProxyAddr string, folderPa } pth, err := ipfs.Unixfs().Add(context.Background(), files.ToDir(ff), opts...) if err != nil { - return cid.Undef, err + return "", err } - return pth.Cid(), nil + return pth.Cid().String(), nil } // ListPayChannels returns a list of payment channels. -func (f *FFS) ListPayChannels(ctx context.Context) ([]ffs.PaychInfo, error) { - resp, err := f.client.ListPayChannels(ctx, &rpc.ListPayChannelsRequest{}) - if err != nil { - return []ffs.PaychInfo{}, err - } - infos := make([]ffs.PaychInfo, len(resp.PayChannels)) - for i, info := range resp.PayChannels { - infos[i] = fromRPCPaychInfo(info) - } - return infos, nil +func (f *FFS) ListPayChannels(ctx context.Context) (*rpc.ListPayChannelsResponse, error) { + return f.client.ListPayChannels(ctx, &rpc.ListPayChannelsRequest{}) } // CreatePayChannel creates a new payment channel. -func (f *FFS) CreatePayChannel(ctx context.Context, from string, to string, amount uint64) (ffs.PaychInfo, cid.Cid, error) { +func (f *FFS) CreatePayChannel(ctx context.Context, from, to string, amount uint64) (*rpc.CreatePayChannelResponse, error) { req := &rpc.CreatePayChannelRequest{ From: from, To: to, Amount: amount, } - resp, err := f.client.CreatePayChannel(ctx, req) - if err != nil { - return ffs.PaychInfo{}, cid.Undef, err - } - messageCid, err := util.CidFromString(resp.ChannelMessageCid) - if err != nil { - return ffs.PaychInfo{}, cid.Undef, err - } - return fromRPCPaychInfo(resp.PayChannel), messageCid, nil + return f.client.CreatePayChannel(ctx, req) } // RedeemPayChannel redeems a payment channel. -func (f *FFS) RedeemPayChannel(ctx context.Context, addr string) error { +func (f *FFS) RedeemPayChannel(ctx context.Context, addr string) (*rpc.RedeemPayChannelResponse, error) { req := &rpc.RedeemPayChannelRequest{PayChannelAddr: addr} - _, err := f.client.RedeemPayChannel(ctx, req) - return err + return f.client.RedeemPayChannel(ctx, req) } // ListStorageDealRecords returns a list of storage deals for the FFS instance according to the provided options. -func (f *FFS) ListStorageDealRecords(ctx context.Context, opts ...ListDealRecordsOption) ([]deals.StorageDealRecord, error) { +func (f *FFS) ListStorageDealRecords(ctx context.Context, opts ...ListDealRecordsOption) (*rpc.ListStorageDealRecordsResponse, error) { conf := &rpc.ListDealRecordsConfig{} for _, opt := range opts { opt(conf) } - res, err := f.client.ListStorageDealRecords(ctx, &rpc.ListStorageDealRecordsRequest{Config: conf}) - if err != nil { - return nil, fmt.Errorf("calling ListStorageDealRecords: %v", err) - } - ret, err := fromRPCStorageDealRecords(res.Records) - if err != nil { - return nil, fmt.Errorf("processing response deal records: %v", err) - } - return ret, nil + return f.client.ListStorageDealRecords(ctx, &rpc.ListStorageDealRecordsRequest{Config: conf}) } // ListRetrievalDealRecords returns a list of retrieval deals for the FFS instance according to the provided options. -func (f *FFS) ListRetrievalDealRecords(ctx context.Context, opts ...ListDealRecordsOption) ([]deals.RetrievalDealRecord, error) { +func (f *FFS) ListRetrievalDealRecords(ctx context.Context, opts ...ListDealRecordsOption) (*rpc.ListRetrievalDealRecordsResponse, error) { conf := &rpc.ListDealRecordsConfig{} for _, opt := range opts { opt(conf) } - res, err := f.client.ListRetrievalDealRecords(ctx, &rpc.ListRetrievalDealRecordsRequest{Config: conf}) - if err != nil { - return nil, fmt.Errorf("calling ListRetrievalDealRecords: %v", err) - } - ret, err := fromRPCRetrievalDealRecords(res.Records) - if err != nil { - return nil, fmt.Errorf("processing response deal records: %v", err) - } - return ret, nil -} - -func toRPCHotConfig(config ffs.HotConfig) *rpc.HotConfig { - return &rpc.HotConfig{ - Enabled: config.Enabled, - AllowUnfreeze: config.AllowUnfreeze, - UnfreezeMaxPrice: config.UnfreezeMaxPrice, - Ipfs: &rpc.IpfsConfig{ - AddTimeout: int64(config.Ipfs.AddTimeout), - }, - } -} - -func toRPCColdConfig(config ffs.ColdConfig) *rpc.ColdConfig { - return &rpc.ColdConfig{ - Enabled: config.Enabled, - Filecoin: &rpc.FilConfig{ - RepFactor: int64(config.Filecoin.RepFactor), - DealMinDuration: config.Filecoin.DealMinDuration, - ExcludedMiners: config.Filecoin.ExcludedMiners, - TrustedMiners: config.Filecoin.TrustedMiners, - CountryCodes: config.Filecoin.CountryCodes, - Renew: &rpc.FilRenew{ - Enabled: config.Filecoin.Renew.Enabled, - Threshold: int64(config.Filecoin.Renew.Threshold), - }, - Addr: config.Filecoin.Addr, - DealStartOffset: config.Filecoin.DealStartOffset, - FastRetrieval: config.Filecoin.FastRetrieval, - MaxPrice: config.Filecoin.MaxPrice, - }, - } -} - -func fromRPCStorageConfig(config *rpc.StorageConfig) ffs.StorageConfig { - if config == nil { - return ffs.StorageConfig{} - } - ret := ffs.StorageConfig{Repairable: config.Repairable} - if config.Hot != nil { - ret.Hot = ffs.HotConfig{ - Enabled: config.Hot.Enabled, - AllowUnfreeze: config.Hot.AllowUnfreeze, - UnfreezeMaxPrice: config.Hot.UnfreezeMaxPrice, - } - if config.Hot.Ipfs != nil { - ret.Hot.Ipfs = ffs.IpfsConfig{ - AddTimeout: int(config.Hot.Ipfs.AddTimeout), - } - } - } - if config.Cold != nil { - ret.Cold = ffs.ColdConfig{ - Enabled: config.Cold.Enabled, - } - if config.Cold.Filecoin != nil { - ret.Cold.Filecoin = ffs.FilConfig{ - RepFactor: int(config.Cold.Filecoin.RepFactor), - DealMinDuration: config.Cold.Filecoin.DealMinDuration, - ExcludedMiners: config.Cold.Filecoin.ExcludedMiners, - CountryCodes: config.Cold.Filecoin.CountryCodes, - TrustedMiners: config.Cold.Filecoin.TrustedMiners, - Addr: config.Cold.Filecoin.Addr, - MaxPrice: config.Cold.Filecoin.MaxPrice, - FastRetrieval: config.Cold.Filecoin.FastRetrieval, - DealStartOffset: config.Cold.Filecoin.DealStartOffset, - } - if config.Cold.Filecoin.Renew != nil { - ret.Cold.Filecoin.Renew = ffs.FilRenew{ - Enabled: config.Cold.Filecoin.Renew.Enabled, - Threshold: int(config.Cold.Filecoin.Renew.Threshold), - } - } - } - } - return ret -} - -func fromRPCDealErrors(des []*rpc.DealError) ([]ffs.DealError, error) { - res := make([]ffs.DealError, len(des)) - for i, de := range des { - var propCid cid.Cid - if de.ProposalCid != "" && de.ProposalCid != "b" { - var err error - propCid, err = util.CidFromString(de.ProposalCid) - if err != nil { - return nil, fmt.Errorf("proposal cid is invalid") - } - } - res[i] = ffs.DealError{ - ProposalCid: propCid, - Miner: de.Miner, - Message: de.Message, - } - } - return res, nil -} - -func fromRPCPaychInfo(info *rpc.PaychInfo) ffs.PaychInfo { - var direction ffs.PaychDir - switch info.Direction { - case rpc.Direction_DIRECTION_INBOUND: - direction = ffs.PaychDirInbound - case rpc.Direction_DIRECTION_OUTBOUND: - direction = ffs.PaychDirOutbound - default: - direction = ffs.PaychDirUnspecified - } - return ffs.PaychInfo{ - CtlAddr: info.CtlAddr, - Addr: info.Addr, - Direction: direction, - } -} - -func fromRPCStorageDealRecords(records []*rpc.StorageDealRecord) ([]deals.StorageDealRecord, error) { - var ret []deals.StorageDealRecord - for _, rpcRecord := range records { - if rpcRecord.DealInfo == nil { - continue - } - rootCid, err := util.CidFromString(rpcRecord.RootCid) - if err != nil { - return nil, err - } - record := deals.StorageDealRecord{ - RootCid: rootCid, - Addr: rpcRecord.Addr, - Time: rpcRecord.Time, - Pending: rpcRecord.Pending, - } - proposalCid, err := util.CidFromString(rpcRecord.DealInfo.ProposalCid) - if err != nil { - return nil, err - } - pieceCid, err := util.CidFromString(rpcRecord.DealInfo.PieceCid) - if err != nil { - return nil, err - } - record.DealInfo = deals.StorageDealInfo{ - ProposalCid: proposalCid, - StateID: rpcRecord.DealInfo.StateId, - StateName: rpcRecord.DealInfo.StateName, - Miner: rpcRecord.DealInfo.Miner, - PieceCID: pieceCid, - Size: rpcRecord.DealInfo.Size, - PricePerEpoch: rpcRecord.DealInfo.PricePerEpoch, - StartEpoch: rpcRecord.DealInfo.StartEpoch, - Duration: rpcRecord.DealInfo.Duration, - DealID: rpcRecord.DealInfo.DealId, - ActivationEpoch: rpcRecord.DealInfo.ActivationEpoch, - Message: rpcRecord.DealInfo.Msg, - } - ret = append(ret, record) - } - return ret, nil -} - -func fromRPCRetrievalDealRecords(records []*rpc.RetrievalDealRecord) ([]deals.RetrievalDealRecord, error) { - var ret []deals.RetrievalDealRecord - for _, rpcRecord := range records { - if rpcRecord.DealInfo == nil { - continue - } - record := deals.RetrievalDealRecord{ - Addr: rpcRecord.Addr, - Time: rpcRecord.Time, - } - rootCid, err := util.CidFromString(rpcRecord.DealInfo.RootCid) - if err != nil { - return nil, err - } - record.DealInfo = deals.RetrievalDealInfo{ - RootCid: rootCid, - Size: rpcRecord.DealInfo.Size, - MinPrice: rpcRecord.DealInfo.MinPrice, - PaymentInterval: rpcRecord.DealInfo.PaymentInterval, - PaymentIntervalIncrease: rpcRecord.DealInfo.PaymentIntervalIncrease, - Miner: rpcRecord.DealInfo.Miner, - MinerPeerID: rpcRecord.DealInfo.MinerPeerId, - } - ret = append(ret, record) - } - return ret, nil -} - -func fromRPCJob(job *rpc.Job) (ffs.StorageJob, error) { - c, err := util.CidFromString(job.Cid) - if err != nil { - return ffs.StorageJob{}, err - } - - var dealInfos []deals.StorageDealInfo - for _, item := range job.DealInfo { - proposalCid, err := util.CidFromString(item.ProposalCid) - if err != nil { - return ffs.StorageJob{}, err - } - pieceCid, err := util.CidFromString(item.PieceCid) - if err != nil { - return ffs.StorageJob{}, err - } - dealInfo := deals.StorageDealInfo{ - ActivationEpoch: item.ActivationEpoch, - DealID: item.DealId, - Duration: item.Duration, - Message: item.Message, - Miner: item.Miner, - PieceCID: pieceCid, - PricePerEpoch: item.PricePerEpoch, - ProposalCid: proposalCid, - Size: item.Size, - StartEpoch: item.StartEpoch, - StateID: item.StateId, - StateName: item.StateName, - } - dealInfos = append(dealInfos, dealInfo) - } - - dealErrors, err := fromRPCDealErrors(job.DealErrors) - if err != nil { - return ffs.StorageJob{}, err - } - - var status ffs.JobStatus - switch job.Status { - case rpc.JobStatus_JOB_STATUS_UNSPECIFIED: - status = ffs.Unspecified - case rpc.JobStatus_JOB_STATUS_QUEUED: - status = ffs.Queued - case rpc.JobStatus_JOB_STATUS_EXECUTING: - status = ffs.Executing - case rpc.JobStatus_JOB_STATUS_FAILED: - status = ffs.Failed - case rpc.JobStatus_JOB_STATUS_CANCELED: - status = ffs.Canceled - case rpc.JobStatus_JOB_STATUS_SUCCESS: - status = ffs.Success - default: - return ffs.StorageJob{}, fmt.Errorf("unknown job status: %v", job.Status.String()) - } - return ffs.StorageJob{ - ID: ffs.JobID(job.Id), - APIID: ffs.APIID(job.ApiId), - Cid: c, - Status: status, - ErrCause: job.ErrCause, - DealInfo: dealInfos, - DealErrors: dealErrors, - CreatedAt: job.CreatedAt, - }, nil + return f.client.ListRetrievalDealRecords(ctx, &rpc.ListRetrievalDealRecordsRequest{Config: conf}) } func newDecoratedIPFSAPI(proxyAddr, ffsToken string) (*httpapi.HttpApi, error) { diff --git a/api/client/health.go b/api/client/health.go index 6346f6964..adc6af634 100644 --- a/api/client/health.go +++ b/api/client/health.go @@ -3,7 +3,6 @@ package client import ( "context" - h "github.com/textileio/powergate/health" "github.com/textileio/powergate/health/rpc" ) @@ -13,21 +12,6 @@ type Health struct { } // Check returns the node health status and any related messages. -func (health *Health) Check(ctx context.Context) (h.Status, []string, error) { - resp, err := health.client.Check(ctx, &rpc.CheckRequest{}) - if err != nil { - return h.Error, nil, err - } - var status h.Status - switch resp.Status { - case rpc.Status_STATUS_OK: - status = h.Ok - case rpc.Status_STATUS_DEGRADED: - status = h.Degraded - case rpc.Status_STATUS_ERROR: - status = h.Error - default: - status = h.Unspecified - } - return status, resp.Messages, nil +func (health *Health) Check(ctx context.Context) (*rpc.CheckResponse, error) { + return health.client.Check(ctx, &rpc.CheckRequest{}) } diff --git a/api/client/health_test.go b/api/client/health_test.go index 0656ce04d..eb9078e4d 100644 --- a/api/client/health_test.go +++ b/api/client/health_test.go @@ -6,7 +6,6 @@ import ( logging "github.com/ipfs/go-log/v2" "github.com/stretchr/testify/require" - h "github.com/textileio/powergate/health" "github.com/textileio/powergate/health/rpc" ) @@ -30,10 +29,10 @@ func TestMain(m *testing.M) { func TestCheck(t *testing.T) { c, done := setupHealth(t) defer done() - status, messages, err := c.Check(ctx) + res, err := c.Check(ctx) require.NoError(t, err) - require.Empty(t, messages) - require.Equal(t, h.Ok, status) + require.Empty(t, res.Messages) + require.Equal(t, rpc.Status_STATUS_OK, res.Status) } func setupHealth(t *testing.T) (*Health, func()) { diff --git a/api/client/miners.go b/api/client/miners.go index 92fcde48b..5e1ac6d23 100644 --- a/api/client/miners.go +++ b/api/client/miners.go @@ -2,9 +2,7 @@ package client import ( "context" - "time" - "github.com/textileio/powergate/index/miner" "github.com/textileio/powergate/index/miner/rpc" ) @@ -14,51 +12,6 @@ type Miners struct { } // Get returns the current index of available asks. -func (a *Miners) Get(ctx context.Context) (*miner.IndexSnapshot, error) { - reply, err := a.client.Get(ctx, &rpc.GetRequest{}) - if err != nil { - return nil, err - } - - info := make(map[string]miner.Meta, len(reply.GetIndex().GetMeta().GetInfo())) - for key, val := range reply.GetIndex().GetMeta().GetInfo() { - info[key] = miner.Meta{ - LastUpdated: time.Unix(val.GetLastUpdated(), 0), - UserAgent: val.GetUserAgent(), - Location: miner.Location{ - Country: val.GetLocation().GetCountry(), - Longitude: val.GetLocation().GetLongitude(), - Latitude: val.GetLocation().GetLatitude(), - }, - Online: val.GetOnline(), - } - } - - metaIndex := miner.MetaIndex{ - Online: reply.GetIndex().GetMeta().GetOnline(), - Offline: reply.GetIndex().GetMeta().GetOffline(), - Info: info, - } - - miners := make(map[string]miner.OnChainData, len(reply.GetIndex().GetChain().GetMiners())) - for key, val := range reply.GetIndex().GetChain().GetMiners() { - miners[key] = miner.OnChainData{ - Power: val.GetPower(), - RelativePower: float64(val.GetRelativePower()), - SectorSize: val.GetSectorSize(), - ActiveDeals: val.GetActiveDeals(), - } - } - - chainIndex := miner.ChainIndex{ - LastUpdated: reply.GetIndex().GetChain().GetLastUpdated(), - Miners: miners, - } - - index := &miner.IndexSnapshot{ - Meta: metaIndex, - OnChain: chainIndex, - } - - return index, nil +func (a *Miners) Get(ctx context.Context) (*rpc.GetResponse, error) { + return a.client.Get(ctx, &rpc.GetRequest{}) } diff --git a/api/client/net.go b/api/client/net.go index 31fb2771d..10731fb73 100644 --- a/api/client/net.go +++ b/api/client/net.go @@ -3,10 +3,6 @@ package client import ( "context" - "github.com/libp2p/go-libp2p-core/peer" - ma "github.com/multiformats/go-multiaddr" - "github.com/textileio/powergate/iplocation" - n "github.com/textileio/powergate/net" "github.com/textileio/powergate/net/rpc" ) @@ -16,105 +12,21 @@ type Net struct { } // ListenAddr returns listener address info for the local node. -func (net *Net) ListenAddr(ctx context.Context) (peer.AddrInfo, error) { - resp, err := net.client.ListenAddr(ctx, &rpc.ListenAddrRequest{}) - if err != nil { - return peer.AddrInfo{}, err - } - addrs := make([]ma.Multiaddr, len(resp.AddrInfo.Addrs)) - for i, addr := range resp.AddrInfo.Addrs { - ma, err := ma.NewMultiaddr(addr) - if err != nil { - return peer.AddrInfo{}, err - } - addrs[i] = ma - } - id, err := peer.Decode(resp.AddrInfo.Id) - if err != nil { - return peer.AddrInfo{}, err - } - return peer.AddrInfo{ - ID: id, - Addrs: addrs, - }, nil +func (net *Net) ListenAddr(ctx context.Context) (*rpc.ListenAddrResponse, error) { + return net.client.ListenAddr(ctx, &rpc.ListenAddrRequest{}) } // Peers returns a list of peers. -func (net *Net) Peers(ctx context.Context) ([]n.PeerInfo, error) { - resp, err := net.client.Peers(ctx, &rpc.PeersRequest{}) - if err != nil { - return nil, err - } - peerInfos := make([]n.PeerInfo, len(resp.Peers)) - for i, p := range resp.Peers { - peerInfo, err := fromProtoPeerInfo(p) - if err != nil { - return nil, err - } - peerInfos[i] = peerInfo - } - return peerInfos, nil +func (net *Net) Peers(ctx context.Context) (*rpc.PeersResponse, error) { + return net.client.Peers(ctx, &rpc.PeersRequest{}) } // FindPeer finds a peer by peer id. -func (net *Net) FindPeer(ctx context.Context, peerID peer.ID) (n.PeerInfo, error) { - resp, err := net.client.FindPeer(ctx, &rpc.FindPeerRequest{PeerId: peerID.String()}) - if err != nil { - return n.PeerInfo{}, err - } - return fromProtoPeerInfo(resp.PeerInfo) +func (net *Net) FindPeer(ctx context.Context, peerID string) (*rpc.FindPeerResponse, error) { + return net.client.FindPeer(ctx, &rpc.FindPeerRequest{PeerId: peerID}) } // Connectedness returns the connection status to a peer. -func (net *Net) Connectedness(ctx context.Context, peerID peer.ID) (n.Connectedness, error) { - resp, err := net.client.Connectedness(ctx, &rpc.ConnectednessRequest{PeerId: peerID.String()}) - if err != nil { - return n.Error, err - } - var con n.Connectedness - switch resp.Connectedness { - case rpc.Connectedness_CONNECTEDNESS_CAN_CONNECT: - con = n.CanConnect - case rpc.Connectedness_CONNECTEDNESS_CANNOT_CONNECT: - con = n.CannotConnect - case rpc.Connectedness_CONNECTEDNESS_CONNECTED: - con = n.Connected - case rpc.Connectedness_CONNECTEDNESS_NOT_CONNECTED: - con = n.NotConnected - case rpc.Connectedness_CONNECTEDNESS_ERROR: - con = n.Error - default: - con = n.Unspecified - } - return con, nil -} - -func fromProtoPeerInfo(proto *rpc.PeerInfo) (n.PeerInfo, error) { - addrs := make([]ma.Multiaddr, len(proto.AddrInfo.Addrs)) - for i, addr := range proto.AddrInfo.Addrs { - ma, err := ma.NewMultiaddr(addr) - if err != nil { - return n.PeerInfo{}, err - } - addrs[i] = ma - } - id, err := peer.Decode(proto.AddrInfo.Id) - if err != nil { - return n.PeerInfo{}, err - } - peerInfo := n.PeerInfo{ - AddrInfo: peer.AddrInfo{ - ID: id, - Addrs: addrs, - }, - } - if proto.Location != nil { - peerInfo.Location = &iplocation.Location{ - Country: proto.Location.Country, - Latitude: proto.Location.Latitude, - Longitude: proto.Location.Longitude, - } - } - - return peerInfo, nil +func (net *Net) Connectedness(ctx context.Context, peerID string) (*rpc.ConnectednessResponse, error) { + return net.client.Connectedness(ctx, &rpc.ConnectednessRequest{PeerId: peerID}) } diff --git a/api/client/net_test.go b/api/client/net_test.go index 37404b9b5..43d24e2f3 100644 --- a/api/client/net_test.go +++ b/api/client/net_test.go @@ -4,51 +4,50 @@ import ( "testing" "github.com/stretchr/testify/require" - n "github.com/textileio/powergate/net" "github.com/textileio/powergate/net/rpc" ) func TestListenAddr(t *testing.T) { c, done := setupNet(t) defer done() - addrInfo, err := c.ListenAddr(ctx) + res, err := c.ListenAddr(ctx) require.NoError(t, err) - require.NotEmpty(t, addrInfo.Addrs) - require.NotEmpty(t, addrInfo.ID) + require.NotEmpty(t, res.AddrInfo.Addrs) + require.NotEmpty(t, res.AddrInfo.Id) } func TestPeers(t *testing.T) { c, done := setupNet(t) defer done() - peers, err := c.Peers(ctx) + res, err := c.Peers(ctx) require.NoError(t, err) - require.NotEmpty(t, peers) + require.NotEmpty(t, res) } func TestFindPeer(t *testing.T) { c, done := setupNet(t) defer done() - peers, err := c.Peers(ctx) + peersRes, err := c.Peers(ctx) require.NoError(t, err) - require.NotEmpty(t, peers) - peer, err := c.FindPeer(ctx, peers[0].AddrInfo.ID) + require.NotEmpty(t, peersRes.Peers) + peerRes, err := c.FindPeer(ctx, peersRes.Peers[0].AddrInfo.Id) require.NoError(t, err) - require.NotEmpty(t, peer.AddrInfo.ID) - require.NotEmpty(t, peer.AddrInfo.Addrs) + require.NotEmpty(t, peerRes.PeerInfo.AddrInfo.Id) + require.NotEmpty(t, peerRes.PeerInfo.AddrInfo.Addrs) // The addrs of peers are in localhost, so // no location information will be available. - require.Nil(t, peer.Location) + require.Nil(t, peerRes.PeerInfo.Location) } func TestConnectedness(t *testing.T) { c, done := setupNet(t) defer done() - peers, err := c.Peers(ctx) + peersRes, err := c.Peers(ctx) require.NoError(t, err) - require.NotEmpty(t, peers) - connectedness, err := c.Connectedness(ctx, peers[0].AddrInfo.ID) + require.NotEmpty(t, peersRes.Peers) + connectednessRes, err := c.Connectedness(ctx, peersRes.Peers[0].AddrInfo.Id) require.NoError(t, err) - require.Equal(t, n.Connected, connectedness) + require.Equal(t, rpc.Connectedness_CONNECTEDNESS_CONNECTED, connectednessRes.Connectedness) } func setupNet(t *testing.T) (*Net, func()) { diff --git a/api/client/reputation.go b/api/client/reputation.go index f53b32a04..c0e370806 100644 --- a/api/client/reputation.go +++ b/api/client/reputation.go @@ -3,8 +3,6 @@ package client import ( "context" - ma "github.com/multiformats/go-multiaddr" - "github.com/textileio/powergate/reputation" "github.com/textileio/powergate/reputation/rpc" ) @@ -14,28 +12,16 @@ type Reputation struct { } // 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 { +func (r *Reputation) AddSource(ctx context.Context, id, maddr string) (*rpc.AddSourceResponse, error) { req := &rpc.AddSourceRequest{ Id: id, - Maddr: maddr.String(), + Maddr: maddr, } - _, err := r.client.AddSource(ctx, req) - return err + return r.client.AddSource(ctx, req) } // GetTopMiners gets the top n miners with best score. -func (r *Reputation) GetTopMiners(ctx context.Context, limit int) ([]reputation.MinerScore, error) { - req := &rpc.GetTopMinersRequest{Limit: int32(limit)} - reply, err := r.client.GetTopMiners(ctx, req) - if err != nil { - return []reputation.MinerScore{}, err - } - topMiners := make([]reputation.MinerScore, len(reply.GetTopMiners())) - for i, val := range reply.GetTopMiners() { - topMiners[i] = reputation.MinerScore{ - Addr: val.GetAddr(), - Score: int(val.GetScore()), - } - } - return topMiners, nil +func (r *Reputation) GetTopMiners(ctx context.Context, limit int32) (*rpc.GetTopMinersResponse, error) { + req := &rpc.GetTopMinersRequest{Limit: limit} + return r.client.GetTopMiners(ctx, req) } diff --git a/api/client/reputation_test.go b/api/client/reputation_test.go index ab70de818..9b9846108 100644 --- a/api/client/reputation_test.go +++ b/api/client/reputation_test.go @@ -3,8 +3,6 @@ package client import ( "testing" - ma "github.com/multiformats/go-multiaddr" - "github.com/stretchr/testify/require" "github.com/textileio/powergate/reputation/rpc" ) @@ -12,10 +10,9 @@ func TestAddSource(t *testing.T) { r, done := setupReputation(t) defer done() - maddr, err := ma.NewMultiaddr("/dns4/lotus-bootstrap-0.sin.fil-test.net/tcp/1347/p2p/12D3KooWLZs8BWtEzRTYET4yR4jzDtPamaA1YsyPQJq6cf2RfxBD") - require.NoError(t, err) + maddr := "/dns4/lotus-bootstrap-0.sin.fil-test.net/tcp/1347/p2p/12D3KooWLZs8BWtEzRTYET4yR4jzDtPamaA1YsyPQJq6cf2RfxBD" - err = r.AddSource(ctx, "id", maddr) + _, err := r.AddSource(ctx, "id", maddr) if err != nil { t.Fatalf("failed to call AddSource: %v", err) } diff --git a/api/client/wallet.go b/api/client/wallet.go index 3fa8e96bf..0890ed66d 100644 --- a/api/client/wallet.go +++ b/api/client/wallet.go @@ -2,7 +2,6 @@ package client import ( "context" - "fmt" proto "github.com/textileio/powergate/proto/powergate/v1" walletRpc "github.com/textileio/powergate/wallet/rpc" @@ -15,28 +14,16 @@ type Wallet struct { } // NewAddress creates a new filecoin address [bls|secp256k1]. -func (w *Wallet) NewAddress(ctx context.Context, typ string) (string, error) { - resp, err := w.walletClient.NewAddress(ctx, &walletRpc.NewAddressRequest{Type: typ}) - if err != nil { - return "", fmt.Errorf("calling NewAddress: %v", err) - } - return resp.GetAddress(), nil +func (w *Wallet) NewAddress(ctx context.Context, typ string) (*walletRpc.NewAddressResponse, error) { + return w.walletClient.NewAddress(ctx, &walletRpc.NewAddressRequest{Type: typ}) } // List returns all wallet addresses. -func (w *Wallet) List(ctx context.Context) ([]string, error) { - resp, err := w.walletClient.List(ctx, &walletRpc.ListRequest{}) - if err != nil { - return nil, fmt.Errorf("calling List: %v", err) - } - return resp.Addresses, nil +func (w *Wallet) List(ctx context.Context) (*walletRpc.ListResponse, error) { + return w.walletClient.List(ctx, &walletRpc.ListRequest{}) } // Balance gets a filecoin wallet's balance. -func (w *Wallet) Balance(ctx context.Context, address string) (uint64, error) { - resp, err := w.powergateClient.Balance(ctx, &proto.BalanceRequest{Address: address}) - if err != nil { - return 0, fmt.Errorf("calling Balance: %v", err) - } - return resp.GetBalance(), nil +func (w *Wallet) Balance(ctx context.Context, address string) (*proto.BalanceResponse, error) { + return w.powergateClient.Balance(ctx, &proto.BalanceRequest{Address: address}) } diff --git a/api/client/wallet_test.go b/api/client/wallet_test.go index 787db4baf..7f2b61b3e 100644 --- a/api/client/wallet_test.go +++ b/api/client/wallet_test.go @@ -12,28 +12,28 @@ func TestNewWallet(t *testing.T) { w, done := setupWallet(t) defer done() - address, err := w.NewAddress(ctx, "bls") + res, err := w.NewAddress(ctx, "bls") require.NoError(t, err) - require.Greater(t, len(address), 0) + require.Greater(t, len(res.Address), 0) } func TestList(t *testing.T) { w, done := setupWallet(t) defer done() - addresses, err := w.List(ctx) + res, err := w.List(ctx) require.NoError(t, err) - require.Greater(t, len(addresses), 0) + require.Greater(t, len(res.Addresses), 0) } func TestWalletBalance(t *testing.T) { w, done := setupWallet(t) defer done() - address, err := w.NewAddress(ctx, "bls") + newAddressRes, err := w.NewAddress(ctx, "bls") require.NoError(t, err) - _, err = w.Balance(ctx, address) + _, err = w.Balance(ctx, newAddressRes.Address) require.NoError(t, err) } diff --git a/cli-docs/pow/pow_asks_query.md b/cli-docs/pow/pow_asks_query.md index e1e1d82f2..7b82c1b15 100644 --- a/cli-docs/pow/pow_asks_query.md +++ b/cli-docs/pow/pow_asks_query.md @@ -13,11 +13,11 @@ pow asks query [flags] ### Options ``` - -h, --help help for query - -l, --limit int limit the number of results (default -1) - -m, --maxPrice uint max price of the asks to query - -o, --offset int offset of results (default -1) - -p, --pieceSize int piece size of the asks to query + -h, --help help for query + -l, --limit int32 limit the number of results (default -1) + -m, --maxPrice uint max price of the asks to query + -o, --offset int32 offset of results (default -1) + -p, --pieceSize uint piece size of the asks to query ``` ### Options inherited from parent commands diff --git a/cli-docs/pow/pow_ffs_paych_redeem.md b/cli-docs/pow/pow_ffs_paych_redeem.md index d756d6371..519b5f235 100644 --- a/cli-docs/pow/pow_ffs_paych_redeem.md +++ b/cli-docs/pow/pow_ffs_paych_redeem.md @@ -7,7 +7,7 @@ Redeem a payment channel Redeem a payment channel ``` -pow ffs paych redeem [from] [to] [amount] [flags] +pow ffs paych redeem [addr] [flags] ``` ### Options diff --git a/cli-docs/pow/pow_reputation_topMiners.md b/cli-docs/pow/pow_reputation_topMiners.md index 9c1145a7f..8e8687408 100644 --- a/cli-docs/pow/pow_reputation_topMiners.md +++ b/cli-docs/pow/pow_reputation_topMiners.md @@ -13,8 +13,8 @@ pow reputation topMiners [flags] ### Options ``` - -h, --help help for topMiners - -l, --limit int limit the number of results (default -1) + -h, --help help for topMiners + -l, --limit int32 limit the number of results (default -1) ``` ### Options inherited from parent commands diff --git a/cmd/pow/cmd/admin.go b/cmd/pow/cmd/admin.go index ca47d001b..37e0e9c3d 100644 --- a/cmd/pow/cmd/admin.go +++ b/cmd/pow/cmd/admin.go @@ -58,10 +58,10 @@ var adminCreateInstanceCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - res, err := fcClient.Admin.CreateInstance(mustAdminAuthCtx(ctx)) + res, err := fcClient.Admin.CreateInstance(adminAuthCtx(ctx)) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) fmt.Println(string(json)) @@ -81,10 +81,10 @@ var adminInstancesCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - res, err := fcClient.Admin.ListInstances(mustAdminAuthCtx(ctx)) + res, err := fcClient.Admin.ListInstances(adminAuthCtx(ctx)) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) fmt.Println(string(json)) @@ -105,13 +105,13 @@ var adminQueuedStorageJobsCmd = &cobra.Command{ defer cancel() res, err := fcClient.Admin.QueuedStorageJobs( - mustAdminAuthCtx(ctx), + adminAuthCtx(ctx), viper.GetString("instance-id"), viper.GetStringSlice("cids")..., ) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) fmt.Println(string(json)) @@ -132,13 +132,13 @@ var adminExecutingStorageJobsCmd = &cobra.Command{ defer cancel() res, err := fcClient.Admin.ExecutingStorageJobs( - mustAdminAuthCtx(ctx), + adminAuthCtx(ctx), viper.GetString("instance-id"), viper.GetStringSlice("cids")..., ) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) fmt.Println(string(json)) @@ -159,13 +159,13 @@ var adminLatestFinalStorageJobsCmd = &cobra.Command{ defer cancel() res, err := fcClient.Admin.LatestFinalStorageJobs( - mustAdminAuthCtx(ctx), + adminAuthCtx(ctx), viper.GetString("instance-id"), viper.GetStringSlice("cids")..., ) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) fmt.Println(string(json)) @@ -186,13 +186,13 @@ var adminLatestSuccessfulStorageJobsCmd = &cobra.Command{ defer cancel() res, err := fcClient.Admin.LatestSuccessfulStorageJobs( - mustAdminAuthCtx(ctx), + adminAuthCtx(ctx), viper.GetString("instance-id"), viper.GetStringSlice("cids")..., ) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) fmt.Println(string(json)) @@ -213,13 +213,13 @@ var adminStorageJobsSummaryCmd = &cobra.Command{ defer cancel() res, err := fcClient.Admin.StorageJobsSummary( - mustAdminAuthCtx(ctx), + adminAuthCtx(ctx), viper.GetString("instance-id"), viper.GetStringSlice("cids")..., ) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) fmt.Println(string(json)) diff --git a/cmd/pow/cmd/asks_get.go b/cmd/pow/cmd/asks_get.go index d3f751935..8e851de59 100644 --- a/cmd/pow/cmd/asks_get.go +++ b/cmd/pow/cmd/asks_get.go @@ -2,12 +2,10 @@ package cmd import ( "context" - "os" - "strconv" + "fmt" - "github.com/caarlos0/spin" - "github.com/logrusorgru/aurora" "github.com/spf13/cobra" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -22,30 +20,12 @@ var getCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - s := spin.New("%s Getting storage asks...") - s.Start() - index, err := fcClient.Asks.Get(ctx) - s.Stop() + res, err := fcClient.Asks.Get(ctx) checkErr(err) - if len(index.Storage) > 0 { - Message("Storage median price price: %v", index.StorageMedianPrice) - Message("Last updated: %v", index.LastUpdated.Format("01/02/06 15:04 MST")) - data := make([][]string, len(index.Storage)) - i := 0 - for _, a := range index.Storage { - data[i] = []string{ - a.Miner, - strconv.Itoa(int(a.Price)), - strconv.Itoa(int(a.MinPieceSize)), - strconv.FormatInt(a.Timestamp, 10), - strconv.FormatInt(a.Expiry, 10), - } - i++ - } - RenderTable(os.Stdout, []string{"miner", "price", "min piece size", "timestamp", "expiry"}, data) - } + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res.Index) + checkErr(err) - Message("Found %d asks", aurora.White(len(index.Storage)).Bold()) + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/asks_query.go b/cmd/pow/cmd/asks_query.go index 32592db69..a1cf43dae 100644 --- a/cmd/pow/cmd/asks_query.go +++ b/cmd/pow/cmd/asks_query.go @@ -3,21 +3,19 @@ package cmd import ( "context" "errors" - "os" - "strconv" + "fmt" - "github.com/caarlos0/spin" - "github.com/logrusorgru/aurora" "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/textileio/powergate/index/ask" + "github.com/textileio/powergate/index/ask/rpc" + "google.golang.org/protobuf/encoding/protojson" ) func init() { queryCmd.Flags().Uint64P("maxPrice", "m", 0, "max price of the asks to query") - queryCmd.Flags().IntP("pieceSize", "p", 0, "piece size of the asks to query") - queryCmd.Flags().IntP("limit", "l", -1, "limit the number of results") - queryCmd.Flags().IntP("offset", "o", -1, "offset of results") + queryCmd.Flags().Uint64P("pieceSize", "p", 0, "piece size of the asks to query") + queryCmd.Flags().Int32P("limit", "l", -1, "limit the number of results") + queryCmd.Flags().Int32P("offset", "o", -1, "offset of results") asksCmd.AddCommand(queryCmd) } @@ -36,8 +34,8 @@ var queryCmd = &cobra.Command{ mp := viper.GetUint64("maxPrice") ps := viper.GetUint64("pieceSize") - l := viper.GetInt("limit") - o := viper.GetInt("offset") + l := viper.GetInt32("limit") + o := viper.GetInt32("offset") if mp == 0 { Fatal(errors.New("maxPrice must be > 0")) @@ -47,34 +45,19 @@ var queryCmd = &cobra.Command{ Fatal(errors.New("pieceSize must be > 0")) } - q := ask.Query{ + q := &rpc.Query{ MaxPrice: mp, PieceSize: ps, Limit: l, Offset: o, } - s := spin.New("%s Querying network for available storage asks...") - s.Start() - asks, err := fcClient.Asks.Query(ctx, q) - s.Stop() + res, err := fcClient.Asks.Query(ctx, q) checkErr(err) - if len(asks) > 0 { - data := make([][]string, len(asks)) - for i, a := range asks { - data[i] = []string{ - a.Miner, - strconv.Itoa(int(a.Price)), - strconv.Itoa(int(a.MinPieceSize)), - strconv.FormatInt(a.Timestamp, 10), - strconv.FormatInt(a.Expiry, 10), - } - } - RenderTable(os.Stdout, []string{"miner", "price", "min piece size", "timestamp", "expiry"}, data) - } - - Message("Found %d asks", aurora.White(len(asks)).Bold()) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) + checkErr(err) + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/faults_get.go b/cmd/pow/cmd/faults_get.go index cc348cddb..b445e711d 100644 --- a/cmd/pow/cmd/faults_get.go +++ b/cmd/pow/cmd/faults_get.go @@ -3,11 +3,9 @@ package cmd import ( "context" "fmt" - "os" - "github.com/caarlos0/spin" - "github.com/logrusorgru/aurora" "github.com/spf13/cobra" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -22,29 +20,12 @@ var getFaultsCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - s := spin.New("%s Getting Faults data...") - s.Start() - index, err := fcClient.Faults.Get(ctx) - s.Stop() + res, err := fcClient.Faults.Get(ctx) checkErr(err) - Message("%v", aurora.Blue("Faults index data:").Bold()) - cmd.Println() - - Message("Tipset key: %v", aurora.White(index.TipSetKey).Bold()) - cmd.Println() - - data := make([][]string, len(index.Miners)) - i := 0 - for id, faults := range index.Miners { - data[i] = []string{ - id, - fmt.Sprintf("%v", faults.Epochs), - } - i++ - } - RenderTable(os.Stdout, []string{"miner", "faults"}, data) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res.Index) + checkErr(err) - Message("Found faults data for %d miners", aurora.White(len(index.Miners)).Bold()) + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/ffs_addrs_list.go b/cmd/pow/cmd/ffs_addrs_list.go index 1cee3d03e..01ec31bfd 100644 --- a/cmd/pow/cmd/ffs_addrs_list.go +++ b/cmd/pow/cmd/ffs_addrs_list.go @@ -28,7 +28,7 @@ var ffsAddrsListCmd = &cobra.Command{ res, err := fcClient.FFS.Addrs(mustAuthCtx(ctx)) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) fmt.Println(string(json)) diff --git a/cmd/pow/cmd/ffs_addrs_new.go b/cmd/pow/cmd/ffs_addrs_new.go index a156cf572..6d7e1763f 100644 --- a/cmd/pow/cmd/ffs_addrs_new.go +++ b/cmd/pow/cmd/ffs_addrs_new.go @@ -3,12 +3,13 @@ package cmd import ( "context" "errors" + "fmt" "time" - "github.com/caarlos0/spin" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/textileio/powergate/api/client" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -45,11 +46,12 @@ var ffsAddrsNewCmd = &cobra.Command{ opts = append(opts, client.WithMakeDefault(makeDefault)) } - s := spin.New("%s Getting FFS instance wallet address...") - s.Start() - addr, err := fcClient.FFS.NewAddr(mustAuthCtx(ctx), args[0], opts...) - s.Stop() + res, err := fcClient.FFS.NewAddr(mustAuthCtx(ctx), args[0], opts...) checkErr(err) - Success("Created new wallet address: %s", addr) + + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) + checkErr(err) + + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/ffs_cancel.go b/cmd/pow/cmd/ffs_cancel.go index f8150810b..144667c19 100644 --- a/cmd/pow/cmd/ffs_cancel.go +++ b/cmd/pow/cmd/ffs_cancel.go @@ -2,13 +2,10 @@ package cmd import ( "context" - "errors" "time" - "github.com/caarlos0/spin" "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/textileio/powergate/ffs" ) func init() { @@ -19,25 +16,16 @@ var ffsCancelCmd = &cobra.Command{ Use: "cancel [jobid]", Short: "Cancel an executing job", Long: `Cancel an executing job`, + Args: cobra.ExactArgs(0), PreRun: func(cmd *cobra.Command, args []string) { err := viper.BindPFlags(cmd.Flags()) checkErr(err) }, Run: func(cmd *cobra.Command, args []string) { - if len(args) != 1 { - Fatal(errors.New("you must provide a job id")) - } - - jid := ffs.JobID(args[0]) ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() - s := spin.New("%s Signaling executing Job cancellation...") - s.Start() - err := fcClient.FFS.CancelJob(mustAuthCtx(ctx), jid) - s.Stop() + _, err := fcClient.FFS.CancelJob(mustAuthCtx(ctx), args[0]) checkErr(err) - Success("Successful cancellation signaling.") - }, } diff --git a/cmd/pow/cmd/ffs_config_default.go b/cmd/pow/cmd/ffs_config_default.go index ae485b34d..2e5eefb74 100644 --- a/cmd/pow/cmd/ffs_config_default.go +++ b/cmd/pow/cmd/ffs_config_default.go @@ -2,12 +2,12 @@ package cmd import ( "context" - "encoding/json" + "fmt" "time" - "github.com/caarlos0/spin" "github.com/spf13/cobra" "github.com/spf13/viper" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -26,15 +26,12 @@ var ffsConfigDefaultCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), time.Second*60) defer cancel() - s := spin.New("%s Getting default storage config...") - s.Start() - config, err := fcClient.FFS.DefaultStorageConfig(mustAuthCtx(ctx)) - s.Stop() + res, err := fcClient.FFS.DefaultStorageConfig(mustAuthCtx(ctx)) checkErr(err) - json, err := json.MarshalIndent(config, "", " ") + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res.DefaultStorageConfig) checkErr(err) - Message("Default storage config:\n%s", string(json)) + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/ffs_config_push.go b/cmd/pow/cmd/ffs_config_push.go index 9f126e217..c2d224443 100644 --- a/cmd/pow/cmd/ffs_config_push.go +++ b/cmd/pow/cmd/ffs_config_push.go @@ -3,19 +3,16 @@ package cmd import ( "bytes" "context" - "encoding/json" - "errors" + "fmt" "io" "os" "time" - "github.com/caarlos0/spin" - "github.com/ipfs/go-cid" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/textileio/powergate/api/client" - "github.com/textileio/powergate/ffs" - "github.com/textileio/powergate/util" + "github.com/textileio/powergate/ffs/rpc" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -30,6 +27,7 @@ var ffsConfigPushCmd = &cobra.Command{ Use: "push [cid]", Short: "Add data to FFS via cid", Long: `Add data to FFS via a cid already in IPFS`, + Args: cobra.ExactArgs(1), PreRun: func(cmd *cobra.Command, args []string) { err := viper.BindPFlags(cmd.Flags()) checkErr(err) @@ -38,13 +36,6 @@ var ffsConfigPushCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), time.Second*60) defer cancel() - if len(args) != 1 { - Fatal(errors.New("you must provide a cid")) - } - - c, err := cid.Parse(args[0]) - checkErr(err) - configPath := viper.GetString("conf") var reader io.Reader @@ -72,8 +63,9 @@ var ffsConfigPushCmd = &cobra.Command{ _, err := buf.ReadFrom(reader) checkErr(err) - config := ffs.StorageConfig{} - checkErr(json.Unmarshal(buf.Bytes(), &config)) + config := &rpc.StorageConfig{} + err = protojson.UnmarshalOptions{}.Unmarshal(buf.Bytes(), config) + checkErr(err) options = append(options, client.WithStorageConfig(config)) } @@ -82,15 +74,16 @@ var ffsConfigPushCmd = &cobra.Command{ options = append(options, client.WithOverride(viper.GetBool("override"))) } - s := spin.New("%s Adding cid storage config to FFS...") - s.Start() - jid, err := fcClient.FFS.PushStorageConfig(mustAuthCtx(ctx), c, options...) - s.Stop() + res, err := fcClient.FFS.PushStorageConfig(mustAuthCtx(ctx), args[0], options...) + checkErr(err) + + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) - Success("Pushed cid storage config for %s to FFS with job id: %v", util.CidToString(c), jid.String()) + + fmt.Println(string(json)) if viper.GetBool("watch") { - watchJobIds(jid) + watchJobIds(res.JobId) } }, } diff --git a/cmd/pow/cmd/ffs_config_set_default.go b/cmd/pow/cmd/ffs_config_set_default.go index ea4db8072..e84afdde6 100644 --- a/cmd/pow/cmd/ffs_config_set_default.go +++ b/cmd/pow/cmd/ffs_config_set_default.go @@ -3,16 +3,15 @@ package cmd import ( "bytes" "context" - "encoding/json" "io" "os" "time" - "github.com/caarlos0/spin" logging "github.com/ipfs/go-log/v2" "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/textileio/powergate/ffs" + "github.com/textileio/powergate/ffs/rpc" + "google.golang.org/protobuf/encoding/protojson" ) var ( @@ -27,6 +26,7 @@ var ffsConfigSetCmd = &cobra.Command{ Use: "set-default [optional file]", Short: "Sets the default cid storage config from stdin or a file", Long: `Sets the default cid storage config from stdin or a file`, + Args: cobra.MaximumNArgs(1), PreRun: func(cmd *cobra.Command, args []string) { err := viper.BindPFlags(cmd.Flags()) checkErr(err) @@ -53,15 +53,11 @@ var ffsConfigSetCmd = &cobra.Command{ _, err := buf.ReadFrom(reader) checkErr(err) - config := ffs.StorageConfig{} - checkErr(json.Unmarshal(buf.Bytes(), &config)) - - s := spin.New("%s Setting default storage config...") - s.Start() - err = fcClient.FFS.SetDefaultStorageConfig(mustAuthCtx(ctx), config) - s.Stop() + config := &rpc.StorageConfig{} + err = protojson.UnmarshalOptions{}.Unmarshal(buf.Bytes(), config) checkErr(err) - Success("Default storage config updated") + _, err = fcClient.FFS.SetDefaultStorageConfig(mustAuthCtx(ctx), config) + checkErr(err) }, } diff --git a/cmd/pow/cmd/ffs_data.go b/cmd/pow/cmd/ffs_data.go index b8a67d3de..567e25566 100644 --- a/cmd/pow/cmd/ffs_data.go +++ b/cmd/pow/cmd/ffs_data.go @@ -35,7 +35,7 @@ var ffsDataCmd = &cobra.Command{ res, err := fcClient.FFS.CidData(mustAuthCtx(ctx), cids...) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) fmt.Println(string(json)) diff --git a/cmd/pow/cmd/ffs_get.go b/cmd/pow/cmd/ffs_get.go index a41879aaa..ce9fbcd7d 100644 --- a/cmd/pow/cmd/ffs_get.go +++ b/cmd/pow/cmd/ffs_get.go @@ -2,14 +2,12 @@ package cmd import ( "context" - "errors" "io" "os" "path" "time" "github.com/caarlos0/spin" - "github.com/ipfs/go-cid" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -24,6 +22,7 @@ var ffsGetCmd = &cobra.Command{ Use: "get [cid] [output file path]", Short: "Get data by cid from ffs", Long: `Get data by cid from ffs`, + Args: cobra.ExactArgs(2), PreRun: func(cmd *cobra.Command, args []string) { err := viper.BindPFlags(cmd.Flags()) checkErr(err) @@ -32,22 +31,15 @@ var ffsGetCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), time.Hour*8) defer cancel() - if len(args) != 2 { - Fatal(errors.New("you must provide cid and output file path arguments")) - } - - c, err := cid.Parse(args[0]) - checkErr(err) - s := spin.New("%s Retrieving specified data...") s.Start() isFolder := viper.GetBool("folder") if isFolder { - err := fcClient.FFS.GetFolder(mustAuthCtx(ctx), viper.GetString("ipfsrevproxy"), c, args[1]) + err := fcClient.FFS.GetFolder(mustAuthCtx(ctx), viper.GetString("ipfsrevproxy"), args[0], args[1]) checkErr(err) } else { - reader, err := fcClient.FFS.Get(mustAuthCtx(ctx), c) + reader, err := fcClient.FFS.Get(mustAuthCtx(ctx), args[0]) checkErr(err) dir := path.Dir(args[1]) diff --git a/cmd/pow/cmd/ffs_id.go b/cmd/pow/cmd/ffs_id.go index 1e9c59679..b2253169c 100644 --- a/cmd/pow/cmd/ffs_id.go +++ b/cmd/pow/cmd/ffs_id.go @@ -2,11 +2,12 @@ package cmd import ( "context" + "fmt" "time" - "github.com/caarlos0/spin" "github.com/spf13/cobra" "github.com/spf13/viper" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -25,11 +26,12 @@ var ffsIDCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), time.Second*60) defer cancel() - s := spin.New("%s Getting FFS instance id...") - s.Start() - id, err := fcClient.FFS.ID(mustAuthCtx(ctx)) - s.Stop() + res, err := fcClient.FFS.ID(mustAuthCtx(ctx)) checkErr(err) - Message("FFS instance id: %s", id.String()) + + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) + checkErr(err) + + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/ffs_log.go b/cmd/pow/cmd/ffs_log.go index 77e7dad36..4ce981995 100644 --- a/cmd/pow/cmd/ffs_log.go +++ b/cmd/pow/cmd/ffs_log.go @@ -2,16 +2,14 @@ package cmd import ( "context" - "errors" "os" "os/signal" "syscall" + "time" - "github.com/ipfs/go-cid" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/textileio/powergate/api/client" - "github.com/textileio/powergate/ffs" ) func init() { @@ -24,29 +22,23 @@ var ffsLogCmd = &cobra.Command{ Use: "log [cid]", Short: "Display logs for specified cid", Long: `Display logs for specified cid`, + Args: cobra.ExactArgs(1), PreRun: func(cmd *cobra.Command, args []string) { err := viper.BindPFlags(cmd.Flags()) checkErr(err) }, Run: func(cmd *cobra.Command, args []string) { - if len(args) != 1 { - Fatal(errors.New("you must provide a cid")) - } - - cid, err := cid.Parse(args[0]) - checkErr(err) - opts := []client.WatchLogsOption{client.WithHistory(true)} jid := viper.GetString("jid") if jid != "" { - opts = append(opts, client.WithJidFilter(ffs.JobID(jid))) + opts = append(opts, client.WithJidFilter(jid)) } - ch := make(chan client.LogEvent) + ch := make(chan client.WatchLogsEvent) ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err = fcClient.FFS.WatchLogs(mustAuthCtx(ctx), ch, cid, opts...) + err := fcClient.FFS.WatchLogs(mustAuthCtx(ctx), ch, args[0], opts...) checkErr(err) c := make(chan os.Signal) @@ -66,7 +58,8 @@ var ffsLogCmd = &cobra.Command{ Fatal(event.Err) break } - Message("%v - %v", event.LogEntry.Timestamp.Format("2006-01-02T15:04:05"), event.LogEntry.Msg) + ts := time.Unix(event.Res.LogEntry.Time, 0) + Message("%v - %v", ts.Format("2006-01-02T15:04:05"), event.Res.LogEntry.Msg) } }, } diff --git a/cmd/pow/cmd/ffs_paych_create.go b/cmd/pow/cmd/ffs_paych_create.go index 58c61f4f3..1609a5353 100644 --- a/cmd/pow/cmd/ffs_paych_create.go +++ b/cmd/pow/cmd/ffs_paych_create.go @@ -2,12 +2,12 @@ package cmd import ( "context" + "fmt" "strconv" - "github.com/caarlos0/spin" "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/textileio/powergate/util" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -32,12 +32,12 @@ var ffsPaychCreateCmd = &cobra.Command{ amt, err := strconv.ParseInt(args[2], 10, 64) checkErr(err) - s := spin.New("%s Creating payment channel...") - s.Start() - chInfo, msgCid, err := fcClient.FFS.CreatePayChannel(mustAuthCtx(ctx), from, to, uint64(amt)) - s.Stop() + res, err := fcClient.FFS.CreatePayChannel(mustAuthCtx(ctx), from, to, uint64(amt)) checkErr(err) - Success("Created payment channel with address %v and message cid %v", chInfo.Addr, util.CidToString(msgCid)) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) + checkErr(err) + + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/ffs_paych_list.go b/cmd/pow/cmd/ffs_paych_list.go index 1f760cfea..ce70e43de 100644 --- a/cmd/pow/cmd/ffs_paych_list.go +++ b/cmd/pow/cmd/ffs_paych_list.go @@ -2,12 +2,11 @@ package cmd import ( "context" - "os" + "fmt" - "github.com/caarlos0/spin" "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/textileio/powergate/ffs" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -26,17 +25,12 @@ var ffsPaychListCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - s := spin.New("%s Retrieving payment channels...") - s.Start() - infos, err := fcClient.FFS.ListPayChannels(mustAuthCtx(ctx)) + res, err := fcClient.FFS.ListPayChannels(mustAuthCtx(ctx)) checkErr(err) - s.Stop() - data := make([][]string, len(infos)) - for i, info := range infos { - data[i] = []string{info.CtlAddr, info.Addr, ffs.PaychDirStr[info.Direction]} - } - Message("Payment channels:") - RenderTable(os.Stdout, []string{"Ctrl Address", "Address", "Direction"}, data) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) + checkErr(err) + + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/ffs_paych_redeem.go b/cmd/pow/cmd/ffs_paych_redeem.go index 94beb2f32..b4980a321 100644 --- a/cmd/pow/cmd/ffs_paych_redeem.go +++ b/cmd/pow/cmd/ffs_paych_redeem.go @@ -3,7 +3,6 @@ package cmd import ( "context" - "github.com/caarlos0/spin" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -13,7 +12,7 @@ func init() { } var ffsPaychRedeemCmd = &cobra.Command{ - Use: "redeem [from] [to] [amount]", + Use: "redeem [addr]", Short: "Redeem a payment channel", Long: `Redeem a payment channel`, Args: cobra.ExactArgs(1), @@ -25,12 +24,7 @@ var ffsPaychRedeemCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - s := spin.New("%s Redeeming payment channel...") - s.Start() - err := fcClient.FFS.RedeemPayChannel(mustAuthCtx(ctx), args[0]) - s.Stop() + _, err := fcClient.FFS.RedeemPayChannel(mustAuthCtx(ctx), args[0]) checkErr(err) - - Success("Redeemed payment channel %v", args[0]) }, } diff --git a/cmd/pow/cmd/ffs_remove.go b/cmd/pow/cmd/ffs_remove.go index 7a7d0d0b3..b8b6f4385 100644 --- a/cmd/pow/cmd/ffs_remove.go +++ b/cmd/pow/cmd/ffs_remove.go @@ -2,11 +2,8 @@ package cmd import ( "context" - "errors" "time" - "github.com/caarlos0/spin" - "github.com/ipfs/go-cid" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -19,6 +16,7 @@ var ffsRemoveCmd = &cobra.Command{ Use: "remove [cid]", Short: "Removes a Cid from being tracked as an active storage", Long: `Removes a Cid from being tracked as an active storage. The Cid should have both Hot and Cold storage disabled, if that isn't the case it will return ErrActiveInStorage`, + Args: cobra.ExactArgs(1), PreRun: func(cmd *cobra.Command, args []string) { err := viper.BindPFlags(cmd.Flags()) checkErr(err) @@ -26,19 +24,7 @@ var ffsRemoveCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*60) defer cancel() - - if len(args) != 1 { - Fatal(errors.New("you must a cid arguments")) - } - - c, err := cid.Parse(args[0]) - checkErr(err) - - s := spin.New("%s Removing cid config...") - s.Start() - err = fcClient.FFS.Remove(mustAuthCtx(ctx), c) - s.Stop() + _, err := fcClient.FFS.Remove(mustAuthCtx(ctx), args[0]) checkErr(err) - Success("Removed cid config") }, } diff --git a/cmd/pow/cmd/ffs_replace.go b/cmd/pow/cmd/ffs_replace.go index 647f24d90..4502c30ec 100644 --- a/cmd/pow/cmd/ffs_replace.go +++ b/cmd/pow/cmd/ffs_replace.go @@ -2,13 +2,12 @@ package cmd import ( "context" - "errors" + "fmt" "time" - "github.com/caarlos0/spin" - "github.com/ipfs/go-cid" "github.com/spf13/cobra" "github.com/spf13/viper" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -21,6 +20,7 @@ var ffsReplaceCmd = &cobra.Command{ Use: "replace [cid1] [cid2]", Short: "Pushes a StorageConfig for c2 equal to that of c1, and removes c1", Long: `Pushes a StorageConfig for c2 equal to that of c1, and removes c1. This operation is more efficient than manually removing and adding in two separate operations`, + Args: cobra.ExactArgs(2), PreRun: func(cmd *cobra.Command, args []string) { err := viper.BindPFlags(cmd.Flags()) checkErr(err) @@ -29,24 +29,16 @@ var ffsReplaceCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), time.Second*60) defer cancel() - if len(args) != 2 { - Fatal(errors.New("you must provide two cid arguments")) - } - - c1, err := cid.Parse(args[0]) - checkErr(err) - c2, err := cid.Parse(args[1]) + res, err := fcClient.FFS.Replace(mustAuthCtx(ctx), args[0], args[1]) checkErr(err) - s := spin.New("%s Replacing cid configuration...") - s.Start() - jid, err := fcClient.FFS.Replace(mustAuthCtx(ctx), c1, c2) - s.Stop() + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) - Success("Replaced cid config with job id: %v", jid.String()) + + fmt.Println(string(json)) if viper.GetBool("watch") { - watchJobIds(jid) + watchJobIds(res.JobId) } }, } diff --git a/cmd/pow/cmd/ffs_retrievals.go b/cmd/pow/cmd/ffs_retrievals.go index 692afd1db..dd6a1090e 100644 --- a/cmd/pow/cmd/ffs_retrievals.go +++ b/cmd/pow/cmd/ffs_retrievals.go @@ -2,16 +2,12 @@ package cmd import ( "context" - "os" - "strconv" - "time" + "fmt" - "github.com/caarlos0/spin" - "github.com/logrusorgru/aurora" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/textileio/powergate/api/client" - "github.com/textileio/powergate/util" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -46,26 +42,12 @@ var ffsRetrievalsCmd = &cobra.Command{ opts = append(opts, client.WithFromAddrs(viper.GetStringSlice("addrs")...)) } - s := spin.New("%s Getting retrieval records...") - s.Start() res, err := fcClient.FFS.ListRetrievalDealRecords(mustAuthCtx(ctx), opts...) - s.Stop() checkErr(err) - if len(res) > 0 { - data := make([][]string, len(res)) - for i, r := range res { - t := time.Unix(r.Time, 0) - data[i] = []string{ - t.Format("01/02/06 15:04 MST"), - r.Addr, - r.DealInfo.Miner, - util.CidToString(r.DealInfo.RootCid), - strconv.Itoa(int(r.DealInfo.Size)), - } - } - RenderTable(os.Stdout, []string{"time", "addr", "miner", "cid", "size"}, data) - } - Message("Found %d retrieval deal records", aurora.White(len(res)).Bold()) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) + checkErr(err) + + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/ffs_send.go b/cmd/pow/cmd/ffs_send.go index 2621718ce..6d287d405 100644 --- a/cmd/pow/cmd/ffs_send.go +++ b/cmd/pow/cmd/ffs_send.go @@ -2,10 +2,8 @@ package cmd import ( "context" - "errors" "strconv" - "github.com/caarlos0/spin" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -18,6 +16,7 @@ var ffsSendCmd = &cobra.Command{ Use: "send [from address] [to address] [amount]", Short: "Send fil from one managed address to any other address", Long: `Send fil from one managed address to any other address`, + Args: cobra.ExactArgs(3), PreRun: func(cmd *cobra.Command, args []string) { err := viper.BindPFlags(cmd.Flags()) checkErr(err) @@ -26,23 +25,13 @@ var ffsSendCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - if len(args) != 3 { - Fatal(errors.New("you must provide from and to addresses and an amount to send")) - } - from := args[0] to := args[1] amount, err := strconv.ParseInt(args[2], 10, 64) checkErr(err) - s := spin.New("%s Sending fil...") - s.Start() - - err = fcClient.FFS.SendFil(mustAuthCtx(ctx), from, to, amount) - s.Stop() + _, err = fcClient.FFS.SendFil(mustAuthCtx(ctx), from, to, amount) checkErr(err) - - Success("Sent %v fil from %v to %v", amount, from, to) }, } diff --git a/cmd/pow/cmd/ffs_sign.go b/cmd/pow/cmd/ffs_sign.go index d1319f410..d38c16118 100644 --- a/cmd/pow/cmd/ffs_sign.go +++ b/cmd/pow/cmd/ffs_sign.go @@ -6,10 +6,9 @@ import ( "fmt" "os" - "github.com/caarlos0/spin" - "github.com/kyokomi/emoji" "github.com/spf13/cobra" "github.com/spf13/viper" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -33,17 +32,15 @@ var signCmd = &cobra.Command{ b, err := hex.DecodeString(args[0]) checkErr(err) - s := spin.New(fmt.Sprintf("%s Signing message with addresses...", "%s")) - s.Start() res, err := fcClient.FFS.Addrs(mustAuthCtx(ctx)) checkErr(err) + data := make([][]string, len(res.Addrs)) for i, a := range res.Addrs { - sig, err := fcClient.FFS.SignMessage(mustAuthCtx(ctx), a.Addr, b) + signRes, err := fcClient.FFS.SignMessage(mustAuthCtx(ctx), a.Addr, b) checkErr(err) - data[i] = []string{a.Addr, hex.EncodeToString(sig)} + data[i] = []string{a.Addr, hex.EncodeToString(signRes.Signature)} } - s.Stop() RenderTable(os.Stdout, []string{"address", "signature"}, data) }, @@ -67,17 +64,12 @@ var verifyCmd = &cobra.Command{ sb, err := hex.DecodeString(args[2]) checkErr(err) - s := spin.New(fmt.Sprintf("%s Verifying signature...", "%s")) - s.Start() - ok, err := fcClient.FFS.VerifyMessage(mustAuthCtx(ctx), args[0], mb, sb) - s.Stop() + res, err := fcClient.FFS.VerifyMessage(mustAuthCtx(ctx), args[0], mb, sb) checkErr(err) - if ok { - _, err := emoji.Println(":heavy_check_mark: The signature corresponds to the wallet address.") - checkErr(err) - } else { - _, err := emoji.Println(":x: The signature doesn't correspond to the wallet address.") - checkErr(err) - } + + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) + checkErr(err) + + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/ffs_stage.go b/cmd/pow/cmd/ffs_stage.go index ab102a8be..e83d2fdde 100644 --- a/cmd/pow/cmd/ffs_stage.go +++ b/cmd/pow/cmd/ffs_stage.go @@ -4,16 +4,15 @@ import ( "context" "errors" "fmt" + "io" "net/http" "os" "strings" "time" - "github.com/caarlos0/spin" - "github.com/ipfs/go-cid" "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/textileio/powergate/util" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -26,6 +25,7 @@ var ffsStageCmd = &cobra.Command{ Use: "stage [path|url]", Short: "Temporarily stage data in the Hot layer in preparation for pushing a cid storage config", Long: `Temporarily stage data in the Hot layer in preparation for pushing a cid storage config`, + Args: cobra.ExactArgs(1), PreRun: func(cmd *cobra.Command, args []string) { err := viper.BindPFlags(cmd.Flags()) checkErr(err) @@ -34,13 +34,11 @@ var ffsStageCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), time.Hour*8) defer cancel() - if len(args) != 1 { - Fatal(errors.New("you must provide a file/folder path")) - } - if strings.HasPrefix(strings.ToLower(args[0]), "http") { - err := stageURL(ctx, args[0]) + res, err := http.DefaultClient.Get(args[0]) checkErr(err) + defer func() { checkErr(res.Body.Close()) }() + stageReader(ctx, res.Body) return } @@ -51,45 +49,25 @@ var ffsStageCmd = &cobra.Command{ if err != nil { Fatal(fmt.Errorf("getting file/folder information: %s", err)) } - var cid cid.Cid - s := spin.New("%s Staging specified asset in FFS hot storage...") - s.Start() if fi.IsDir() { - cid, err = fcClient.FFS.StageFolder(mustAuthCtx(ctx), viper.GetString("ipfsrevproxy"), args[0]) + c, err := fcClient.FFS.StageFolder(mustAuthCtx(ctx), viper.GetString("ipfsrevproxy"), args[0]) checkErr(err) + Success("Staged folder with cid: %s", c) } else { f, err := os.Open(args[0]) checkErr(err) defer func() { checkErr(f.Close()) }() - - ptrCid, err := fcClient.FFS.Stage(mustAuthCtx(ctx), f) - checkErr(err) - cid = *ptrCid + stageReader(ctx, f) } - s.Stop() - Success("Staged asset in FFS hot storage with cid: %s", util.CidToString(cid)) }, } -func stageURL(ctx context.Context, urlstr string) error { - res, err := http.DefaultClient.Get(urlstr) - if err != nil { - return fmt.Errorf("GET %s: %w", urlstr, err) - } - - defer func() { checkErr(res.Body.Close()) }() +func stageReader(ctx context.Context, reader io.Reader) { + res, err := fcClient.FFS.Stage(mustAuthCtx(ctx), reader) + checkErr(err) - var cid cid.Cid - s := spin.New("%s Staging URL in FFS hot storage...") - s.Start() - defer s.Stop() - ptrCid, err := fcClient.FFS.Stage(mustAuthCtx(ctx), res.Body) - if err != nil { - return err - } + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) + checkErr(err) - cid = *ptrCid - s.Stop() - Success("Staged asset in FFS hot storage with cid: %s", util.CidToString(cid)) - return nil + fmt.Println(string(json)) } diff --git a/cmd/pow/cmd/ffs_storage.go b/cmd/pow/cmd/ffs_storage.go index 26b4b2d09..173c57e34 100644 --- a/cmd/pow/cmd/ffs_storage.go +++ b/cmd/pow/cmd/ffs_storage.go @@ -2,16 +2,12 @@ package cmd import ( "context" - "os" - "strconv" - "time" + "fmt" - "github.com/caarlos0/spin" - "github.com/logrusorgru/aurora" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/textileio/powergate/api/client" - "github.com/textileio/powergate/util" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -54,35 +50,12 @@ var ffsStorageCmd = &cobra.Command{ opts = append(opts, client.WithIncludeFinal(viper.GetBool("include-final"))) } - s := spin.New("%s Retrieving deal records...") - s.Start() res, err := fcClient.FFS.ListStorageDealRecords(mustAuthCtx(ctx), opts...) - s.Stop() checkErr(err) - if len(res) > 0 { - data := make([][]string, len(res)) - for i, r := range res { - t := time.Unix(r.Time, 0) - pending := "" - if r.Pending { - pending = "pending" - } - data[i] = []string{ - util.CidToString(r.RootCid), - pending, - strconv.FormatInt(r.DealInfo.ActivationEpoch, 10), - t.Format("01/02/06 15:04 MST"), - r.Addr, - r.DealInfo.Miner, - strconv.Itoa(int(r.DealInfo.DealID)), - strconv.Itoa(int(r.DealInfo.PricePerEpoch)), - strconv.Itoa(int(r.DealInfo.Size)), - strconv.Itoa(int(r.DealInfo.Duration)), - } - } - RenderTable(os.Stdout, []string{"cid", "pending", "active epoch", "time", "addr", "miner", "deal id", "price/epoch", "size", "duration"}, data) - } - Message("Found %d storage deal records", aurora.White(len(res)).Bold()) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) + checkErr(err) + + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/ffs_storage_job.go b/cmd/pow/cmd/ffs_storage_job.go index 15a97ef3e..2f5bfc966 100644 --- a/cmd/pow/cmd/ffs_storage_job.go +++ b/cmd/pow/cmd/ffs_storage_job.go @@ -7,7 +7,6 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/textileio/powergate/ffs" "google.golang.org/protobuf/encoding/protojson" ) @@ -42,15 +41,13 @@ var ffsGetStorageJobCmd = &cobra.Command{ checkErr(err) }, Run: func(cmd *cobra.Command, args []string) { - jid := ffs.JobID(args[0]) - ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - res, err := fcClient.FFS.StorageJob(mustAuthCtx(ctx), jid) + res, err := fcClient.FFS.StorageJob(mustAuthCtx(ctx), args[0]) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res.Job) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res.Job) checkErr(err) fmt.Println(string(json)) @@ -78,7 +75,7 @@ var ffsQueuedStorageJobsCmd = &cobra.Command{ res, err := fcClient.FFS.QueuedStorageJobs(mustAuthCtx(ctx), cids...) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) fmt.Println(string(json)) @@ -106,7 +103,7 @@ var ffsExecutingStorageJobsCmd = &cobra.Command{ res, err := fcClient.FFS.ExecutingStorageJobs(mustAuthCtx(ctx), cids...) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) fmt.Println(string(json)) @@ -134,7 +131,7 @@ var ffsLatestFinalStorageJobsCmd = &cobra.Command{ res, err := fcClient.FFS.LatestFinalStorageJobs(mustAuthCtx(ctx), cids...) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) fmt.Println(string(json)) @@ -162,7 +159,7 @@ var ffsLatestSuccessfulStorageJobsCmd = &cobra.Command{ res, err := fcClient.FFS.LatestSuccessfulStorageJobs(mustAuthCtx(ctx), cids...) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) fmt.Println(string(json)) @@ -190,7 +187,7 @@ var ffsStorageJobsSummaryCmd = &cobra.Command{ res, err := fcClient.FFS.StorageJobsSummary(mustAuthCtx(ctx), cids...) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) fmt.Println(string(json)) @@ -213,7 +210,7 @@ var ffsStorageConfigForJobCmd = &cobra.Command{ res, err := fcClient.Jobs.StorageConfigForJob(mustAuthCtx(ctx), args[0]) checkErr(err) - json, err := protojson.MarshalOptions{Multiline: true, Indent: " "}.Marshal(res) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res.StorageConfig) checkErr(err) fmt.Println(string(json)) diff --git a/cmd/pow/cmd/ffs_watch.go b/cmd/pow/cmd/ffs_watch.go index e50267029..7dfb2bf88 100644 --- a/cmd/pow/cmd/ffs_watch.go +++ b/cmd/pow/cmd/ffs_watch.go @@ -2,7 +2,6 @@ package cmd import ( "context" - "errors" "fmt" "os" "os/signal" @@ -15,7 +14,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/textileio/powergate/api/client" - "github.com/textileio/powergate/ffs" + "github.com/textileio/powergate/ffs/rpc" ) func init() { @@ -26,36 +25,28 @@ var ffsWatchCmd = &cobra.Command{ Use: "watch [jobid,...]", Short: "Watch for job status updates", Long: `Watch for job status updates`, + Args: cobra.ExactArgs(1), PreRun: func(cmd *cobra.Command, args []string) { err := viper.BindPFlags(cmd.Flags()) checkErr(err) }, Run: func(cmd *cobra.Command, args []string) { - if len(args) != 1 { - Fatal(errors.New("you must provide a comma-separated list of job ids")) - } - - idStrings := strings.Split(args[0], ",") - jobIds := make([]ffs.JobID, len(idStrings)) - for i, s := range idStrings { - jobIds[i] = ffs.JobID(s) - } - + jobIds := strings.Split(args[0], ",") watchJobIds(jobIds...) }, } -func watchJobIds(jobIds ...ffs.JobID) { - state := make(map[string]*client.JobEvent, len(jobIds)) +func watchJobIds(jobIds ...string) { + state := make(map[string]*client.WatchJobsEvent, len(jobIds)) for _, jobID := range jobIds { - state[jobID.String()] = nil + state[jobID] = nil } writer := goterminal.New(os.Stdout) updateJobsOutput(writer, state) - ch := make(chan client.JobEvent) + ch := make(chan client.WatchJobsEvent) ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -75,7 +66,7 @@ func watchJobIds(jobIds ...ffs.JobID) { if !ok { break } - state[event.Job.ID.String()] = &event + state[event.Res.Job.Id] = &event updateJobsOutput(writer, state) if jobsComplete(state) { break @@ -83,7 +74,7 @@ func watchJobIds(jobIds ...ffs.JobID) { } } -func updateJobsOutput(writer *goterminal.Writer, state map[string]*client.JobEvent) { +func updateJobsOutput(writer *goterminal.Writer, state map[string]*client.WatchJobsEvent) { keys := make([]string, 0, len(state)) for k := range state { keys = append(keys, k) @@ -94,15 +85,15 @@ func updateJobsOutput(writer *goterminal.Writer, state map[string]*client.JobEve for _, k := range keys { if state[k] != nil { var val string - if state[k].Job.Status == ffs.Failed { - val = fmt.Sprintf("%v %v", displayName(state[k].Job.Status), state[k].Job.ErrCause) + if state[k].Res.Job.Status == rpc.JobStatus_JOB_STATUS_FAILED { + val = fmt.Sprintf("%v %v", displayName(state[k].Res.Job.Status), state[k].Res.Job.ErrCause) } else if state[k].Err != nil { val = fmt.Sprintf("Error: %v", state[k].Err.Error()) } else { - val = displayName(state[k].Job.Status) + val = displayName(state[k].Res.Job.Status) } data = append(data, []string{k, val, "", "", ""}) - for _, dealInfo := range state[k].Job.DealInfo { + for _, dealInfo := range state[k].Res.Job.DealInfo { data = append(data, []string{"", "", dealInfo.Miner, strconv.FormatUint(dealInfo.PricePerEpoch, 10), dealInfo.StateName}) } } else { @@ -116,12 +107,12 @@ func updateJobsOutput(writer *goterminal.Writer, state map[string]*client.JobEve _ = writer.Print() } -func jobsComplete(state map[string]*client.JobEvent) bool { +func jobsComplete(state map[string]*client.WatchJobsEvent) bool { for _, event := range state { processing := false if event == nil || - event.Job.Status == ffs.Executing || - event.Job.Status == ffs.Queued { + event.Res.Job.Status == rpc.JobStatus_JOB_STATUS_EXECUTING || + event.Res.Job.Status == rpc.JobStatus_JOB_STATUS_QUEUED { processing = true } if processing && event != nil && event.Err == nil { @@ -131,8 +122,8 @@ func jobsComplete(state map[string]*client.JobEvent) bool { return true } -func displayName(s ffs.JobStatus) string { - name, ok := ffs.JobStatusStr[s] +func displayName(s rpc.JobStatus) string { + name, ok := rpc.JobStatus_name[int32(s)] if !ok { return "Unknown" } diff --git a/cmd/pow/cmd/health.go b/cmd/pow/cmd/health.go index ff874ab66..4527a9304 100644 --- a/cmd/pow/cmd/health.go +++ b/cmd/pow/cmd/health.go @@ -2,11 +2,11 @@ package cmd import ( "context" - "os" + "fmt" - "github.com/caarlos0/spin" "github.com/spf13/cobra" "github.com/spf13/viper" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -25,19 +25,12 @@ var healthCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - s := spin.New("%s Checking node health...") - s.Start() - status, messages, err := fcClient.Health.Check(ctx) - s.Stop() + res, err := fcClient.Health.Check(ctx) checkErr(err) - Success("Health status: %v", status.String()) - if len(messages) > 0 { - rows := make([][]string, len(messages)) - for i, message := range messages { - rows[i] = []string{message} - } - RenderTable(os.Stdout, []string{"messages"}, rows) - } + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) + checkErr(err) + + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/helpers.go b/cmd/pow/cmd/helpers.go index 95130f7f1..ac2037a43 100644 --- a/cmd/pow/cmd/helpers.go +++ b/cmd/pow/cmd/helpers.go @@ -64,10 +64,7 @@ func mustAuthCtx(ctx context.Context) context.Context { return context.WithValue(ctx, client.AuthKey, token) } -func mustAdminAuthCtx(ctx context.Context) context.Context { +func adminAuthCtx(ctx context.Context) context.Context { token := viper.GetString("admin-token") - if token == "" { - Fatal(errors.New("must provide --admin-token")) - } return context.WithValue(ctx, client.AdminKey, token) } diff --git a/cmd/pow/cmd/miners_get.go b/cmd/pow/cmd/miners_get.go index dae0adb98..4e55d8068 100644 --- a/cmd/pow/cmd/miners_get.go +++ b/cmd/pow/cmd/miners_get.go @@ -3,13 +3,10 @@ package cmd import ( "context" "fmt" - "os" - "strconv" - "time" - "github.com/caarlos0/spin" "github.com/logrusorgru/aurora" "github.com/spf13/cobra" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -24,57 +21,15 @@ var getMinersCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - s := spin.New("%s Getting miners data...") - s.Start() - index, err := fcClient.Miners.Get(ctx) - s.Stop() + res, err := fcClient.Miners.Get(ctx) checkErr(err) - Message("%v", aurora.Blue("Miner metadata:").Bold()) - cmd.Println() - - Message("%v miners online", aurora.White(index.Meta.Online).Bold()) - Message("%v miners offline", aurora.White(index.Meta.Offline).Bold()) - cmd.Println() - - data := make([][]string, len(index.Meta.Info)) - i := 0 - for id, meta := range index.Meta.Info { - data[i] = []string{ - id, - meta.UserAgent, - meta.Location.Country, - fmt.Sprintf("%v", meta.Online), - meta.LastUpdated.Format("01/02/06 15:04 MST"), - } - i++ - } - RenderTable(os.Stdout, []string{"miner", "user agent", "location", "online", "last updated"}, data) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) + checkErr(err) - Message("Found metadata for %d miners", aurora.White(len(index.Meta.Info)).Bold()) - cmd.Println() + fmt.Println(string(json)) - Message("%v", aurora.Blue("Miner on chain data:").Bold()) + Message("%v", aurora.Blue("Miner metadata:").Bold()) cmd.Println() - - chainData := make([][]string, len(index.OnChain.Miners)) - i = 0 - for id, minerData := range index.OnChain.Miners { - chainData[i] = []string{ - id, - strconv.Itoa(int(minerData.Power)), - strconv.Itoa(int(minerData.RelativePower)), - strconv.Itoa(int(minerData.SectorSize)), - strconv.Itoa(int(minerData.ActiveDeals)), - } - i++ - } - - RenderTable(os.Stdout, []string{"miner", "power", "relativePower", "sectorSize", "activeDeals"}, chainData) - - lastUpdated := time.Unix(index.OnChain.LastUpdated, 0).Format("01/02/06 15:04 MST") - - Message("Found on chain data for %d miners", aurora.White(len(index.OnChain.Miners)).Bold()) - Message("Chain data last updated %v", aurora.White(lastUpdated).Bold()) }, } diff --git a/cmd/pow/cmd/net_addr.go b/cmd/pow/cmd/net_addr.go index c4f8d5242..4ec0bc35a 100644 --- a/cmd/pow/cmd/net_addr.go +++ b/cmd/pow/cmd/net_addr.go @@ -2,10 +2,10 @@ package cmd import ( "context" - "encoding/json" + "fmt" - "github.com/caarlos0/spin" "github.com/spf13/cobra" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -20,15 +20,12 @@ var netListenAddrCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - s := spin.New("%s Getting listen address...") - s.Start() - addrInfo, err := fcClient.Net.ListenAddr(ctx) - s.Stop() + res, err := fcClient.Net.ListenAddr(ctx) checkErr(err) - bytes, err := json.MarshalIndent(addrInfo, "", " ") + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res.AddrInfo) checkErr(err) - Success(string(bytes)) + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/net_connectedness.go b/cmd/pow/cmd/net_connectedness.go index b7f44accc..7309fc40c 100644 --- a/cmd/pow/cmd/net_connectedness.go +++ b/cmd/pow/cmd/net_connectedness.go @@ -2,11 +2,10 @@ package cmd import ( "context" - "errors" + "fmt" - "github.com/caarlos0/spin" - "github.com/libp2p/go-libp2p-core/peer" "github.com/spf13/cobra" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -17,24 +16,17 @@ var netConnectednessCmd = &cobra.Command{ Use: "connectedness [peerID]", Short: "Check connectedness to a specified peer", Long: `Check connectedness to a specified peer`, + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - if len(args) != 1 { - Fatal(errors.New("you must provide a peer id argument")) - } - - peerID, err := peer.Decode(args[0]) + res, err := fcClient.Net.Connectedness(ctx, args[0]) checkErr(err) - s := spin.New("%s Checking connectedness to peer...") - s.Start() - checkErr(err) - connectedness, err := fcClient.Net.Connectedness(ctx, peerID) - s.Stop() + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) - Success("Connectedness: %v", connectedness.String()) + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/net_find.go b/cmd/pow/cmd/net_find.go index a8576e0d8..2dc6af317 100644 --- a/cmd/pow/cmd/net_find.go +++ b/cmd/pow/cmd/net_find.go @@ -2,12 +2,10 @@ package cmd import ( "context" - "encoding/json" - "errors" + "fmt" - "github.com/caarlos0/spin" - "github.com/libp2p/go-libp2p-core/peer" "github.com/spf13/cobra" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -18,25 +16,17 @@ var netFindCmd = &cobra.Command{ Use: "find [peerID]", Short: "Find a peer by peer id", Long: `Find a peer by peer id`, + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - if len(args) != 1 { - Fatal(errors.New("you must provide a peer id argument")) - } - - s := spin.New("%s Finding peer...") - s.Start() - peerID, err := peer.Decode(args[0]) - checkErr(err) - peerInfo, err := fcClient.Net.FindPeer(ctx, peerID) - s.Stop() + res, err := fcClient.Net.FindPeer(ctx, args[0]) checkErr(err) - bytes, err := json.MarshalIndent(peerInfo, "", " ") + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res.PeerInfo) checkErr(err) - Success(string(bytes)) + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/net_peers.go b/cmd/pow/cmd/net_peers.go index 5ec5dc93e..19723035e 100644 --- a/cmd/pow/cmd/net_peers.go +++ b/cmd/pow/cmd/net_peers.go @@ -2,10 +2,10 @@ package cmd import ( "context" - "encoding/json" + "fmt" - "github.com/caarlos0/spin" "github.com/spf13/cobra" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -20,15 +20,12 @@ var netPeersCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - s := spin.New("%s Getting peers...") - s.Start() - peers, err := fcClient.Net.Peers(ctx) - s.Stop() + res, err := fcClient.Net.Peers(ctx) checkErr(err) - bytes, err := json.MarshalIndent(peers, "", " ") + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) - Success(string(bytes)) + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/reputation_add_source.go b/cmd/pow/cmd/reputation_add_source.go index 870350e35..a0dfcf49e 100644 --- a/cmd/pow/cmd/reputation_add_source.go +++ b/cmd/pow/cmd/reputation_add_source.go @@ -4,8 +4,6 @@ import ( "context" "errors" - "github.com/caarlos0/spin" - ma "github.com/multiformats/go-multiaddr" "github.com/spf13/cobra" ) @@ -35,15 +33,7 @@ var addSourceCmd = &cobra.Command{ Fatal(errors.New("must provide a miner address")) } - maddr, err := ma.NewMultiaddr(address) + _, err := fcClient.Reputation.AddSource(ctx, id, address) checkErr(err) - - s := spin.New("%s Adding source...") - s.Start() - err = fcClient.Reputation.AddSource(ctx, id, maddr) - s.Stop() - checkErr(err) - - Success("Source added") }, } diff --git a/cmd/pow/cmd/reputation_top_miners.go b/cmd/pow/cmd/reputation_top_miners.go index f57e2bf73..17a1743e0 100644 --- a/cmd/pow/cmd/reputation_top_miners.go +++ b/cmd/pow/cmd/reputation_top_miners.go @@ -2,16 +2,14 @@ package cmd import ( "context" - "os" - "strconv" + "fmt" - "github.com/caarlos0/spin" - "github.com/logrusorgru/aurora" "github.com/spf13/cobra" + "google.golang.org/protobuf/encoding/protojson" ) func init() { - topMinersCmd.Flags().IntP("limit", "l", -1, "limit the number of results") + topMinersCmd.Flags().Int32P("limit", "l", -1, "limit the number of results") reputationCmd.AddCommand(topMinersCmd) } @@ -24,25 +22,15 @@ var topMinersCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - limit, err := cmd.Flags().GetInt("limit") + limit, err := cmd.Flags().GetInt32("limit") checkErr(err) - s := spin.New("%s Fetching top miners...") - s.Start() - topMiners, err := fcClient.Reputation.GetTopMiners(ctx, limit) - s.Stop() + res, err := fcClient.Reputation.GetTopMiners(ctx, limit) checkErr(err) - data := make([][]string, len(topMiners)) - for i, minerScore := range topMiners { - data[i] = []string{ - minerScore.Addr, - strconv.Itoa(minerScore.Score), - } - } - - RenderTable(os.Stdout, []string{"miner", "score"}, data) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) + checkErr(err) - Message("Showing data for %d miners", aurora.White(len(topMiners)).Bold()) + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/wallet_balance.go b/cmd/pow/cmd/wallet_balance.go index 43b027273..fb67f7b83 100644 --- a/cmd/pow/cmd/wallet_balance.go +++ b/cmd/pow/cmd/wallet_balance.go @@ -4,9 +4,9 @@ import ( "context" "fmt" - "github.com/caarlos0/spin" "github.com/spf13/cobra" "github.com/spf13/viper" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -17,23 +17,21 @@ var balanceCmd = &cobra.Command{ Use: "balance [address]", Short: "Print the balance of the specified wallet address", Long: `Print the balance of the specified wallet address`, + Args: cobra.ExactArgs(1), PreRun: func(cmd *cobra.Command, args []string) { err := viper.BindPFlags(cmd.Flags()) checkErr(err) }, - Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - addr := args[0] + res, err := fcClient.Wallet.Balance(ctx, args[0]) + checkErr(err) - s := spin.New(fmt.Sprintf("%s Checking balance for %s...", "%s", addr)) - s.Start() - bal, err := fcClient.Wallet.Balance(ctx, addr) - s.Stop() + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) checkErr(err) - Success("Balance: %v", bal) + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/wallet_list.go b/cmd/pow/cmd/wallet_list.go index 0fbc5770e..9c7dd0f22 100644 --- a/cmd/pow/cmd/wallet_list.go +++ b/cmd/pow/cmd/wallet_list.go @@ -3,11 +3,10 @@ package cmd import ( "context" "fmt" - "os" - "github.com/caarlos0/spin" "github.com/spf13/cobra" "github.com/spf13/viper" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -26,17 +25,12 @@ var listCmd = &cobra.Command{ ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout) defer cancel() - s := spin.New(fmt.Sprintf("%s Getting wallet addresses...", "%s")) - s.Start() - addrs, err := fcClient.Wallet.List(ctx) - s.Stop() + res, err := fcClient.Wallet.List(ctx) checkErr(err) - data := make([][]string, len(addrs)) - for i, addr := range addrs { - data[i] = []string{addr} - } + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) + checkErr(err) - RenderTable(os.Stdout, []string{"address"}, data) + fmt.Println(string(json)) }, } diff --git a/cmd/pow/cmd/wallet_new.go b/cmd/pow/cmd/wallet_new.go index 49b72b3f3..a9cca5c75 100644 --- a/cmd/pow/cmd/wallet_new.go +++ b/cmd/pow/cmd/wallet_new.go @@ -2,10 +2,11 @@ package cmd import ( "context" + "fmt" - "github.com/caarlos0/spin" "github.com/spf13/cobra" "github.com/spf13/viper" + "google.golang.org/protobuf/encoding/protojson" ) func init() { @@ -28,12 +29,12 @@ var newCmd = &cobra.Command{ typ, err := cmd.Flags().GetString("type") checkErr(err) - s := spin.New("%s Creating new wallet address...") - s.Start() - address, err := fcClient.Wallet.NewAddress(ctx, typ) - s.Stop() + res, err := fcClient.Wallet.NewAddress(ctx, typ) checkErr(err) - Success("Wallet address: %v", address) + json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res) + checkErr(err) + + fmt.Println(string(json)) }, } diff --git a/cmd/powbench/runner/runner.go b/cmd/powbench/runner/runner.go index d12fa8fb1..000b8d6b4 100644 --- a/cmd/powbench/runner/runner.go +++ b/cmd/powbench/runner/runner.go @@ -9,8 +9,8 @@ import ( logging "github.com/ipfs/go-log/v2" "github.com/textileio/powergate/api/client" - "github.com/textileio/powergate/ffs" - "github.com/textileio/powergate/health" + ffsRpc "github.com/textileio/powergate/ffs/rpc" + healthRpc "github.com/textileio/powergate/health/rpc" "github.com/textileio/powergate/util" ) @@ -52,12 +52,12 @@ func Run(ctx context.Context, ts TestSetup) error { } func sanityCheck(ctx context.Context, c *client.Client) error { - s, _, err := c.Health.Check(ctx) + res, err := c.Health.Check(ctx) if err != nil { return fmt.Errorf("health check call: %s", err) } - if s != health.Ok { - return fmt.Errorf("reported health check not Ok: %s", s) + if res.Status != healthRpc.Status_STATUS_OK { + return fmt.Errorf("reported health check not Ok: %s", res.Status.String()) } return nil } @@ -103,65 +103,65 @@ func run(ctx context.Context, c *client.Client, id int, seed int, size int64, ad lr := io.LimitReader(ra, size) log.Infof("[%d] Adding to hot layer...", id) - ci, err := c.FFS.Stage(ctx, lr) + statgeRes, err := c.FFS.Stage(ctx, lr) if err != nil { return fmt.Errorf("importing data to hot storage (ipfs node): %s", err) } - log.Infof("[%d] Pushing %s to FFS...", id, *ci) + log.Infof("[%d] Pushing %s to FFS...", id, statgeRes.Cid) // For completeness, fields that could be relied on defaults // are explicitly kept here to have a better idea about their // existence. // This configuration will stop being static when we incorporate // other test cases. - storageConfig := ffs.StorageConfig{ + storageConfig := &ffsRpc.StorageConfig{ Repairable: false, - Hot: ffs.HotConfig{ + Hot: &ffsRpc.HotConfig{ Enabled: true, AllowUnfreeze: false, UnfreezeMaxPrice: 0, - Ipfs: ffs.IpfsConfig{ + Ipfs: &ffsRpc.IpfsConfig{ AddTimeout: 30, }, }, - Cold: ffs.ColdConfig{ + Cold: &ffsRpc.ColdConfig{ Enabled: true, - Filecoin: ffs.FilConfig{ + Filecoin: &ffsRpc.FilConfig{ RepFactor: 1, DealMinDuration: util.MinDealDuration, Addr: addr, CountryCodes: nil, ExcludedMiners: nil, TrustedMiners: []string{minerAddr}, - Renew: ffs.FilRenew{}, + Renew: &ffsRpc.FilRenew{}, }, }, } - jid, err := c.FFS.PushStorageConfig(ctx, *ci, client.WithStorageConfig(storageConfig)) + pushRes, err := c.FFS.PushStorageConfig(ctx, statgeRes.Cid, client.WithStorageConfig(storageConfig)) if err != nil { return fmt.Errorf("pushing to FFS: %s", err) } - log.Infof("[%d] Pushed successfully, queued job %s. Waiting for termination...", id, jid) - chJob := make(chan client.JobEvent, 1) + log.Infof("[%d] Pushed successfully, queued job %s. Waiting for termination...", id, pushRes.JobId) + chJob := make(chan client.WatchJobsEvent, 1) ctxWatch, cancel := context.WithCancel(ctx) defer cancel() - err = c.FFS.WatchJobs(ctxWatch, chJob, jid) + err = c.FFS.WatchJobs(ctxWatch, chJob, pushRes.JobId) if err != nil { return fmt.Errorf("opening listening job status: %s", err) } - var s client.JobEvent + var s client.WatchJobsEvent for s = range chJob { if s.Err != nil { return fmt.Errorf("job watching: %s", s.Err) } - log.Infof("[%d] Job changed to status %s", id, ffs.JobStatusStr[s.Job.Status]) - if s.Job.Status == ffs.Failed || s.Job.Status == ffs.Canceled { + log.Infof("[%d] Job changed to status %s", id, s.Res.Job.Status.String()) + if s.Res.Job.Status == ffsRpc.JobStatus_JOB_STATUS_FAILED || s.Res.Job.Status == ffsRpc.JobStatus_JOB_STATUS_CANCELED { return fmt.Errorf("job execution failed or was canceled") } - if s.Job.Status == ffs.Success { + if s.Res.Job.Status == ffsRpc.JobStatus_JOB_STATUS_SUCCESS { return nil } } diff --git a/cmd/powbench/runner/runner_test.go b/cmd/powbench/runner/runner_test.go index 3aef0d2e1..84bb1c46f 100644 --- a/cmd/powbench/runner/runner_test.go +++ b/cmd/powbench/runner/runner_test.go @@ -10,7 +10,7 @@ import ( logging "github.com/ipfs/go-log/v2" "github.com/stretchr/testify/require" "github.com/textileio/powergate/api/client" - "github.com/textileio/powergate/health" + "github.com/textileio/powergate/health/rpc" ) var ( @@ -77,9 +77,9 @@ func spinup(t *testing.T) *client.Client { require.NoError(t, err) ctx, cancel := context.WithTimeout(context.Background(), time.Second*3) defer cancel() - s, _, err := c.Health.Check(ctx) + res, err := c.Health.Check(ctx) if err == nil { - require.Equal(t, health.Ok, s) + require.Equal(t, rpc.Status_STATUS_OK, res.Status) break } time.Sleep(time.Second) diff --git a/ffs/rpc/rpc.proto b/ffs/rpc/rpc.proto index 09b1ebb0b..8e8d57722 100644 --- a/ffs/rpc/rpc.proto +++ b/ffs/rpc/rpc.proto @@ -401,13 +401,13 @@ message GetResponse { bytes chunk = 1; } -message SendFilRequest { - string from = 1; - string to = 2; - int64 amount = 3; -} +message SendFilRequest { + string from = 1; + string to = 2; + int64 amount = 3; +} -message SendFilResponse { +message SendFilResponse { } message StageRequest { diff --git a/go.mod b/go.mod index 3a8961ce0..277e1fef3 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,6 @@ require ( github.com/ipfs/interface-go-ipfs-core v0.4.0 github.com/ipld/go-car v0.1.1-0.20200923150018-8cdef32e2da4 github.com/jessevdk/go-assets v0.0.0-20160921144138-4f4301a06e15 - github.com/kyokomi/emoji v2.2.4+incompatible github.com/libp2p/go-libp2p v0.11.0 github.com/libp2p/go-libp2p-core v0.6.1 github.com/libp2p/go-libp2p-kad-dht v0.8.3 diff --git a/go.sum b/go.sum index 6e6119510..29cc4bb3c 100644 --- a/go.sum +++ b/go.sum @@ -858,8 +858,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kyokomi/emoji v2.2.4+incompatible h1:np0woGKwx9LiHAQmwZx79Oc0rHpNw3o+3evou4BEPv4= -github.com/kyokomi/emoji v2.2.4+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA= github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=