allowance

package
v0.10.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2022 License: MIT Imports: 30 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package allowance contains

  • chaincode methods names {service_name}Chaincode_{method_name}
  • chaincode interface definition {service_name}Chaincode
  • chaincode gateway definition {service_name}}Gateway
  • chaincode service to cckit router registration func

Package allowance is a reverse proxy.

It translates gRPC into RESTful JSON APIs.

Index

Constants

View Source
const (

	// AllowanceServiceChaincodeMethodPrefix allows to use multiple services with same method names in one chaincode
	AllowanceServiceChaincodeMethodPrefix = ""

	AllowanceServiceChaincode_GetAllowance = AllowanceServiceChaincodeMethodPrefix + "GetAllowance"

	AllowanceServiceChaincode_Approve = AllowanceServiceChaincodeMethodPrefix + "Approve"

	AllowanceServiceChaincode_TransferFrom = AllowanceServiceChaincodeMethodPrefix + "TransferFrom"
)

AllowanceServiceChaincode method names

Variables

View Source
var (
	ErrOwnerOnly             = errors.New(`owner only`)
	ErrAllowanceInsufficient = errors.New(`allowance insufficient`)
)
View Source
var (
	StateMappings = m.StateMappings{}.
					Add(&Allowance{},
			m.PKeySchema(&AllowanceId{}),
			m.List(&Allowances{}),
		)

	EventMappings = m.EventMappings{}.
					Add(&Approved{}).
					Add(&TransferredFrom{})
)
View Source
var AllowanceServiceSwagger []byte
View Source
var File_token_service_allowance_allowance_proto protoreflect.FileDescriptor

Functions

func Event

func Event(ctx router.Context) state.Event

Event with chaincode mappings

func RegisterAllowanceServiceChaincode

func RegisterAllowanceServiceChaincode(r *cckit_router.Group, cc AllowanceServiceChaincode) error

RegisterAllowanceServiceChaincode registers service methods as chaincode router handlers

func RegisterAllowanceServiceHandler

func RegisterAllowanceServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

RegisterAllowanceServiceHandler registers the http handlers for service AllowanceService to "mux". The handlers forward requests to the grpc endpoint over "conn".

func RegisterAllowanceServiceHandlerClient

func RegisterAllowanceServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client AllowanceServiceClient) error

RegisterAllowanceServiceHandlerClient registers the http handlers for service AllowanceService to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "AllowanceServiceClient". Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "AllowanceServiceClient" doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in "AllowanceServiceClient" to call the correct interceptors.

func RegisterAllowanceServiceHandlerFromEndpoint

func RegisterAllowanceServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)

RegisterAllowanceServiceHandlerFromEndpoint is same as RegisterAllowanceServiceHandler but automatically dials to "endpoint" and closes the connection when "ctx" gets done.

func RegisterAllowanceServiceHandlerServer

func RegisterAllowanceServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server AllowanceServiceServer) error

RegisterAllowanceServiceHandlerServer registers the http handlers for service AllowanceService to "mux". UnaryRPC :call AllowanceServiceServer directly. StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterAllowanceServiceHandlerFromEndpoint instead.

func RegisterAllowanceServiceServer

func RegisterAllowanceServiceServer(s *grpc.Server, srv AllowanceServiceServer)

func State

func State(ctx router.Context) m.MappedState

State with chaincode mappings

Types

type Allowance

type Allowance struct {
	OwnerAddress   string   `protobuf:"bytes,1,opt,name=owner_address,json=ownerAddress,proto3" json:"owner_address,omitempty"`
	SpenderAddress string   `protobuf:"bytes,2,opt,name=spender_address,json=spenderAddress,proto3" json:"spender_address,omitempty"`
	Token          []string `protobuf:"bytes,3,rep,name=token,proto3" json:"token,omitempty"`
	Amount         uint64   `protobuf:"varint,4,opt,name=amount,proto3" json:"amount,omitempty"`
	// contains filtered or unexported fields
}

Allowance

func (*Allowance) Descriptor deprecated

func (*Allowance) Descriptor() ([]byte, []int)

Deprecated: Use Allowance.ProtoReflect.Descriptor instead.

func (*Allowance) GetAmount

func (x *Allowance) GetAmount() uint64

func (*Allowance) GetOwnerAddress

func (x *Allowance) GetOwnerAddress() string

func (*Allowance) GetSpenderAddress

func (x *Allowance) GetSpenderAddress() string

func (*Allowance) GetToken

func (x *Allowance) GetToken() []string

func (*Allowance) ProtoMessage

func (*Allowance) ProtoMessage()

func (*Allowance) ProtoReflect

func (x *Allowance) ProtoReflect() protoreflect.Message

func (*Allowance) Reset

func (x *Allowance) Reset()

func (*Allowance) String

func (x *Allowance) String() string

func (*Allowance) Validate

func (this *Allowance) Validate() error

type AllowanceId

type AllowanceId struct {
	OwnerAddress   string   `protobuf:"bytes,1,opt,name=owner_address,json=ownerAddress,proto3" json:"owner_address,omitempty"`
	SpenderAddress string   `protobuf:"bytes,2,opt,name=spender_address,json=spenderAddress,proto3" json:"spender_address,omitempty"`
	Token          []string `protobuf:"bytes,3,rep,name=token,proto3" json:"token,omitempty"`
	// contains filtered or unexported fields
}

Allowance identifier

func (*AllowanceId) Descriptor deprecated

func (*AllowanceId) Descriptor() ([]byte, []int)

Deprecated: Use AllowanceId.ProtoReflect.Descriptor instead.

func (*AllowanceId) GetOwnerAddress

func (x *AllowanceId) GetOwnerAddress() string

func (*AllowanceId) GetSpenderAddress

func (x *AllowanceId) GetSpenderAddress() string

func (*AllowanceId) GetToken

func (x *AllowanceId) GetToken() []string

func (*AllowanceId) ProtoMessage

func (*AllowanceId) ProtoMessage()

func (*AllowanceId) ProtoReflect

func (x *AllowanceId) ProtoReflect() protoreflect.Message

func (*AllowanceId) Reset

func (x *AllowanceId) Reset()

func (*AllowanceId) String

func (x *AllowanceId) String() string

func (*AllowanceId) Validate

func (this *AllowanceId) Validate() error

type AllowanceRequest

type AllowanceRequest struct {
	OwnerAddress   string   `protobuf:"bytes,1,opt,name=owner_address,json=ownerAddress,proto3" json:"owner_address,omitempty"`
	SpenderAddress string   `protobuf:"bytes,2,opt,name=spender_address,json=spenderAddress,proto3" json:"spender_address,omitempty"`
	Token          []string `protobuf:"bytes,3,rep,name=token,proto3" json:"token,omitempty"`
	// contains filtered or unexported fields
}

func (*AllowanceRequest) Descriptor deprecated

func (*AllowanceRequest) Descriptor() ([]byte, []int)

Deprecated: Use AllowanceRequest.ProtoReflect.Descriptor instead.

func (*AllowanceRequest) GetOwnerAddress

func (x *AllowanceRequest) GetOwnerAddress() string

func (*AllowanceRequest) GetSpenderAddress

func (x *AllowanceRequest) GetSpenderAddress() string

func (*AllowanceRequest) GetToken

func (x *AllowanceRequest) GetToken() []string

func (*AllowanceRequest) ProtoMessage

func (*AllowanceRequest) ProtoMessage()

func (*AllowanceRequest) ProtoReflect

func (x *AllowanceRequest) ProtoReflect() protoreflect.Message

func (*AllowanceRequest) Reset

func (x *AllowanceRequest) Reset()

func (*AllowanceRequest) String

func (x *AllowanceRequest) String() string

func (*AllowanceRequest) Validate

func (this *AllowanceRequest) Validate() error

type AllowanceServiceChaincode

type AllowanceServiceChaincode interface {
	GetAllowance(cckit_router.Context, *AllowanceRequest) (*Allowance, error)

	Approve(cckit_router.Context, *ApproveRequest) (*Allowance, error)

	TransferFrom(cckit_router.Context, *TransferFromRequest) (*TransferFromResponse, error)
}

AllowanceServiceChaincode chaincode methods interface

type AllowanceServiceChaincodeLocalResolver

type AllowanceServiceChaincodeLocalResolver struct {
	// contains filtered or unexported fields
}

AllowanceServiceChaincodeResolver interface for service resolver

func (*AllowanceServiceChaincodeLocalResolver) Resolve

type AllowanceServiceChaincodeLocatorResolver

type AllowanceServiceChaincodeLocatorResolver struct {
	// contains filtered or unexported fields
}

AllowanceServiceChaincodeResolver interface for service resolver

func (*AllowanceServiceChaincodeLocatorResolver) Resolve

type AllowanceServiceChaincodeResolver

type AllowanceServiceChaincodeResolver interface {
	Resolve(ctx cckit_router.Context) (AllowanceServiceChaincode, error)
}

AllowanceServiceChaincodeResolver interface for service resolver

type AllowanceServiceChaincodeStubInvoker

type AllowanceServiceChaincodeStubInvoker struct {
	Invoker cckit_gateway.ChaincodeStubInvoker
}

func (*AllowanceServiceChaincodeStubInvoker) Approve

func (*AllowanceServiceChaincodeStubInvoker) GetAllowance

func (*AllowanceServiceChaincodeStubInvoker) TransferFrom

type AllowanceServiceClient

type AllowanceServiceClient interface {
	// Returns the remaining number of tokens that spender will be allowed to spend on behalf of owner through transfersender.
	// This is zero by default.
	GetAllowance(ctx context.Context, in *AllowanceRequest, opts ...grpc.CallOption) (*Allowance, error)
	// Sets amount as the allowance of spender over the caller’s tokens.
	// Emits an ApprovalEvent
	Approve(ctx context.Context, in *ApproveRequest, opts ...grpc.CallOption) (*Allowance, error)
	// Moves amount tokens from sender to recipient using the allowance mechanism.
	// Amount is then deducted from the caller’s allowance.
	// Emits TransferEvent
	TransferFrom(ctx context.Context, in *TransferFromRequest, opts ...grpc.CallOption) (*TransferFromResponse, error)
}

AllowanceServiceClient is the client API for AllowanceService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

type AllowanceServiceGateway

type AllowanceServiceGateway struct {
	ChaincodeInstance cckit_gateway.ChaincodeInstance
}

gateway implementation gateway can be used as kind of SDK, GRPC or REST server ( via grpc-gateway or clay )

func NewAllowanceServiceGateway

func NewAllowanceServiceGateway(sdk cckit_sdk.SDK, channel, chaincode string, opts ...cckit_gateway.Opt) *AllowanceServiceGateway

NewAllowanceServiceGateway creates gateway to access chaincode method via chaincode service

func NewAllowanceServiceGatewayFromInstance

func NewAllowanceServiceGatewayFromInstance(chaincodeInstance cckit_gateway.ChaincodeInstance) *AllowanceServiceGateway

func (*AllowanceServiceGateway) Approve

func (*AllowanceServiceGateway) GetAllowance

func (*AllowanceServiceGateway) Invoker

func (*AllowanceServiceGateway) ServiceDef

ServiceDef returns service definition

func (*AllowanceServiceGateway) TransferFrom

type AllowanceServiceServer

type AllowanceServiceServer interface {
	// Returns the remaining number of tokens that spender will be allowed to spend on behalf of owner through transfersender.
	// This is zero by default.
	GetAllowance(context.Context, *AllowanceRequest) (*Allowance, error)
	// Sets amount as the allowance of spender over the caller’s tokens.
	// Emits an ApprovalEvent
	Approve(context.Context, *ApproveRequest) (*Allowance, error)
	// Moves amount tokens from sender to recipient using the allowance mechanism.
	// Amount is then deducted from the caller’s allowance.
	// Emits TransferEvent
	TransferFrom(context.Context, *TransferFromRequest) (*TransferFromResponse, error)
}

AllowanceServiceServer is the server API for AllowanceService service.

type Allowances

type Allowances struct {
	Items []*Allowance `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"`
	// contains filtered or unexported fields
}

func (*Allowances) Descriptor deprecated

func (*Allowances) Descriptor() ([]byte, []int)

Deprecated: Use Allowances.ProtoReflect.Descriptor instead.

func (*Allowances) GetItems

func (x *Allowances) GetItems() []*Allowance

func (*Allowances) ProtoMessage

func (*Allowances) ProtoMessage()

func (*Allowances) ProtoReflect

func (x *Allowances) ProtoReflect() protoreflect.Message

func (*Allowances) Reset

func (x *Allowances) Reset()

func (*Allowances) String

func (x *Allowances) String() string

func (*Allowances) Validate

func (this *Allowances) Validate() error

type ApproveRequest

type ApproveRequest struct {
	OwnerAddress   string   `protobuf:"bytes,1,opt,name=owner_address,json=ownerAddress,proto3" json:"owner_address,omitempty"`
	SpenderAddress string   `protobuf:"bytes,2,opt,name=spender_address,json=spenderAddress,proto3" json:"spender_address,omitempty"`
	Amount         uint64   `protobuf:"varint,3,opt,name=amount,proto3" json:"amount,omitempty"`
	Token          []string `protobuf:"bytes,4,rep,name=token,proto3" json:"token,omitempty"`
	// contains filtered or unexported fields
}

func (*ApproveRequest) Descriptor deprecated

func (*ApproveRequest) Descriptor() ([]byte, []int)

Deprecated: Use ApproveRequest.ProtoReflect.Descriptor instead.

func (*ApproveRequest) GetAmount

func (x *ApproveRequest) GetAmount() uint64

func (*ApproveRequest) GetOwnerAddress

func (x *ApproveRequest) GetOwnerAddress() string

func (*ApproveRequest) GetSpenderAddress

func (x *ApproveRequest) GetSpenderAddress() string

func (*ApproveRequest) GetToken

func (x *ApproveRequest) GetToken() []string

func (*ApproveRequest) ProtoMessage

func (*ApproveRequest) ProtoMessage()

func (*ApproveRequest) ProtoReflect

func (x *ApproveRequest) ProtoReflect() protoreflect.Message

func (*ApproveRequest) Reset

func (x *ApproveRequest) Reset()

func (*ApproveRequest) String

func (x *ApproveRequest) String() string

func (*ApproveRequest) Validate

func (this *ApproveRequest) Validate() error

type Approved

type Approved struct {
	OwnerAddress   string   `protobuf:"bytes,1,opt,name=owner_address,json=ownerAddress,proto3" json:"owner_address,omitempty"`
	SpenderAddress string   `protobuf:"bytes,2,opt,name=spender_address,json=spenderAddress,proto3" json:"spender_address,omitempty"`
	Token          []string `protobuf:"bytes,3,rep,name=token,proto3" json:"token,omitempty"`
	Amount         uint64   `protobuf:"varint,4,opt,name=amount,proto3" json:"amount,omitempty"`
	// contains filtered or unexported fields
}

Approved event is emitted when Approve method has been invoked

func (*Approved) Descriptor deprecated

func (*Approved) Descriptor() ([]byte, []int)

Deprecated: Use Approved.ProtoReflect.Descriptor instead.

func (*Approved) GetAmount

func (x *Approved) GetAmount() uint64

func (*Approved) GetOwnerAddress

func (x *Approved) GetOwnerAddress() string

func (*Approved) GetSpenderAddress

func (x *Approved) GetSpenderAddress() string

func (*Approved) GetToken

func (x *Approved) GetToken() []string

func (*Approved) ProtoMessage

func (*Approved) ProtoMessage()

func (*Approved) ProtoReflect

func (x *Approved) ProtoReflect() protoreflect.Message

func (*Approved) Reset

func (x *Approved) Reset()

func (*Approved) String

func (x *Approved) String() string

func (*Approved) Validate

func (this *Approved) Validate() error

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(balance *balance.Service) *Service

func (*Service) Approve

func (s *Service) Approve(ctx router.Context, req *ApproveRequest) (*Allowance, error)

func (*Service) GetAllowance

func (s *Service) GetAllowance(ctx router.Context, req *AllowanceRequest) (*Allowance, error)

func (*Service) TransferFrom

func (s *Service) TransferFrom(ctx router.Context, req *TransferFromRequest) (*TransferFromResponse, error)

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(ctx router.Context) *Store

func (*Store) Get

func (s *Store) Get(ownerAddress, spenderAddress string, token []string) (*Allowance, error)

func (*Store) Set

func (s *Store) Set(ownerAddress, spenderAddress string, token []string, amount uint64) (*Allowance, error)

func (*Store) Sub

func (s *Store) Sub(ownerAddress, spenderAddress string, token []string, amount uint64) (*Allowance, error)

type TransferFromRequest

type TransferFromRequest struct {
	OwnerAddress     string   `protobuf:"bytes,1,opt,name=owner_address,json=ownerAddress,proto3" json:"owner_address,omitempty"`
	RecipientAddress string   `protobuf:"bytes,2,opt,name=recipient_address,json=recipientAddress,proto3" json:"recipient_address,omitempty"`
	Amount           uint64   `protobuf:"varint,3,opt,name=amount,proto3" json:"amount,omitempty"`
	Token            []string `protobuf:"bytes,4,rep,name=token,proto3" json:"token,omitempty"`
	// contains filtered or unexported fields
}

func (*TransferFromRequest) Descriptor deprecated

func (*TransferFromRequest) Descriptor() ([]byte, []int)

Deprecated: Use TransferFromRequest.ProtoReflect.Descriptor instead.

func (*TransferFromRequest) GetAmount

func (x *TransferFromRequest) GetAmount() uint64

func (*TransferFromRequest) GetOwnerAddress

func (x *TransferFromRequest) GetOwnerAddress() string

func (*TransferFromRequest) GetRecipientAddress

func (x *TransferFromRequest) GetRecipientAddress() string

func (*TransferFromRequest) GetToken

func (x *TransferFromRequest) GetToken() []string

func (*TransferFromRequest) ProtoMessage

func (*TransferFromRequest) ProtoMessage()

func (*TransferFromRequest) ProtoReflect

func (x *TransferFromRequest) ProtoReflect() protoreflect.Message

func (*TransferFromRequest) Reset

func (x *TransferFromRequest) Reset()

func (*TransferFromRequest) String

func (x *TransferFromRequest) String() string

func (*TransferFromRequest) Validate

func (this *TransferFromRequest) Validate() error

type TransferFromResponse

type TransferFromResponse struct {
	OwnerAddress     string   `protobuf:"bytes,1,opt,name=owner_address,json=ownerAddress,proto3" json:"owner_address,omitempty"`
	RecipientAddress string   `protobuf:"bytes,2,opt,name=recipient_address,json=recipientAddress,proto3" json:"recipient_address,omitempty"`
	Token            []string `protobuf:"bytes,3,rep,name=token,proto3" json:"token,omitempty"`
	Amount           uint64   `protobuf:"varint,4,opt,name=amount,proto3" json:"amount,omitempty"`
	// contains filtered or unexported fields
}

func (*TransferFromResponse) Descriptor deprecated

func (*TransferFromResponse) Descriptor() ([]byte, []int)

Deprecated: Use TransferFromResponse.ProtoReflect.Descriptor instead.

func (*TransferFromResponse) GetAmount

func (x *TransferFromResponse) GetAmount() uint64

func (*TransferFromResponse) GetOwnerAddress

func (x *TransferFromResponse) GetOwnerAddress() string

func (*TransferFromResponse) GetRecipientAddress

func (x *TransferFromResponse) GetRecipientAddress() string

func (*TransferFromResponse) GetToken

func (x *TransferFromResponse) GetToken() []string

func (*TransferFromResponse) ProtoMessage

func (*TransferFromResponse) ProtoMessage()

func (*TransferFromResponse) ProtoReflect

func (x *TransferFromResponse) ProtoReflect() protoreflect.Message

func (*TransferFromResponse) Reset

func (x *TransferFromResponse) Reset()

func (*TransferFromResponse) String

func (x *TransferFromResponse) String() string

func (*TransferFromResponse) Validate

func (this *TransferFromResponse) Validate() error

type TransferredFrom

type TransferredFrom struct {
	OwnerAddress     string   `protobuf:"bytes,1,opt,name=owner_address,json=ownerAddress,proto3" json:"owner_address,omitempty"`
	SpenderAddress   string   `protobuf:"bytes,2,opt,name=spender_address,json=spenderAddress,proto3" json:"spender_address,omitempty"`
	RecipientAddress string   `protobuf:"bytes,3,opt,name=recipient_address,json=recipientAddress,proto3" json:"recipient_address,omitempty"`
	Token            []string `protobuf:"bytes,4,rep,name=token,proto3" json:"token,omitempty"`
	Amount           uint64   `protobuf:"varint,5,opt,name=amount,proto3" json:"amount,omitempty"`
	// contains filtered or unexported fields
}

TransferredFrom event is emitted when TransferFrom method has been invoked

func (*TransferredFrom) Descriptor deprecated

func (*TransferredFrom) Descriptor() ([]byte, []int)

Deprecated: Use TransferredFrom.ProtoReflect.Descriptor instead.

func (*TransferredFrom) GetAmount

func (x *TransferredFrom) GetAmount() uint64

func (*TransferredFrom) GetOwnerAddress

func (x *TransferredFrom) GetOwnerAddress() string

func (*TransferredFrom) GetRecipientAddress

func (x *TransferredFrom) GetRecipientAddress() string

func (*TransferredFrom) GetSpenderAddress

func (x *TransferredFrom) GetSpenderAddress() string

func (*TransferredFrom) GetToken

func (x *TransferredFrom) GetToken() []string

func (*TransferredFrom) ProtoMessage

func (*TransferredFrom) ProtoMessage()

func (*TransferredFrom) ProtoReflect

func (x *TransferredFrom) ProtoReflect() protoreflect.Message

func (*TransferredFrom) Reset

func (x *TransferredFrom) Reset()

func (*TransferredFrom) String

func (x *TransferredFrom) String() string

func (*TransferredFrom) Validate

func (this *TransferredFrom) Validate() error

type UnimplementedAllowanceServiceServer

type UnimplementedAllowanceServiceServer struct {
}

UnimplementedAllowanceServiceServer can be embedded to have forward compatible implementations.

func (*UnimplementedAllowanceServiceServer) Approve

func (*UnimplementedAllowanceServiceServer) GetAllowance

func (*UnimplementedAllowanceServiceServer) TransferFrom

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL