1use std::time::Duration;
2
3use eyre::Result;
4use ethers_core::types::{Address, H256};
5
6use crate::{
7 metrics::Metrics, L1Client, rollup::RollupNode, OutputOracle, client::Varro, config::Config,
8};
9
10#[derive(Debug, Default, Clone)]
14pub struct VarroBuilder {
15 pub l1_client: Option<L1Client>,
17 pub rollup_node: Option<RollupNode>,
19 pub output_oracle: Option<OutputOracle>,
21 pub allow_non_finalized: Option<bool>,
23 pub proposer: Option<Address>,
25 pub output_private_key: Option<H256>,
27 pub polling_interval: Option<Duration>,
29 pub metrics: Option<Metrics>,
31}
32
33impl TryFrom<Config> for VarroBuilder {
34 type Error = eyre::Report;
35
36 fn try_from(conf: Config) -> std::result::Result<Self, Self::Error> {
37 Ok(Self {
38 l1_client: Some(conf.get_l1_client()?),
39 rollup_node: Some(conf.get_rollup_node_client()?),
40 output_oracle: Some(conf.get_output_oracle()?),
41 allow_non_finalized: Some(conf.allow_non_finalized),
42 proposer: Some(conf.output_oracle_address),
43 output_private_key: Some(conf.get_output_private_key()?),
44 polling_interval: Some(conf.polling_interval),
45 metrics: None,
46 })
47 }
48}
49
50impl VarroBuilder {
51 pub fn new() -> Self {
53 Self::default()
54 }
55
56 pub fn with_metrics(&mut self, metrics: Metrics) -> &mut Self {
58 self.metrics = Some(metrics);
59 self
60 }
61
62 pub fn with_l1_client(&mut self, l1_client: L1Client) -> &mut Self {
64 self.l1_client = Some(l1_client);
65 self
66 }
67
68 pub fn with_rollup_node(&mut self, rollup_node: RollupNode) -> &mut Self {
70 self.rollup_node = Some(rollup_node);
71 self
72 }
73
74 pub fn with_output_oracle(&mut self, output_oracle: OutputOracle) -> &mut Self {
76 self.output_oracle = Some(output_oracle);
77 self
78 }
79
80 pub fn with_allow_non_finalized(&mut self, allow_non_finalized: bool) -> &mut Self {
82 self.allow_non_finalized = Some(allow_non_finalized);
83 self
84 }
85
86 pub fn with_proposer(&mut self, proposer: Address) -> &mut Self {
88 self.proposer = Some(proposer);
89 self
90 }
91
92 pub fn with_output_private_key(&mut self, output_private_key: H256) -> &mut Self {
95 self.output_private_key = Some(output_private_key);
96 self
97 }
98
99 pub fn with_polling_interval(&mut self, polling_interval: Duration) -> &mut Self {
101 self.polling_interval = Some(polling_interval);
102 self
103 }
104
105 pub fn build(self) -> Result<Varro> {
107 Ok(Varro::try_from(self)?)
108 }
109}