Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove default value 0000 0000 0000 0000 of Hex #1482

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion protocol/src/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{ckb_blake2b_256, types::Hex};

lazy_static::lazy_static! {
pub static ref CHAIN_ID: ArcSwap<u64> = ArcSwap::from_pointee(Default::default());
pub static ref PROTOCOL_VERSION: ArcSwap<Hex> = ArcSwap::from_pointee(Default::default());
pub static ref PROTOCOL_VERSION: ArcSwap<Hex> = ArcSwap::from_pointee(Hex::with_length(8));

pub static ref DUMMY_INPUT_OUT_POINT: packed::OutPoint
= packed::OutPointBuilder::default()
Expand Down
24 changes: 17 additions & 7 deletions protocol/src/types/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ impl Hex {
Hex(Bytes::default())
}

pub fn with_length(len: usize) -> Self {
Hex(vec![0u8; len].into())
}

pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
Expand Down Expand Up @@ -108,12 +112,6 @@ impl Hex {
}
}

impl Default for Hex {
fn default() -> Self {
Hex(vec![0u8; 8].into())
}
}

impl AsRef<[u8]> for Hex {
fn as_ref(&self) -> &[u8] {
&self.0
Expand Down Expand Up @@ -459,7 +457,7 @@ pub struct Validator {
pub vote_weight: u32,
}

#[derive(RlpEncodable, RlpDecodable, Serialize, Deserialize, Clone, PartialEq, Eq, Default)]
#[derive(RlpEncodable, RlpDecodable, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct ValidatorExtend {
pub bls_pub_key: Hex,
pub pub_key: Hex,
Expand Down Expand Up @@ -492,6 +490,18 @@ impl From<&ValidatorExtend> for Validator {
}
}

impl Default for ValidatorExtend {
fn default() -> Self {
Self {
bls_pub_key: Hex::with_length(8),
pub_key: Hex::with_length(8),
address: Default::default(),
propose_weight: Default::default(),
vote_weight: Default::default(),
}
}
}

impl std::fmt::Debug for ValidatorExtend {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let bls_pub_key = self.bls_pub_key.as_string_trim0x();
Expand Down
Loading