Browse Source

Run 'cargo fmt'

liquid_e
Roman Zeyde 6 years ago
parent
commit
e0c877126e
No known key found for this signature in database GPG Key ID: 87CAE5FA46917CBB
  1. 3
      src/bin/electrs.rs
  2. 3
      src/bulk.rs
  3. 6
      src/daemon.rs
  4. 2
      src/errors.rs
  5. 15
      src/index.rs
  6. 3
      src/mempool.rs
  7. 6
      src/query.rs
  8. 44
      src/rest.rs
  9. 6
      src/store.rs
  10. 12
      src/util.rs
  11. 9
      src/utils/address.rs

3
src/bin/electrs.rs

@ -54,7 +54,8 @@ fn run_server(config: Config) -> Result<()> {
index.reload(&store); // make sure the block header index is up-to-date
store
}
}.enable_compaction(); // enable auto compactions before starting incremental index updates.
}
.enable_compaction(); // enable auto compactions before starting incremental index updates.
let app = App::new(store, index, daemon)?;
let query = Query::new(app.clone(), config.extended_db_enabled, &metrics);

3
src/bulk.rs

@ -254,6 +254,7 @@ pub fn index_blk_files(
});
store.write(vec![parser.last_indexed_row()]);
store
}).join()
})
.join()
.expect("writer panicked"))
}

6
src/daemon.rs

@ -94,7 +94,8 @@ fn parse_hash(value: &Value) -> Result<Sha256dHash> {
value
.as_str()
.chain_err(|| format!("non-string value: {}", value))?,
).chain_err(|| format!("non-hex value: {}", value))?)
)
.chain_err(|| format!("non-hex value: {}", value))?)
}
fn header_from_value(value: Value) -> Result<BlockHeader> {
@ -274,7 +275,8 @@ impl Connection {
.next()
.chain_err(|| {
ErrorKind::Connection("disconnected from daemon while receiving".to_owned())
})?.chain_err(|| "failed to read status")?;
})?
.chain_err(|| "failed to read status")?;
let mut headers = HashMap::new();
for line in iter {
let line = line.chain_err(|| ErrorKind::Connection("failed to read".to_owned()))?;

2
src/errors.rs

@ -1,6 +1,6 @@
use chan_signal::Signal;
error_chain!{
error_chain! {
types {
Error, ErrorKind, ResultExt, Result;
}

15
src/index.rs

@ -52,7 +52,8 @@ impl TxInRow {
code: b'I',
prev_hash_prefix: hash_prefix(&txid[..]),
prev_index: output_index as u16,
}).unwrap()
})
.unwrap()
}
pub fn to_row(&self) -> Row {
@ -94,7 +95,8 @@ impl TxOutRow {
bincode::serialize(&TxOutKey {
code: b'O',
script_hash_prefix: hash_prefix(&script_hash[..HASH_PREFIX_LEN]),
}).unwrap()
})
.unwrap()
}
pub fn to_row(&self) -> Row {
@ -251,7 +253,8 @@ pub fn index_block(block: &Block, height: u32, extended_db_enabled: bool) -> Vec
key: bincode::serialize(&BlockKey {
code: b'B',
hash: full_hash(&blockhash[..]),
}).unwrap(),
})
.unwrap(),
value: serialize(&block.header),
});
@ -262,7 +265,8 @@ pub fn index_block(block: &Block, height: u32, extended_db_enabled: bool) -> Vec
key: bincode::serialize(&BlockKey {
code: b'M',
hash: full_hash(&blockhash[..]),
}).unwrap(),
})
.unwrap(),
value: bincode::serialize(&blockmeta).unwrap(),
});
}
@ -274,7 +278,8 @@ pub fn index_block(block: &Block, height: u32, extended_db_enabled: bool) -> Vec
key: bincode::serialize(&BlockKey {
code: b'X',
hash: full_hash(&blockhash[..]),
}).unwrap(),
})
.unwrap(),
value: bincode::serialize(&txids).unwrap(),
});
}

3
src/mempool.rs

@ -206,7 +206,8 @@ impl Tracker {
None // ignore this transaction for now
}
}
}).collect();
})
.collect();
if entries.is_empty() {
return Ok(());
}

6
src/query.rs

@ -448,7 +448,8 @@ impl Query {
.unwrap()
.get_txn(&txid)
.map(|tx| serialize(&tx))
}).chain_err(|| format!("cannot find tx {}", txid))?)
})
.chain_err(|| format!("cannot find tx {}", txid))?)
} else {
// fetch from bitcoind
let tx_val = self.app.daemon().gettransaction_raw(txid, false)?;
@ -511,7 +512,8 @@ impl Query {
.map(|txid| {
Sha256dHash::from_hex(txid.as_str().chain_err(|| "txid not string")?)
.chain_err(|| "invalid hex")
}).collect::<Result<Vec<Sha256dHash>>>()?)
})
.collect::<Result<Vec<Sha256dHash>>>()?)
}
}

44
src/rest.rs

@ -21,7 +21,8 @@ use std::str::FromStr;
use std::sync::Arc;
use std::thread;
use util::{
get_script_asm, script_to_address, full_hash, BlockHeaderMeta, FullHash, PegOutRequest, TransactionStatus,
full_hash, get_script_asm, script_to_address, BlockHeaderMeta, FullHash, PegOutRequest,
TransactionStatus,
};
use utils::address::Address;
@ -605,8 +606,8 @@ fn handle_request(
attach_txs_data(&mut txs, config, query);
json_response(txs, TTL_LONG)
}
(&Method::GET, Some(script_type @ &"address"), Some(script_str), None, None) |
(&Method::GET, Some(script_type @ &"scripthash"), Some(script_str), None, None) => {
(&Method::GET, Some(script_type @ &"address"), Some(script_str), None, None)
| (&Method::GET, Some(script_type @ &"scripthash"), Some(script_str), None, None) => {
// @TODO create new AddressStatsValue struct?
let script_hash = to_scripthash(script_type, script_str, &config.network_type)?;
match query.status(&script_hash[..]) {
@ -628,8 +629,20 @@ fn handle_request(
Err(err) => bail!(err),
}
}
(&Method::GET, Some(script_type @ &"address"), Some(script_str), Some(&"txs"), start_index) |
(&Method::GET, Some(script_type @ &"scripthash"), Some(script_str), Some(&"txs"), start_index) => {
(
&Method::GET,
Some(script_type @ &"address"),
Some(script_str),
Some(&"txs"),
start_index,
)
| (
&Method::GET,
Some(script_type @ &"scripthash"),
Some(script_str),
Some(&"txs"),
start_index,
) => {
let start_index = start_index
.map_or(0u32, |el| el.parse().unwrap_or(0))
.max(0u32) as usize;
@ -659,8 +672,14 @@ fn handle_request(
json_response(txs, TTL_SHORT)
}
(&Method::GET, Some(script_type @ &"address"), Some(script_str), Some(&"utxo"), None) |
(&Method::GET, Some(script_type @ &"scripthash"), Some(script_str), Some(&"utxo"), None) => {
(&Method::GET, Some(script_type @ &"address"), Some(script_str), Some(&"utxo"), None)
| (
&Method::GET,
Some(script_type @ &"scripthash"),
Some(script_str),
Some(&"utxo"),
None,
) => {
let script_hash = to_scripthash(script_type, script_str, &config.network_type)?;
let status = query.status(&script_hash[..])?;
let utxos: Vec<UtxoValue> = status
@ -740,7 +759,8 @@ fn handle_request(
|| SpendingValue::default(),
|spend| SpendingValue::from(spend),
)
}).collect();
})
.collect();
// @TODO long ttl if all outputs are either spent long ago or unspendable
json_response(spends, TTL_SHORT)
}
@ -800,11 +820,15 @@ fn blocks(query: &Arc<Query>, start_height: Option<usize>) -> Result<Response<Bo
json_response(values, TTL_SHORT)
}
fn to_scripthash(script_type: &str, script_str: &str, network: &Network) -> Result<FullHash, HttpError> {
fn to_scripthash(
script_type: &str,
script_str: &str,
network: &Network,
) -> Result<FullHash, HttpError> {
match script_type {
"address" => address_to_scripthash(script_str, network),
"scripthash" => Ok(full_hash(&hex::decode(script_str)?)),
_ => bail!("Invalid script type".to_string())
_ => bail!("Invalid script type".to_string()),
}
}

6
src/store.rs

@ -212,8 +212,10 @@ pub fn verify_index_compatibility(store: &DBStore, config: &Config) {
key: b"C".to_vec(),
value: compatibility_bytes,
}]),
Some(x) => if x != compatibility_bytes {
Some(x) => {
if x != compatibility_bytes {
panic!("Incompatible database found. Changing --light mode requires a reindex.");
},
}
}
}
}

12
src/util.rs

@ -190,7 +190,8 @@ impl HeaderList {
height: height,
hash: hashed_header.blockhash,
header: hashed_header.header,
}).collect()
})
.collect()
}
pub fn apply(&mut self, new_headers: Vec<HeaderEntry>) {
@ -352,7 +353,8 @@ pub fn script_to_address(script: &Script, network: &Network) -> Option<String> {
u5::try_from_u8(0).expect("0<32"),
script[2..22].to_vec(),
B32Network::from(network),
).unwrap(),
)
.unwrap(),
))
} else if script.is_v0_p2wsh() {
Some(Payload::WitnessProgram(
@ -360,7 +362,8 @@ pub fn script_to_address(script: &Script, network: &Network) -> Option<String> {
u5::try_from_u8(0).expect("0<32"),
script[2..34].to_vec(),
B32Network::from(network),
).unwrap(),
)
.unwrap(),
))
} else {
None
@ -370,7 +373,8 @@ pub fn script_to_address(script: &Script, network: &Network) -> Option<String> {
Address {
payload: payload?,
network: *network,
}.to_string(),
}
.to_string(),
)
}

9
src/utils/address.rs

@ -106,7 +106,8 @@ impl Address {
u5::try_from_u8(0).expect("0<32"),
Hash160::from_data(&pk.serialize()[..])[..].to_vec(),
Address::bech_network(network),
).unwrap(),
)
.unwrap(),
),
}
}
@ -141,7 +142,8 @@ impl Address {
u5::try_from_u8(0).expect("0<32"),
d.to_vec(),
Address::bech_network(network),
).unwrap(),
)
.unwrap(),
),
}
}
@ -200,7 +202,8 @@ impl Address {
Payload::WitnessProgram(ref witprog) => script::Builder::new()
.push_int(witprog.version().to_u8() as i64)
.push_slice(witprog.program()),
}.into_script()
}
.into_script()
}
}

Loading…
Cancel
Save