client

package
v0.0.0-...-d686ba8 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2021 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0

Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0

Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0

Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0

Copyright IBM Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BroadcastReceive

func BroadcastReceive(broadcast Broadcast, addr string, responses chan common.Status, errs chan error)

broadReceive waits until it receives the response from broadcast stream

func BroadcastSend

func BroadcastSend(broadcast Broadcast, addr string, envelope *common.Envelope) error

broadcastSend sends transaction envelope to orderer service

func BroadcastWaitForResponse

func BroadcastWaitForResponse(responses chan common.Status, errs chan error) (common.Status, error)

broadcastWaitForResponse reads from response and errs chans until responses chan is closed

func CreateDeliverEnvelope

func CreateDeliverEnvelope(channelId string, creator []byte, signer SignerIdentity, cert *tls.Certificate) (*common.Envelope, error)

create a signed envelope with SeekPosition_Newest for block

func CreateEnvelope

func CreateEnvelope(data []byte, header *common.Header, signer SignerIdentity) (*common.Envelope, error)

CreateEnvelope creates a common.Envelope with given tx bytes, header, and Signer

func CreateHeader

func CreateHeader(txType common.HeaderType, channelId string, creator []byte, tlsCertHash []byte) (string, *common.Header, error)

CreateHeader creates common.Header for a token transaction tlsCertHash is for client TLS cert, only applicable when ClientAuthRequired is true

func DeliverReceive

func DeliverReceive(df DeliverFiltered, address string, txid string, eventCh chan TxEvent) error

func DeliverSend

func DeliverSend(df DeliverFiltered, address string, envelope *common.Envelope) error

func DeliverWaitForResponse

func DeliverWaitForResponse(ctx context.Context, eventCh chan TxEvent, txid string) (bool, error)

DeliverWaitForResponse waits for either eventChan has value (i.e., response has been received) or ctx is timed out This function assumes that the eventCh is only for the specified txid If an eventCh is shared by multiple transactions, a loop should be used to listen to events from multiple transactions

func ValidateClientConfig

func ValidateClientConfig(config *ClientConfig) error

Types

type Broadcast

type Broadcast interface {
	Send(m *common.Envelope) error
	Recv() (*ab.BroadcastResponse, error)
	CloseSend() error
}

Broadcast defines the interface that abstracts grpc calls to broadcast transactions to orderer

type Client

type Client struct {
	SigningIdentity tk.SigningIdentity
	Prover          Prover
	TxSubmitter     FabricTxSubmitter
}

Client represents the client struct that calls Prover and TxSubmitter

func (*Client) Issue

func (c *Client) Issue(tokensToIssue []*token.TokenToIssue) ([]byte, error)

func (*Client) Transfer

func (c *Client) Transfer(tokenIDs [][]byte, shares []*token.RecipientTransferShare) ([]byte, error)

Transfer is the function that the client calls to transfer his tokens. Transfer takes as parameter an array of token.RecipientTransferShare that identifies who receives the tokens and describes how the tokens are distributed.

type ClientConfig

type ClientConfig struct {
	ChannelId     string
	MspDir        string
	MspId         string
	TlsEnabled    bool
	OrdererCfg    ConnectionConfig
	CommitPeerCfg ConnectionConfig
	ProverPeerCfg ConnectionConfig
}

ClientConfig will be updated after the CR for token client config is merged, where the config data will be populated based on a config file.

type ConnectionConfig

type ConnectionConfig struct {
	Address            string
	TlsRootCertFile    string
	ServerNameOverride string
}

ConnectionConfig contains data required to establish grpc connection to a peer or orderer

type DeliverClient

type DeliverClient interface {
	// NewDeliverFilterd returns a DeliverFiltered
	NewDeliverFiltered(ctx context.Context, opts ...grpc.CallOption) (DeliverFiltered, error)

	// Certificate returns tls certificate for the deliver client to commit peer
	Certificate() *tls.Certificate
}

DeliverClient defines the interface to create a DeliverFiltered client

func NewDeliverClient

func NewDeliverClient(config *ClientConfig) (DeliverClient, error)

type DeliverFiltered

type DeliverFiltered interface {
	Send(*common.Envelope) error
	Recv() (*pb.DeliverResponse, error)
	CloseSend() error
}

DeliverFiltered defines the interface that abstracts deliver filtered grpc calls to commit peer

type FabricTxSubmitter

type FabricTxSubmitter interface {

	// Submit allows the client to build and submit a fabric transaction for fabtoken that has as
	// payload a serialized tx; it takes as input an array of bytes
	// and returns an error indicating the success or the failure of the tx submission and an error
	// explaining why.
	Submit(tx []byte) error
}

type OrdererClient

type OrdererClient interface {
	// NewBroadcast returns a Broadcast
	NewBroadcast(ctx context.Context, opts ...grpc.CallOption) (Broadcast, error)

	// Certificate returns tls certificate for the orderer client
	Certificate() *tls.Certificate
}

OrdererClient defines the interface to create a Broadcast

func NewOrdererClient

func NewOrdererClient(config *ClientConfig) (OrdererClient, error)

type Prover

type Prover interface {

	// RequestImport allows the client to submit an issue request to a prover peer service;
	// the function takes as parameters tokensToIssue and the signing identity of the client;
	// it returns a response in bytes and an error message in the case the request fails.
	// The response corresponds to a serialized TokenTransaction protobuf message.
	RequestImport(tokensToIssue []*token.TokenToIssue, signingIdentity tk.SigningIdentity) ([]byte, error)

	// RequestTransfer allows the client to submit a transfer request to a prover peer service;
	// the function takes as parameters a fabtoken application credential, the identifiers of the tokens
	// to be transfererd and the shares describing how they are going to be distributed
	// among recipients; it returns a response in bytes and an error message in the case the
	// request fails
	RequestTransfer(tokenIDs [][]byte, shares []*token.RecipientTransferShare, signingIdentity tk.SigningIdentity) ([]byte, error)
}

type ProverPeer

type ProverPeer struct {
	ChannelID        string
	ProverClient     token.ProverClient
	RandomnessReader io.Reader
	Time             TimeFunc
}

func (*ProverPeer) CreateSignedCommand

func (prover *ProverPeer) CreateSignedCommand(payload interface{}, signingIdentity tk.SigningIdentity) (*token.SignedCommand, error)

func (*ProverPeer) RequestImport

func (prover *ProverPeer) RequestImport(tokensToIssue []*token.TokenToIssue, signingIdentity tk.SigningIdentity) ([]byte, error)

func (*ProverPeer) RequestTransfer

func (prover *ProverPeer) RequestTransfer(
	tokenIDs [][]byte,
	shares []*token.RecipientTransferShare,
	signingIdentity tk.SigningIdentity) ([]byte, error)

type Signer

type Signer interface {
	// Sign signs the given payload and returns a signature
	Sign([]byte) ([]byte, error)
}

type SignerIdentity

type SignerIdentity interface {
	Signer

	// Serialize returns a byte representation of this identity which is used to verify
	// messages signed by this SignerIdentity
	Serialize() ([]byte, error)
}

SignerIdentity signs messages and serializes its public identity to bytes

type TimeFunc

type TimeFunc func() time.Time

type TxEvent

type TxEvent struct {
	Txid       string
	Committed  bool
	CommitPeer string
	Err        error
}

TxEvent contains information for token transaction commit If application wants to be notified when a token transaction is committed, do the following: - create a event chan with size 1 or bigger, e.g. txChan := make(chan TxEvent, 1) - call client.SubmitTransactionWithChan(txBytes, txChan) - implement a function to read TxEvent from txChan so that it will be notified when transaction is committed or failed

type TxSubmitter

type TxSubmitter struct {
	Config        *ClientConfig
	Signer        SignerIdentity
	Creator       []byte
	OrdererClient OrdererClient
	DeliverClient DeliverClient
}

func NewTxSubmitter

func NewTxSubmitter(config *ClientConfig) (*TxSubmitter, error)

NewTransactionSubmitter creates a new TxSubmitter from token client config

func (*TxSubmitter) CreateTxEnvelope

func (s *TxSubmitter) CreateTxEnvelope(txBytes []byte) (string, *common.Envelope, error)

func (*TxSubmitter) SubmitTransaction

func (s *TxSubmitter) SubmitTransaction(txEnvelope *common.Envelope, waitTimeInSeconds int) (committed bool, txId string, err error)

SubmitTransaction submits a token transaction to fabric. It takes TokenTransaction bytes and waitTimeInSeconds as input parameters. The 'waitTimeInSeconds' indicates how long to wait for transaction commit event. If it is 0, the function will not wait for transaction to be committed. If it is greater than 0, the function will wait until timeout or transaction is committed, whichever is earlier

func (*TxSubmitter) SubmitTransactionWithChan

func (s *TxSubmitter) SubmitTransactionWithChan(txEnvelope *common.Envelope, eventCh chan TxEvent) (committed bool, txId string, err error)

SubmitTransactionWithChan submits a token transaction to fabric with an event channel. This function does not wait for transaction commit and returns as soon as the orderer client receives the response. The application will be notified on transaction completion by reading events from the eventCh. When the transaction is committed or failed, an event will be added to eventCh so that the application will be notified. If eventCh has buffer size 0 or its buffer is full, an error will be returned.

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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