1use std::collections::HashMap;
9use std::ops::{Deref, DerefMut};
10
11use pchain_types::{
12 blockchain::{Command, Transaction},
13 cryptography::{PublicAddress, Sha256Hash},
14};
15
16#[derive(Clone, Default)]
18pub(crate) struct BaseTx {
19 pub signer: PublicAddress,
20 pub hash: Sha256Hash,
21 pub nonce: u64,
22 pub gas_limit: u64,
23 pub priority_fee_per_gas: u64,
24}
25
26impl From<&Transaction> for BaseTx {
27 fn from(tx: &Transaction) -> Self {
28 Self {
29 signer: tx.signer,
30 hash: tx.hash,
31 nonce: tx.nonce,
32 gas_limit: tx.gas_limit,
33 priority_fee_per_gas: tx.priority_fee_per_gas,
34 }
35 }
36}
37
38#[derive(Clone)]
40pub(crate) struct CallTx {
41 pub base_tx: BaseTx,
42 pub target: PublicAddress,
43 pub method: String,
44 pub arguments: Option<Vec<Vec<u8>>>,
45 pub amount: Option<u64>,
46}
47
48impl Deref for CallTx {
49 type Target = BaseTx;
50 fn deref(&self) -> &Self::Target {
51 &self.base_tx
52 }
53}
54
55impl DerefMut for CallTx {
56 fn deref_mut(&mut self) -> &mut Self::Target {
57 &mut self.base_tx
58 }
59}
60
61#[derive(Clone, Debug)]
63pub(crate) struct DeferredCommand {
64 pub contract_address: PublicAddress,
65 pub command: Command,
66}
67
68#[derive(Debug, Default, Clone, PartialEq, Eq)]
70pub struct BlockchainParams {
71 pub this_block_number: u64,
73 pub prev_block_hash: Sha256Hash,
75 pub this_base_fee: u64,
77 pub timestamp: u32,
79 pub random_bytes: Sha256Hash,
81 pub proposer_address: PublicAddress,
83 pub treasury_address: PublicAddress,
85 pub cur_view: u64,
87 pub validator_performance: Option<ValidatorPerformance>,
90}
91
92#[derive(Debug, Clone, Default, PartialEq, Eq)]
94pub struct ValidatorPerformance {
95 pub blocks_per_epoch: u32,
97 pub stats: HashMap<PublicAddress, BlockProposalStats>,
99}
100
101#[derive(Debug, Clone, PartialEq, Eq)]
103pub struct BlockProposalStats {
104 pub num_of_proposed_blocks: u32,
106}
107
108impl BlockProposalStats {
109 pub fn new(num_of_proposed_blocks: u32) -> Self {
110 Self {
111 num_of_proposed_blocks,
112 }
113 }
114}