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
#![deny(
missing_debug_implementations,
missing_docs,
unsafe_code,
bare_trait_objects
)]
#[macro_use]
extern crate exonum_derive;
#[macro_use]
extern crate failure;
#[macro_use]
extern crate serde_derive;
pub use crate::schema::Schema;
pub mod api;
pub mod proto;
pub mod schema;
pub mod transactions;
pub mod wallet;
use exonum_merkledb::Snapshot;
use exonum::{
api::ServiceApiBuilder,
blockchain::{self, Transaction, TransactionSet},
crypto::Hash,
helpers::fabric::{self, Context},
messages::RawTransaction,
};
use crate::transactions::WalletTransactions;
const CRYPTOCURRENCY_SERVICE_ID: u16 = 128;
const SERVICE_NAME: &str = "cryptocurrency";
const INITIAL_BALANCE: u64 = 100;
#[derive(Default, Debug)]
pub struct Service;
impl blockchain::Service for Service {
fn service_id(&self) -> u16 {
CRYPTOCURRENCY_SERVICE_ID
}
fn service_name(&self) -> &str {
SERVICE_NAME
}
fn state_hash(&self, view: &dyn Snapshot) -> Vec<Hash> {
let schema = Schema::new(view);
schema.state_hash()
}
fn tx_from_raw(&self, raw: RawTransaction) -> Result<Box<dyn Transaction>, failure::Error> {
WalletTransactions::tx_from_raw(raw).map(Into::into)
}
fn wire_api(&self, builder: &mut ServiceApiBuilder) {
api::PublicApi::wire(builder);
}
}
#[derive(Debug)]
pub struct ServiceFactory;
impl fabric::ServiceFactory for ServiceFactory {
fn service_name(&self) -> &str {
SERVICE_NAME
}
fn make_service(&mut self, _: &Context) -> Box<dyn blockchain::Service> {
Box::new(Service)
}
}