Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
fix: Skip system logs if not exists (#401)
Browse files Browse the repository at this point in the history
* fix: Skip system logs if not exists

* chore: Update rust ci
  • Loading branch information
classicalliu authored Jun 17, 2022
1 parent b173596 commit 741b34e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
target
key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
- name: Install moleculec v0.7.2
run: CARGO_TARGET_DIR=target/ cargo install moleculec --version 0.7.2
run: CARGO_TARGET_DIR=target/ cargo install moleculec --locked --version 0.7.2
- name: Build
run: cargo build --verbose
- name: Check format
Expand Down
73 changes: 43 additions & 30 deletions crates/indexer/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,37 +263,50 @@ impl Web3Indexer {
let log_item_vec = tx_receipt.logs();

// read polyjuice system log
let polyjuice_system_log = parse_log(
log_item_vec
.clone()
.into_iter()
.find(|item| u8::from(item.service_flag()) == GW_LOG_POLYJUICE_SYSTEM)
.as_ref()
.ok_or_else(|| anyhow!("no system logs"))?,
&gw_tx_hash,
)?;

let (contract_address, tx_gas_used) = if let GwLog::PolyjuiceSystem {
gas_used,
cumulative_gas_used: _,
created_address,
status_code: _,
} = polyjuice_system_log
{
let tx_gas_used = gas_used.into();
cumulative_gas_used += tx_gas_used;
let contract_address =
if polyjuice_args.is_create && created_address != [0u8; 20] {
Some(created_address)
let polyjuice_system_log_item = log_item_vec
.clone()
.into_iter()
.find(|item| u8::from(item.service_flag()) == GW_LOG_POLYJUICE_SYSTEM);

let (contract_address, tx_gas_used) = match polyjuice_system_log_item {
Some(item) => {
let polyjuice_system_log = parse_log(&item, &gw_tx_hash)?;
if let GwLog::PolyjuiceSystem {
gas_used,
cumulative_gas_used: _,
created_address,
status_code: _,
} = polyjuice_system_log
{
let tx_gas_used: u128 = gas_used.into();
cumulative_gas_used += tx_gas_used;
let contract_address =
if polyjuice_args.is_create && created_address != [0u8; 20] {
Some(created_address)
} else {
None
};
(contract_address, tx_gas_used)
} else {
None
};
(contract_address, tx_gas_used)
} else {
return Err(anyhow!(
"can't find polyjuice system log from logs: tx_hash: {}",
hex(gw_tx_hash.as_slice())?
));
return Err(anyhow!(
"can't find polyjuice system log from logs: tx_hash: {}",
hex(gw_tx_hash.as_slice())?
));
}
}
None => {
let gw_tx_hash_hex = hex(gw_tx_hash.as_slice()).unwrap_or_else(|_| {
format!("Can't convert tx_hash: {:?} to hex format", gw_tx_hash)
});
log::error!(
"no system logs in tx_hash: {}, block_number: {}, index: {}, exit_code: {}",
gw_tx_hash_hex,
block_number,
tx_index,
tx_receipt.exit_code()
);
(None, polyjuice_args.gas_limit as u128)
}
};

let exit_code: u8 = tx_receipt.exit_code().into();
Expand Down

0 comments on commit 741b34e

Please sign in to comment.