13 releases (7 breaking)

✓ Uses Rust 2018 edition

0.12.0 Aug 14, 2019
0.11.0 Mar 15, 2019
0.10.2 Jan 22, 2019
0.10.0 Dec 14, 2018
0.6.0 Mar 6, 2018

#9 in Cryptocurrencies

Download history 52/week @ 2019-05-01 37/week @ 2019-05-08 44/week @ 2019-05-15 79/week @ 2019-05-22 55/week @ 2019-05-29 55/week @ 2019-06-05 128/week @ 2019-06-12 124/week @ 2019-06-19 97/week @ 2019-06-26 34/week @ 2019-07-03 64/week @ 2019-07-10 20/week @ 2019-07-17 13/week @ 2019-07-24 48/week @ 2019-07-31 28/week @ 2019-08-07

256 downloads per month

Apache-2.0

1.5MB
30K SLoC

exonum-time

Travis Build Status CircleCI Build Status Docs.rs License: Apache-2.0 rust 1.33.0+ required

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:

[dependencies]
exonum = "0.12.0"
exonum-time = "0.12.0"

Add the time oracle service to the blockchain in the main project file:

extern crate exonum;
extern crate exonum_time;

use exonum::helpers::fabric::NodeBuilder;
use exonum_time::TimeServiceFactory;

fn main() {
    exonum::helpers::init_logger().unwrap();
    NodeBuilder::new()
        .with_service(Box::new(TimeServiceFactory))
        .run();
}

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):

#[derive(Serialize, Deserialize, Debug, Clone, ProtobufConvert)]
#[exonum(pb = "proto::TimeTx")]
/// Transaction, which must be executed no later than the specified time (field `time`).
struct TimeTx {
    time: DateTime<Utc>,
}

#[derive(Serialize, Deserialize, Debug, Clone, TransactionSet)]
enum TimeTransactions {
    TimeTx(TimeTx),
}

impl Transaction for TimeTx {
    fn execute(&self, view: &mut Fork) {
        // Import schema.
        let time_schema = exonum_time::TimeSchema::new(&view);
        // The time in the transaction should be less than in the blockchain.
        match time_schema.time().get() {
            Some(current_time) if current_time <= self.time => {
                // Execute transaction business logic.
            }
            _ => {}
        }
    }
}

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:

let time_schema = exonum_time::TimeSchema::new(&view);
// Gets the times of all validators.
let validators_time = time_schema.validators_time();
// Gets the time of validator with a public key equal to `public_key`.
let validator_time = time_schema.validators_time().get(&public_key);

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.

Dependencies

~43MB
~821K SLoC