Apply suggestions from code review

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Kris Nuttycombe 2021-11-25 08:28:53 -07:00 committed by Kris Nuttycombe
parent 59a4c84112
commit 6ee0dea218
1 changed files with 7 additions and 17 deletions

View File

@ -78,12 +78,10 @@ pub extern "C" fn orchard_incoming_viewing_key_to_address(
key: *const IncomingViewingKey, key: *const IncomingViewingKey,
diversifier_index: *const [u8; 11], diversifier_index: *const [u8; 11],
) -> *mut Address { ) -> *mut Address {
let key = unsafe { let key =
key.as_ref() unsafe { key.as_ref() }.expect("Orchard incoming viewing key pointer may not be null.");
.expect("Orchard incoming viewing key pointer may not be null.")
};
let diversifier_index = unsafe { DiversifierIndex::from(*diversifier_index) }; let diversifier_index = DiversifierIndex::from(unsafe { *diversifier_index });
Box::into_raw(Box::new(key.address_at(diversifier_index))) Box::into_raw(Box::new(key.address_at(diversifier_index)))
} }
@ -93,10 +91,8 @@ pub extern "C" fn orchard_incoming_viewing_key_serialize(
stream: Option<StreamObj>, stream: Option<StreamObj>,
write_cb: Option<WriteCb>, write_cb: Option<WriteCb>,
) -> bool { ) -> bool {
let key = unsafe { let key =
key.as_ref() unsafe { key.as_ref() }.expect("Orchard incoming viewing key pointer may not be null.");
.expect("Orchard incoming viewing key pointer may not be null.")
};
let mut writer = CppStreamWriter::from_raw_parts(stream, write_cb.unwrap()); let mut writer = CppStreamWriter::from_raw_parts(stream, write_cb.unwrap());
match writer.write_all(&key.to_bytes()) { match writer.write_all(&key.to_bytes()) {
@ -173,10 +169,7 @@ pub extern "C" fn orchard_full_viewing_key_serialize(
stream: Option<StreamObj>, stream: Option<StreamObj>,
write_cb: Option<WriteCb>, write_cb: Option<WriteCb>,
) -> bool { ) -> bool {
let key = unsafe { let key = unsafe { key.as_ref() }.expect("Orchard full viewing key pointer may not be null.");
key.as_ref()
.expect("Orchard full viewing key pointer may not be null.")
};
let mut writer = CppStreamWriter::from_raw_parts(stream, write_cb.unwrap()); let mut writer = CppStreamWriter::from_raw_parts(stream, write_cb.unwrap());
match key.write(&mut writer) { match key.write(&mut writer) {
@ -272,10 +265,7 @@ pub extern "C" fn orchard_spending_key_serialize(
stream: Option<StreamObj>, stream: Option<StreamObj>,
write_cb: Option<WriteCb>, write_cb: Option<WriteCb>,
) -> bool { ) -> bool {
let key = unsafe { let key = unsafe { key.as_ref() }.expect("Orchard spending key pointer may not be null.");
key.as_ref()
.expect("Orchard spending key pointer may not be null.")
};
let mut writer = CppStreamWriter::from_raw_parts(stream, write_cb.unwrap()); let mut writer = CppStreamWriter::from_raw_parts(stream, write_cb.unwrap());
match writer.write_all(key.to_bytes()) { match writer.write_all(key.to_bytes()) {