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

chore: supplements ckb-gen-types with two type conversions that used to exist in ckb-standalone-types #4293

Merged
Merged
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
18 changes: 18 additions & 0 deletions util/gen-types/src/conversion/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,31 @@ impl Pack<packed::Byte32> for [u8; 32] {
}
}

impl<'r> Unpack<[u8; 32]> for packed::Byte32Reader<'r> {
fn unpack(&self) -> [u8; 32] {
let mut b = [0u8; 32];
b.copy_from_slice(self.raw_data());
b
}
}
impl_conversion_for_entity_unpack!([u8; 32], Byte32);

impl Pack<packed::ProposalShortId> for [u8; 10] {
fn pack(&self) -> packed::ProposalShortId {
packed::ProposalShortId::from_slice(&self[..])
.expect("impossible: fail to pack to ProposalShortId")
}
}

impl<'r> Unpack<[u8; 10]> for packed::ProposalShortIdReader<'r> {
fn unpack(&self) -> [u8; 10] {
let mut b = [0u8; 10];
b.copy_from_slice(self.raw_data());
b
}
}
impl_conversion_for_entity_unpack!([u8; 10], ProposalShortId);

impl Pack<packed::Bytes> for Bytes {
fn pack(&self) -> packed::Bytes {
let len = (self.len() as u32).to_le_bytes();
Expand Down
Loading