fabric: github.com/hyperledger/fabric/token/client Index | Files | Directories

package client

import "github.com/hyperledger/fabric/token/client"

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

Package Files

client.go config.go deliver_client.go msp.go orderer_client.go prover.go tx_submitter.go

func BroadcastReceive Uses

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 Uses

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

broadcastSend sends transaction envelope to orderer service

func BroadcastWaitForResponse Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

func DeliverSend Uses

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

func DeliverWaitForResponse Uses

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 Uses

func ValidateClientConfig(config *ClientConfig) error

type Broadcast Uses

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 Uses

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

Client represents the client struct that calls Prover and TxSubmitter

func (*Client) Issue Uses

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

func (*Client) Transfer Uses

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 Uses

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 Uses

type ConnectionConfig struct {
    Address            string
    TlsRootCertFile    string
    ServerNameOverride string
}

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

type DeliverClient Uses

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 Uses

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

type DeliverFiltered Uses

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 Uses

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 Uses

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 Uses

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

type Prover Uses

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 Uses

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

func (*ProverPeer) CreateSignedCommand Uses

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

func (*ProverPeer) RequestImport Uses

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

func (*ProverPeer) RequestTransfer Uses

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

type Signer Uses

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

type SignerIdentity Uses

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 Uses

type TimeFunc func() time.Time

type TxEvent Uses

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 Uses

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

func NewTxSubmitter Uses

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

NewTransactionSubmitter creates a new TxSubmitter from token client config

func (*TxSubmitter) CreateTxEnvelope Uses

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

func (*TxSubmitter) SubmitTransaction Uses

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 Uses

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

PathSynopsis
mockCode generated by counterfeiter.

Package client imports 26 packages (graph) and is imported by 1 packages. Updated 2018-12-13. Refresh now. Tools for package owners.