fabricclient

package
v1.0.0-alpha2 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2017 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestBlock = &po.DeliverResponse{
	Type: &po.DeliverResponse_Block{
		Block: &common.Block{
			Data: &common.BlockData{
				Data: [][]byte{[]byte("test")},
			},
		},
	},
}

TestBlock is a test block

Functions

func BuildChannelHeader

func BuildChannelHeader(headerType common.HeaderType, chainID string, txID string, epoch uint64, chaincodeID string, timestamp time.Time) (*common.ChannelHeader, error)

BuildChannelHeader is a utility method to build a common chain header

func BuildHeader

func BuildHeader(creator []byte, channelHeader *common.ChannelHeader, nonce []byte) (*common.Header, error)

BuildHeader ...

func ComputeTxID

func ComputeTxID(nonce []byte, creator []byte) (string, error)

ComputeTxID computes a transaction ID from a given nonce and creator ID

func CreateSeekGenesisBlockRequest

func CreateSeekGenesisBlockRequest(channelName string, creator []byte) []byte

CreateSeekGenesisBlockRequest creates a seek request for block 0 on the specified channel. This request is sent to the ordering service to request blocks

func GenerateRandomNonce

func GenerateRandomNonce() ([]byte, error)

GenerateRandomNonce generates a random nonce

func GetLastConfigFromBlock

func GetLastConfigFromBlock(block *common.Block) (*common.LastConfig, error)

GetLastConfigFromBlock returns the LastConfig data from the given block

func MarshalOrPanic

func MarshalOrPanic(pb proto.Message) []byte

MarshalOrPanic serializes a protobuf message and panics if this operation fails.

func NewNewestSeekPosition

func NewNewestSeekPosition() *ab.SeekPosition

NewNewestSeekPosition returns a SeekPosition that requests the newest block

func NewSimpleMockBlock

func NewSimpleMockBlock() *common.Block

NewSimpleMockBlock returns a simple mock block

func NewSpecificSeekPosition

func NewSpecificSeekPosition(index uint64) *ab.SeekPosition

NewSpecificSeekPosition returns a SeekPosition that requests the block at the given index

func PackageCC

func PackageCC(chaincodePath string, chaincodeType string) ([]byte, error)

PackageCC ... *

  • Utility function to package a chaincode. The contents will be returned as a byte array. *
  • @param {string} chaincodePath required - String of the path to location of
  • the source code of the chaincode
  • @param {string} chaincodeType optional - String of the type of chaincode
  • ['golang', 'car', 'java'] (default 'golang')
  • @returns {[]byte} byte array

func QueryByChaincode

func QueryByChaincode(chaincodeName string, args []string, targets []Peer, clientContext Client) ([][]byte, error)

QueryByChaincode .. *

  • Sends a proposal to one or more endorsing peers that will be handled by the chaincode.
  • This request will be presented to the chaincode 'invoke' and must understand
  • from the arguments that this is a query request. The chaincode must also return
  • results in the byte array format and the caller will have to be able to decode
  • these results
  • @parame {string} chaincode name
  • @param {[]string} invoke arguments
  • @param {[]Peer} target peers
  • @returns {[][]byte} an array of payloads

func SignObjectWithKey

func SignObjectWithKey(object []byte, key bccsp.Key,
	hashOpts bccsp.HashOpts, signerOpts bccsp.SignerOpts, cryptoSuite bccsp.BCCSP) ([]byte, error)

SignObjectWithKey will sign the given object with the given key, hashOpts and signerOpts

Types

type Chain

type Chain interface {
	GetName() string
	Initialize(data []byte) error
	IsSecurityEnabled() bool
	GetTCertBatchSize() int
	SetTCertBatchSize(batchSize int)
	AddPeer(peer Peer) error
	RemovePeer(peer Peer)
	GetPeers() []Peer
	GetAnchorPeers() []OrgAnchorPeer
	SetPrimaryPeer(peer Peer) error
	GetPrimaryPeer() Peer
	AddOrderer(orderer Orderer) error
	RemoveOrderer(orderer Orderer)
	GetOrderers() []Orderer
	SetMSPManager(mspManager msp.MSPManager)
	GetMSPManager() msp.MSPManager
	GetGenesisBlock(request *GenesisBlockRequest) (*common.Block, error)
	JoinChannel(request *JoinChannelRequest) ([]*TransactionProposalResponse, error)
	UpdateChain() bool
	IsReadonly() bool
	QueryInfo() (*common.BlockchainInfo, error)
	QueryBlock(blockNumber int) (*common.Block, error)
	QueryBlockByHash(blockHash []byte) (*common.Block, error)
	QueryTransaction(transactionID string) (*pb.ProcessedTransaction, error)
	QueryInstantiatedChaincodes() (*pb.ChaincodeQueryResponse, error)
	QueryByChaincode(chaincodeName string, args []string, targets []Peer) ([][]byte, error)
	CreateTransactionProposal(chaincodeName string, chainID string, args []string, sign bool, transientData map[string][]byte) (*TransactionProposal, error)
	SendTransactionProposal(proposal *TransactionProposal, retry int, targets []Peer) ([]*TransactionProposalResponse, error)
	CreateTransaction(resps []*TransactionProposalResponse) (*Transaction, error)
	SendTransaction(tx *Transaction) ([]*TransactionResponse, error)
	SendInstantiateProposal(chaincodeName string, chainID string, args []string, chaincodePath string, chaincodeVersion string, targets []Peer) ([]*TransactionProposalResponse, string, error)
	GetOrganizationUnits() ([]string, error)
	QueryExtensionInterface() ChainExtension
	LoadConfigUpdateEnvelope(data []byte) error
}

Chain ... *

  • Chain representing a chain with which the client SDK interacts. *
  • The “Chain” object captures settings for a channel, which is created by
  • the orderers to isolate transactions delivery to peers participating on channel.
  • A chain must be initialized after it has been configured with the list of peers
  • and orderers. The initialization sends a get configuration block request to the
  • primary orderer to retrieve the configuration settings for this channel.

func NewChain

func NewChain(name string, client Client) (Chain, error)

NewChain ... * * @param {string} name to identify different chain instances. The naming of chain instances * is enforced by the ordering service and must be unique within the blockchain network * @param {Client} clientContext An instance of {@link Client} that provides operational context * such as submitting User etc.

type ChainExtension

type ChainExtension interface {
	GetClientContext() Client

	SignPayload(payload []byte) (*SignedEnvelope, error)
	BroadcastEnvelope(envelope *SignedEnvelope) ([]*TransactionResponse, error)

	// TODO: This should go somewhere else - see TransactionProposal.GetBytes(). - deprecated
	GetProposalBytes(tp *TransactionProposal) ([]byte, error)
}

The ChainExtension interface allows extensions of the SDK to add functionality to Chain overloads.

type Client

type Client interface {
	NewChain(name string) (Chain, error)
	GetChain(name string) Chain
	ExtractChannelConfig(configEnvelope []byte) ([]byte, error)
	SignChannelConfig(config []byte) (*common.ConfigSignature, error)
	CreateChannel(request *CreateChannelRequest) error
	QueryChainInfo(name string, peers []Peer) (Chain, error)
	SetStateStore(stateStore kvs.KeyValueStore)
	GetStateStore() kvs.KeyValueStore
	SetCryptoSuite(cryptoSuite bccsp.BCCSP)
	GetCryptoSuite() bccsp.BCCSP
	SaveUserToStateStore(user User, skipPersistence bool) error
	LoadUserFromStateStore(name string) (User, error)
	InstallChaincode(chaincodeName string, chaincodePath string, chaincodeVersion string, chaincodePackage []byte, targets []Peer) ([]*TransactionProposalResponse, string, error)
	QueryChannels(peer Peer) (*pb.ChannelQueryResponse, error)
	QueryInstalledChaincodes(peer Peer) (*pb.ChaincodeQueryResponse, error)
	GetIdentity() ([]byte, error)
	GetUserContext() User
	SetUserContext(user User)
}

Client ...

  • Main interaction handler with end user. A client instance provides a handler to interact
  • with a network of peers, orderers and optionally member services. An application using the
  • SDK may need to interact with multiple networks, each through a separate instance of the Client. *
  • Each client when initially created should be initialized with configuration data from the
  • consensus service, which includes a list of trusted roots, orderer certificates and IP addresses,
  • and a list of peer certificates and IP addresses that it can access. This must be done out of band
  • as part of bootstrapping the application environment. It is also the responsibility of the application
  • to maintain the configuration of a client as the SDK does not persist this object. *
  • Each Client instance can maintain several {@link Chain} instances representing channels and the associated
  • private ledgers. * *

func NewClient

func NewClient() Client

NewClient ...

  • Returns a Client instance

type CreateChannelRequest

type CreateChannelRequest struct {
	// required - The name of the new channel
	Name string
	// required - The Orderer to send the update request
	Orderer Orderer
	// optional - the envelope object containing all
	// required settings and signatures to initialize this channel.
	// This envelope would have been created by the command
	// line tool "configtx"
	Envelope []byte
	// optional - ConfigUpdate object built by the
	// buildChannelConfig() method of this package
	Config []byte
	// optional - the list of collected signatures
	// required by the channel create policy when using the `config` parameter.
	// see signChannelConfig() method of this package
	Signatures []*common.ConfigSignature
	// optional - transaction ID
	// required when using the `config` parameter
	TxID string
	// optional - nonce
	// required when using the `config` parameter
	Nonce []byte
}

CreateChannelRequest requests channel creation on the network

type GenesisBlockRequest

type GenesisBlockRequest struct {
	TxID  string
	Nonce []byte
}

GenesisBlockRequest ...

type JoinChannelRequest

type JoinChannelRequest struct {
	Targets      []Peer
	GenesisBlock *common.Block
	TxID         string
	Nonce        []byte
}

JoinChannelRequest allows a set of peers to transact on a channel on the network

type MockBroadcastServer

type MockBroadcastServer struct {
	DeliverError                 error
	BroadcastInternalServerError bool
}

MockBroadcastServer mock broadcast server

func (*MockBroadcastServer) Broadcast

Broadcast mock broadcast

func (*MockBroadcastServer) Deliver

Deliver mock deliver

type MockConfigBlockBuilder

type MockConfigBlockBuilder struct {
	MockConfigGroupBuilder
	Index           uint64
	LastConfigIndex uint64
}

MockConfigBlockBuilder is used to build a mock Chain configuration block

func (*MockConfigBlockBuilder) Build

func (b *MockConfigBlockBuilder) Build() *common.Block

Build creates a mock Chain configuration Block

type MockConfigGroupBuilder

type MockConfigGroupBuilder struct {
	Version        uint64
	ModPolicy      string
	OrdererAddress string
	MSPNames       []string
	RootCA         string
}

MockConfigGroupBuilder is used to build a mock ConfigGroup

type MockConfigUpdateEnvelopeBuilder

type MockConfigUpdateEnvelopeBuilder struct {
	MockConfigGroupBuilder
	ChannelID string
}

MockConfigUpdateEnvelopeBuilder builds a mock ConfigUpdateEnvelope

func (*MockConfigUpdateEnvelopeBuilder) Build

Build builds an Envelope that contains a mock ConfigUpdateEnvelope

func (*MockConfigUpdateEnvelopeBuilder) BuildBytes

func (b *MockConfigUpdateEnvelopeBuilder) BuildBytes() []byte

BuildBytes builds an Envelope that contains a mock ConfigUpdateEnvelope and returns the marshaled bytes

type MockCryptoSuite

type MockCryptoSuite struct {
}

MockCryptoSuite implementation

func (*MockCryptoSuite) Decrypt

func (m *MockCryptoSuite) Decrypt(k bccsp.Key, ciphertext []byte,
	opts bccsp.DecrypterOpts) (plaintext []byte, err error)

Decrypt mock decrypt

func (*MockCryptoSuite) Encrypt

func (m *MockCryptoSuite) Encrypt(k bccsp.Key, plaintext []byte,
	opts bccsp.EncrypterOpts) (ciphertext []byte, err error)

Encrypt mock encrypt

func (*MockCryptoSuite) GetHash

func (m *MockCryptoSuite) GetHash(opts bccsp.HashOpts) (h hash.Hash, err error)

GetHash mock get hash

func (*MockCryptoSuite) GetKey

func (m *MockCryptoSuite) GetKey(ski []byte) (k bccsp.Key, err error)

GetKey mock get key

func (*MockCryptoSuite) Hash

func (m *MockCryptoSuite) Hash(msg []byte, opts bccsp.HashOpts) (hash []byte, err error)

Hash mock hash

func (*MockCryptoSuite) KeyDeriv

func (m *MockCryptoSuite) KeyDeriv(k bccsp.Key,
	opts bccsp.KeyDerivOpts) (dk bccsp.Key, err error)

KeyDeriv mock key derivation

func (*MockCryptoSuite) KeyGen

func (m *MockCryptoSuite) KeyGen(opts bccsp.KeyGenOpts) (k bccsp.Key, err error)

KeyGen mock key gen

func (*MockCryptoSuite) KeyImport

func (m *MockCryptoSuite) KeyImport(raw interface{},
	opts bccsp.KeyImportOpts) (k bccsp.Key, err error)

KeyImport mock key import

func (*MockCryptoSuite) Sign

func (m *MockCryptoSuite) Sign(k bccsp.Key, digest []byte,
	opts bccsp.SignerOpts) (signature []byte, err error)

Sign mock signing

func (*MockCryptoSuite) Verify

func (m *MockCryptoSuite) Verify(k bccsp.Key, signature, digest []byte,
	opts bccsp.SignerOpts) (valid bool, err error)

Verify mock verify

type MockEndorserServer

type MockEndorserServer struct {
	ProposalError error
	AddkvWrite    bool
}

MockEndorserServer mock endoreser server to process endorsement proposals

func (*MockEndorserServer) ProcessProposal

func (m *MockEndorserServer) ProcessProposal(context context.Context,
	proposal *pb.SignedProposal) (*pb.ProposalResponse, error)

ProcessProposal mock implementation that returns success if error is not set error if it is

type MockOrderer

type MockOrderer interface {
	Orderer
	// Enqueues a mock error to be returned to the client calling SendBroadcast
	EnqueueSendBroadcastError(err error)
	// Enqueues a mock value (block or error) for delivery
	EnqueueForSendDeliver(value interface{})
}

MockOrderer is a mock fabricclient.Orderer Nothe that calling broadcast doesn't deliver anythng. This implies that the broadcast side and the deliver side are totally independent from the mocking point of view.

type Orderer

type Orderer interface {
	GetURL() string
	SendBroadcast(envelope *SignedEnvelope) (*common.Status, error)
	SendDeliver(envelope *SignedEnvelope) (chan *common.Block, chan error)
}

Orderer The Orderer class represents a peer in the target blockchain network to which HFC sends a block of transactions of endorsed proposals requiring ordering.

func CreateNewOrdererWithRootCAs

func CreateNewOrdererWithRootCAs(url string, ordererRootCAs [][]byte, serverHostOverride string) (Orderer, error)

CreateNewOrdererWithRootCAs Returns a new Orderer instance using the passed in orderer root CAs

func NewMockOrderer

func NewMockOrderer(url string, broadcastListener chan *SignedEnvelope) Orderer

NewMockOrderer ...

func NewOrderer

func NewOrderer(url string, certificate string, serverHostOverride string) (Orderer, error)

NewOrderer Returns a Orderer instance

type OrgAnchorPeer

type OrgAnchorPeer struct {
	Org  string
	Host string
	Port int32
}

OrgAnchorPeer contains information about an anchor peer on this chain

type Peer

type Peer interface {
	ConnectEventSource()
	IsEventListened(event string, chain Chain) (bool, error)
	AddListener(eventType string, eventTypeData interface{}, eventCallback interface{}) (string, error)
	RemoveListener(eventListenerRef string) (bool, error)
	GetName() string
	SetName(name string)
	GetRoles() []string
	SetRoles(roles []string)
	GetEnrollmentCertificate() *pem.Block
	SetEnrollmentCertificate(pem *pem.Block)
	GetURL() string
	SendProposal(proposal *TransactionProposal) (*TransactionProposalResponse, error)
}

Peer ... *

  • The Peer class represents a peer in the target blockchain network to which
  • HFC sends endorsement proposals, transaction ordering or query requests. *
  • The Peer class represents the remote Peer node and its network membership materials,
  • aka the ECert used to verify signatures. Peer membership represents organizations,
  • unlike User membership which represents individuals. *
  • When constructed, a Peer instance can be designated as an event source, in which case
  • a “eventSourceUrl” attribute should be configured. This allows the SDK to automatically
  • attach transaction event listeners to the event stream. *
  • It should be noted that Peer event streams function at the Peer level and not at the
  • chain and chaincode levels.

func NewPeer

func NewPeer(url string, certificate string, serverHostOverride string) (Peer, error)

NewPeer ... *

  • Constructs a Peer given its endpoint configuration settings. *
  • @param {string} url The URL with format of "host:port".

type SignedEnvelope

type SignedEnvelope struct {
	Payload   []byte
	Signature []byte
}

A SignedEnvelope can can be sent to an orderer for broadcasting

type Transaction

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

The Transaction object created from an endorsed proposal

type TransactionProposal

type TransactionProposal struct {
	TransactionID string

	SignedProposal *pb.SignedProposal
	Proposal       *pb.Proposal
}

The TransactionProposal object to be send to the endorsers

func CreateTransactionProposal

func CreateTransactionProposal(chaincodeName string, chainID string,
	args []string, sign bool, transientData map[string][]byte, clientContext Client) (*TransactionProposal, error)

CreateTransactionProposal ...

func (*TransactionProposal) GetBytes

func (tp *TransactionProposal) GetBytes() ([]byte, error)

GetBytes returns the serialized bytes of this proposal

type TransactionProposalResponse

type TransactionProposalResponse struct {
	Endorser string
	Err      error
	Status   int32

	Proposal         *TransactionProposal
	ProposalResponse *pb.ProposalResponse
}

TransactionProposalResponse ... *

  • The TransactionProposalResponse result object returned from endorsers.

func SendTransactionProposal

func SendTransactionProposal(proposal *TransactionProposal, retry int, targetPeers []Peer) ([]*TransactionProposalResponse, error)

SendTransactionProposal ...

func (*TransactionProposalResponse) GetPayload

func (tpr *TransactionProposalResponse) GetPayload() []byte

GetPayload returns the response payload

func (*TransactionProposalResponse) GetResponsePayload

func (tpr *TransactionProposalResponse) GetResponsePayload() []byte

GetResponsePayload returns the response object payload

type TransactionResponse

type TransactionResponse struct {
	Orderer string
	Err     error
}

TransactionResponse ... *

  • The TransactionProposalResponse result object returned from orderers.

type User

type User interface {
	GetName() string
	GetRoles() []string
	SetRoles([]string)
	GetEnrollmentCertificate() []byte
	SetEnrollmentCertificate(cert []byte)
	SetPrivateKey(privateKey bccsp.Key)
	GetPrivateKey() bccsp.Key
	GenerateTcerts(count int, attributes []string)
}

User ... *

  • The User struct represents users that have been enrolled and represented by
  • an enrollment certificate (ECert) and a signing key. The ECert must have
  • been signed by one of the CAs the blockchain network has been configured to trust.
  • An enrolled user (having a signing key and ECert) can conduct chaincode deployments,
  • transactions and queries with the Chain. *
  • User ECerts can be obtained from a CA beforehand as part of deploying the application,
  • or it can be obtained from the optional Fabric COP service via its enrollment process. *
  • Sometimes User identities are confused with Peer identities. User identities represent
  • signing capability because it has access to the private key, while Peer identities in
  • the context of the application/SDK only has the certificate for verifying signatures.
  • An application cannot use the Peer identity to sign things because the application doesn’t
  • have access to the Peer identity’s private key. *

func NewUser

func NewUser(name string) User

NewUser ... *

  • Constructor for a user. *
  • @param {string} name - The user name

type UserJSON

type UserJSON struct {
	PrivateKeySKI         []byte
	EnrollmentCertificate []byte
}

UserJSON ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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