bitxhub/api/grpc/receipt.go

29 lines
882 B
Go
Raw Permalink Normal View History

2020-03-29 21:32:01 +08:00
package grpc
import (
"context"
"errors"
"fmt"
2020-03-29 21:32:01 +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"
"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)
if hash == nil {
return nil, status.Newf(codes.InvalidArgument, fmt.Sprintf("invalid format of receipt hash %s for querying receipt", hash)).Err()
}
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
}