Skip to content

Commit

Permalink
fix: cli
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniFrenchBread committed Jul 15, 2024
1 parent 51adf91 commit e0e9c7a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
4 changes: 1 addition & 3 deletions cmd/kv_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"math"
"os"

zg_common "github.com/0glabs/0g-storage-client/common"
"github.com/0glabs/0g-storage-client/common/blockchain"
Expand All @@ -14,7 +13,6 @@ import (
"github.com/0glabs/0g-storage-client/node"
"github.com/0glabs/0g-storage-client/transfer"
"github.com/ethereum/go-ethereum/common"
providers "github.com/openweb3/go-rpc-provider/provider_wrapper"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -95,7 +93,7 @@ func kvWrite(*cobra.Command, []string) {

var clients []*node.Client
if kvWriteArgs.indexer != "" {
indexerClient, err := indexer.NewClient(kvWriteArgs.indexer, providers.Option{Logger: os.Stderr})
indexerClient, err := indexer.NewClient(kvWriteArgs.indexer, indexer.IndexerClientOption{LogOption: zg_common.LogOption{Logger: logrus.StandardLogger()}})
if err != nil {
logrus.WithError(err).Fatal("Failed to initialize indexer client")
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"context"
"os"

zg_common "github.com/0glabs/0g-storage-client/common"
"github.com/0glabs/0g-storage-client/common/blockchain"
Expand All @@ -13,7 +12,6 @@ import (
"github.com/0glabs/0g-storage-client/transfer"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
providers "github.com/openweb3/go-rpc-provider/provider_wrapper"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -92,7 +90,7 @@ func upload(*cobra.Command, []string) {
defer file.Close()

if uploadArgs.indexer != "" {
indexerClient, err := indexer.NewClient(uploadArgs.indexer, providers.Option{Logger: os.Stderr})
indexerClient, err := indexer.NewClient(uploadArgs.indexer, indexer.IndexerClientOption{LogOption: zg_common.LogOption{Logger: logrus.StandardLogger()}})
if err != nil {
logrus.WithError(err).Fatal("Failed to initialize indexer client")
}
Expand Down
24 changes: 13 additions & 11 deletions indexer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,35 @@ import (
"github.com/openweb3/go-rpc-provider/interfaces"
providers "github.com/openweb3/go-rpc-provider/provider_wrapper"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

// Requires `Client` implements the `Interface` interface.
var _ Interface = (*Client)(nil)

type Client struct {
interfaces.Provider
providerOption providers.Option
option IndexerClientOption
}

func NewClient(url string, option ...providers.Option) (*Client, error) {
var opt providers.Option
type IndexerClientOption struct {
ProviderOption providers.Option
LogOption common.LogOption
}

func NewClient(url string, option ...IndexerClientOption) (*Client, error) {
var opt IndexerClientOption
if len(option) > 0 {
opt = option[0]
}

provider, err := providers.NewProviderWithOption(url, opt)
provider, err := providers.NewProviderWithOption(url, opt.ProviderOption)
if err != nil {
return nil, err
}

return &Client{
Provider: provider,
providerOption: opt,
Provider: provider,
option: opt,
}, nil
}

Expand All @@ -58,7 +62,7 @@ func (c *Client) SelectNodes(ctx context.Context, expectedReplica uint) ([]*node
}
clients := make([]*node.Client, len(nodes))
for i, shardedNode := range nodes {
clients[i], err = node.NewClient(shardedNode.URL, c.providerOption)
clients[i], err = node.NewClient(shardedNode.URL, c.option.ProviderOption)
if err != nil {
return nil, errors.WithMessage(err, fmt.Sprintf("failed to initialize storage node client with %v", shardedNode.URL))
}
Expand All @@ -71,9 +75,7 @@ func (c *Client) NewUploaderFromIndexerNodes(ctx context.Context, flow *contract
if err != nil {
return nil, err
}
logger := logrus.New()
logger.Out = c.providerOption.Logger
return transfer.NewUploader(flow, clients, common.LogOption{Logger: logger})
return transfer.NewUploader(flow, clients, c.option.LogOption)
}

func (c *Client) Upload(ctx context.Context, flow *contract.FlowContract, data core.IterableData, option ...transfer.UploadOption) error {
Expand Down

0 comments on commit e0e9c7a

Please sign in to comment.