Browse Source

Fix some format issues

android-patches
Roman Zeyde 5 years ago
parent
commit
f0a7a325af
No known key found for this signature in database GPG Key ID: 87CAE5FA46917CBB
  1. 2
      src/bulk.rs
  2. 8
      src/cache.rs
  3. 4
      src/daemon.rs
  4. 2
      src/index.rs
  5. 2
      src/mempool.rs
  6. 7
      src/query.rs
  7. 14
      src/rpc.rs
  8. 2
      src/util.rs

2
src/bulk.rs

@ -1,6 +1,6 @@
use bitcoin::hash_types::BlockHash;
use bitcoin::blockdata::block::Block; use bitcoin::blockdata::block::Block;
use bitcoin::consensus::encode::{deserialize, Decodable}; use bitcoin::consensus::encode::{deserialize, Decodable};
use bitcoin::hash_types::BlockHash;
use libc; use libc;
use std::collections::HashSet; use std::collections::HashSet;
use std::fs; use std::fs;

8
src/cache.rs

@ -1,9 +1,9 @@
use crate::errors::*; use crate::errors::*;
use crate::metrics::{CounterVec, MetricOpts, Metrics}; use crate::metrics::{CounterVec, MetricOpts, Metrics};
use bitcoin::hash_types::{BlockHash, Txid};
use bitcoin::blockdata::transaction::Transaction; use bitcoin::blockdata::transaction::Transaction;
use bitcoin::consensus::encode::deserialize; use bitcoin::consensus::encode::deserialize;
use bitcoin::hash_types::{BlockHash, Txid};
use lru::LruCache; use lru::LruCache;
use prometheus::IntGauge; use prometheus::IntGauge;
use std::hash::Hash; use std::hash::Hash;
@ -83,11 +83,7 @@ impl BlockTxIDsCache {
} }
} }
pub fn get_or_else<F>( pub fn get_or_else<F>(&self, blockhash: &BlockHash, load_txids_func: F) -> Result<Vec<Txid>>
&self,
blockhash: &BlockHash,
load_txids_func: F,
) -> Result<Vec<Txid>>
where where
F: FnOnce() -> Result<Vec<Txid>>, F: FnOnce() -> Result<Vec<Txid>>,
{ {

4
src/daemon.rs

@ -1,11 +1,11 @@
use base64; use base64;
use bitcoin_hashes::Hash;
use bitcoin::hash_types::{BlockHash, Txid};
use bitcoin::blockdata::block::{Block, BlockHeader}; use bitcoin::blockdata::block::{Block, BlockHeader};
use bitcoin::blockdata::transaction::Transaction; use bitcoin::blockdata::transaction::Transaction;
use bitcoin::consensus::encode::{deserialize, serialize}; use bitcoin::consensus::encode::{deserialize, serialize};
use bitcoin::hash_types::{BlockHash, Txid};
use bitcoin::network::constants::Network; use bitcoin::network::constants::Network;
use bitcoin_hashes::hex::{FromHex, ToHex}; use bitcoin_hashes::hex::{FromHex, ToHex};
use bitcoin_hashes::Hash;
use glob; use glob;
use hex; use hex;
use serde_json::{from_str, from_value, Map, Value}; use serde_json::{from_str, from_value, Map, Value};

2
src/index.rs

@ -1,8 +1,8 @@
use bincode; use bincode;
use bitcoin::hash_types::{BlockHash, Txid};
use bitcoin::blockdata::block::{Block, BlockHeader}; use bitcoin::blockdata::block::{Block, BlockHeader};
use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut}; use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut};
use bitcoin::consensus::encode::{deserialize, serialize}; use bitcoin::consensus::encode::{deserialize, serialize};
use bitcoin::hash_types::{BlockHash, Txid};
use crypto::digest::Digest; use crypto::digest::Digest;
use crypto::sha2::Sha256; use crypto::sha2::Sha256;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};

2
src/mempool.rs

@ -1,5 +1,5 @@
use bitcoin::hash_types::Txid;
use bitcoin::blockdata::transaction::Transaction; use bitcoin::blockdata::transaction::Transaction;
use bitcoin::hash_types::Txid;
use hex; use hex;
use std::collections::{BTreeMap, HashMap, HashSet}; use std::collections::{BTreeMap, HashMap, HashSet};
use std::iter::FromIterator; use std::iter::FromIterator;

7
src/query.rs

@ -1,6 +1,6 @@
use bitcoin::blockdata::transaction::Transaction; use bitcoin::blockdata::transaction::Transaction;
use bitcoin::consensus::encode::deserialize; use bitcoin::consensus::encode::deserialize;
use bitcoin::hash_types::{Txid, BlockHash, TxMerkleNode}; use bitcoin::hash_types::{BlockHash, TxMerkleNode, Txid};
use bitcoin::hashes::sha256d::Hash as Sha256dHash; use bitcoin::hashes::sha256d::Hash as Sha256dHash;
use bitcoin_hashes::hex::ToHex; use bitcoin_hashes::hex::ToHex;
use bitcoin_hashes::Hash; use bitcoin_hashes::Hash;
@ -122,10 +122,7 @@ fn merklize<T: Hash>(left: T, right: T) -> T {
<T as Hash>::hash(&data) <T as Hash>::hash(&data)
} }
fn create_merkle_branch_and_root<T: Hash>( fn create_merkle_branch_and_root<T: Hash>(mut hashes: Vec<T>, mut index: usize) -> (Vec<T>, T) {
mut hashes: Vec<T>,
mut index: usize,
) -> (Vec<T>, T) {
let mut merkle = vec![]; let mut merkle = vec![];
while hashes.len() > 1 { while hashes.len() > 1 {
if hashes.len() % 2 != 0 { if hashes.len() % 2 != 0 {

14
src/rpc.rs

@ -1,7 +1,7 @@
use bitcoin::blockdata::transaction::Transaction; use bitcoin::blockdata::transaction::Transaction;
use bitcoin::consensus::encode::{deserialize, serialize}; use bitcoin::consensus::encode::{deserialize, serialize};
use bitcoin_hashes::hex::{FromHex, ToHex}; use bitcoin_hashes::hex::{FromHex, ToHex};
use bitcoin_hashes::{Hash, sha256d::Hash as Sha256dHash}; use bitcoin_hashes::{sha256d::Hash as Sha256dHash, Hash};
use error_chain::ChainedError; use error_chain::ChainedError;
use hex; use hex;
use serde_json::{from_str, Value}; use serde_json::{from_str, Value};
@ -202,7 +202,8 @@ impl Connection {
} }
fn blockchain_scripthash_subscribe(&mut self, params: &[Value]) -> Result<Value> { fn blockchain_scripthash_subscribe(&mut self, params: &[Value]) -> Result<Value> {
let script_hash = hash_from_value::<Sha256dHash>(params.get(0)).chain_err(|| "bad script_hash")?; let script_hash =
hash_from_value::<Sha256dHash>(params.get(0)).chain_err(|| "bad script_hash")?;
let status = self.query.status(&script_hash[..])?; let status = self.query.status(&script_hash[..])?;
let result = status.hash().map_or(Value::Null, |h| json!(hex::encode(h))); let result = status.hash().map_or(Value::Null, |h| json!(hex::encode(h)));
self.status_hashes.insert(script_hash, result.clone()); self.status_hashes.insert(script_hash, result.clone());
@ -210,7 +211,8 @@ impl Connection {
} }
fn blockchain_scripthash_get_balance(&self, params: &[Value]) -> Result<Value> { fn blockchain_scripthash_get_balance(&self, params: &[Value]) -> Result<Value> {
let script_hash = hash_from_value::<Sha256dHash>(params.get(0)).chain_err(|| "bad script_hash")?; let script_hash =
hash_from_value::<Sha256dHash>(params.get(0)).chain_err(|| "bad script_hash")?;
let status = self.query.status(&script_hash[..])?; let status = self.query.status(&script_hash[..])?;
Ok( Ok(
json!({ "confirmed": status.confirmed_balance(), "unconfirmed": status.mempool_balance() }), json!({ "confirmed": status.confirmed_balance(), "unconfirmed": status.mempool_balance() }),
@ -218,7 +220,8 @@ impl Connection {
} }
fn blockchain_scripthash_get_history(&self, params: &[Value]) -> Result<Value> { fn blockchain_scripthash_get_history(&self, params: &[Value]) -> Result<Value> {
let script_hash = hash_from_value::<Sha256dHash>(params.get(0)).chain_err(|| "bad script_hash")?; let script_hash =
hash_from_value::<Sha256dHash>(params.get(0)).chain_err(|| "bad script_hash")?;
let status = self.query.status(&script_hash[..])?; let status = self.query.status(&script_hash[..])?;
Ok(json!(Value::Array( Ok(json!(Value::Array(
status status
@ -230,7 +233,8 @@ impl Connection {
} }
fn blockchain_scripthash_listunspent(&self, params: &[Value]) -> Result<Value> { fn blockchain_scripthash_listunspent(&self, params: &[Value]) -> Result<Value> {
let script_hash = hash_from_value::<Sha256dHash>(params.get(0)).chain_err(|| "bad script_hash")?; let script_hash =
hash_from_value::<Sha256dHash>(params.get(0)).chain_err(|| "bad script_hash")?;
Ok(unspent_from_status(&self.query.status(&script_hash[..])?)) Ok(unspent_from_status(&self.query.status(&script_hash[..])?))
} }

2
src/util.rs

@ -1,6 +1,6 @@
use bitcoin::blockdata::block::BlockHeader;
use bitcoin::hash_types::BlockHash; use bitcoin::hash_types::BlockHash;
use bitcoin::util::hash::BitcoinHash; use bitcoin::util::hash::BitcoinHash;
use bitcoin::blockdata::block::BlockHeader;
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryInto; use std::convert::TryInto;
use std::fmt; use std::fmt;

Loading…
Cancel
Save