bitcoincore_rpc/
lib.rs

1// To the extent possible under law, the author(s) have dedicated all
2// copyright and related and neighboring rights to this software to
3// the public domain worldwide. This software is distributed without
4// any warranty.
5//
6// You should have received a copy of the CC0 Public Domain Dedication
7// along with this software.
8// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
9//
10
11//! # Rust Client for Bitcoin Core API
12//!
13//! This is a client library for the Bitcoin Core JSON-RPC API.
14//!
15
16#![crate_name = "bitcoincore_rpc"]
17#![crate_type = "rlib"]
18
19#[macro_use]
20extern crate log;
21#[allow(unused)]
22#[macro_use] // `macro_use` is needed for v1.24.0 compilation.
23extern crate serde;
24
25pub extern crate jsonrpc;
26
27pub extern crate bitcoincore_rpc_json;
28pub use crate::json::bitcoint4;
29pub use bitcoincore_rpc_json as json;
30use json::bitcoint4::consensus::{Decodable, ReadExt};
31use json::bitcoint4::hashes::hex::HexIterator;
32
33mod client;
34mod error;
35mod queryable;
36
37pub use crate::client::*;
38pub use crate::error::Error;
39pub use crate::queryable::*;
40
41fn deserialize_hex<T: Decodable>(hex: &str) -> Result<T> {
42    let mut reader = HexIterator::new(&hex)?;
43    let object = Decodable::consensus_decode(&mut reader)?;
44    if reader.read_u8().is_ok() {
45        Err(Error::BitcoinSerialization(bitcoint4::consensus::encode::Error::ParseFailed(
46            "data not consumed entirely when explicitly deserializing",
47        )))
48    } else {
49        Ok(object)
50    }
51}