github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-supply-chain-master/processor/src/main.rs (about) 1 // Copyright 2018 Cargill Incorporated 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #[macro_use] 16 extern crate clap; 17 extern crate crypto; 18 extern crate log4rs; 19 #[macro_use] 20 extern crate log; 21 extern crate protobuf; 22 extern crate rustc_serialize; 23 extern crate sawtooth_sdk; 24 25 mod handler; 26 mod addressing; 27 mod messages; 28 29 use std::process; 30 use log::LogLevelFilter; 31 use log4rs::append::console::ConsoleAppender; 32 use log4rs::config::{Appender, Config, Root}; 33 use log4rs::encode::pattern::PatternEncoder; 34 35 use sawtooth_sdk::processor::TransactionProcessor; 36 37 use handler::SupplyChainTransactionHandler; 38 39 fn main() { 40 let matches = clap_app!(intkey => 41 (version: crate_version!()) 42 (about: "SupplyChain 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 = LogLevelFilter::Warn, 56 1 => console_log_level = LogLevelFilter::Info, 57 2 => console_log_level = LogLevelFilter::Debug, 58 3 | _ => console_log_level = LogLevelFilter::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(_) => process::exit(1), 73 }; 74 75 match log4rs::init_config(config) { 76 Ok(_) => (), 77 Err(_) => process::exit(1), 78 } 79 80 let handler = SupplyChainTransactionHandler::new(); 81 let mut processor = TransactionProcessor::new(endpoint); 82 83 info!("Console logging level: {}", console_log_level); 84 85 processor.add_handler(&handler); 86 processor.start(); 87 }