2017-07-05 11:16:47 +00:00
|
|
|
.. highlight:: kotlin
|
|
|
|
|
2017-10-13 09:36:25 +00:00
|
|
|
Writing a custom notary service (experimental)
|
|
|
|
==============================================
|
2017-07-05 11:16:47 +00:00
|
|
|
|
2018-03-06 12:22:09 +00:00
|
|
|
.. warning:: Customising a notary service is still an experimental feature and not recommended for most use-cases. The APIs
|
2018-10-10 12:31:29 +00:00
|
|
|
for writing a custom notary may change in the future.
|
2017-07-05 11:16:47 +00:00
|
|
|
|
2018-10-10 12:31:29 +00:00
|
|
|
The first step is to create a service class in your CorDapp that extends the ``NotaryService`` abstract class.
|
|
|
|
This will ensure that it is recognised as a notary service.
|
|
|
|
The custom notary service class should provide a constructor with two parameters of types ``ServiceHubInternal`` and ``PublicKey``.
|
|
|
|
Note that ``ServiceHubInternal`` does not provide any API stability guarantees.
|
2017-07-05 11:16:47 +00:00
|
|
|
|
2019-02-20 19:56:08 +00:00
|
|
|
.. literalinclude:: ../../samples/notary-demo/workflows/src/main/kotlin/net/corda/notarydemo/MyCustomNotaryService.kt
|
2017-07-05 11:16:47 +00:00
|
|
|
:language: kotlin
|
|
|
|
:start-after: START 1
|
|
|
|
:end-before: END 1
|
|
|
|
|
|
|
|
The next step is to write a notary service flow. You are free to copy and modify the existing built-in flows such
|
|
|
|
as ``ValidatingNotaryFlow``, ``NonValidatingNotaryFlow``, or implement your own from scratch (following the
|
|
|
|
``NotaryFlow.Service`` template). Below is an example of a custom flow for a *validating* notary service:
|
|
|
|
|
2019-02-20 19:56:08 +00:00
|
|
|
.. literalinclude:: ../../samples/notary-demo/workflows/src/main/kotlin/net/corda/notarydemo/MyCustomNotaryService.kt
|
2017-07-05 11:16:47 +00:00
|
|
|
:language: kotlin
|
|
|
|
:start-after: START 2
|
|
|
|
:end-before: END 2
|
2017-10-13 09:36:25 +00:00
|
|
|
|
|
|
|
To enable the service, add the following to the node configuration:
|
|
|
|
|
2019-04-11 13:43:47 +00:00
|
|
|
.. code-block:: none
|
2017-10-13 09:36:25 +00:00
|
|
|
|
|
|
|
notary : {
|
|
|
|
validating : true # Set to false if your service is non-validating
|
2018-10-10 12:31:29 +00:00
|
|
|
className : "net.corda.notarydemo.MyCustomValidatingNotaryService" # The fully qualified name of your service class
|
2019-07-12 11:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Testing your custom notary service
|
2019-08-23 12:08:53 +00:00
|
|
|
----------------------------------
|
2019-07-12 11:27:21 +00:00
|
|
|
|
|
|
|
To create a flow test that uses your custom notary service, you can set the class name of the custom notary service as follows in your flow test:
|
|
|
|
|
|
|
|
.. literalinclude:: ../../testing/node-driver/src/test/kotlin/net/corda/testing/node/CustomNotaryTest.kt
|
|
|
|
:language: kotlin
|
|
|
|
:start-after: START 1
|
|
|
|
:end-before: END 1
|
|
|
|
|
|
|
|
After this, your custom notary will be the default notary on the mock network, and can be used in the same way as described in :doc:`flow-testing`.
|
|
|
|
|