Skip to content

Commit

Permalink
fix programs
Browse files Browse the repository at this point in the history
  • Loading branch information
leviathanbeak committed Jul 21, 2023
1 parent 76a8661 commit dc46bbd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
4 changes: 3 additions & 1 deletion packages/fuels-programs/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ impl<'a, I: Iterator<Item = &'a Receipt>> ExtractLogIdData for I {
type Output = FilterMap<Self, fn(&Receipt) -> Option<(LogId, Vec<u8>)>>;
fn extract_log_id_and_data(self) -> Self::Output {
self.filter_map(|r| match r {
Receipt::LogData { rb, data, id, .. } => Some((LogId(*id, *rb), data.clone())),
Receipt::LogData { rb, data, id, .. } => {
Some((LogId(*id, *rb), data.clone().unwrap_or_default()))
}
Receipt::Log { ra, rb, id, .. } => Some((LogId(*id, *rb), ra.to_be_bytes().to_vec())),
_ => None,
})
Expand Down
23 changes: 10 additions & 13 deletions packages/fuels-programs/src/receipt_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,13 @@ impl ReceiptParser {
}

fn extract_return_data(&mut self, contract_id: &ContractId) -> Option<Vec<u8>> {
for (index, receipt) in self.receipts.iter_mut().enumerate() {
if let Receipt::ReturnData { id, data, .. } = receipt {
if id == contract_id {
let data = std::mem::take(data);
self.receipts.remove(index);
return Some(data);
}
}
}
None
self.receipts
.iter_mut()
.position(|receipt| receipt.id() == Some(contract_id))
.and_then(|index| match self.receipts.remove(index) {
Receipt::ReturnData { data, .. } => data,
_ => None,
})
}

fn extract_return(&mut self, contract_id: &ContractId) -> Option<Vec<u8>> {
Expand Down Expand Up @@ -134,10 +131,10 @@ impl ReceiptParser {
..
},
) if *first_id == *contract_id
&& !first_data.is_empty()
&& !first_data.is_none()
&& *second_id == ContractId::zeroed() =>
{
Some(vec_data)
vec_data.as_ref()
}
_ => None,
}
Expand Down Expand Up @@ -176,7 +173,7 @@ mod tests {
ptr: Default::default(),
len: Default::default(),
digest: Default::default(),
data: data.to_vec(),
data: Some(data.to_vec()),
pc: Default::default(),
is: Default::default(),
}
Expand Down

0 comments on commit dc46bbd

Please sign in to comment.