1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#![deny(missing_debug_implementations, missing_docs)]
extern crate bodyparser;
#[macro_use]
extern crate exonum;
#[macro_use]
extern crate failure;
extern crate iron;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
extern crate params;
extern crate router;
#[macro_use]
extern crate serde_derive;
#[cfg(test)]
#[macro_use]
extern crate exonum_testkit;
#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;
use exonum::api::Api;
use exonum::blockchain::{self, Transaction, ApiContext};
use exonum::crypto::Hash;
use exonum::encoding::Error as EncodingError;
use exonum::helpers::fabric::{self, Context};
use exonum::messages::RawTransaction;
use exonum::storage::Snapshot;
use iron::Handler;
use router::Router;
mod api;
mod errors;
mod schema;
#[cfg(test)]
mod tests;
mod transactions;
pub use errors::ErrorCode;
pub use schema::{MaybeVote, Schema, ProposeData};
pub use transactions::{Propose, Vote};
pub const SERVICE_ID: u16 = 1;
#[derive(Debug, Default)]
pub struct Service {}
impl blockchain::Service for Service {
fn service_name(&self) -> &'static str {
"configuration"
}
fn service_id(&self) -> u16 {
SERVICE_ID
}
fn state_hash(&self, snapshot: &Snapshot) -> Vec<Hash> {
let schema = Schema::new(snapshot);
schema.state_hash()
}
fn tx_from_raw(&self, raw: RawTransaction) -> Result<Box<Transaction>, EncodingError> {
transactions::tx_from_raw(raw)
}
fn public_api_handler(&self, ctx: &ApiContext) -> Option<Box<Handler>> {
let mut router = Router::new();
let api = api::PublicApi::new(ctx);
api.wire(&mut router);
Some(Box::new(router))
}
fn private_api_handler(&self, ctx: &ApiContext) -> Option<Box<Handler>> {
let mut router = Router::new();
let api = api::PrivateApi::new(ctx);
api.wire(&mut router);
Some(Box::new(router))
}
}
#[derive(Debug)]
pub struct ServiceFactory;
impl fabric::ServiceFactory for ServiceFactory {
fn make_service(&mut self, _: &Context) -> Box<blockchain::Service> {
Box::new(Service {})
}
}