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 extendingChaincodeBase
directly however new projects should implementContractInterface
and use the contract programming model instead.- See Also:
org.hyperledger.fabric.contract
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ChaincodeBase.CCState
Chaincode 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.String
CORE_CHAINCODE_LOGGING_LEVEL
static java.lang.String
CORE_CHAINCODE_LOGGING_SHIM
static java.lang.String
DEFAULT_HOST
static java.lang.String
DEFAULT_MAX_INBOUND_MESSAGE_SIZE
Default to 100MB for maximum inbound grpc message size.static int
DEFAULT_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 void
connectToPeer()
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.Properties
getChaincodeConfig()
Obtains configuration specifically for running the chaincode and settable on a per chaincode basis rather than taking properties from the Peers' configuration.ChaincodeServerProperties
getChaincodeServerConfig()
The properties for starting as chaincode-as-a-service.ChaincodeBase.CCState
getState()
abstract Chaincode.Response
init(ChaincodeStub stub)
Called during an instantiate transaction after the container has been established, allowing the chaincode to initialize its internal data.protected void
initializeLogging()
abstract Chaincode.Response
invoke(ChaincodeStub stub)
Called for every Invoke transaction.boolean
isServer()
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.Response
newErrorResponse()
Deprecated.protected static Chaincode.Response
newErrorResponse(byte[] payload)
Deprecated.protected static Chaincode.Response
newErrorResponse(java.lang.String message)
Deprecated.protected static Chaincode.Response
newErrorResponse(java.lang.String message, byte[] payload)
Deprecated.protected static Chaincode.Response
newErrorResponse(java.lang.Throwable throwable)
Deprecated.protected static Chaincode.Response
newSuccessResponse()
Deprecated.protected static Chaincode.Response
newSuccessResponse(byte[] payload)
Deprecated.protected static Chaincode.Response
newSuccessResponse(java.lang.String message)
Deprecated.protected static Chaincode.Response
newSuccessResponse(java.lang.String message, byte[] payload)
Deprecated.protected void
processCommandLineOptions(java.lang.String[] args)
void
processEnvironmentOptions()
set fields from env.void
setState(ChaincodeBase.CCState newState)
void
start(java.lang.String[] args)
Start chaincode.static java.lang.String
toJsonString(org.hyperledger.fabric.protos.peer.ChaincodeMessage message)
Debug Message.void
validateOptions()
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:Chaincode
Called 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:Chaincode
Called 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.IOException
connect 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.IOException
create 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
-
-