gateway

package
v0.0.0-...-3287af7 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package gateway enables Go developers to build client applications using the Hyperledger Fabric programming model as described in the 'Developing Applications' chapter of the Fabric documentation: https://hyperledger-fabric.readthedocs.io/en/latest/developapps/developing_applications.html

A Gateway object is created using the Connect() function to connect to a 'gateway' peer as specified in a network configuration file, using an identity stored in a wallet. Interactions with smart contracts are then invoked within the context of this gateway connection.

See https://github.com/hyperledger/fabric-samples/blob/master/fabcar/go/fabcar.go for a working sample.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigOption

type ConfigOption = func(*Gateway) error

ConfigOption specifies the gateway configuration source.

func WithConfig

func WithConfig(config core.ConfigProvider) ConfigOption

WithConfig configures the gateway from a network config, such as a ccp file.

Parameters:
config is a ConfigProvider function which provides config backend

Returns:
A ConfigOption which can be passed as the first parameter to the Connect() function

func WithSDK

func WithSDK(sdk *fabsdk.FabricSDK) ConfigOption

WithSDK configures the gateway with the configuration from an existing FabricSDK instance

Parameters:
sdk is an instance of fabsdk.FabricSDK from which the configuration is extracted

Returns:
A ConfigOption which can be passed as the first parameter to the Connect() function

type Contract

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

A Contract object represents a smart contract instance in a network. Applications should get a Contract instance from a Network using the GetContract method

func (*Contract) CreateTransaction

func (c *Contract) CreateTransaction(name string, opts ...TransactionOption) (*Transaction, error)

CreateTransaction creates an object representing a specific invocation of a transaction function implemented by this contract, and provides more control over the transaction invocation using the optional arguments. A new transaction object must be created for each transaction invocation.

Parameters:
name is the name of the transaction function to be invoked in the smart contract.
opts are the options to be associated with the transaction.

Returns:
A Transaction object for subsequent evaluation or submission.

func (*Contract) EvaluateTransaction

func (c *Contract) EvaluateTransaction(name string, args ...string) ([]byte, error)

EvaluateTransaction will evaluate a transaction function and return its results. The transaction function 'name' will be evaluated on the endorsing peers but the responses will not be sent to the ordering service and hence will not be committed to the ledger. This can be used for querying the world state.

Parameters:
name is the name of the transaction function to be invoked in the smart contract.
args are the arguments to be sent to the transaction function.

Returns:
The return value of the transaction function in the smart contract.

func (*Contract) Name

func (c *Contract) Name() string

Name returns the name of the smart contract

func (*Contract) RegisterEvent

func (c *Contract) RegisterEvent(eventFilter string) (fab.Registration, <-chan *fab.CCEvent, error)

RegisterEvent registers for chaincode events. Unregister must be called when the registration is no longer needed.

Parameters:
eventFilter is the chaincode event filter (regular expression) for which events are to be received

Returns:
the registration and a channel that is used to receive events. The channel is closed when Unregister is called.

func (*Contract) SubmitTransaction

func (c *Contract) SubmitTransaction(name string, args ...string) ([]byte, error)

SubmitTransaction will submit a transaction to the ledger. The transaction function 'name' will be evaluated on the endorsing peers and then submitted to the ordering service for committing to the ledger.

Parameters:
name is the name of the transaction function to be invoked in the smart contract.
args are the arguments to be sent to the transaction function.

Returns:
The return value of the transaction function in the smart contract.

func (*Contract) Unregister

func (c *Contract) Unregister(registration fab.Registration)

Unregister removes the given registration and closes the event channel.

Parameters:
registration is the registration handle that was returned from RegisterContractEvent method

type Gateway

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

Gateway is the entry point to a Fabric network

func Connect

func Connect(config ConfigOption, identity IdentityOption, options ...Option) (*Gateway, error)

Connect to a gateway defined by a network config file. Must specify a config option, an identity option and zero or more strategy options.

Parameters:
config is a ConfigOption used to specify the network connection configuration.  This must contain connection details for at least one 'gateway' peer.
identity is an IdentityOption which assigns a signing identity for all interactions under this Gateway connection.
options specifies other gateway options

Returns:
A Transaction object for subsequent evaluation or submission.

func (*Gateway) Close

func (gw *Gateway) Close()

Close the gateway connection and all associated resources, including removing listeners attached to networks and contracts created by the gateway.

func (*Gateway) GetNetwork

func (gw *Gateway) GetNetwork(name string) (*Network, error)

GetNetwork returns an object representing a network channel.

Parameters:
name is the name of the network channel

Returns:
A Network object representing the channel

type Identity

type Identity interface {
	// contains filtered or unexported methods
}

Identity represents a specific identity format

type IdentityOption

type IdentityOption = func(*Gateway) error

IdentityOption specifies the user identity under which all transactions are performed for this gateway instance.

func WithIdentity

func WithIdentity(wallet wallet, label string) IdentityOption

WithIdentity is an optional argument to the Connect method which specifies the identity that is to be used to connect to the network. All operations under this gateway connection will be performed using this identity.

Parameters:
wallet is a Wallet implementation that contains identities
label is the name of the identity in the wallet to associate with the gateway

Returns:
An IdentityOption which can be passed as the second parameter to the Connect() function

func WithUser

func WithUser(user string) IdentityOption

WithUser is an optional argument to the Connect method which specifies the identity that is to be used to connect to the network. The creadentials are extracted from the credential store specified in the connection profile. All operations under this gateway connection will be performed using this identity.

Parameters:
user is the name of the user in the credential store.

Returns:
An IdentityOption which can be passed as the second parameter to the Connect() function

type Network

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

A Network object represents the set of peers in a Fabric network (channel). Applications should get a Network instance from a Gateway using the GetNetwork method.

func (*Network) GetContract

func (n *Network) GetContract(chaincodeID string) *Contract

GetContract returns instance of a smart contract on the current network.

Parameters:
chaincodeID is the name of the chaincode that contains the smart contract

Returns:
A Contract object representing the smart contract

func (*Network) GetContractWithName

func (n *Network) GetContractWithName(chaincodeID string, name string) *Contract

GetContractWithName returns instance of a smart contract on the current network. If the chaincode instance contains more than one smart contract class (available using the latest contract programming model), then an individual class can be selected.

Parameters:
chaincodeID is the name of the chaincode that contains the smart contract
name is the class name of the smart contract within the chaincode.

Returns:
A Contract object representing the smart contract

func (*Network) Name

func (n *Network) Name() string

Name is the name of the network (also known as channel name)

func (*Network) RegisterBlockEvent

func (n *Network) RegisterBlockEvent() (fab.Registration, <-chan *fab.BlockEvent, error)

RegisterBlockEvent registers for block events. Unregister must be called when the registration is no longer needed.

Returns:
the registration and a channel that is used to receive events. The channel is closed when Unregister is called.

func (*Network) RegisterFilteredBlockEvent

func (n *Network) RegisterFilteredBlockEvent() (fab.Registration, <-chan *fab.FilteredBlockEvent, error)

RegisterFilteredBlockEvent registers for filtered block events. Unregister must be called when the registration is no longer needed.

Returns:
the registration and a channel that is used to receive events. The channel is closed when Unregister is called.

func (*Network) Unregister

func (n *Network) Unregister(registration fab.Registration)

Unregister removes the given registration and closes the event channel.

Parameters:
registration is the registration handle that was returned from RegisterBlockEvent method

type Option

type Option = func(*Gateway) error

Option functional arguments can be supplied when connecting to the gateway.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout is an optional argument to the Connect method which defines the commit timeout for all transaction submissions for this gateway.

type Transaction

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

A Transaction represents a specific invocation of a transaction function, and provides flexibility over how that transaction is invoked. Applications should obtain instances of this class from a Contract using the Contract.CreateTransaction method.

Instances of this class are stateful. A new instance <strong>must</strong> be created for each transaction invocation.

func (*Transaction) Evaluate

func (txn *Transaction) Evaluate(args ...string) ([]byte, error)

Evaluate a transaction function and return its results. The transaction function will be evaluated on the endorsing peers but the responses will not be sent to the ordering service and hence will not be committed to the ledger. This can be used for querying the world state.

func (*Transaction) RegisterCommitEvent

func (txn *Transaction) RegisterCommitEvent() <-chan *fab.TxStatusEvent

RegisterCommitEvent registers for a commit event for this transaction.

Returns:
the channel that is used to receive the event. The channel is closed after the event is queued.

func (*Transaction) Submit

func (txn *Transaction) Submit(args ...string) ([]byte, error)

Submit a transaction to the ledger. The transaction function represented by this object will be evaluated on the endorsing peers and then submitted to the ordering service for committing to the ledger.

type TransactionOption

type TransactionOption = func(*Transaction) error

TransactionOption functional arguments can be supplied when creating a transaction object

func WithEndorsingPeers

func WithEndorsingPeers(peers ...string) TransactionOption

WithEndorsingPeers is an optional argument to the CreateTransaction method which sets the peers that should be used for endorsement of transaction submitted to the ledger using Submit()

func WithTransient

func WithTransient(data map[string][]byte) TransactionOption

WithTransient is an optional argument to the CreateTransaction method which sets the transient data that will be passed to the transaction function but will not be stored on the ledger. This can be used to pass private data to a transaction function.

type Wallet

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

A Wallet stores identity information used to connect to a Hyperledger Fabric network. Instances are created using factory methods on the implementing objects.

func NewFileSystemWallet

func NewFileSystemWallet(path string) (*Wallet, error)

NewFileSystemWallet creates an instance of a wallet, held in memory. This implementation is not backed by a persistent store.

Parameters:
path specifies where on the filesystem to store the wallet.

Returns:
A Wallet object.

func NewInMemoryWallet

func NewInMemoryWallet() *Wallet

NewInMemoryWallet creates an instance of a wallet, held in memory.

Returns:
A Wallet object.

func (*Wallet) Exists

func (w *Wallet) Exists(label string) bool

Exists tests whether the wallet contains an identity for the given label.

Parameters:
label specifies the name of the identity in the wallet.

Returns:
True if the named identity is in the wallet.

func (*Wallet) Get

func (w *Wallet) Get(label string) (Identity, error)

Get an identity from the wallet. The implementation class of the identity object will vary depending on its type.

Parameters:
label specifies the name of the identity in the wallet.

Returns:
The identity object.

func (*Wallet) List

func (w *Wallet) List() ([]string, error)

List returns the labels of all identities in the wallet.

Returns:
A list of identity labels in the wallet.

func (*Wallet) Put

func (w *Wallet) Put(label string, id Identity) error

Put an identity into the wallet

Parameters:
label specifies the name to be associated with the identity.
id specifies the identity to store in the wallet.

func (*Wallet) Remove

func (w *Wallet) Remove(label string) error

Remove an identity from the wallet. If the identity does not exist, this method does nothing.

Parameters:
label specifies the name of the identity in the wallet.

type WalletStore

type WalletStore interface {
	Put(label string, stream []byte) error
	Get(label string) ([]byte, error)
	List() ([]string, error)
	Exists(label string) bool
	Remove(label string) error
}

WalletStore is the interface for implementations that provide backing storage for identities in a wallet. To create create a new backing store, implement all the methods defined in this interface and provide a factory method that wraps an instance of this in a new Wallet object. E.g:

  func NewMyWallet() *Wallet {
	   store := &myWalletStore{ }
	   return &Wallet{store}
  }

type X509Identity

type X509Identity struct {
	Version     int         `json:"version"`
	MspID       string      `json:"mspId"`
	IDType      string      `json:"type"`
	Credentials credentials `json:"credentials"`
}

X509Identity represents an X509 identity

func NewX509Identity

func NewX509Identity(mspid string, cert string, key string) *X509Identity

NewX509Identity creates an X509 identity for storage in a wallet

func (*X509Identity) Certificate

func (x *X509Identity) Certificate() string

Certificate returns the X509 certificate PEM

func (*X509Identity) Key

func (x *X509Identity) Key() string

Key returns the private key PEM

Jump to

Keyboard shortcuts

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