Documentation ¶
Index ¶
Constants ¶
const SystemContractName = "org.hyperledger.fabric"
SystemContractName the name of the system smart contract
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContractChaincode ¶
type ContractChaincode struct { DefaultContract string Info metadata.InfoMetadata TransactionSerializer serializer.TransactionSerializer // contains filtered or unexported fields }
ContractChaincode a struct to meet the chaincode interface and provide routing of calls to contracts
func NewChaincode ¶
func NewChaincode(contracts ...ContractInterface) (*ContractChaincode, error)
NewChaincode creates a new chaincode using contracts passed. The function parses each of the passed functions and stores details about their make-up to be used by the chaincode. Public functions of the contracts are stored and are made callable in the chaincode. The function will error if contracts are invalid e.g. public functions take in illegal types. A system contract is added to the chaincode which provides functionality for getting the metadata of the chaincode. The generated metadata is a JSON formatted MetadataContractChaincode containing each contract as a name and details of the public functions and types they take in/return. It also outlines version details for contracts and the chaincode. If these are blank strings this is set to latest. The names for parameters do not match those used in the functions, instead they are recorded as param0, param1, ..., paramN. If there exists a file contract-metadata/metadata.json then this will overwrite the generated metadata. The contents of this file must validate against the schema. The transaction serializer for the contract is set to be the JSONSerializer by default. This can be updated using by changing the TransactionSerializer property
func (*ContractChaincode) Init ¶
func (cc *ContractChaincode) Init(stub shim.ChaincodeStubInterface) peer.Response
Init is called during Instantiate transaction after the chaincode container has been established for the first time, passes off details of the request to Invoke for handling the request if a function name is passed, otherwise returns shim.Success
func (*ContractChaincode) Invoke ¶
func (cc *ContractChaincode) Invoke(stub shim.ChaincodeStubInterface) peer.Response
Invoke is called to update or query the ledger in a proposal transaction. Takes the args passed in the transaction and uses the first argument to identify the contract and function of that contract to be called. The remaining args are then used as parameters to that function. Args are converted from strings to the expected parameter types of the function before being passed using the set transaction serializer for the ContractChaincode. A transaction context is generated and is passed, if required, as the first parameter to the named function. Before and after functions are called before and after the named function passed if the contract defines such functions to exist. If the before function returns an error the named function is not called and its error is returned in shim.Error. If the after function returns an error then its value is returned to shim.Error otherwise the value returned from the named function is returned as shim.Success (formatted by the transaction serializer). If an unknown name is passed as part of the first arg a shim.Error is returned. If a valid name is passed but the function name is unknown then the contract with that name's unknown function is called and its value returned as success or error depending on its return. If no unknown function is defined for the contract then shim.Error is returned by Invoke. In the case of unknown function names being passed (and the unknown handler returns an error) or the named function returning an error then the after function if defined is not called. If the named function or unknown function handler returns a non-error type then then the after transaction is sent this value. The same transaction context is passed as a pointer to before, after, named and unknown functions on each Invoke. If no contract name is passed then the default contract is used.
func (*ContractChaincode) Start ¶
func (cc *ContractChaincode) Start() error
Start starts the chaincode in the fabric shim