Class ChaincodeBase

  • All Implemented Interfaces:
    Chaincode

    public abstract class ChaincodeBase
    extends java.lang.Object
    implements Chaincode
    Abstract implementation of Chaincode.

    All chaincode implementations must extend the abstract class ChaincodeBase. It is possible to implement chaincode by extending ChaincodeBase directly however new projects should implement ContractInterface and use the contract programming model instead.

    See Also:
    org.hyperledger.fabric.contract
    • 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_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
    • Constructor Detail

      • ChaincodeBase

        public ChaincodeBase()
    • 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.
        Specified by:
        init in interface Chaincode
        Parameters:
        stub - the chaincode stub
        Returns:
        the chaincode response
      • 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.
        Specified by:
        invoke in interface Chaincode
        Parameters:
        stub - the chaincode stub
        Returns:
        the chaincode response
      • 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.
      • toJsonString

        public static java.lang.String toJsonString​(org.hyperledger.fabric.protos.peer.ChaincodeMessage message)
        Debug Message.
        Parameters:
        message -
        Returns:
        JSON Form of message