Skip to content

Commit 7350909

Browse files
alxiongtwittner
andcommitted
avoid panic, remove unnecessary contract func and Deserialize
Co-authored-by: Toralf Wittner <[email protected]>
1 parent ac1a591 commit 7350909

File tree

4 files changed

+26
-43
lines changed

4 files changed

+26
-43
lines changed

contracts/src/KeyManager.sol

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,6 @@ contract KeyManager is Initializable, OwnableUpgradeable, UUPSUpgradeable {
196196
return nextCommitteeId - 1;
197197
}
198198

199-
/**
200-
* @notice This function is used to get the committee members.
201-
* @dev We need this because alloy binding for `.committees(id)` getter doesn't include dynamic array pointer
202-
* @dev Reverts if the id is greater than the length of the committees mapping.
203-
* @dev Reverts if the id is less than the head committee id.
204-
* @param id The id of the committee.
205-
* @return members The committee members.
206-
*/
207-
function getMembersById(uint64 id) external view virtual returns (CommitteeMember[] memory members) {
208-
if (id < _oldestStoredCommitteeId || committees[id].id != id) {
209-
revert CommitteeIdDoesNotExist(id);
210-
}
211-
return committees[id].members;
212-
}
213-
214199
/**
215200
* @notice This function is used to get the committee by id.
216201
* @dev Reverts if the id is greater than the length of the committees mapping.

timeboost-contract/src/binaries/deploy.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use alloy::{primitives::Address, providers::WalletProvider};
1616
use anyhow::{Context, Result};
1717
use clap::Parser;
18-
use serde::{Deserialize, Serialize};
18+
use serde::Serialize;
1919
use std::{fs, path::PathBuf};
2020
use timeboost_contract::provider::build_provider;
2121
use timeboost_utils::types::logging;
@@ -39,20 +39,19 @@ struct Args {
3939

4040
/// Config type for the key manager who has the permission to update the KeyManager contract
4141
/// See `test-configs/keymanager.toml` for an example
42-
#[derive(Debug, Deserialize, Serialize)]
42+
#[derive(Debug, Serialize)]
4343
struct KeyManagerConfig {
4444
wallet: LocalWalletConfig,
4545
deployments: Deployments,
4646
}
4747

48-
#[derive(Debug, Deserialize, Serialize)]
48+
#[derive(Debug, Serialize)]
4949
struct LocalWalletConfig {
5050
mnemonic: String,
5151
account_index: u32,
5252
}
5353

54-
#[derive(Debug, Deserialize, Serialize)]
55-
#[allow(dead_code)]
54+
#[derive(Debug, Serialize)]
5655
struct Deployments {
5756
/// RPC endpoint of the target chain
5857
chain_url: Url,
@@ -85,7 +84,7 @@ async fn main() -> Result<()> {
8584
cfg.wallet.mnemonic.clone(),
8685
cfg.wallet.account_index,
8786
cfg.deployments.chain_url.clone(),
88-
);
87+
)?;
8988

9089
let manager = provider.default_signer_address();
9190
info!("Deploying with manager address: {manager:#x}");
@@ -104,7 +103,6 @@ async fn main() -> Result<()> {
104103
fs::write(out, &toml)?;
105104
info!(file=?out, "Config written to file");
106105
} else {
107-
println!("===== OUTPUT ======");
108106
println!("{toml}");
109107
}
110108

timeboost-contract/src/deployer.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ mod tests {
4848
use alloy::{providers::WalletProvider, sol_types::SolValue};
4949
use rand::prelude::*;
5050

51-
use crate::{CommitteeMemberSol, KeyManager};
51+
use crate::{CommitteeMemberSol, CommitteeSol, KeyManager};
5252

5353
#[tokio::test]
5454
async fn test_key_manager_deployment() {
@@ -76,24 +76,19 @@ mod tests {
7676
.unwrap();
7777

7878
// make sure next committee is correctly registered
79-
assert_eq!(contract.nextCommitteeId().call().await.unwrap(), 1);
8079
assert_eq!(
8180
contract
82-
.committees(0)
83-
.call()
84-
.await
85-
.unwrap()
86-
.effectiveTimestamp,
87-
timestamp
88-
);
89-
assert_eq!(
90-
contract
91-
.getMembersById(0)
81+
.getCommitteeById(0)
9282
.call()
9383
.await
9484
.unwrap()
9585
.abi_encode_sequence(),
96-
members.abi_encode_sequence()
86+
CommitteeSol {
87+
id: 0,
88+
effectiveTimestamp: timestamp,
89+
members,
90+
}
91+
.abi_encode_sequence()
9792
);
9893
}
9994
}

timeboost-contract/src/provider.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use alloy::{
99
layers::AnvilProvider,
1010
utils::JoinedRecommendedFillers,
1111
},
12-
signers::local::{MnemonicBuilder, PrivateKeySigner, coins_bip39::English},
12+
signers::local::{LocalSignerError, MnemonicBuilder, PrivateKeySigner, coins_bip39::English},
1313
transports::http::reqwest::Url,
1414
};
1515

@@ -30,19 +30,24 @@ pub type TestProviderWithWallet = FillProvider<
3030
>;
3131

3232
/// Build a local signer from wallet mnemonic and account index
33-
pub fn build_signer(mnemonic: String, account_index: u32) -> PrivateKeySigner {
33+
pub fn build_signer(
34+
mnemonic: String,
35+
account_index: u32,
36+
) -> Result<PrivateKeySigner, LocalSignerError> {
3437
MnemonicBuilder::<English>::default()
3538
.phrase(mnemonic)
36-
.index(account_index)
37-
.expect("wrong mnemonic or index")
39+
.index(account_index)?
3840
.build()
39-
.expect("fail to build signer")
4041
}
4142

4243
/// a handy thin wrapper around wallet builder and provider builder that directly
4344
/// returns an instantiated `Provider` with default fillers with wallet, ready to send tx
44-
pub fn build_provider(mnemonic: String, account_index: u32, url: Url) -> HttpProviderWithWallet {
45-
let signer = build_signer(mnemonic, account_index);
45+
pub fn build_provider(
46+
mnemonic: String,
47+
account_index: u32,
48+
url: Url,
49+
) -> Result<HttpProviderWithWallet, LocalSignerError> {
50+
let signer = build_signer(mnemonic, account_index)?;
4651
let wallet = EthereumWallet::from(signer);
47-
ProviderBuilder::new().wallet(wallet).connect_http(url)
52+
Ok(ProviderBuilder::new().wallet(wallet).connect_http(url))
4853
}

0 commit comments

Comments
 (0)