Skip to content

Commit

Permalink
rename imported protobuf package name (#64)
Browse files Browse the repository at this point in the history
Co-authored-by: DylanYong <dylan.y@nodereal.io>
  • Loading branch information
sysvm and yzhaoyu authored Jan 31, 2023
1 parent 4b61d32 commit a3602b3
Show file tree
Hide file tree
Showing 38 changed files with 345 additions and 342 deletions.
20 changes: 10 additions & 10 deletions mock/inscription_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"sync"

types "github.com/bnb-chain/greenfield-storage-provider/pkg/types/v1"
ptypesv1pb "github.com/bnb-chain/greenfield-storage-provider/pkg/types/v1"
)

var (
Expand All @@ -20,8 +20,8 @@ type ChainEvent struct {

// InscriptionChainMock mock the inscription chain
type InscriptionChainMock struct {
objectByHash map[string]*types.ObjectInfo
objectByName map[string]*types.ObjectInfo
objectByHash map[string]*ptypesv1pb.ObjectInfo
objectByName map[string]*ptypesv1pb.ObjectInfo
events map[string][]chan interface{}
notifyCh chan *ChainEvent
stopCh chan struct{}
Expand All @@ -33,8 +33,8 @@ type InscriptionChainMock struct {
// NewInscriptionChainMock return the InscriptionChainMock instance
func NewInscriptionChainMock() *InscriptionChainMock {
cli := &InscriptionChainMock{
objectByHash: make(map[string]*types.ObjectInfo),
objectByName: make(map[string]*types.ObjectInfo),
objectByHash: make(map[string]*ptypesv1pb.ObjectInfo),
objectByName: make(map[string]*ptypesv1pb.ObjectInfo),
events: make(map[string][]chan interface{}),
notifyCh: make(chan *ChainEvent, 10),
stopCh: make(chan struct{}),
Expand Down Expand Up @@ -87,7 +87,7 @@ func (cli *InscriptionChainMock) eventLoop() {
}

// QueryObjectByTx return the object info by create object tx hash.
func (cli *InscriptionChainMock) QueryObjectByTx(txHash []byte) (*types.ObjectInfo, error) {
func (cli *InscriptionChainMock) QueryObjectByTx(txHash []byte) (*ptypesv1pb.ObjectInfo, error) {
cli.mu.Lock()
defer cli.mu.Unlock()
obj, ok := cli.objectByHash[string(txHash)]
Expand All @@ -98,7 +98,7 @@ func (cli *InscriptionChainMock) QueryObjectByTx(txHash []byte) (*types.ObjectIn
}

// QueryObjectByName return the object info by create object bucketName/objectName.
func (cli *InscriptionChainMock) QueryObjectByName(name string) (*types.ObjectInfo, error) {
func (cli *InscriptionChainMock) QueryObjectByName(name string) (*ptypesv1pb.ObjectInfo, error) {
cli.mu.Lock()
defer cli.mu.Unlock()
obj, ok := cli.objectByName[name]
Expand All @@ -109,7 +109,7 @@ func (cli *InscriptionChainMock) QueryObjectByName(name string) (*types.ObjectIn
}

// CreateObjectByTxHash create the object info on the mock inscription chain.
func (cli *InscriptionChainMock) CreateObjectByTxHash(txHash []byte, object *types.ObjectInfo) {
func (cli *InscriptionChainMock) CreateObjectByTxHash(txHash []byte, object *ptypesv1pb.ObjectInfo) {
cli.mu.Lock()
defer cli.mu.Unlock()
cli.objectID++
Expand All @@ -127,7 +127,7 @@ func (cli *InscriptionChainMock) CreateObjectByTxHash(txHash []byte, object *typ
}

// CreateObjectByName create the object info on the mock inscription chain.
func (cli *InscriptionChainMock) CreateObjectByName(txHash []byte, object *types.ObjectInfo) {
func (cli *InscriptionChainMock) CreateObjectByName(txHash []byte, object *ptypesv1pb.ObjectInfo) {
cli.mu.Lock()
defer cli.mu.Unlock()
cli.objectID++
Expand All @@ -140,7 +140,7 @@ func (cli *InscriptionChainMock) CreateObjectByName(txHash []byte, object *types
}

// SealObjectByTxHash seal the object on the mock inscription chain.
func (cli *InscriptionChainMock) SealObjectByTxHash(txHash []byte, object *types.ObjectInfo) {
func (cli *InscriptionChainMock) SealObjectByTxHash(txHash []byte, object *ptypesv1pb.ObjectInfo) {
cli.mu.Lock()
defer cli.mu.Unlock()
object.TxHash = txHash
Expand Down
6 changes: 3 additions & 3 deletions mock/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mock
import (
"time"

types "github.com/bnb-chain/greenfield-storage-provider/pkg/types/v1"
ptypesv1pb "github.com/bnb-chain/greenfield-storage-provider/pkg/types/v1"
"github.com/bnb-chain/greenfield-storage-provider/util/hash"
)

Expand All @@ -20,7 +20,7 @@ func NewSignerServerMock(chain *InscriptionChainMock) *SignerServerMock {
}

// BroadcastCreateObjectMessage mock broadcast create object message to inscription chain
func (signer *SignerServerMock) BroadcastCreateObjectMessage(object *types.ObjectInfo) []byte {
func (signer *SignerServerMock) BroadcastCreateObjectMessage(object *ptypesv1pb.ObjectInfo) []byte {
txHash := hash.GenerateChecksum([]byte(time.Now().String()))
go func() {
time.Sleep(1 * time.Second)
Expand All @@ -30,7 +30,7 @@ func (signer *SignerServerMock) BroadcastCreateObjectMessage(object *types.Objec
}

// BroadcastSealObjectMessage mock broadcast seal object message to inscription chain
func (signer *SignerServerMock) BroadcastSealObjectMessage(object *types.ObjectInfo) []byte {
func (signer *SignerServerMock) BroadcastSealObjectMessage(object *ptypesv1pb.ObjectInfo) []byte {
txHash := hash.GenerateChecksum([]byte(time.Now().String()))
go func() {
time.Sleep(1 * time.Second)
Expand Down
8 changes: 4 additions & 4 deletions model/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package errors
import (
"errors"

service "github.com/bnb-chain/greenfield-storage-provider/service/types/v1"
stypesv1pb "github.com/bnb-chain/greenfield-storage-provider/service/types/v1"
)

// piece store errors
Expand Down Expand Up @@ -66,9 +66,9 @@ var (
ErrReceivedPieceCount = errors.New("syncer service received piece count is wrong")
)

func MakeErrMsgResponse(err error) *service.ErrMessage {
return &service.ErrMessage{
ErrCode: service.ErrCode_ERR_CODE_ERROR,
func MakeErrMsgResponse(err error) *stypesv1pb.ErrMessage {
return &stypesv1pb.ErrMessage{
ErrCode: stypesv1pb.ErrCode_ERR_CODE_ERROR,
ErrMsg: err.Error(),
}
}
10 changes: 5 additions & 5 deletions model/piecestore/piece_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"

merrors "github.com/bnb-chain/greenfield-storage-provider/model/errors"
types "github.com/bnb-chain/greenfield-storage-provider/pkg/types/v1"
ptypesv1pb "github.com/bnb-chain/greenfield-storage-provider/pkg/types/v1"
"github.com/bnb-chain/greenfield-storage-provider/util/log"
)

Expand Down Expand Up @@ -35,13 +35,13 @@ func DecodeSegmentPieceKey(pieceKey string) (uint64, uint32, error) {
}

// EncodePieceKey encodes piece store key
func EncodePieceKey(rType types.RedundancyType, objectId uint64, segmentIndex, pieceIndex uint32) (string, error) {
func EncodePieceKey(rType ptypesv1pb.RedundancyType, objectId uint64, segmentIndex, pieceIndex uint32) (string, error) {
var pieceKey string
if rType == types.RedundancyType_REDUNDANCY_TYPE_EC_TYPE_UNSPECIFIED {
if rType == ptypesv1pb.RedundancyType_REDUNDANCY_TYPE_EC_TYPE_UNSPECIFIED {
pieceKey = EncodeECPieceKey(objectId, segmentIndex, pieceIndex)
} else if rType == types.RedundancyType_REDUNDANCY_TYPE_REPLICA_TYPE {
} else if rType == ptypesv1pb.RedundancyType_REDUNDANCY_TYPE_REPLICA_TYPE {
pieceKey = EncodeSegmentPieceKey(objectId, pieceIndex)
} else if rType == types.RedundancyType_REDUNDANCY_TYPE_INLINE_TYPE {
} else if rType == ptypesv1pb.RedundancyType_REDUNDANCY_TYPE_INLINE_TYPE {
pieceKey = EncodeSegmentPieceKey(objectId, pieceIndex)
} else {
return "", merrors.ErrRedundancyType
Expand Down
4 changes: 2 additions & 2 deletions service/challenge/challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/bnb-chain/greenfield-storage-provider/model"
"github.com/bnb-chain/greenfield-storage-provider/service/client"
service "github.com/bnb-chain/greenfield-storage-provider/service/types/v1"
stypesv1pb "github.com/bnb-chain/greenfield-storage-provider/service/types/v1"
"github.com/bnb-chain/greenfield-storage-provider/store/metadb"
"github.com/bnb-chain/greenfield-storage-provider/store/metadb/leveldb"
"github.com/bnb-chain/greenfield-storage-provider/util/log"
Expand Down Expand Up @@ -73,7 +73,7 @@ func (challenge *Challenge) Start(ctx context.Context) error {
return
}
grpcServer := grpc.NewServer()
service.RegisterChallengeServiceServer(grpcServer, challenge)
stypesv1pb.RegisterChallengeServiceServer(grpcServer, challenge)
reflection.Register(grpcServer)
if err = grpcServer.Serve(lis); err != nil {
log.Errorw("syncer serve failed", "error", err)
Expand Down
9 changes: 5 additions & 4 deletions service/challenge/challenge_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ import (
"errors"

"github.com/bnb-chain/greenfield-storage-provider/model/piecestore"
service "github.com/bnb-chain/greenfield-storage-provider/service/types/v1"
stypesv1pb "github.com/bnb-chain/greenfield-storage-provider/service/types/v1"
"github.com/bnb-chain/greenfield-storage-provider/store/metadb"
"github.com/bnb-chain/greenfield-storage-provider/util/log"
)

// ChallengePiece implement challenge service server interface and handle the grpc request.
func (challenge *Challenge) ChallengePiece(ctx context.Context, req *service.ChallengeServiceChallengePieceRequest) (resp *service.ChallengeServiceChallengePieceResponse, err error) {
func (challenge *Challenge) ChallengePiece(ctx context.Context, req *stypesv1pb.ChallengeServiceChallengePieceRequest) (
resp *stypesv1pb.ChallengeServiceChallengePieceResponse, err error) {
ctx = log.Context(ctx, req)
resp = &service.ChallengeServiceChallengePieceResponse{
resp = &stypesv1pb.ChallengeServiceChallengePieceResponse{
TraceId: req.TraceId,
ObjectId: req.ObjectId,
}
defer func() {
if err != nil {
resp.ErrMessage.ErrCode = service.ErrCode_ERR_CODE_ERROR
resp.ErrMessage.ErrCode = stypesv1pb.ErrCode_ERR_CODE_ERROR
resp.ErrMessage.ErrMsg = err.Error()
log.CtxErrorw(ctx, "change failed", "error", err)
}
Expand Down
14 changes: 8 additions & 6 deletions service/client/downloader_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

service "github.com/bnb-chain/greenfield-storage-provider/service/types/v1"
stypesv1pb "github.com/bnb-chain/greenfield-storage-provider/service/types/v1"
"github.com/bnb-chain/greenfield-storage-provider/util/log"
)

type DownloaderClient struct {
address string
downloader service.DownloaderServiceClient
downloader stypesv1pb.DownloaderServiceClient
conn *grpc.ClientConn
}

Expand All @@ -29,7 +29,7 @@ func NewDownloaderClient(address string) (*DownloaderClient, error) {
client := &DownloaderClient{
address: address,
conn: conn,
downloader: service.NewDownloaderServiceClient(conn),
downloader: stypesv1pb.NewDownloaderServiceClient(conn),
}
return client, nil
}
Expand All @@ -38,19 +38,21 @@ func (client *DownloaderClient) Close() error {
return client.conn.Close()
}

func (client *DownloaderClient) DownloaderObject(ctx context.Context, req *service.DownloaderServiceDownloaderObjectRequest, opts ...grpc.CallOption) (service.DownloaderService_DownloaderObjectClient, error) {
func (client *DownloaderClient) DownloaderObject(ctx context.Context, req *stypesv1pb.DownloaderServiceDownloaderObjectRequest,
opts ...grpc.CallOption) (stypesv1pb.DownloaderService_DownloaderObjectClient, error) {
ctx = log.Context(context.Background(), req)
return client.downloader.DownloaderObject(ctx, req, opts...)
}

func (client *DownloaderClient) DownloaderSegment(ctx context.Context, in *service.DownloaderServiceDownloaderSegmentRequest, opts ...grpc.CallOption) (*service.DownloaderServiceDownloaderSegmentResponse, error) {
func (client *DownloaderClient) DownloaderSegment(ctx context.Context, in *stypesv1pb.DownloaderServiceDownloaderSegmentRequest,
opts ...grpc.CallOption) (*stypesv1pb.DownloaderServiceDownloaderSegmentResponse, error) {
resp, err := client.downloader.DownloaderSegment(ctx, in, opts...)
ctx = log.Context(ctx, resp)
if err != nil {
log.CtxErrorw(ctx, "downloader segment failed", "error", err)
return nil, err
}
if resp.GetErrMessage() != nil && resp.GetErrMessage().GetErrCode() != service.ErrCode_ERR_CODE_SUCCESS_UNSPECIFIED {
if resp.GetErrMessage() != nil && resp.GetErrMessage().GetErrCode() != stypesv1pb.ErrCode_ERR_CODE_SUCCESS_UNSPECIFIED {
log.CtxErrorw(ctx, "downloader segment response code is not success", "error", resp.GetErrMessage().GetErrMsg())
return nil, errors.New(resp.GetErrMessage().GetErrMsg())
}
Expand Down
Loading

0 comments on commit a3602b3

Please sign in to comment.