exonum-time
Exonum-time is a time oracle service for Exonum blockchain framework. This service allows to determine time, import it from the external world to the blockchain and keep its current value in the blockchain.
Usage
Include exonum-time
as a dependency in your Cargo.toml
:
[]
= "0.13.0-rc.2"
= "0.13.0-rc.2"
= "0.13.0-rc.2"
Add the time oracle service to the blockchain in the main project file:
extern crate exonum;
extern crate exonum_cli;
extern crate exonum_time;
use NodeBuilder;
use TimeServiceFactory;
use MarkerService;
Importing the data schema
Typical usage of the service boils down to importing the schema and calling its
time()
or validators_time()
methods.
Below is an example of a method for processing a transaction, which must be executed no later than the specified time (this time is written in the transaction body in a separate field):
/// The argument of the `MarkerInterface::mark` method.
/// Marker service transactions interface definition.
;
/// Marker service database schema.
See the full implementation of the service, which uses the time oracle.
You can get the time of each validator node in the same manner the consolidated time of the system is obtained:
// Gets the data of time service instance
let data = context.data;
let time_service_data = data
.for_service
.expect;
let time_schema = new;
// Gets the times of all validators.
let validators_time = time_schema.time.get;
// Gets the time of validator with a public key equal to `public_key`.
let validator_time = time_schema.validators_times.get;
Further Reading
Consult the crate docs for more details about the service Rust API, and the service description in Exonum docs for a more high-level perspective, in particular, the design rationale and the proof of correctness.
Other languages support
License
exonum-time
is licensed under the Apache License (Version 2.0).
See LICENSE for details.