github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/sdk/examples/xo_rust/src/main.rs (about) 1 /* 2 * Copyright 2018 Bitwise IO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * ----------------------------------------------------------------------------- 16 */ 17 18 #[macro_use] 19 extern crate clap; 20 extern crate crypto; 21 #[macro_use] 22 extern crate log; 23 extern crate log4rs; 24 extern crate sawtooth_sdk; 25 26 mod handler; 27 28 use log::LevelFilter; 29 use log4rs::append::console::ConsoleAppender; 30 use log4rs::config::{Appender, Config, Root}; 31 use log4rs::encode::pattern::PatternEncoder; 32 33 use sawtooth_sdk::processor::TransactionProcessor; 34 35 use handler::handler::XoTransactionHandler; 36 37 use std::process; 38 39 fn main() { 40 let matches = clap_app!(xo => 41 (version: crate_version!()) 42 (about: "XO Transaction Processor (Rust)") 43 (@arg connect: -C --connect +takes_value 44 "connection endpoint for validator") 45 (@arg verbose: -v --verbose +multiple 46 "increase output verbosity")) 47 .get_matches(); 48 49 let endpoint = matches 50 .value_of("connect") 51 .unwrap_or("tcp://localhost:4004"); 52 53 let console_log_level; 54 match matches.occurrences_of("verbose") { 55 0 => console_log_level = LevelFilter::Warn, 56 1 => console_log_level = LevelFilter::Info, 57 2 => console_log_level = LevelFilter::Debug, 58 3 | _ => console_log_level = LevelFilter::Trace, 59 } 60 61 let stdout = ConsoleAppender::builder() 62 .encoder(Box::new(PatternEncoder::new( 63 "{h({l:5.5})} | {({M}:{L}):20.20} | {m}{n}", 64 ))) 65 .build(); 66 67 let config = match Config::builder() 68 .appender(Appender::builder().build("stdout", Box::new(stdout))) 69 .build(Root::builder().appender("stdout").build(console_log_level)) 70 { 71 Ok(x) => x, 72 Err(e) => { 73 for err in e.errors().iter() { 74 error!("Configuration error: {}", err.to_string()); 75 } 76 process::exit(1); 77 } 78 }; 79 80 match log4rs::init_config(config) { 81 Ok(_) => (), 82 Err(e) => { 83 error!("Configuration error: {}", e.to_string()); 84 process::exit(1); 85 } 86 } 87 88 let handler = XoTransactionHandler::new(); 89 let mut processor = TransactionProcessor::new(endpoint); 90 91 info!("Console logging level: {}", console_log_level); 92 93 processor.add_handler(&handler); 94 processor.start(); 95 }