Skip to content

Commit

Permalink
chore: resolve review issue
Browse files Browse the repository at this point in the history
  • Loading branch information
quake committed Mar 22, 2019
1 parent 12d46cd commit 988dbe6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,28 @@ where
}

pub struct BlockCellProvider<'a> {
output_indexs: FnvHashMap<H256, usize>,
output_indices: FnvHashMap<H256, usize>,
block: &'a Block,
}

impl<'a> BlockCellProvider<'a> {
pub fn new(block: &'a Block) -> Self {
let mut output_indexs = FnvHashMap::default();
for (i, tx) in block.commit_transactions().iter().enumerate() {
output_indexs.insert(tx.hash(), i);
}
let output_indices = block
.commit_transactions()
.iter()
.enumerate()
.map(|(idx, tx)| (tx.hash(), idx))
.collect();
Self {
output_indexs,
output_indices,
block,
}
}
}

impl<'a> CellProvider for BlockCellProvider<'a> {
fn cell(&self, out_point: &OutPoint) -> CellStatus {
if let Some(i) = self.output_indexs.get(&out_point.hash) {
if let Some(i) = self.output_indices.get(&out_point.hash) {
match self.block.commit_transactions()[*i]
.outputs()
.get(out_point.index as usize)
Expand Down

0 comments on commit 988dbe6

Please sign in to comment.