github.com/s7techlab/cckit@v0.10.5/examples/token/service/account/account.go (about)

     1  package account
     2  
     3  import (
     4  	"encoding/base64"
     5  	"errors"
     6  
     7  	"google.golang.org/protobuf/types/known/emptypb"
     8  
     9  	"github.com/s7techlab/cckit/identity"
    10  	"github.com/s7techlab/cckit/router"
    11  )
    12  
    13  type LocalService struct {
    14  }
    15  
    16  func NewLocalService() *LocalService {
    17  	return &LocalService{}
    18  }
    19  
    20  func (l *LocalService) GetInvokerAddress(ctx router.Context, _ *emptypb.Empty) (*AddressId, error) {
    21  	invoker, err := identity.FromStub(ctx.Stub())
    22  	if err != nil {
    23  		return nil, err
    24  	}
    25  
    26  	return l.GetAddress(ctx,
    27  		&GetAddressRequest{PublicKey: identity.MarshalPublicKey(invoker.Cert.PublicKey)})
    28  }
    29  
    30  func (l *LocalService) GetAddress(ctx router.Context, req *GetAddressRequest) (*AddressId, error) {
    31  	return &AddressId{
    32  		Address: base64.StdEncoding.EncodeToString(req.PublicKey),
    33  	}, nil
    34  }
    35  
    36  func (l *LocalService) GetAccount(ctx router.Context, id *AccountId) (*Account, error) {
    37  	return nil, errors.New(`no accounts implemented`)
    38  }
    39  
    40  type Remote struct {
    41  }