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
// Copyright 2018 The Exonum Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! # Introduction
//!
//! Private blockchain infrastructure necessitates additional measures for
//! accountability of the blockchain validators.
//! In public proof of work blockchains (e.g., Bitcoin), accountability is purely economic and is
//! based on game theory and equivocation or retroactive modifications being economically costly.
//! Not so in private blockchains, where these two behaviors
//! are a real threat per any realistic threat model that assumes
//! that the blockchain is of use not only to the system validators,
//! but also to third parties.
//!
//! This crate implements a protocol for blockchain anchoring onto the Bitcoin blockchain
//! that utilizes the native Bitcoin capabilities of creating multisig([p2sh][1]) transactions.
//! This transactions contains metadata from Exonum blockchain (block's hash on corresponding
//! height) and forms a chain.
//!
//! You can read the details in [specification][2].
//!
//! [1]: https://bitcoin.org/en/glossary/p2sh-multisig
//! [2]: https://github.com/exonum/exonum-doc/blob/master/src/advanced/bitcoin-anchoring.md
//!
//! # Examples
//!
//! Create application with anchoring service
//!
//! ```rust,no_run
//! extern crate exonum;
//! extern crate exonum_btc_anchoring as anchoring;
//! extern crate exonum_configuration as configuration;
//! use exonum::helpers::fabric::NodeBuilder;
//! use exonum::helpers;
//!
//! fn main() {
//!     exonum::crypto::init();
//!     helpers::init_logger().unwrap();
//!     let node = NodeBuilder::new()
//!        .with_service(Box::new(configuration::ServiceFactory))
//!        .with_service(Box::new(anchoring::ServiceFactory));
//!     node.run();
//! }
//! ```
//!

#![warn(
    missing_docs,
    missing_debug_implementations,
    unsafe_code,
    bare_trait_objects
)]

use log::{error, warn};

mod handler;
mod proto;

pub use crate::factory::BtcAnchoringFactory as ServiceFactory;
pub use crate::service::{
    BtcAnchoringService, BTC_ANCHORING_SERVICE_ID, BTC_ANCHORING_SERVICE_NAME,
};

pub mod api;
pub mod blockchain;
pub mod btc;
pub mod config;
pub mod rpc;
pub mod test_helpers;

pub(crate) mod factory;
pub(crate) mod service;

pub(crate) trait ResultEx {
    fn log_error(self);
    fn log_warn(self);
}

impl<T: ::std::fmt::Display> ResultEx for Result<(), T> {
    fn log_error(self) {
        if let Err(e) = self {
            error!("{}", e);
        }
    }

    fn log_warn(self) {
        if let Err(e) = self {
            warn!("{}", e);
        }
    }
}