Documentation ¶
Index ¶
- Variables
- func BuildChannelHeader(headerType common.HeaderType, chainID string, txID string, epoch uint64, ...) (*common.ChannelHeader, error)
- func BuildHeader(creator []byte, channelHeader *common.ChannelHeader, nonce []byte) (*common.Header, error)
- func ComputeTxID(nonce []byte, creator []byte) (string, error)
- func CreateSeekGenesisBlockRequest(channelName string, creator []byte) []byte
- func GenerateRandomNonce() ([]byte, error)
- func GetLastConfigFromBlock(block *common.Block) (*common.LastConfig, error)
- func MarshalOrPanic(pb proto.Message) []byte
- func NewNewestSeekPosition() *ab.SeekPosition
- func NewSimpleMockBlock() *common.Block
- func NewSpecificSeekPosition(index uint64) *ab.SeekPosition
- func PackageCC(chaincodePath string, chaincodeType string) ([]byte, error)
- func QueryByChaincode(chaincodeName string, args []string, targets []Peer, clientContext Client) ([][]byte, error)
- func SignObjectWithKey(object []byte, key bccsp.Key, hashOpts bccsp.HashOpts, ...) ([]byte, error)
- type Chain
- type ChainExtension
- type Client
- type CreateChannelRequest
- type GenesisBlockRequest
- type JoinChannelRequest
- type MockBroadcastServer
- type MockConfigBlockBuilder
- type MockConfigGroupBuilder
- type MockConfigUpdateEnvelopeBuilder
- type MockCryptoSuite
- func (m *MockCryptoSuite) Decrypt(k bccsp.Key, ciphertext []byte, opts bccsp.DecrypterOpts) (plaintext []byte, err error)
- func (m *MockCryptoSuite) Encrypt(k bccsp.Key, plaintext []byte, opts bccsp.EncrypterOpts) (ciphertext []byte, err error)
- func (m *MockCryptoSuite) GetHash(opts bccsp.HashOpts) (h hash.Hash, err error)
- func (m *MockCryptoSuite) GetKey(ski []byte) (k bccsp.Key, err error)
- func (m *MockCryptoSuite) Hash(msg []byte, opts bccsp.HashOpts) (hash []byte, err error)
- func (m *MockCryptoSuite) KeyDeriv(k bccsp.Key, opts bccsp.KeyDerivOpts) (dk bccsp.Key, err error)
- func (m *MockCryptoSuite) KeyGen(opts bccsp.KeyGenOpts) (k bccsp.Key, err error)
- func (m *MockCryptoSuite) KeyImport(raw interface{}, opts bccsp.KeyImportOpts) (k bccsp.Key, err error)
- func (m *MockCryptoSuite) Sign(k bccsp.Key, digest []byte, opts bccsp.SignerOpts) (signature []byte, err error)
- func (m *MockCryptoSuite) Verify(k bccsp.Key, signature, digest []byte, opts bccsp.SignerOpts) (valid bool, err error)
- type MockEndorserServer
- type MockOrderer
- type Orderer
- type OrgAnchorPeer
- type Peer
- type SignedEnvelope
- type Transaction
- type TransactionProposal
- type TransactionProposalResponse
- type TransactionResponse
- type User
- type UserJSON
Constants ¶
This section is empty.
Variables ¶
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 ¶
ComputeTxID computes a transaction ID from a given nonce and creator ID
func CreateSeekGenesisBlockRequest ¶
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 ¶
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 ¶
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 ¶
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 ¶
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
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 ¶
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. * *
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 ¶
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 ¶
MockBroadcastServer mock broadcast server
func (*MockBroadcastServer) Broadcast ¶
func (m *MockBroadcastServer) Broadcast(server po.AtomicBroadcast_BroadcastServer) error
Broadcast mock broadcast
func (*MockBroadcastServer) Deliver ¶
func (m *MockBroadcastServer) Deliver(server po.AtomicBroadcast_DeliverServer) error
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 ¶
func (b *MockConfigUpdateEnvelopeBuilder) Build() *common.Envelope
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) GetKey ¶
func (m *MockCryptoSuite) GetKey(ski []byte) (k bccsp.Key, err error)
GetKey mock get key
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 ¶
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 ...
type OrgAnchorPeer ¶
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.
type SignedEnvelope ¶
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 ¶
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. *