Package org.hyperledger.fabric.shim
Class ChaincodeBase
- java.lang.Object
-
- org.hyperledger.fabric.shim.ChaincodeBase
-
- All Implemented Interfaces:
Chaincode
public abstract class ChaincodeBase extends java.lang.Object implements Chaincode
Abstract implementation ofChaincode.All chaincode implementations must extend the abstract class
ChaincodeBase. It is possible to implement chaincode by extendingChaincodeBasedirectly however new projects should implementContractInterfaceand use the contract programming model instead.- See Also:
org.hyperledger.fabric.contract
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classChaincodeBase.CCStateChaincode State.-
Nested classes/interfaces inherited from interface org.hyperledger.fabric.shim.Chaincode
Chaincode.Response
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCORE_CHAINCODE_LOGGING_LEVELstatic java.lang.StringCORE_CHAINCODE_LOGGING_SHIMstatic java.lang.StringDEFAULT_HOSTstatic java.lang.StringDEFAULT_MAX_INBOUND_MESSAGE_SIZEDefault to 100MB for maximum inbound grpc message size.static intDEFAULT_PORT
-
Constructor Summary
Constructors Constructor Description ChaincodeBase()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidconnectToPeer()protected io.grpc.stub.StreamObserver<org.hyperledger.fabric.protos.peer.ChaincodeMessage>connectToPeer(io.grpc.stub.StreamObserver<org.hyperledger.fabric.protos.peer.ChaincodeMessage> requestObserver)connect external chaincode to peer for chat.java.util.PropertiesgetChaincodeConfig()Obtains configuration specifically for running the chaincode and settable on a per chaincode basis rather than taking properties from the Peers' configuration.ChaincodeServerPropertiesgetChaincodeServerConfig()The properties for starting as chaincode-as-a-service.ChaincodeBase.CCStategetState()abstract Chaincode.Responseinit(ChaincodeStub stub)Called during an instantiate transaction after the container has been established, allowing the chaincode to initialize its internal data.protected voidinitializeLogging()abstract Chaincode.Responseinvoke(ChaincodeStub stub)Called for every Invoke transaction.booleanisServer()Use the CHAINCODE_SERVER_ADDRESS as the key to swap mode.io.grpc.ManagedChannelBuilder<?>newChannelBuilder()create NettyChannel for host:port with tls if tlsEnabled.protected static Chaincode.ResponsenewErrorResponse()Deprecated.protected static Chaincode.ResponsenewErrorResponse(byte[] payload)Deprecated.protected static Chaincode.ResponsenewErrorResponse(java.lang.String message)Deprecated.protected static Chaincode.ResponsenewErrorResponse(java.lang.String message, byte[] payload)Deprecated.protected static Chaincode.ResponsenewErrorResponse(java.lang.Throwable throwable)Deprecated.protected static Chaincode.ResponsenewSuccessResponse()Deprecated.protected static Chaincode.ResponsenewSuccessResponse(byte[] payload)Deprecated.protected static Chaincode.ResponsenewSuccessResponse(java.lang.String message)Deprecated.protected static Chaincode.ResponsenewSuccessResponse(java.lang.String message, byte[] payload)Deprecated.protected voidprocessCommandLineOptions(java.lang.String[] args)voidprocessEnvironmentOptions()set fields from env.voidsetState(ChaincodeBase.CCState newState)voidstart(java.lang.String[] args)Start chaincode.static java.lang.StringtoJsonString(org.hyperledger.fabric.protos.peer.ChaincodeMessage message)Debug Message.voidvalidateOptions()Validate init parameters from env chaincode base.
-
-
-
Field Detail
-
CORE_CHAINCODE_LOGGING_SHIM
public static final java.lang.String CORE_CHAINCODE_LOGGING_SHIM
- See Also:
- Constant Field Values
-
CORE_CHAINCODE_LOGGING_LEVEL
public static final java.lang.String CORE_CHAINCODE_LOGGING_LEVEL
- See Also:
- Constant Field Values
-
DEFAULT_HOST
public static final java.lang.String DEFAULT_HOST
- See Also:
- Constant Field Values
-
DEFAULT_PORT
public static final int DEFAULT_PORT
- See Also:
- Constant Field Values
-
DEFAULT_MAX_INBOUND_MESSAGE_SIZE
public static final java.lang.String DEFAULT_MAX_INBOUND_MESSAGE_SIZE
Default to 100MB for maximum inbound grpc message size.- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public abstract Chaincode.Response init(ChaincodeStub stub)
Description copied from interface:ChaincodeCalled during an instantiate transaction after the container has been established, allowing the chaincode to initialize its internal data.
-
invoke
public abstract Chaincode.Response invoke(ChaincodeStub stub)
Description copied from interface:ChaincodeCalled for every Invoke transaction. The chaincode may change its state variables.
-
start
public void start(java.lang.String[] args)
Start chaincode.- Parameters:
args- command line arguments
-
connectToPeer
protected final void connectToPeer() throws java.io.IOException- Throws:
java.io.IOException
-
connectToPeer
protected io.grpc.stub.StreamObserver<org.hyperledger.fabric.protos.peer.ChaincodeMessage> connectToPeer(io.grpc.stub.StreamObserver<org.hyperledger.fabric.protos.peer.ChaincodeMessage> requestObserver) throws java.io.IOExceptionconnect external chaincode to peer for chat.- Parameters:
requestObserver- reqeust from peer- Returns:
- itm - The InnvocationTask Manager handles the message level communication with the peer.
- Throws:
java.io.IOException- validation fields exception
-
initializeLogging
protected final void initializeLogging()
-
isServer
public boolean isServer()
Use the CHAINCODE_SERVER_ADDRESS as the key to swap mode.- Returns:
- true if this should be run as `chaincode-as-a-service`
-
validateOptions
public void validateOptions()
Validate init parameters from env chaincode base.
-
processCommandLineOptions
protected final void processCommandLineOptions(java.lang.String[] args)
-
processEnvironmentOptions
public final void processEnvironmentOptions()
set fields from env.
-
getChaincodeConfig
public java.util.Properties getChaincodeConfig()
Obtains configuration specifically for running the chaincode and settable on a per chaincode basis rather than taking properties from the Peers' configuration.- Returns:
- Configuration
-
getChaincodeServerConfig
public final ChaincodeServerProperties getChaincodeServerConfig() throws java.net.URISyntaxException
The properties for starting as chaincode-as-a-service.- Returns:
- ChaincodeServerProperties populated
- Throws:
java.net.URISyntaxException
-
newChannelBuilder
public final io.grpc.ManagedChannelBuilder<?> newChannelBuilder() throws java.io.IOExceptioncreate NettyChannel for host:port with tls if tlsEnabled.- Returns:
- ManagedChannelBuilder
- Throws:
java.io.IOException- while createSSLContext()
-
newSuccessResponse
@Deprecated protected static Chaincode.Response newSuccessResponse(java.lang.String message, byte[] payload)
Deprecated.
-
newSuccessResponse
@Deprecated protected static Chaincode.Response newSuccessResponse()
Deprecated.
-
newSuccessResponse
@Deprecated protected static Chaincode.Response newSuccessResponse(java.lang.String message)
Deprecated.
-
newSuccessResponse
@Deprecated protected static Chaincode.Response newSuccessResponse(byte[] payload)
Deprecated.
-
newErrorResponse
@Deprecated protected static Chaincode.Response newErrorResponse(java.lang.String message, byte[] payload)
Deprecated.
-
newErrorResponse
@Deprecated protected static Chaincode.Response newErrorResponse()
Deprecated.
-
newErrorResponse
@Deprecated protected static Chaincode.Response newErrorResponse(java.lang.String message)
Deprecated.
-
newErrorResponse
@Deprecated protected static Chaincode.Response newErrorResponse(byte[] payload)
Deprecated.
-
newErrorResponse
@Deprecated protected static Chaincode.Response newErrorResponse(java.lang.Throwable throwable)
Deprecated.
-
getState
public final ChaincodeBase.CCState getState()
- Returns:
- State
-
setState
public final void setState(ChaincodeBase.CCState newState)
- Parameters:
newState-
-
toJsonString
public static java.lang.String toJsonString(org.hyperledger.fabric.protos.peer.ChaincodeMessage message)
Debug Message.- Parameters:
message-- Returns:
- JSON Form of message
-
-