common

package
v0.0.0-...-1a8e90c Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2017 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsURL

func AsURL(host string, port int) string

AsURL return a URL in the form host:port

func Base64URLDecode

func Base64URLDecode(data string) ([]byte, error)

Base64URLDecode decodes the base64 string into a byte array

func Base64URLEncode

func Base64URLEncode(data []byte) string

Base64URLEncode encodes the byte array into a base64 string

Types

type Action

type Action struct {
	Writer io.Writer
	// contains filtered or unexported fields
}

Action is the base implementation of the Action interface.

func (*Action) ChannelClient

func (action *Action) ChannelClient() (apifabclient.Channel, error)

ChannelClient creates a new ChannelClient

func (*Action) Client

func (action *Action) Client() apifabclient.FabricClient

Client returns the Fabric client

func (*Action) EventHub

func (action *Action) EventHub() (apifabclient.EventHub, error)

EventHub returns the event hub.

func (*Action) Flags

func (action *Action) Flags() *pflag.FlagSet

Flags returns the flag-set

func (*Action) Initialize

func (action *Action) Initialize(flags *pflag.FlagSet) error

Initialize initializes the action using the given flags

func (*Action) Orderers

func (action *Action) Orderers() ([]apifabclient.Orderer, error)

Orderers returns all Orderers from the set of configured Orderers

func (*Action) OrgAdminUser

func (action *Action) OrgAdminUser(orgID string) apifabclient.User

OrgAdminUser returns the pre-enrolled administrative user for the given organization

func (*Action) OrgID

func (action *Action) OrgID() string

OrgID returns the organization ID of the first peer in the list of peers

func (*Action) OrgOfPeer

func (action *Action) OrgOfPeer(peerURL string) (string, error)

OrgOfPeer returns the organization ID of the given peer

func (*Action) OrgOrdererAdminUser

func (action *Action) OrgOrdererAdminUser(orgID string) apifabclient.User

OrgOrdererAdminUser returns the pre-enrolled orderer admin user for the given organization

func (*Action) OrgUser

func (action *Action) OrgUser(orgID string) apifabclient.User

OrgUser returns the pre-enrolled user for the given organization

func (*Action) Peer

func (action *Action) Peer() apifabclient.Peer

Peer returns the first peer in the list of selected peers

func (*Action) PeerFromURL

func (action *Action) PeerFromURL(url string) apifabclient.Peer

PeerFromURL returns the peer for the given URL

func (*Action) Peers

func (action *Action) Peers() []apifabclient.Peer

Peers returns the peers

func (*Action) PeersByOrg

func (action *Action) PeersByOrg() map[string][]apifabclient.Peer

PeersByOrg returns the peers mapped by organization

func (*Action) Printer

func (action *Action) Printer() Printer

Printer returns the Printer

func (*Action) RandomOrderer

func (action *Action) RandomOrderer() (apifabclient.Orderer, error)

RandomOrderer chooses a random Orderer from the set of configured Orderers

func (*Action) SetUserContext

func (action *Action) SetUserContext(user apifabclient.User) *UserContext

SetUserContext sets the current user for the client TODO: This function should disappear when the SDK introduces sessions

func (*Action) Terminate

func (action *Action) Terminate()

Terminate closes any open connections. This function should be called at the end of every command invocation.

func (*Action) User

func (action *Action) User() (apifabclient.User, error)

User returns the enrolled user. If the user doesn't exist then a new user is enrolled.

type ArgStruct

type ArgStruct struct {
	Func string   `json:"Func"`
	Args []string `json:"Args"`
}

ArgStruct is used for marshalling arguments to chaincode invocations

type CLIConfig

type CLIConfig interface {
	apiconfig.Config

	// Logger returns the Logger for the CLI tool
	Logger() *logging.Logger

	// LoggingLevel specifies the logging level (DEBUG, INFO, WARNING, ERROR, or CRITICAL)
	LoggingLevel() string
	InitLoggingLevel(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// ConfigFile specified the path of the configuration file
	ConfigFile() string
	InitConfigFile(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// OrgID specifies the ID of the current organization. If multiple org IDs are specified then the first one is returned.
	OrgID() string

	// OrgIDs returns a comma-separated list of organization IDs
	OrgIDs() []string
	InitOrgIDs(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// ChannelID returns the channel ID
	ChannelID() string
	InitChannelID(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// UserName returns the name of the enrolled user
	UserName() string
	InitUserName(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// UserPassword is the password to use when enrolling a user
	UserPassword() string
	InitUserPassword(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// ChaincodeID returns the chaicode ID
	ChaincodeID() string
	InitChaincodeID(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// ChaincodePath returns the source path of the chaincode to install/instantiate
	ChaincodePath() string
	InitChaincodePath(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// ChaincodeVersion returns the version of the chaincode
	ChaincodeVersion() string
	InitChaincodeVersion(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// ChaincodeEvent the name of the chaincode event to listen for
	ChaincodeEvent() string
	InitChaincodeEvent(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// PeerURL returns a comma-separated list of peers in the format host1:port1,host2:port2,...
	PeerURL() string
	InitPeerURL(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// OrdererURL returns the URL of the orderer
	OrdererURL() string
	InitOrdererURL(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// OrdererTLSCertificate is the path of the orderer TLS certificate
	OrdererTLSCertificate() string
	InitOrdererTLSCertificate(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// Iterations returns the number of times that a chaincode should be invoked
	Iterations() int
	InitIterations(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// SleepTime returns the number of milliseconds to sleep between invocations of a chaincode
	SleepTime() int64
	InitSleepTime(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// BlockNum returns the block number (where 0 is the first block)
	BlockNum() int
	InitBlockNum(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// BlockHash specifies the hash of the block
	BlockHash() string
	InitBlockHash(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// Traverse returns the number of blocks to traverse backwards in the query block command
	Traverse() int
	InitTraverse(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// PrintFormat returns the print (output) format for a block
	PrintFormat() string
	InitPrintFormat(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// Writer returns the writer for output
	Writer() string
	InitWriter(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// Args returns the chaincode invocation arguments as a JSON string in the format, {"Func":"function","Args":["arg1","arg2",...]}
	Args() string
	InitArgs(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// TxFile is the path of the .tx file used to create a channel
	TxFile() string
	InitTxFile(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// TxID returns the transaction ID
	TxID() string
	InitTxID(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// ChaincodePolicy returns the chaincode policy string, e.g Nof(1,(SignedBy(Org1Msp),SignedBy(Org2MSP)))
	ChaincodePolicy() string
	InitChaincodePolicy(flags *pflag.FlagSet, defaultValueAndDescription ...string)

	// Timeout returns the timeout (in milliseconds) for various operations
	Timeout() time.Duration
	InitTimeout(flags *pflag.FlagSet, defaultValueAndDescription ...string)
}

CLIConfig extendsthe fabric API config and provides additional configuration options

func Config

func Config() CLIConfig

Config returns the CLI configuration

type Formatter

type Formatter interface {
	// PrintHeader outputs a header
	PrintHeader()

	// PrintFooter outputs a footer
	PrintFooter()

	// Element starts an element
	Element(element string)

	// ElementEnd ends an element
	ElementEnd()

	// Field outputs the value of a field
	Field(field string, value interface{})

	// Array starts an array
	Array(element string)

	// ArrayEnd ends the array
	ArrayEnd()

	// Item starts a complex array item
	Item(element string, index interface{})

	// ItemEnd ends an array item
	ItemEnd()

	// ItemValue outputs a simple array item
	ItemValue(element string, index interface{}, value interface{})

	// Value outputs a value
	Value(value interface{})

	// Print outputs additional info
	Print(frmt string, vars ...interface{})
}

Formatter outputs the data in a specific format

func NewFormatter

func NewFormatter(format OutputFormat, writerType WriterType) Formatter

NewFormatter returns a new Formatter given the format and writer type. nil is returned if no formatter exists for the given type

type OutputFormat

type OutputFormat uint8

OutputFormat specifies the format for printing data

const (
	// RAW displays the raw data
	RAW OutputFormat = iota

	// JSON formats the data into Java Script Object Notation format
	JSON

	// DISPLAY formats the data into a human readable format
	DISPLAY
)

func AsOutputFormat

func AsOutputFormat(f string) OutputFormat

AsOutputFormat returns the OutputFormat given an Output Format string

func (OutputFormat) String

func (f OutputFormat) String() string

type Printer

type Printer interface {
	// PrintBlockchainInfo outputs BlockchainInfo
	PrintBlockchainInfo(info *fabricCommon.BlockchainInfo)

	// PrintBlock outputs a Block
	PrintBlock(block *fabricCommon.Block)

	// PrintChannels outputs the array of ChannelInfo
	PrintChannels(channels []*fabricPeer.ChannelInfo)

	// PrintChaincodes outputs the given array of ChaincodeInfo
	PrintChaincodes(chaincodes []*fabricPeer.ChaincodeInfo)

	// PrintProcessedTransaction outputs a ProcessedTransaction
	PrintProcessedTransaction(tx *fabricPeer.ProcessedTransaction)

	// PrintChaincodeData outputs ChaincodeData
	PrintChaincodeData(ccdata *ccprovider.ChaincodeData)

	// PrintTxProposalResponses outputs the proposal responses
	PrintTxProposalResponses(responses []*apitxn.TransactionProposalResponse)

	// PrintChaincodeEvent outputs a chaincode event
	PrintChaincodeEvent(event *apifabclient.ChaincodeEvent)
}

Printer is used for printing various data structures

func NewPrinter

func NewPrinter(format OutputFormat, writerType WriterType) Printer

NewPrinter returns a new Printer of the given OutputFormat and WriterType

type UserContext

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

UserContext restores a previously saved user context TODO: This is a temporary construct which should be removed when the SDK introduces sessions

func (*UserContext) Restore

func (c *UserContext) Restore()

Restore restores the user context

type Writer

type Writer interface {
	Write(format string, a ...interface{}) error
}

Writer writes the output

func NewWriter

func NewWriter(writerType WriterType) Writer

NewWriter returns a new writer given the writer type

type WriterType

type WriterType uint8

WriterType specifies the format for printing data

const (
	// STDOUT writes to standard out
	STDOUT WriterType = iota

	// STDERR writes to standard error
	STDERR

	// LOG writes to the logger
	LOG
)

func AsWriterType

func AsWriterType(t string) WriterType

AsWriterType returns the WriterType given a Writer Type string

func (WriterType) String

func (f WriterType) String() string

Jump to

Keyboard shortcuts

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