1
0
Fork 0
mirror of https://github.com/romanz/electrs.git synced 2025-02-25 07:17:41 +01:00

Fix vec![] usage

This commit is contained in:
Roman Zeyde 2018-05-26 12:07:57 +03:00
parent 1786fa69ed
commit 421e1877bb
No known key found for this signature in database
GPG key ID: 87CAE5FA46917CBB
6 changed files with 14 additions and 14 deletions

View file

@ -127,7 +127,7 @@ impl Daemon {
.iter() .iter()
.map(|params| json!({"method": method, "params": params})) .map(|params| json!({"method": method, "params": params}))
.collect(); .collect();
let mut result = Vec::new(); let mut result = vec![];
for reply in self.call_jsonrpc(&reqs) for reply in self.call_jsonrpc(&reqs)
.chain_err(|| format!("RPC failed: {}", reqs))? .chain_err(|| format!("RPC failed: {}", reqs))?
.as_array_mut() .as_array_mut()
@ -164,7 +164,7 @@ impl Daemon {
Ok(deserialize(&header_bytes) Ok(deserialize(&header_bytes)
.chain_err(|| format!("failed to parse blockheader {}", header_hex))?) .chain_err(|| format!("failed to parse blockheader {}", header_hex))?)
} }
let mut result = Vec::new(); let mut result = vec![];
for h in headers { for h in headers {
result.push(header_from_value(h)?); result.push(header_from_value(h)?);
} }
@ -207,7 +207,7 @@ impl Daemon {
pub fn getmempooltxids(&self) -> Result<Vec<Sha256dHash>> { pub fn getmempooltxids(&self) -> Result<Vec<Sha256dHash>> {
let txids: Value = self.request("getrawmempool", json!([/*verbose=*/ false]))?; let txids: Value = self.request("getrawmempool", json!([/*verbose=*/ false]))?;
let mut result = Vec::new(); let mut result = vec![];
for value in txids.as_array().chain_err(|| "non-array result")? { for value in txids.as_array().chain_err(|| "non-array result")? {
result.push(parse_hash(&value).chain_err(|| "invalid txid")?); result.push(parse_hash(&value).chain_err(|| "invalid txid")?);
} }

View file

@ -177,7 +177,7 @@ pub fn index_transaction(txn: &Transaction, height: usize, rows: &mut Vec<Row>)
} }
fn index_block(block: &Block, height: usize) -> Vec<Row> { fn index_block(block: &Block, height: usize) -> Vec<Row> {
let mut rows = Vec::new(); let mut rows = vec![];
for txn in &block.txdata { for txn in &block.txdata {
index_transaction(&txn, height, &mut rows); index_transaction(&txn, height, &mut rows);
} }

View file

@ -40,7 +40,7 @@ impl ReadStore for MempoolStore {
fn scan(&self, prefix: &[u8]) -> Vec<Row> { fn scan(&self, prefix: &[u8]) -> Vec<Row> {
let map = self.map.read().unwrap(); let map = self.map.read().unwrap();
let range = map.range((Bound::Included(prefix.to_vec()), Bound::Unbounded)); let range = map.range((Bound::Included(prefix.to_vec()), Bound::Unbounded));
let mut rows = Vec::new(); let mut rows = vec![];
for (key, value) in range { for (key, value) in range {
if !key.starts_with(prefix) { if !key.starts_with(prefix) {
break; break;
@ -133,7 +133,7 @@ impl Tracker {
} }
fn update_tx_index(&mut self) { fn update_tx_index(&mut self) {
let mut rows = Vec::new(); let mut rows = vec![];
for stats in self.stats.values() { for stats in self.stats.values() {
index_transaction(&stats.tx, 0, &mut rows) index_transaction(&stats.tx, 0, &mut rows)
} }
@ -145,7 +145,7 @@ impl Tracker {
entries.sort_unstable_by(|e1, e2| { entries.sort_unstable_by(|e1, e2| {
e2.fee_per_vbyte().partial_cmp(&e1.fee_per_vbyte()).unwrap() e2.fee_per_vbyte().partial_cmp(&e1.fee_per_vbyte()).unwrap()
}); });
let mut histogram = Vec::new(); let mut histogram = vec![];
let mut bin_size = 0; let mut bin_size = 0;
let mut last_fee_rate = None; let mut last_fee_rate = None;
for e in entries { for e in entries {

View file

@ -139,7 +139,7 @@ impl Query {
} }
fn load_txns(&self, store: &ReadStore, prefixes: Vec<HashPrefix>) -> Result<Vec<TxnHeight>> { fn load_txns(&self, store: &ReadStore, prefixes: Vec<HashPrefix>) -> Result<Vec<TxnHeight>> {
let mut txns = Vec::new(); let mut txns = vec![];
for txid_prefix in prefixes { for txid_prefix in prefixes {
for tx_row in txrows_by_prefix(store, &txid_prefix) { for tx_row in txrows_by_prefix(store, &txid_prefix) {
let txid: Sha256dHash = deserialize(&tx_row.key.txid).unwrap(); let txid: Sha256dHash = deserialize(&tx_row.key.txid).unwrap();
@ -162,7 +162,7 @@ impl Query {
store, store,
txids_by_funding_output(store, &funding.txn_id, funding.output_index), txids_by_funding_output(store, &funding.txn_id, funding.output_index),
)?; )?;
let mut spending_inputs = Vec::new(); let mut spending_inputs = vec![];
for t in &spending_txns { for t in &spending_txns {
for input in t.txn.input.iter() { for input in t.txn.input.iter() {
if input.prev_hash == funding.txn_id if input.prev_hash == funding.txn_id
@ -185,7 +185,7 @@ impl Query {
} }
fn find_funding_outputs(&self, t: &TxnHeight, script_hash: &[u8]) -> Vec<FundingOutput> { fn find_funding_outputs(&self, t: &TxnHeight, script_hash: &[u8]) -> Vec<FundingOutput> {
let mut result = Vec::new(); let mut result = vec![];
let txn_id = t.txn.txid(); let txn_id = t.txn.txid();
for (index, output) in t.txn.output.iter().enumerate() { for (index, output) in t.txn.output.iter().enumerate() {
if compute_script_hash(&output.script_pubkey[..]) == script_hash { if compute_script_hash(&output.script_pubkey[..]) == script_hash {
@ -256,7 +256,7 @@ impl Query {
pub fn get_headers(&self, heights: &[usize]) -> Vec<BlockHeader> { pub fn get_headers(&self, heights: &[usize]) -> Vec<BlockHeader> {
let headers_list = self.app.index().headers_list(); let headers_list = self.app.index().headers_list();
let headers = headers_list.headers(); let headers = headers_list.headers();
let mut result = Vec::new(); let mut result = vec![];
for height in heights { for height in heights {
let header: &BlockHeader = match headers.get(*height) { let header: &BlockHeader = match headers.get(*height) {
Some(header) => header.header(), Some(header) => header.header(),
@ -290,7 +290,7 @@ impl Query {
.iter() .iter()
.position(|txid| txid == tx_hash) .position(|txid| txid == tx_hash)
.chain_err(|| format!("missing txid {}", tx_hash))?; .chain_err(|| format!("missing txid {}", tx_hash))?;
let mut merkle = Vec::new(); let mut merkle = vec![];
let mut index = pos; let mut index = pos;
while txids.len() > 1 { while txids.len() > 1 {
if txids.len() % 2 != 0 { if txids.len() % 2 != 0 {

View file

@ -99,7 +99,7 @@ impl Connection {
fn blockchain_block_get_header(&self, params: &[Value]) -> Result<Value> { fn blockchain_block_get_header(&self, params: &[Value]) -> Result<Value> {
let height = params.get(0).chain_err(|| "missing height")?; let height = params.get(0).chain_err(|| "missing height")?;
let height = height.as_u64().chain_err(|| "non-number height")? as usize; let height = height.as_u64().chain_err(|| "non-number height")? as usize;
let headers = self.query.get_headers(&vec![height]); let headers = self.query.get_headers(&[height]);
Ok(json!(jsonify_header(&headers[0], height))) Ok(json!(jsonify_header(&headers[0], height)))
} }

View file

@ -76,7 +76,7 @@ impl ReadStore for DBStore {
// TODO: use generators // TODO: use generators
fn scan(&self, prefix: &[u8]) -> Vec<Row> { fn scan(&self, prefix: &[u8]) -> Vec<Row> {
let mut rows = Vec::new(); let mut rows = vec![];
let mut iter = self.db.raw_iterator(); let mut iter = self.db.raw_iterator();
iter.seek(prefix); iter.seek(prefix);
while iter.valid() { while iter.valid() {