corda/docs/source/tutorial-custom-notary.rst
2017-09-14 09:30:37 +01:00

1.6 KiB

Writing a custom notary service

Warning

Customising a notary service is an advanced feature and not recommended for most use-cases. Currently, customising Raft or BFT notaries is not yet fully supported. If you want to write your own Raft notary you will have to implement a custom database connector (or use a separate database for the notary), and use a custom configuration file.

Similarly to writing an oracle service, the first step is to create a service class in your CorDapp and annotate it with @CordaService. The Corda node scans for any class with this annotation and initialises them. The only requirement is that the class provide a constructor with a single parameter of type ServiceHub.

example-code/src/main/kotlin/net/corda/docs/CustomNotaryTutorial.kt

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:

example-code/src/main/kotlin/net/corda/docs/CustomNotaryTutorial.kt

To ensure the custom notary is installed and advertised by the node, specify it in the configuration file:

extraAdvertisedServiceIds : ["corda.notary.validating.mycustom"]