2020-03-29 21:32:01 +08:00
|
|
|
package grpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-04-15 10:37:47 +08:00
|
|
|
"errors"
|
2020-10-23 15:29:47 +08:00
|
|
|
"fmt"
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2021-04-15 10:37:47 +08:00
|
|
|
"github.com/meshplus/bitxhub-kit/storage"
|
2020-03-29 21:32:01 +08:00
|
|
|
"github.com/meshplus/bitxhub-kit/types"
|
|
|
|
"github.com/meshplus/bitxhub-model/pb"
|
2021-04-15 10:37:47 +08:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
2020-03-29 21:32:01 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func (cbs *ChainBrokerService) GetReceipt(ctx context.Context, req *pb.TransactionHashMsg) (*pb.Receipt, error) {
|
2020-10-21 23:46:21 +08:00
|
|
|
hash := types.NewHashByStr(req.TxHash)
|
2020-10-23 15:29:47 +08:00
|
|
|
if hash == nil {
|
2021-04-23 10:04:10 +08:00
|
|
|
return nil, status.Newf(codes.InvalidArgument, fmt.Sprintf("invalid format of receipt hash %s for querying receipt", hash)).Err()
|
2020-10-23 15:29:47 +08:00
|
|
|
}
|
2021-04-15 10:37:47 +08:00
|
|
|
r, err := cbs.api.Broker().GetReceipt(hash)
|
|
|
|
if err != nil {
|
|
|
|
if errors.Is(storage.ErrorNotFound, err) {
|
|
|
|
return nil, status.Newf(codes.NotFound, fmt.Sprintf("cannot found receipt for %s", hash), err.Error()).Err()
|
|
|
|
}
|
|
|
|
return nil, status.Newf(codes.Internal, "internal handling error", err.Error()).Err()
|
|
|
|
}
|
|
|
|
return r, nil
|
2020-03-29 21:32:01 +08:00
|
|
|
}
|