Browse Source

Fix small formatting issues

chaintope/fix-wrong-block-pos
Roman Zeyde 6 years ago
parent
commit
db853e1fe1
No known key found for this signature in database GPG Key ID: 87CAE5FA46917CBB
  1. 2
      src/fake.rs
  2. 22
      src/index.rs
  3. 4
      src/store.rs

2
src/fake.rs

@ -13,7 +13,7 @@ impl ReadStore for FakeStore {
}
impl WriteStore for FakeStore {
fn write<I: IntoIterator<Item=Row>>(&self, _rows: I) {}
fn write<I: IntoIterator<Item = Row>>(&self, _rows: I) {}
fn flush(&self) {}
}

22
src/index.rs

@ -170,7 +170,10 @@ pub fn compute_script_hash(data: &[u8]) -> FullHash {
hash
}
pub fn index_transaction<'a>(txn: &'a Transaction, height: usize) -> impl 'a + Iterator<Item=Row> {
pub fn index_transaction<'a>(
txn: &'a Transaction,
height: usize,
) -> impl 'a + Iterator<Item = Row> {
let null_hash = Sha256dHash::default();
let txid: Sha256dHash = txn.txid();
@ -181,13 +184,18 @@ pub fn index_transaction<'a>(txn: &'a Transaction, height: usize) -> impl 'a + I
Some(TxInRow::new(&txid, &input).to_row())
}
});
let outputs = txn.output.iter().map(move |output| TxOutRow::new(&txid, &output).to_row());
let outputs = txn
.output
.iter()
.map(move |output| TxOutRow::new(&txid, &output).to_row());
// Persist transaction ID and confirmed height
inputs.chain(outputs).chain(std::iter::once(TxRow::new(&txid, height as u32).to_row()))
inputs
.chain(outputs)
.chain(std::iter::once(TxRow::new(&txid, height as u32).to_row()))
}
pub fn index_block<'a>(block: &'a Block, height: usize) -> impl 'a + Iterator<Item=Row> {
pub fn index_block<'a>(block: &'a Block, height: usize) -> impl 'a + Iterator<Item = Row> {
let blockhash = block.bitcoin_hash();
// Persist block hash and header
let row = Row {
@ -198,7 +206,11 @@ pub fn index_block<'a>(block: &'a Block, height: usize) -> impl 'a + Iterator<It
.unwrap(),
value: serialize(&block.header),
};
block.txdata.iter().flat_map(move |txn| index_transaction(&txn, height)).chain(std::iter::once(row))
block
.txdata
.iter()
.flat_map(move |txn| index_transaction(&txn, height))
.chain(std::iter::once(row))
}
pub fn last_indexed_block(blockhash: &Sha256dHash) -> Row {

4
src/store.rs

@ -21,7 +21,7 @@ pub trait ReadStore: Sync {
}
pub trait WriteStore: Sync {
fn write<I: IntoIterator<Item=Row>>(&self, rows: I);
fn write<I: IntoIterator<Item = Row>>(&self, rows: I);
fn flush(&self);
}
@ -148,7 +148,7 @@ impl ReadStore for DBStore {
}
impl WriteStore for DBStore {
fn write<I: IntoIterator<Item=Row>>(&self, rows: I) {
fn write<I: IntoIterator<Item = Row>>(&self, rows: I) {
let mut batch = rocksdb::WriteBatch::default();
for row in rows {
batch.put(row.key.as_slice(), row.value.as_slice()).unwrap();

Loading…
Cancel
Save