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 |
---|---|
Transaction |
convertToTransaction(BinaryMessage message)
Converts an Exonum transaction message to an executable transaction of this service.
|
void |
createPublicApiHandlers(Node node,
io.vertx.ext.web.Router router)
Creates handlers that makes up the public API of this service.
|
short |
getId()
Returns the id of the service.
|
java.lang.String |
getName()
Returns the name of the service.
|
default java.util.List<HashCode> |
getStateHashes(Snapshot snapshot)
Returns a list of root hashes of all Merklized tables defined by this service,
as of the given snapshot of the blockchain state.
|
default java.util.Optional<java.lang.String> |
initialize(Fork fork)
Initializes the service.
|
short getId()
java.lang.String getName()
default java.util.Optional<java.lang.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(BinaryMessage message)
message
- a transaction message
(i.e., whose message type is a transaction and service id is set to the id of
this service)java.lang.IllegalArgumentException
- if the message is not a transaction of this servicejava.lang.NullPointerException
- if message is nulldefault java.util.List<HashCode> getStateHashes(Snapshot snapshot)
The core uses this list to aggregate hashes of tables defined by all services into a single Merklized 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)
Please note that the path prefix is stripped from the request path when it is forwarded to the given router. For example, if your service name is «cryptocurrency», and you have two endpoints «/send-money» and «/balance», use these names when defining handlers, and they will be available by paths «/cryptocurrency/send-money» and «/cryptocurrency/balance»:
router.get("/balance").handler((rc) -> {
rc.response().end("$1’000’000");
});
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 serviceCopyright © 2018 Exonum. All rights reserved.