github.com/Finschia/finschia-sdk@v0.48.1/testutil/testdata/grpc_query.go (about)

     1  package testdata
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/gogo/protobuf/proto"
     8  
     9  	"github.com/Finschia/finschia-sdk/codec/types"
    10  )
    11  
    12  type QueryImpl struct{}
    13  
    14  var _ QueryServer = QueryImpl{}
    15  
    16  func (e QueryImpl) TestAny(_ context.Context, request *TestAnyRequest) (*TestAnyResponse, error) {
    17  	animal, ok := request.AnyAnimal.GetCachedValue().(Animal)
    18  	if !ok {
    19  		return nil, fmt.Errorf("expected Animal")
    20  	}
    21  
    22  	any, err := types.NewAnyWithValue(animal.(proto.Message))
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  
    27  	return &TestAnyResponse{HasAnimal: &HasAnimal{
    28  		Animal: any,
    29  		X:      10,
    30  	}}, nil
    31  }
    32  
    33  func (e QueryImpl) Echo(_ context.Context, req *EchoRequest) (*EchoResponse, error) {
    34  	return &EchoResponse{Message: req.Message}, nil
    35  }
    36  
    37  func (e QueryImpl) SayHello(_ context.Context, request *SayHelloRequest) (*SayHelloResponse, error) {
    38  	greeting := fmt.Sprintf("Hello %s!", request.Name)
    39  	return &SayHelloResponse{Greeting: greeting}, nil
    40  }
    41  
    42  var _ types.UnpackInterfacesMessage = &TestAnyRequest{}
    43  
    44  func (m *TestAnyRequest) UnpackInterfaces(unpacker types.AnyUnpacker) error {
    45  	var animal Animal
    46  	return unpacker.UnpackAny(m.AnyAnimal, &animal)
    47  }
    48  
    49  var _ types.UnpackInterfacesMessage = &TestAnyResponse{}
    50  
    51  func (m *TestAnyResponse) UnpackInterfaces(unpacker types.AnyUnpacker) error {
    52  	return m.HasAnimal.UnpackInterfaces(unpacker)
    53  }