{"modulePath":"github.com/eric-erki/https-hyperledger.org","version":"v1.4.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package client\n\nCopyright IBM Corp. All Rights Reserved.\n\nSPDX-License-Identifier: Apache-2.0\n\nCopyright IBM Corp. All Rights Reserved.\n\nSPDX-License-Identifier: Apache-2.0\n\nCopyright IBM Corp. All Rights Reserved.\n\nSPDX-License-Identifier: Apache-2.0\n\nCopyright IBM Corp. All Rights Reserved.\n\nSPDX-License-Identifier: Apache-2.0\n\nCopyright IBM Corp. All Rights Reserved.\n\nSPDX-License-Identifier: Apache-2.0\n\n## Functions\n\n```go\nfunc BroadcastReceive(broadcast Broadcast, addr string, responses chan common.Status, errs chan error)\n```\nbroadReceive waits until it receives the response from broadcast stream\n\n```go\nfunc BroadcastSend(broadcast Broadcast, addr string, envelope *common.Envelope) error\n```\nbroadcastSend sends transaction envelope to orderer service\n\n```go\nfunc BroadcastWaitForResponse(responses chan common.Status, errs chan error) (common.Status, error)\n```\nbroadcastWaitForResponse reads from response and errs chans until responses chan is closed\n\n```go\nfunc CreateDeliverEnvelope(channelId string, creator []byte, signer SignerIdentity, cert *tls.Certificate) (*common.Envelope, error)\n```\ncreate a signed envelope with SeekPosition\\_Newest for block\n\n```go\nfunc CreateEnvelope(data []byte, header *common.Header, signer SignerIdentity) (*common.Envelope, error)\n```\nCreateEnvelope creates a common.Envelope with given tx bytes, header, and Signer\n\n```go\nfunc CreateHeader(txType common.HeaderType, channelId string, creator []byte, tlsCertHash []byte) (string, *common.Header, error)\n```\nCreateHeader creates common.Header for a token transaction tlsCertHash is for client TLS cert, only applicable when ClientAuthRequired is true\n\n```go\nfunc DeliverReceive(df DeliverFiltered, address string, txid string, eventCh chan TxEvent) error\n```\n\n```go\nfunc DeliverSend(df DeliverFiltered, address string, envelope *common.Envelope) error\n```\n\n```go\nfunc DeliverWaitForResponse(ctx context.Context, eventCh chan TxEvent, txid string) (bool, error)\n```\nDeliverWaitForResponse 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\n\n```go\nfunc ValidateClientConfig(config *ClientConfig) error\n```\n\n## Types\n\n```go\ntype Broadcast interface {\n\tSend(m *common.Envelope) error\n\tRecv() (*ab.BroadcastResponse, error)\n\tCloseSend() error\n}\n```\nBroadcast defines the interface that abstracts grpc calls to broadcast transactions to orderer\n\n```go\ntype Client struct {\n\tSigningIdentity tk.SigningIdentity\n\tProver          Prover\n\tTxSubmitter     FabricTxSubmitter\n}\n```\nClient represents the client struct that calls Prover and TxSubmitter\n\n```go\nfunc (c *Client) Issue(tokensToIssue []*token.TokenToIssue) ([]byte, error)\n```\n\n```go\nfunc (c *Client) Transfer(tokenIDs [][]byte, shares []*token.RecipientTransferShare) ([]byte, error)\n```\nTransfer 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.\n\n```go\ntype ClientConfig struct {\n\tChannelId     string\n\tMspDir        string\n\tMspId         string\n\tTlsEnabled    bool\n\tOrdererCfg    ConnectionConfig\n\tCommitPeerCfg ConnectionConfig\n\tProverPeerCfg ConnectionConfig\n}\n```\nClientConfig will be updated after the CR for token client config is merged, where the config data will be populated based on a config file.\n\n```go\ntype ConnectionConfig struct {\n\tAddress            string\n\tTlsRootCertFile    string\n\tServerNameOverride string\n}\n```\nConnectionConfig contains data required to establish grpc connection to a peer or orderer\n\n```go\ntype DeliverClient interface {\n\t// NewDeliverFilterd returns a DeliverFiltered\n\tNewDeliverFiltered(ctx context.Context, opts ...grpc.CallOption) (DeliverFiltered, error)\n\n\t// Certificate returns tls certificate for the deliver client to commit peer\n\tCertificate() *tls.Certificate\n}\n```\nDeliverClient defines the interface to create a DeliverFiltered client\n\n```go\nfunc NewDeliverClient(config *ClientConfig) (DeliverClient, error)\n```\n\n```go\ntype DeliverFiltered interface {\n\tSend(*common.Envelope) error\n\tRecv() (*pb.DeliverResponse, error)\n\tCloseSend() error\n}\n```\nDeliverFiltered defines the interface that abstracts deliver filtered grpc calls to commit peer\n\n```go\ntype FabricTxSubmitter interface {\n\n\t// Submit allows the client to build and submit a fabric transaction for fabtoken that has as\n\t// payload a serialized tx; it takes as input an array of bytes\n\t// and returns an error indicating the success or the failure of the tx submission and an error\n\t// explaining why.\n\tSubmit(tx []byte) error\n}\n```\n\n```go\ntype OrdererClient interface {\n\t// NewBroadcast returns a Broadcast\n\tNewBroadcast(ctx context.Context, opts ...grpc.CallOption) (Broadcast, error)\n\n\t// Certificate returns tls certificate for the orderer client\n\tCertificate() *tls.Certificate\n}\n```\nOrdererClient defines the interface to create a Broadcast\n\n```go\nfunc NewOrdererClient(config *ClientConfig) (OrdererClient, error)\n```\n\n```go\ntype Prover interface {\n\n\t// RequestImport allows the client to submit an issue request to a prover peer service;\n\t// the function takes as parameters tokensToIssue and the signing identity of the client;\n\t// it returns a response in bytes and an error message in the case the request fails.\n\t// The response corresponds to a serialized TokenTransaction protobuf message.\n\tRequestImport(tokensToIssue []*token.TokenToIssue, signingIdentity tk.SigningIdentity) ([]byte, error)\n\n\t// RequestTransfer allows the client to submit a transfer request to a prover peer service;\n\t// the function takes as parameters a fabtoken application credential, the identifiers of the tokens\n\t// to be transfererd and the shares describing how they are going to be distributed\n\t// among recipients; it returns a response in bytes and an error message in the case the\n\t// request fails\n\tRequestTransfer(tokenIDs [][]byte, shares []*token.RecipientTransferShare, signingIdentity tk.SigningIdentity) ([]byte, error)\n}\n```\n\n```go\ntype ProverPeer struct {\n\tChannelID        string\n\tProverClient     token.ProverClient\n\tRandomnessReader io.Reader\n\tTime             TimeFunc\n}\n```\n\n```go\nfunc (prover *ProverPeer) CreateSignedCommand(payload interface{}, signingIdentity tk.SigningIdentity) (*token.SignedCommand, error)\n```\n\n```go\nfunc (prover *ProverPeer) RequestImport(tokensToIssue []*token.TokenToIssue, signingIdentity tk.SigningIdentity) ([]byte, error)\n```\n\n```go\nfunc (prover *ProverPeer) RequestTransfer(\n\ttokenIDs [][]byte,\n\tshares []*token.RecipientTransferShare,\n\tsigningIdentity tk.SigningIdentity) ([]byte, error)\n```\n\n```go\ntype Signer interface {\n\t// Sign signs the given payload and returns a signature\n\tSign([]byte) ([]byte, error)\n}\n```\n\n```go\ntype SignerIdentity interface {\n\tSigner\n\n\t// Serialize returns a byte representation of this identity which is used to verify\n\t// messages signed by this SignerIdentity\n\tSerialize() ([]byte, error)\n}\n```\nSignerIdentity signs messages and serializes its public identity to bytes\n\n```go\ntype TimeFunc func() time.Time\n```\n\n```go\ntype TxEvent struct {\n\tTxid       string\n\tCommitted  bool\n\tCommitPeer string\n\tErr        error\n}\n```\nTxEvent 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\n\n```go\ntype TxSubmitter struct {\n\tConfig        *ClientConfig\n\tSigner        SignerIdentity\n\tCreator       []byte\n\tOrdererClient OrdererClient\n\tDeliverClient DeliverClient\n}\n```\n\n```go\nfunc NewTxSubmitter(config *ClientConfig) (*TxSubmitter, error)\n```\nNewTransactionSubmitter creates a new TxSubmitter from token client config\n\n```go\nfunc (s *TxSubmitter) CreateTxEnvelope(txBytes []byte) (string, *common.Envelope, error)\n```\n\n```go\nfunc (s *TxSubmitter) SubmitTransaction(txEnvelope *common.Envelope, waitTimeInSeconds int) (committed bool, txId string, err error)\n```\nSubmitTransaction 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\n\n```go\nfunc (s *TxSubmitter) SubmitTransactionWithChan(txEnvelope *common.Envelope, eventCh chan TxEvent) (committed bool, txId string, err error)\n```\nSubmitTransactionWithChan 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.\n\n","path":"github.com/eric-erki/https-hyperledger.org/token/client","name":"client","synopsis":"","isRedistributable":true}
