public interface Service
You shall usually subclass an AbstractService which implements some of the methods
declared in this interface.
| Modifier and Type | Method and Description |
|---|---|
default void |
afterCommit(BlockCommittedEvent event)
Handles read-only block commit event.
|
Transaction |
convertToTransaction(RawTransaction rawTransaction)
Converts an Exonum raw transaction to an executable transaction of this service.
|
void |
createPublicApiHandlers(Node node,
io.vertx.ext.web.Router router)
Creates handlers that make up the public HTTP API of this service.
|
short |
getId()
Returns the id of the service.
|
String |
getName()
Returns the name of the service.
|
default List<com.exonum.binding.common.hash.HashCode> |
getStateHashes(Snapshot snapshot)
Returns a list of root hashes of all Merkelized tables defined by this service,
as of the given snapshot of the blockchain state.
|
default Optional<String> |
initialize(Fork fork)
Initializes the service.
|
short getId()
String getName()
default Optional<String> initialize(Fork fork)
The service configuration parameters must be provided as a JSON string. It is recorded in a table of global configuration parameters of each service deployed in the network.
fork - a database fork to apply changes to. Not valid after this method returnsOptional.empty() if the service
does not have any configuration parameters.Transaction convertToTransaction(RawTransaction rawTransaction)
rawTransaction - a raw transaction to be convertedIllegalArgumentException - if the raw transaction is malformed
or it doesn't belong to this serviceNullPointerException - if raw transaction is nulldefault List<com.exonum.binding.common.hash.HashCode> getStateHashes(Snapshot snapshot)
The core uses this list to aggregate hashes of tables defined by all services into a single Merkelized meta-map. The hash of this meta-map is considered the hash of the entire blockchain state and is recorded as such in blocks and Precommit messages.
snapshot - a snapshot of the blockchain state. Not valid after this method returnsProofListIndexProxy.getRootHash(),
ProofMapIndexProxy.getRootHash()void createPublicApiHandlers(Node node, io.vertx.ext.web.Router router)
/api/services/<service-name>.
Please note that the path prefix shown above is stripped from the request path when it is forwarded to the given router. For example, if your service name is «timestamping», and you have an endpoint «/timestamp», use «/timestamp» as the endpoint name when defining the handler and it will be available by path «/api/services/timestamping/timestamp»:
router.get("/timestamp").handler((rc) -> {
rc.response().end("2019-04-01T10:15:30+02:00[Europe/Kiev]");
});
node - a set-up Exonum node, providing an interface to access
the current blockchain state and submit transactionsrouter - a router responsible for handling requests to this servicedefault void afterCommit(BlockCommittedEvent event)
This method is invoked synchronously from the thread that commits the block, therefore, implementations of this method must not perform any blocking or long-running operations.
Any exceptions in this method will be swallowed and will not affect the processing of transactions or blocks.
event - the read-only context allowing to access the blockchain state as of that committed
blockCopyright © 2019 Exonum. All rights reserved.