Skip to content

Commit

Permalink
Fix compilation errors
Browse files Browse the repository at this point in the history
Co-Authored-By: mariari <[email protected]>
  • Loading branch information
sug0 and mariari committed Oct 4, 2023
1 parent e93e97e commit 7eb80b1
Show file tree
Hide file tree
Showing 98 changed files with 725 additions and 915 deletions.
6 changes: 2 additions & 4 deletions apps/src/lib/cli/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::fs::File;
use std::io::{self, Write};

use borsh::BorshSerialize;
use borsh_ext::BorshSerializeExt;
use color_eyre::eyre::Result;
use itertools::sorted;
use masp_primitives::zip32::ExtendedFullViewingKey;
Expand Down Expand Up @@ -535,9 +535,7 @@ fn key_export<IO: Io>(
wallet
.find_key(alias.to_lowercase(), None)
.map(|keypair| {
let file_data = keypair
.try_to_vec()
.expect("Encoding keypair shouldn't fail");
let file_data = keypair.serialize_to_vec();
let file_name = format!("key_{}", alias.to_lowercase());
let mut file = File::create(&file_name).unwrap();

Expand Down
8 changes: 3 additions & 5 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use std::io;
use std::iter::Iterator;
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSerialize};
use borsh::BorshDeserialize;
use borsh_ext::BorshSerializeExt;
use data_encoding::HEXLOWER;
use itertools::Either;
use masp_primitives::asset_type::AssetType;
Expand Down Expand Up @@ -868,10 +869,7 @@ pub async fn query_shielded_balance<
// Compute the unique asset identifier from the token address
let token = token;
let _asset_type = AssetType::new(
(token.clone(), epoch.0)
.try_to_vec()
.expect("token addresses should serialize")
.as_ref(),
(token.clone(), epoch.0).serialize_to_vec().as_ref(),
)
.unwrap();
let token_alias = wallet.lookup_alias(&token);
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ const TMP_FILE_NAME: &str = "shielded.tmp";

#[derive(Debug, BorshSerialize, BorshDeserialize, Clone)]
pub struct CLIShieldedUtils {
#[borsh_skip]
#[borsh(skip)]
context_dir: PathBuf,
}

Expand Down
13 changes: 6 additions & 7 deletions apps/src/lib/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::io::Write;
use std::path::{Path, PathBuf};
use std::str::FromStr;

use borsh::BorshSerialize;
use borsh_ext::BorshSerializeExt;
use flate2::read::GzDecoder;
use flate2::write::GzEncoder;
use flate2::Compression;
Expand Down Expand Up @@ -384,12 +384,12 @@ pub fn id_from_pk(pk: &common::PublicKey) -> TendermintNodeId {
match pk {
common::PublicKey::Ed25519(_) => {
let _pk: ed25519::PublicKey = pk.try_to_pk().unwrap();
let digest = Sha256::digest(_pk.try_to_vec().unwrap().as_slice());
let digest = Sha256::digest(_pk.serialize_to_vec().as_slice());
bytes.copy_from_slice(&digest[..TENDERMINT_NODE_ID_LENGTH]);
}
common::PublicKey::Secp256k1(_) => {
let _pk: secp256k1::PublicKey = pk.try_to_pk().unwrap();
let digest = Sha256::digest(_pk.try_to_vec().unwrap().as_slice());
let digest = Sha256::digest(_pk.serialize_to_vec().as_slice());
bytes.copy_from_slice(&digest[..TENDERMINT_NODE_ID_LENGTH]);
}
}
Expand Down Expand Up @@ -705,7 +705,7 @@ pub fn init_network(

// Generate the chain ID first
let genesis = genesis_config::load_genesis_config(config_clean.clone());
let genesis_bytes = genesis.try_to_vec().unwrap();
let genesis_bytes = genesis.serialize_to_vec();
let chain_id = ChainId::from_genesis(chain_id_prefix, genesis_bytes);
let chain_dir = global_args.base_dir.join(chain_id.as_str());
let genesis_path = global_args
Expand Down Expand Up @@ -1126,12 +1126,11 @@ pub fn write_tendermint_node_key(
// but does not for secp256k1.
let (node_keypair, key_str) = match node_sk {
common::SecretKey::Ed25519(sk) => (
[sk.try_to_vec().unwrap(), sk.ref_to().try_to_vec().unwrap()]
.concat(),
[sk.serialize_to_vec(), sk.ref_to().serialize_to_vec()].concat(),
"Ed25519",
),
common::SecretKey::Secp256k1(sk) => {
(sk.try_to_vec().unwrap(), "Secp256k1")
(sk.serialize_to_vec(), "Secp256k1")
}
};

Expand Down
12 changes: 6 additions & 6 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ pub mod genesis_config {
}

#[derive(Debug, BorshSerialize, BorshDeserialize)]
#[borsh_init(init)]
#[borsh(init=init)]
pub struct Genesis {
pub genesis_time: DateTimeUtc,
pub native_token: Address,
Expand Down Expand Up @@ -1136,7 +1136,7 @@ pub fn genesis(num_validators: u64) -> Genesis {

#[cfg(test)]
pub mod tests {
use borsh::BorshSerialize;
use borsh_ext::BorshSerializeExt;
use namada::types::address::testing::gen_established_address;
use namada::types::key::*;
use rand::prelude::ThreadRng;
Expand All @@ -1152,7 +1152,7 @@ pub mod tests {
let mut rng: ThreadRng = thread_rng();
let keypair: common::SecretKey =
ed25519::SigScheme::generate(&mut rng).try_to_sk().unwrap();
let kp_arr = keypair.try_to_vec().unwrap();
let kp_arr = keypair.serialize_to_vec();
let (protocol_keypair, _eth_hot_bridge_keypair, dkg_keypair) =
wallet::defaults::validator_keys();

Expand All @@ -1169,14 +1169,14 @@ pub mod tests {
println!("address: {}", address);
println!("keypair: {:?}", kp_arr);
println!("protocol_keypair: {:?}", protocol_keypair);
println!("dkg_keypair: {:?}", dkg_keypair.try_to_vec().unwrap());
println!("dkg_keypair: {:?}", dkg_keypair.serialize_to_vec());
println!(
"eth_cold_gov_keypair: {:?}",
eth_cold_gov_keypair.try_to_vec().unwrap()
eth_cold_gov_keypair.serialize_to_vec()
);
println!(
"eth_hot_bridge_keypair: {:?}",
eth_hot_bridge_keypair.try_to_vec().unwrap()
eth_hot_bridge_keypair.serialize_to_vec()
);
}
}
22 changes: 5 additions & 17 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,10 +1200,7 @@ mod test_finalize_block {
shell
.wl_storage
.storage
.write(
&balance_key,
Amount::native_whole(1000).try_to_vec().unwrap(),
)
.write(&balance_key, Amount::native_whole(1000).serialize_to_vec())
.unwrap();

// create some wrapper txs
Expand Down Expand Up @@ -1385,10 +1382,7 @@ mod test_finalize_block {
shell
.wl_storage
.storage
.write(
&balance_key,
Amount::native_whole(1000).try_to_vec().unwrap(),
)
.write(&balance_key, Amount::native_whole(1000).serialize_to_vec())
.unwrap();

// create two decrypted txs
Expand Down Expand Up @@ -1638,7 +1632,7 @@ mod test_finalize_block {
&KeccakHash([1; 32]),
3.into(),
);
let value = BlockHeight(4).try_to_vec().expect("Test failed");
let value = BlockHeight(4).serialize_to_vec();
shell
.wl_storage
.storage
Expand All @@ -1649,10 +1643,7 @@ mod test_finalize_block {
shell
.wl_storage
.storage
.write(
&get_nonce_key(),
Uint::from(1).try_to_vec().expect("Test failed"),
)
.write(&get_nonce_key(), Uint::from(1).serialize_to_vec())
.expect("Test failed");
let (tx, action) = craft_tx(&mut shell);
let processed_tx = ProcessedTx {
Expand Down Expand Up @@ -1828,10 +1819,7 @@ mod test_finalize_block {
shell
.wl_storage
.storage
.write(
&balance_key,
Amount::native_whole(1000).try_to_vec().unwrap(),
)
.write(&balance_key, Amount::native_whole(1000).serialize_to_vec())
.unwrap();

// Add a proposal to be executed on next epoch change.
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/node/ledger/shell/init_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ where
genesis::genesis(&self.base_dir, &self.wl_storage.storage.chain_id);
#[cfg(not(any(test, feature = "dev")))]
{
let genesis_bytes = genesis.try_to_vec().unwrap();
let genesis_bytes = genesis.serialize_to_vec();
let errors =
self.wl_storage.storage.chain_id.validate(genesis_bytes);
use itertools::Itertools;
Expand Down Expand Up @@ -210,7 +210,7 @@ where
self.wl_storage
.write_bytes(
&namada::eth_bridge::storage::active_key(),
EthBridgeStatus::Disabled.try_to_vec().unwrap(),
EthBridgeStatus::Disabled.serialize_to_vec(),
)
.unwrap();
}
Expand Down
11 changes: 6 additions & 5 deletions apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use std::path::{Path, PathBuf};
#[allow(unused_imports)]
use std::rc::Rc;

use borsh::{BorshDeserialize, BorshSerialize};
use borsh::BorshDeserialize;
use borsh_ext::BorshSerializeExt;
use masp_primitives::transaction::Transaction;
use namada::core::hints;
use namada::core::ledger::eth_bridge;
Expand Down Expand Up @@ -93,10 +94,10 @@ fn key_to_tendermint(
) -> std::result::Result<public_key::Sum, ParsePublicKeyError> {
match pk {
common::PublicKey::Ed25519(_) => ed25519::PublicKey::try_from_pk(pk)
.map(|pk| public_key::Sum::Ed25519(pk.try_to_vec().unwrap())),
.map(|pk| public_key::Sum::Ed25519(pk.serialize_to_vec())),
common::PublicKey::Secp256k1(_) => {
secp256k1::PublicKey::try_from_pk(pk)
.map(|pk| public_key::Sum::Secp256k1(pk.try_to_vec().unwrap()))
.map(|pk| public_key::Sum::Secp256k1(pk.serialize_to_vec()))
}
}
}
Expand Down Expand Up @@ -1973,7 +1974,7 @@ mod test_utils {
.wl_storage
.write_bytes(
&active_key(),
EthBridgeStatus::Disabled.try_to_vec().expect("Test failed"),
EthBridgeStatus::Disabled.serialize_to_vec(),
)
.expect("Test failed");
}
Expand Down Expand Up @@ -2307,7 +2308,7 @@ mod abciplus_mempool_tests {
})));
// invalid tx type, it doesn't match the
// tx type declared in the header
tx.set_data(Data::new(ext.try_to_vec().expect("Test falied")));
tx.set_data(Data::new(ext.serialize_to_vec()));
tx.add_section(Section::Signature(Signature::new(
tx.sechashes(),
[(0, protocol_key)].into_iter().collect(),
Expand Down
16 changes: 6 additions & 10 deletions apps/src/lib/node/ledger/shell/prepare_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ mod test_prepare_proposal {
#[cfg(feature = "abcipp")]
use std::collections::{BTreeSet, HashMap};

use borsh::BorshSerialize;
use borsh_ext::BorshSerializeExt;
use namada::core::ledger::storage_api::collections::lazy_map::{
NestedSubKey, SubKey,
};
Expand Down Expand Up @@ -584,8 +584,7 @@ mod test_prepare_proposal {
bridge_pool_root: Some(bp_root),
validator_set_update: None,
}
.try_to_vec()
.expect("Test failed");
.serialize_to_vec();

let vote = ExtendedVoteInfo {
vote_extension,
Expand Down Expand Up @@ -1027,7 +1026,7 @@ mod test_prepare_proposal {
validator_set_update: None,
};
let vote = ExtendedVoteInfo {
vote_extension: vote_extension.try_to_vec().unwrap(),
vote_extension: vote_extension.serialize_to_vec(),
..Default::default()
};
// this should panic
Expand Down Expand Up @@ -1082,10 +1081,7 @@ mod test_prepare_proposal {
shell
.wl_storage
.storage
.write(
&balance_key,
Amount::native_whole(1_000).try_to_vec().unwrap(),
)
.write(&balance_key, Amount::native_whole(1_000).serialize_to_vec())
.unwrap();

let mut req = RequestPrepareProposal {
Expand Down Expand Up @@ -1150,11 +1146,11 @@ mod test_prepare_proposal {
assert_eq!(
received
.iter()
.map(|x| x.try_to_vec().unwrap())
.map(|x| x.serialize_to_vec())
.collect::<Vec<_>>(),
expected_txs
.iter()
.map(|x| x.try_to_vec().unwrap())
.map(|x| x.serialize_to_vec())
.collect::<Vec<_>>(),
);
}
Expand Down
5 changes: 1 addition & 4 deletions apps/src/lib/node/ledger/shell/process_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2180,10 +2180,7 @@ mod test_process_proposal {
shell
.wl_storage
.storage
.write(
&balance_key,
Amount::native_whole(1000).try_to_vec().unwrap(),
)
.write(&balance_key, Amount::native_whole(1000).serialize_to_vec())
.unwrap();

let mut wrapper =
Expand Down
6 changes: 2 additions & 4 deletions apps/src/lib/node/ledger/shell/queries.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Shell methods for querying state
use borsh::BorshSerialize;
use borsh_ext::BorshSerializeExt;
use ferveo_common::TendermintValidator;
use namada::ledger::pos::into_tm_voting_power;
use namada::ledger::queries::{RequestCtx, ResponseQuery};
Expand Down Expand Up @@ -84,9 +84,7 @@ where
&self,
pk: &common::PublicKey,
) -> Option<TendermintValidator<EllipticCurve>> {
let pk_bytes = pk
.try_to_vec()
.expect("Serializing public key should not fail");
let pk_bytes = pk.serialize_to_vec();
// get the current epoch
let (current_epoch, _) = self.wl_storage.storage.get_current_epoch();

Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/node/ledger/shell/vote_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ where
_req: request::ExtendVote,
) -> response::ExtendVote {
response::ExtendVote {
vote_extension: self.craft_extension().try_to_vec().unwrap(),
vote_extension: self.craft_extension().serialize_to_vec(),
}
}

Expand Down
Loading

0 comments on commit 7eb80b1

Please sign in to comment.