Browse Source

Reformat source code using Rust 1.31

new-index
Roman Zeyde 6 years ago
parent
commit
7d8c0b8191
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. 30
      src/new_index.rs
  7. 8
      src/store.rs
  8. 12
      src/util.rs

3
src/bin/electrs.rs

@ -52,7 +52,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)?;

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

@ -26,7 +26,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> {
@ -207,7 +208,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

@ -53,7 +53,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 {
@ -95,7 +96,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 {
@ -252,7 +254,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),
});
@ -263,7 +266,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(),
});
}
@ -275,7 +279,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(),
});
}

30
src/new_index.rs

@ -112,7 +112,8 @@ impl Indexer {
.map(|history_row| match history_row.key.txinfo {
TxHistoryInfo::Funding(txid, ..) => txid,
TxHistoryInfo::Spending(txid, ..) => txid,
}).map(|txid| deserialize(&txid).expect("failed to deserialize Sha256dHash txid"))
})
.map(|txid| deserialize(&txid).expect("failed to deserialize Sha256dHash txid"))
// TODO: check tx confirmation status
.collect();
debug!("txids: {:?}", txids);
@ -151,7 +152,8 @@ impl Indexer {
let txn: Transaction = deserialize(&rawtx).expect("failed to parse Transaction");
assert_eq!(*txid, txn.txid());
(*txid, txn)
}).collect()
})
.collect()
}
fn lookup_txos(
@ -164,7 +166,8 @@ impl Indexer {
.lookup_txo(&txid, *vout)
.expect("missing txo in txns db");
((*txid, *vout), txo)
}).collect()
})
.collect()
}
fn lookup_txo(&self, txid: &Sha256dHash, vout: usize) -> Option<TxOut> {
@ -220,7 +223,8 @@ fn bitcoind_fetcher(
.map(|(block, entry)| BlockEntry {
block,
entry: entry.clone(), // TODO: remove this clone()
}).collect();
})
.collect();
assert_eq!(block_entries.len(), entries.len());
sender
.send(block_entries)
@ -259,7 +263,8 @@ fn blkfiles_fetcher(
debug!("unknown block {}", blockhash);
None
})
}).collect();
})
.collect();
trace!("fetched {} blocks", block_entries.len());
sender
.send(block_entries)
@ -368,7 +373,8 @@ fn db_scan(db: &rocksdb::DB, prefix: &[u8]) -> Vec<DBRow> {
.map(|(k, v)| DBRow {
key: k.into_vec(),
value: v.into_vec(),
}).collect()
})
.collect()
}
fn db_write(db: &rocksdb::DB, mut rows: Vec<DBRow>) {
@ -502,7 +508,8 @@ impl TxOutRow {
code: b'O',
txid: txid.to_bytes(),
vout: vout as u16,
}).unwrap()
})
.unwrap()
}
fn to_row(self) -> DBRow {
@ -578,7 +585,8 @@ fn add_blocks(block_entries: &[BlockEntry]) -> Vec<DBRow> {
add_transaction(tx, blockheight, blockhash, &mut rows);
}
rows
}).flatten()
})
.flatten()
.collect()
}
@ -610,7 +618,8 @@ fn get_previous_txos(block_entries: &[BlockEntry]) -> BTreeSet<(Sha256dHash, usi
}
})
})
}).collect()
})
.collect()
}
fn index_blocks(
@ -626,7 +635,8 @@ fn index_blocks(
index_transaction(tx, height, previous_txos_map, &mut rows);
}
rows
}).flatten()
})
.flatten()
.collect()
}

8
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 {
panic!("Incompatible database found. Changing --light mode requires a reindex.");
},
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(),
to_bech_network(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(),
to_bech_network(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(),
)
}

Loading…
Cancel
Save