script/research/blockchain-explorer: updated to latest darkfi structures

This commit is contained in:
skoupidi
2024-04-01 22:34:54 +03:00
parent 85c80e1bd3
commit e8cb2d1f51

View File

@@ -21,12 +21,10 @@ use std::{fs::File, io::Write};
use clap::Parser;
use darkfi::{
blockchain::{
block_store::{
Block, BlockDifficulty, BlockDifficultyStore, BlockOrderStore, BlockRanks, BlockStore,
},
contract_store::{ContractStateStore, WasmStore},
block_store::{Block, BlockDifficulty, BlockRanks, BlockStore},
contract_store::ContractStore,
header_store::{Header, HeaderStore},
tx_store::{PendingTxOrderStore, PendingTxStore, TxStore},
tx_store::TxStore,
Blockchain,
},
cli_desc,
@@ -125,27 +123,6 @@ impl BlockInfo {
}
}
#[derive(Debug)]
struct BlockInfoChain {
_blocks: Vec<BlockInfo>,
}
impl BlockInfoChain {
pub fn new(blockstore: &BlockStore) -> BlockInfoChain {
let mut _blocks = Vec::new();
let result = blockstore.get_all();
match result {
Ok(iter) => {
for (hash, block) in iter.iter() {
_blocks.push(BlockInfo::new(*hash, block));
}
}
Err(e) => println!("Error: {:?}", e),
}
BlockInfoChain { _blocks }
}
}
#[derive(Debug)]
struct OrderInfo {
_height: u64,
@@ -158,27 +135,6 @@ impl OrderInfo {
}
}
#[derive(Debug)]
struct BlockOrderStoreInfo {
_order: Vec<OrderInfo>,
}
impl BlockOrderStoreInfo {
pub fn new(orderstore: &BlockOrderStore) -> BlockOrderStoreInfo {
let mut _order = Vec::new();
let result = orderstore.get_all();
match result {
Ok(iter) => {
for (height, hash) in iter.iter() {
_order.push(OrderInfo::new(*height, *hash));
}
}
Err(e) => println!("Error: {:?}", e),
}
BlockOrderStoreInfo { _order }
}
}
#[derive(Debug)]
struct BlockRanksInfo {
_target_rank: BigUint,
@@ -220,23 +176,45 @@ impl BlockDifficultyInfo {
}
#[derive(Debug)]
struct BlockDifficultyStoreInfo {
_difficulties: Vec<BlockDifficultyInfo>,
struct BlockStoreInfo {
_main: Vec<BlockInfo>,
_order: Vec<OrderInfo>,
_difficulty: Vec<BlockDifficultyInfo>,
}
impl BlockDifficultyStoreInfo {
pub fn new(difficultiesstore: &BlockDifficultyStore) -> BlockDifficultyStoreInfo {
let mut _difficulties = Vec::new();
let result = difficultiesstore.get_all();
impl BlockStoreInfo {
pub fn new(blockstore: &BlockStore) -> BlockStoreInfo {
let mut _main = Vec::new();
let result = blockstore.get_all();
match result {
Ok(iter) => {
for (_, difficulty) in iter.iter() {
_difficulties.push(BlockDifficultyInfo::new(difficulty));
for (hash, block) in iter.iter() {
_main.push(BlockInfo::new(*hash, block));
}
}
Err(e) => println!("Error: {:?}", e),
}
BlockDifficultyStoreInfo { _difficulties }
let mut _order = Vec::new();
let result = blockstore.get_all_order();
match result {
Ok(iter) => {
for (height, hash) in iter.iter() {
_order.push(OrderInfo::new(*height, *hash));
}
}
Err(e) => println!("Error: {:?}", e),
}
let mut _difficulty = Vec::new();
let result = blockstore.get_all_difficulty();
match result {
Ok(iter) => {
for (_, difficulty) in iter.iter() {
_difficulty.push(BlockDifficultyInfo::new(difficulty));
}
}
Err(e) => println!("Error: {:?}", e),
}
BlockStoreInfo { _main, _order, _difficulty }
}
}
@@ -252,66 +230,70 @@ impl TxInfo {
}
}
#[derive(Debug)]
struct TxLocationInfo {
_hash: blake3::Hash,
_block_height: u64,
_index: u64,
}
impl TxLocationInfo {
pub fn new(_hash: blake3::Hash, _block_height: u64, _index: u64) -> TxLocationInfo {
TxLocationInfo { _hash, _block_height, _index }
}
}
#[derive(Debug)]
struct TxStoreInfo {
_transactions: Vec<TxInfo>,
_main: Vec<TxInfo>,
_location: Vec<TxLocationInfo>,
_pending: Vec<TxInfo>,
_pending_order: Vec<OrderInfo>,
}
impl TxStoreInfo {
pub fn new(txstore: &TxStore) -> TxStoreInfo {
let mut _transactions = Vec::new();
let mut _main = Vec::new();
let result = txstore.get_all();
match result {
Ok(iter) => {
for (hash, tx) in iter.iter() {
_transactions.push(TxInfo::new(*hash, tx));
_main.push(TxInfo::new(*hash, tx));
}
}
Err(e) => println!("Error: {:?}", e),
}
TxStoreInfo { _transactions }
}
}
#[derive(Debug)]
struct PendingTxStoreInfo {
_transactions: Vec<TxInfo>,
}
impl PendingTxStoreInfo {
pub fn new(pendingtxstore: &PendingTxStore) -> PendingTxStoreInfo {
let mut _transactions = Vec::new();
let result = pendingtxstore.get_all();
let mut _location = Vec::new();
let result = txstore.get_all_location();
match result {
Ok(iter) => {
for (hash, location) in iter.iter() {
_location.push(TxLocationInfo::new(*hash, location.0, location.1));
}
}
Err(e) => println!("Error: {:?}", e),
}
let mut _pending = Vec::new();
let result = txstore.get_all_pending();
match result {
Ok(iter) => {
for (hash, tx) in iter.iter() {
_transactions.push(TxInfo::new(*hash, tx));
_pending.push(TxInfo::new(*hash, tx));
}
}
Err(e) => println!("Error: {:?}", e),
}
PendingTxStoreInfo { _transactions }
}
}
#[derive(Debug)]
struct PendingTxOrderStoreInfo {
_order: Vec<OrderInfo>,
}
impl PendingTxOrderStoreInfo {
pub fn new(orderstore: &PendingTxOrderStore) -> PendingTxOrderStoreInfo {
let mut _order = Vec::new();
let result = orderstore.get_all();
let mut _pending_order = Vec::new();
let result = txstore.get_all_pending_order();
match result {
Ok(iter) => {
for (height, hash) in iter.iter() {
_order.push(OrderInfo::new(*height, *hash));
_pending_order.push(OrderInfo::new(*height, *hash));
}
}
Err(e) => println!("Error: {:?}", e),
}
PendingTxOrderStoreInfo { _order }
TxStoreInfo { _main, _location, _pending, _pending_order }
}
}
@@ -327,27 +309,6 @@ impl ContractStateInfo {
}
}
#[derive(Debug)]
struct ContractStateStoreInfo {
_contracts: Vec<ContractStateInfo>,
}
impl ContractStateStoreInfo {
pub fn new(contractsstore: &ContractStateStore) -> ContractStateStoreInfo {
let mut _contracts = Vec::new();
let result = contractsstore.get_all();
match result {
Ok(iter) => {
for (id, state_hash) in iter.iter() {
_contracts.push(ContractStateInfo::new(*id, state_hash));
}
}
Err(e) => println!("Error: {:?}", e),
}
ContractStateStoreInfo { _contracts }
}
}
#[derive(Debug)]
struct WasmInfo {
_id: ContractId,
@@ -362,51 +323,51 @@ impl WasmInfo {
}
#[derive(Debug)]
struct WasmStoreInfo {
_wasm_bincodes: Vec<WasmInfo>,
struct ContractStoreInfo {
_state: Vec<ContractStateInfo>,
_wasm: Vec<WasmInfo>,
}
impl WasmStoreInfo {
pub fn new(wasmstore: &WasmStore) -> WasmStoreInfo {
let mut _wasm_bincodes = Vec::new();
let result = wasmstore.get_all();
impl ContractStoreInfo {
pub fn new(contractsstore: &ContractStore) -> ContractStoreInfo {
let mut _state = Vec::new();
let result = contractsstore.get_all_states();
match result {
Ok(iter) => {
for (id, bincode) in iter.iter() {
_wasm_bincodes.push(WasmInfo::new(*id, bincode));
for (id, state_hash) in iter.iter() {
_state.push(ContractStateInfo::new(*id, state_hash));
}
}
Err(e) => println!("Error: {:?}", e),
}
WasmStoreInfo { _wasm_bincodes }
let mut _wasm = Vec::new();
let result = contractsstore.get_all_wasm();
match result {
Ok(iter) => {
for (id, bincode) in iter.iter() {
_wasm.push(WasmInfo::new(*id, bincode));
}
}
Err(e) => println!("Error: {:?}", e),
}
ContractStoreInfo { _state, _wasm }
}
}
#[derive(Debug)]
struct BlockchainInfo {
_headers: HeaderStoreInfo,
_blocks: BlockInfoChain,
_order: BlockOrderStoreInfo,
_difficulties: BlockDifficultyStoreInfo,
_blocks: BlockStoreInfo,
_transactions: TxStoreInfo,
_pending_txs: PendingTxStoreInfo,
_pending_txs_order: PendingTxOrderStoreInfo,
_contracts: ContractStateStoreInfo,
_wasm_bincode: WasmStoreInfo,
_contracts: ContractStoreInfo,
}
impl BlockchainInfo {
pub fn new(blockchain: &Blockchain) -> BlockchainInfo {
BlockchainInfo {
_headers: HeaderStoreInfo::new(&blockchain.headers),
_blocks: BlockInfoChain::new(&blockchain.blocks),
_order: BlockOrderStoreInfo::new(&blockchain.order),
_difficulties: BlockDifficultyStoreInfo::new(&blockchain.difficulties),
_blocks: BlockStoreInfo::new(&blockchain.blocks),
_transactions: TxStoreInfo::new(&blockchain.transactions),
_pending_txs: PendingTxStoreInfo::new(&blockchain.pending_txs),
_pending_txs_order: PendingTxOrderStoreInfo::new(&blockchain.pending_txs_order),
_contracts: ContractStateStoreInfo::new(&blockchain.contracts),
_wasm_bincode: WasmStoreInfo::new(&blockchain.wasm_bincode),
_contracts: ContractStoreInfo::new(&blockchain.contracts),
}
}
}