Documentation
¶
Overview ¶
Package shim provides APIs for the chaincode to access its state variables, transaction context and call other chaincodes.
Index ¶
- Constants
- Variables
- func NewClientConnection(addr string, kopts *KeepaliveOptions, creds credentials.TransportCredentials, ...) (*grpc.ClientConn, error)
- func ParseConfig() error
- func Start(cc Chaincode) error
- type Chaincode
- type ChaincodeStub
- func (stub *ChaincodeStub) GetBalance(who string) (string, error)
- func (stub *ChaincodeStub) GetCcid() string
- func (stub *ChaincodeStub) GetCreator() string
- func (stub *ChaincodeStub) GetData() [][]byte
- func (stub *ChaincodeStub) GetFuncAndArgs() (string, []string)
- func (stub *ChaincodeStub) GetOwner() string
- func (stub *ChaincodeStub) GetState(key string) ([]byte, error)
- func (stub *ChaincodeStub) GetStateByRange(startKey, endKey string) (map[string][]byte, error)
- func (stub *ChaincodeStub) GetStates(keys ...string) (map[string][]byte, error)
- func (stub *ChaincodeStub) GetStringData() []string
- func (stub *ChaincodeStub) GetTxid() string
- func (stub *ChaincodeStub) PutState(key string, value []byte, ifNotExist bool) error
- func (stub *ChaincodeStub) PutStates(states map[string][]byte, keys ...string) error
- func (stub *ChaincodeStub) Transfer(to, coin string) error
- type ChaincodeStubInterface
- type Handler
- type KeepaliveOptions
- type NetConfig
- type PeerInfo
- type RespStatus
- type Stream
- type Token
Constants ¶
const ( MaxRecvMsgSize = 100 * 1024 * 1024 // 100 Mbytes MaxSendMsgSize = 100 * 1024 * 1024 // 100 Mbytes DefaultTimeout = 3 * time.Second // 3 seconds )
Constants for gRPC communication between chaincode and peer.
Variables ¶
var DefaultKeepaliveOptions = &KeepaliveOptions{ ClientInterval: time.Duration(1) * time.Minute, ClientTimeout: time.Duration(20) * time.Second, }
DefaultKeepaliveOptions defines default KeepaliveOptions.
Functions ¶
func NewClientConnection ¶
func NewClientConnection(addr string, kopts *KeepaliveOptions, creds credentials.TransportCredentials, block bool) (*grpc.ClientConn, error)
NewClientConnection creates new gRPC connection to peer.
func ParseConfig ¶
func ParseConfig() error
ParseConfig interpret program arguments into relevant configurations.
Types ¶
type Chaincode ¶
type Chaincode interface { Init(stub ChaincodeStubInterface) error Invoke(stub ChaincodeStubInterface) error }
Chaincode interface must be implemented by all chaincodes. The Avis runs the transactions by calling these functions as specified.
type ChaincodeStub ¶
type ChaincodeStub struct {
// contains filtered or unexported fields
}
ChaincodeStub is an object passed to chaincode for handling of APIs.
func (*ChaincodeStub) GetBalance ¶
func (stub *ChaincodeStub) GetBalance(who string) (string, error)
GetBalance returns balance of requested account.
func (*ChaincodeStub) GetCcid ¶
func (stub *ChaincodeStub) GetCcid() string
GetCcid returns id of chaincode instance to 20 Bytes hex string.
func (*ChaincodeStub) GetCreator ¶
func (stub *ChaincodeStub) GetCreator() string
GetCreator returns creator.
func (*ChaincodeStub) GetData ¶
func (stub *ChaincodeStub) GetData() [][]byte
GetData returns data from ChaincodeStub.
func (*ChaincodeStub) GetFuncAndArgs ¶
func (stub *ChaincodeStub) GetFuncAndArgs() (string, []string)
GetFuncAndArgs returns the arguments as array of strings.
func (*ChaincodeStub) GetOwner ¶
func (stub *ChaincodeStub) GetOwner() string
GetOwner returns owner address of chaincode instance to 20 Bytes hex string.
func (*ChaincodeStub) GetState ¶
func (stub *ChaincodeStub) GetState(key string) ([]byte, error)
GetState returns the byte array value specified by the `key`.
func (*ChaincodeStub) GetStateByRange ¶ added in v0.0.2
func (stub *ChaincodeStub) GetStateByRange(startKey, endKey string) (map[string][]byte, error)
GetStateByRange function can be invoked by a chaincode to query of a range of keys in the state. Assuming the startKey and endKey are in lexical order, an iterator will be returned that can be used to iterate over all keys between the startKey and endKey, inclusive.
func (*ChaincodeStub) GetStates ¶
func (stub *ChaincodeStub) GetStates(keys ...string) (map[string][]byte, error)
GetStates returns map of the byte array value specified by the multiple `key`.
func (*ChaincodeStub) GetStringData ¶
func (stub *ChaincodeStub) GetStringData() []string
GetStringData returns data which converted to string.
func (*ChaincodeStub) GetTxid ¶
func (stub *ChaincodeStub) GetTxid() string
GetTxid returns transaction id.
func (*ChaincodeStub) PutState ¶
func (stub *ChaincodeStub) PutState(key string, value []byte, ifNotExist bool) error
PutState writes the specified `value` and `key` into the ledger.
func (*ChaincodeStub) PutStates ¶
func (stub *ChaincodeStub) PutStates(states map[string][]byte, keys ...string) error
PutStates writes the value from `states` into the ledger.
func (*ChaincodeStub) Transfer ¶
func (stub *ChaincodeStub) Transfer(to, coin string) error
Transfer sends 'coin' amount of coins to address 'to'.
type ChaincodeStubInterface ¶
type ChaincodeStubInterface interface { GetCcid() string GetOwner() string GetTxid() string GetCreator() string GetData() [][]byte GetStringData() []string GetFuncAndArgs() (string, []string) GetState(key string) ([]byte, error) GetStates(keys ...string) (map[string][]byte, error) GetStateByRange(startKey, endKey string) (map[string][]byte, error) PutState(key string, value []byte, ifNotExist bool) error PutStates(states map[string][]byte, keys ...string) error Transfer(to, coin string) error GetBalance(who string) (string, error) }
ChaincodeStubInterface is used by chaincode apps to access and modify their ledgers.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler responsible for management of shim side of chaincode stream.
type KeepaliveOptions ¶
KeepaliveOptions defines KeepaliveOptions.
type NetConfig ¶
type NetConfig struct { //Clients []ClientInfo `json:"clients"` Peers []PeerInfo `json:"peers"` }
NetConfig is used by chaincode apps.
type PeerInfo ¶
type PeerInfo struct { ID int `json:"id"` //Ip string `json:"ip"` //AdminListen string `json:"admin_listen"` //EndorserListen string `json:"endorser_listen"` ChaincodeListen string `json:"chaincode_listen"` }
PeerInfo describes peer information.
type RespStatus ¶
type RespStatus uint8
RespStatus describes response status.
const ( RespStatusError RespStatus = iota RespStatusUpdate RespStatusQuery )
These constants comprise the RespStatus enumeration.
type Stream ¶
type Stream interface { Send(*pb.ChaincodeMessage) error Recv() (*pb.ChaincodeMessage, error) CloseSend() error }
Stream is interface for stream between Peer and chaincode instance.
type Token ¶
type Token interface { Transfer(stub ChaincodeStubInterface, to, amount string) error GetBalance(stub ChaincodeStubInterface, who string) error GetTotalSupply(stub ChaincodeStubInterface) error }
Token is standard for implementing tokens.