Class: Contract

Contract

The main Contact class that all code working within a Chaincode Container must be extending. Overriding of the `beforeTransaction` `afterTransaction` `unknownTransaction` and `createContext` are all optional Supplying a name within the constructor is also option and will default to ''

new Contract(name)

Constructor - supplying a name is recommended but is not mandatory.
Parameters:
Name Type Description
name String name for the logic within this contract

Methods


<static> _isContract(obj)

isContract provides functionality to check if a passed object is a contract type. Enables checking if its a contract for when contract-api is "required" by different modules
Parameters:
Name Type Description
obj Object

<async> afterTransaction(ctx, result)

'afterTransaction' will be called before any of the transaction functions within your contract Override this method to implement your own processing. Examples of what you may wish to code are Logging, Event Publishing If an error is thrown, the whole transaction will be rejected
Parameters:
Name Type Description
ctx Context the transactional context
result Object value that is returned from the transaction function

<async> beforeTransaction(ctx)

'beforeTransaction' will be called before any of the transaction functions within your contract Override this method to implement your own processing. Examples of what you may wish to code are Logging, Event Publishing or Permissions checks If an error is thrown, the whole transaction will be rejected
Parameters:
Name Type Description
ctx Context the transactional context

createContext()

'createContext' is called before any after, before, unknown or user defined transaction function. This permits contracts to use their own subclass of context to add additinal processing. After this function returns, the chaincodeStub and client identity objects will be injected. No chaincode apis are available for calling directly within this function. Nor should the constructor of the subclasses context assume any other setup.
Returns:
a context implementation that must subclass context
Type
Context

getName()

Returns:
returns the namepsace
Type
String

<async> unknownTransaction(ctx)

'unknownTransaction' will be called if the required transaction function requested does not exist Override this method to implement your own processing. If an error is thrown, the whole transaction will be rejected
Parameters:
Name Type Description
ctx Context the transactional context