Skip to content

Commit

Permalink
Merge branch 'tomas/inline-borsh-ext' (#4177)
Browse files Browse the repository at this point in the history
* tomas/inline-borsh-ext:
  changelog: add #4177
  inline the borsh-ext fn in core
  • Loading branch information
tzemanovic committed Dec 11, 2024
2 parents ea76477 + ce55dbc commit 08c16b7
Show file tree
Hide file tree
Showing 53 changed files with 82 additions and 103 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/miscellaneous/4177-inline-borsh-ext.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Inline borsh-ext crate function in namada_core crate.
([\#4177](https://github.com/anoma/namada/pull/4177))
16 changes: 0 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/apps_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ namada_wallet = { path = "../wallet", features = ["std"]}
async-trait.workspace = true
base64.workspace = true
borsh.workspace = true
borsh-ext.workspace = true
clap.workspace = true
color-eyre.workspace = true
config.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions crates/apps_lib/src/cli/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ use std::fs::File;
use std::io::{self, Write};
use std::str::FromStr;

use borsh::BorshDeserialize;
use borsh_ext::BorshSerializeExt;
use color_eyre::eyre::Result;
use itertools::sorted;
use ledger_namada_rs::{BIP44Path, NamadaApp};
use namada_core::chain::BlockHeight;
use namada_core::masp::{ExtendedSpendingKey, MaspValue, PaymentAddress};
use namada_sdk::address::{Address, DecodeError};
use namada_sdk::borsh::{BorshDeserialize, BorshSerializeExt};
use namada_sdk::io::{display_line, edisplay_line, Io};
use namada_sdk::key::*;
use namada_sdk::masp::find_valid_diversifier;
Expand Down
2 changes: 1 addition & 1 deletion crates/apps_lib/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use std::collections::{BTreeMap, BTreeSet};
use std::io;

use borsh::BorshDeserialize;
use color_eyre::owo_colors::OwoColorize;
use data_encoding::HEXLOWER;
use either::Either;
Expand All @@ -15,6 +14,7 @@ use masp_primitives::zip32::ExtendedFullViewingKey;
use namada_core::masp::{BalanceOwner, MaspEpoch};
use namada_core::token::Amount;
use namada_sdk::address::{Address, InternalAddress, MASP};
use namada_sdk::borsh::BorshDeserialize;
use namada_sdk::chain::{BlockHeight, Epoch};
use namada_sdk::collections::{HashMap, HashSet};
use namada_sdk::control_flow::time::{Duration, Instant};
Expand Down
3 changes: 1 addition & 2 deletions crates/apps_lib/src/client/tx.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::fs::File;
use std::io::Write;

use borsh::BorshDeserialize;
use borsh_ext::BorshSerializeExt;
use color_eyre::owo_colors::OwoColorize;
use ledger_namada_rs::{BIP44Path, NamadaApp};
use masp_primitives::sapling::redjubjub;
Expand All @@ -15,6 +13,7 @@ use masp_primitives::zip32::{ExtendedFullViewingKey, PseudoExtendedKey};
use namada_core::masp::MaspTransaction;
use namada_sdk::address::{Address, ImplicitAddress, MASP};
use namada_sdk::args::TxBecomeValidator;
use namada_sdk::borsh::{BorshDeserialize, BorshSerializeExt};
use namada_sdk::collections::HashMap;
use namada_sdk::governance::cli::onchain::{
DefaultProposal, PgfFundingProposal, PgfStewardProposal,
Expand Down
2 changes: 1 addition & 1 deletion crates/apps_lib/src/client/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::fs::{self, File, OpenOptions};
use std::io::Write;
use std::path::{Path, PathBuf};

use borsh_ext::BorshSerializeExt;
use color_eyre::owo_colors::OwoColorize;
use flate2::read::GzDecoder;
use flate2::write::GzEncoder;
Expand All @@ -12,6 +11,7 @@ use itertools::Either;
use namada_sdk::account::AccountPublicKeysMap;
use namada_sdk::address::{Address, ImplicitAddress};
use namada_sdk::args::DeviceTransport;
use namada_sdk::borsh::BorshSerializeExt;
use namada_sdk::chain::ChainId;
use namada_sdk::dec::Dec;
use namada_sdk::ibc::trace::ibc_token;
Expand Down
4 changes: 2 additions & 2 deletions crates/apps_lib/src/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use std::collections::BTreeMap;
use std::fmt::{Display, Formatter};
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSerialize};
use derivative::Derivative;
use namada_macros::BorshDeserializer;
#[cfg(feature = "migrations")]
use namada_migrations::*;
use namada_sdk::address::{Address, EstablishedAddress};
use namada_sdk::borsh::{BorshDeserialize, BorshSerialize};
use namada_sdk::collections::HashMap;
use namada_sdk::eth_bridge::EthereumBridgeParams;
use namada_sdk::governance::parameters::GovernanceParameters;
Expand Down Expand Up @@ -672,8 +672,8 @@ pub fn make_dev_genesis(

#[cfg(test)]
pub mod tests {
use borsh_ext::BorshSerializeExt;
use namada_sdk::address::testing::gen_established_address;
use namada_sdk::borsh::BorshSerializeExt;
use namada_sdk::key::*;
use rand::prelude::ThreadRng;
use rand::thread_rng;
Expand Down
3 changes: 1 addition & 2 deletions crates/apps_lib/src/config/genesis/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ use std::collections::BTreeMap;
use std::path::Path;
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSerialize};
use borsh_ext::BorshSerializeExt;
use eyre::eyre;
use namada_macros::BorshDeserializer;
#[cfg(feature = "migrations")]
use namada_migrations::*;
use namada_sdk::address::{
Address, EstablishedAddress, EstablishedAddressGen, InternalAddress,
};
use namada_sdk::borsh::{BorshDeserialize, BorshSerialize, BorshSerializeExt};
use namada_sdk::chain::{ChainId, ChainIdPrefix};
use namada_sdk::eth_bridge::EthereumBridgeParams;
use namada_sdk::governance::pgf::parameters::PgfParameters;
Expand Down
2 changes: 1 addition & 1 deletion crates/apps_lib/src/config/genesis/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use std::collections::{BTreeMap, BTreeSet};
use std::marker::PhantomData;
use std::path::Path;

use borsh::{BorshDeserialize, BorshSerialize};
use namada_macros::BorshDeserializer;
#[cfg(feature = "migrations")]
use namada_migrations::*;
use namada_sdk::address::Address;
use namada_sdk::borsh::{BorshDeserialize, BorshSerialize};
use namada_sdk::dec::Dec;
use namada_sdk::eth_bridge::storage::parameters::{
Contracts, Erc20WhitelistEntry, MinimumConfirmations,
Expand Down
3 changes: 1 addition & 2 deletions crates/apps_lib/src/config/genesis/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use std::env;
use std::fmt::Debug;
use std::net::SocketAddr;

use borsh::{BorshDeserialize, BorshSerialize};
use borsh_ext::BorshSerializeExt;
use itertools::{Either, Itertools};
use ledger_namada_rs::NamadaApp;
use namada_macros::BorshDeserializer;
Expand All @@ -15,6 +13,7 @@ use namada_migrations::*;
use namada_sdk::account::AccountPublicKeysMap;
use namada_sdk::address::{Address, EstablishedAddress};
use namada_sdk::args::{DeviceTransport, Tx as TxArgs};
use namada_sdk::borsh::{BorshDeserialize, BorshSerialize, BorshSerializeExt};
use namada_sdk::chain::ChainId;
use namada_sdk::collections::HashSet;
use namada_sdk::dec::Dec;
Expand Down
2 changes: 1 addition & 1 deletion crates/apps_lib/src/tendermint_node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::{Path, PathBuf};

use borsh_ext::BorshSerializeExt;
use namada_sdk::borsh::BorshSerializeExt;
use namada_sdk::key::*;
use serde_json::json;
use sha2::{Digest, Sha256};
Expand Down
1 change: 0 additions & 1 deletion crates/benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ namada_vp = { path = "../vp" }
masp_primitives.workspace = true
masp_proofs = { workspace = true, features = ["benchmarks", "multicore"] }
borsh.workspace = true
borsh-ext.workspace = true
criterion = { version = "0.5", features = ["html_reports"] }
lazy_static.workspace= true
prost.workspace = true
Expand Down
1 change: 0 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ arbitrary = { workspace = true, optional = true }
arse-merkle-tree.workspace = true
bech32.workspace = true
borsh.workspace = true
borsh-ext.workspace = true
chrono.workspace = true
data-encoding.workspace = true
ed25519-consensus.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,10 @@ impl InternalAddress {

#[cfg(test)]
pub mod tests {
use borsh_ext::BorshSerializeExt;
use proptest::prelude::*;

use super::*;
use crate::borsh::BorshSerializeExt;

/// Run `cargo test gen_established_address -- --nocapture` to generate a
/// new established address.
Expand Down
33 changes: 33 additions & 0 deletions crates/core/src/borsh.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! Borsh binary encoding (re-exported) from official crate with custom
//! ext.
pub use borsh::*;

/// Extensions to types implementing [`BorshSerialize`].
pub trait BorshSerializeExt {
/// Serialize a value to a [`Vec`] of bytes.
fn serialize_to_vec(&self) -> Vec<u8>;
}

impl<T: BorshSerialize> BorshSerializeExt for T {
fn serialize_to_vec(&self) -> Vec<u8> {
let Ok(vec) = borsh::to_vec(self) else {
unreachable!("Serializing to a Vec should be infallible");
};
vec
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_serialize_equal() {
let to_seriailze =
"this is some cool shizzle I can guarantee that much - t. knower";
let serialized_this_lib = to_seriailze.serialize_to_vec();
let serialized_borsh_native = borsh::to_vec(&to_seriailze).unwrap();
assert_eq!(serialized_this_lib, serialized_borsh_native);
}
}
2 changes: 1 addition & 1 deletion crates/core/src/eth_bridge_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use std::borrow::Cow;

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use borsh_ext::BorshSerializeExt;
use ethabi::token::Token;
use namada_macros::{BorshDeserializer, StorageKeys};
#[cfg(feature = "migrations")]
Expand All @@ -16,6 +15,7 @@ use super::keccak::KeccakHash;
use super::storage::{self, KeySeg};
use crate as namada_core; // This is needed for `StorageKeys` macro
use crate::address::Address;
use crate::borsh::BorshSerializeExt;
use crate::eth_abi::Encode;
use crate::ethereum_events::{
EthAddress, TransferToEthereum as TransferToEthereumEvent,
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/ethereum_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::fmt::{Display, Formatter};
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use borsh_ext::BorshSerializeExt;
use ethabi::ethereum_types::{H160, U256 as ethUint};
use ethabi::Token;
use eyre::{eyre, Context};
Expand All @@ -15,6 +14,7 @@ use namada_migrations::*;
use serde::{Deserialize, Serialize};

use crate::address::Address;
use crate::borsh::BorshSerializeExt;
use crate::eth_abi::Encode;
use crate::ethereum_structs::Erc20Transfer;
use crate::hash::Hash;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/key/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::fmt::{self, Display};
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use borsh_ext::BorshSerializeExt;
use data_encoding::{HEXLOWER, HEXUPPER};
use namada_macros::BorshDeserializer;
#[cfg(feature = "migrations")]
Expand All @@ -19,6 +18,7 @@ use super::{
ParseSignatureError, RefTo, SchemeType, SigScheme as SigSchemeTrait,
VerifySigError,
};
use crate::borsh::BorshSerializeExt;
use crate::ethereum_events::EthAddress;
use crate::key::{SignableBytes, StorageHasher};
use crate::{impl_display_and_from_str_via_format, string_encoding};
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/key/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::io::{Read, Write};
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use borsh_ext::BorshSerializeExt;
use data_encoding::HEXLOWER;
use namada_macros::BorshDeserializer;
#[cfg(feature = "migrations")]
Expand All @@ -22,6 +21,7 @@ use super::{
ParsePublicKeyError, ParseSecretKeyError, ParseSignatureError, RefTo,
SchemeType, SigScheme as SigSchemeTrait, SignableBytes, VerifySigError,
};
use crate::borsh::BorshSerializeExt;
use crate::key::StorageHasher;

const PUBLIC_KEY_LENGTH: usize = 32;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::hash::Hash;
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use borsh_ext::BorshSerializeExt;
use data_encoding::HEXUPPER;
use namada_macros::BorshDeserializer;
#[cfg(feature = "migrations")]
Expand All @@ -21,6 +20,7 @@ use sha2::{Digest, Sha256};
use thiserror::Error;

use crate::address;
use crate::borsh::BorshSerializeExt;
use crate::hash::{KeccakHasher, Sha256Hasher, StorageHasher};
use crate::keccak::{keccak_hash, KeccakHash};

Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/key/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::io::{ErrorKind, Read, Write};
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use borsh_ext::BorshSerializeExt;
use data_encoding::HEXLOWER;
use ethabi::Token;
use k256::ecdsa::RecoveryId;
Expand All @@ -27,6 +26,7 @@ use super::{
ParsePublicKeyError, ParseSecretKeyError, ParseSignatureError, RefTo,
SchemeType, SigScheme as SigSchemeTrait, SignableBytes, VerifySigError,
};
use crate::borsh::BorshSerializeExt;
use crate::eth_abi::Encode;
use crate::ethereum_events::EthAddress;
use crate::key::StorageHasher;
Expand Down
Loading

0 comments on commit 08c16b7

Please sign in to comment.