github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/sdk/examples/intkey_rust/src/main.rs (about) 1 /* 2 * Copyright 2017 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 extern crate cbor; 19 #[macro_use] 20 extern crate clap; 21 extern crate crypto; 22 #[macro_use] 23 extern crate log; 24 extern crate log4rs; 25 extern crate sawtooth_sdk; 26 27 mod handler; 28 29 use log::LevelFilter; 30 use log4rs::append::console::ConsoleAppender; 31 use log4rs::config::{Appender, Config, Root}; 32 use log4rs::encode::pattern::PatternEncoder; 33 34 use std::process; 35 36 use sawtooth_sdk::processor::TransactionProcessor; 37 38 use handler::IntkeyTransactionHandler; 39 40 fn main() { 41 let matches = clap_app!(intkey => 42 (version: crate_version!()) 43 (about: "Intkey Transaction Processor (Rust)") 44 (@arg connect: -C --connect +takes_value 45 "connection endpoint for validator") 46 (@arg verbose: -v --verbose +multiple 47 "increase output verbosity")) 48 .get_matches(); 49 50 let endpoint = matches 51 .value_of("connect") 52 .unwrap_or("tcp://localhost:4004"); 53 54 let console_log_level; 55 match matches.occurrences_of("verbose") { 56 0 => console_log_level = LevelFilter::Warn, 57 1 => console_log_level = LevelFilter::Info, 58 2 => console_log_level = LevelFilter::Debug, 59 3 | _ => console_log_level = LevelFilter::Trace, 60 } 61 62 let stdout = ConsoleAppender::builder() 63 .encoder(Box::new(PatternEncoder::new( 64 "{h({l:5.5})} | {({M}:{L}):20.20} | {m}{n}", 65 ))) 66 .build(); 67 68 let config = match Config::builder() 69 .appender(Appender::builder().build("stdout", Box::new(stdout))) 70 .build(Root::builder().appender("stdout").build(console_log_level)) 71 { 72 Ok(x) => x, 73 Err(e) => { 74 for err in e.errors().iter() { 75 info!("Configuration error: {}", err.to_string()); 76 } 77 process::exit(1); 78 } 79 }; 80 81 match log4rs::init_config(config) { 82 Ok(_) => (), 83 Err(e) => { 84 info!("Configuration error: {}", e.to_string()); 85 process::exit(1); 86 } 87 } 88 89 let handler = IntkeyTransactionHandler::new(); 90 let mut processor = TransactionProcessor::new(endpoint); 91 92 info!("Console logging level: {}", console_log_level); 93 94 processor.add_handler(&handler); 95 processor.start(); 96 }