git.delta.rocks / unique-network / refs/commits / c0388a3fec74

difftreelog

feat eth logger

Yaroslav Bolyukin2021-04-30parent: #c019326.patch.diff
in: master

2 files changed

addedpallets/nft/src/eth/log.rsdiffbeforeafterboth
after · pallets/nft/src/eth/log.rs
1use pallet_evm::PrecompileLog;2use sp_std::cell::RefCell;3use sp_std::vec::Vec;4use sp_core::{H160, H256};56#[derive(Default)]7pub struct LogRecorder(RefCell<Vec<(Vec<H256>, Vec<u8>)>>);89impl LogRecorder {10    pub fn log(&self, topics: Vec<H256>, data: super::abi::AbiWriter) {11        self.0.borrow_mut().push((topics, data.finish()));12    }13    fn retrieve_logs(self) -> Vec<(Vec<H256>, Vec<u8>)> {14        self.0.replace(Vec::new())15    }16    pub fn retrieve_logs_for_contract(self, contract: H160) -> Vec<PrecompileLog> {17        // TODO: Remove reallocation18        self.retrieve_logs().into_iter()19            .map(|(topics, data)| PrecompileLog(contract.clone(), topics, data))20            .collect()21    }22}23impl Drop for LogRecorder {24    fn drop(&mut self) {25        #[cfg(feature = "std")]26        {27            // In debug mode, log recorder panics if dropped with logs left28            let logs = self.0.borrow();29            if !logs.is_empty() {30                eprintln!("Logs lost:");31                for line in logs.iter() {32                    eprintln!("{:?} {:?}", line.0, line.1);33                }34                panic!();35            }36        }37    }38}
modifiedpallets/nft/src/eth/mod.rsdiffbeforeafterboth
--- a/pallets/nft/src/eth/mod.rs
+++ b/pallets/nft/src/eth/mod.rs
@@ -2,4 +2,5 @@
 use account::CrossAccountId;
 pub mod abi;
 use abi::{AbiReader, AbiWriter};
+pub mod log;