Replace custom to_hex with hex::encode
The custom to_hex function has a bug where it does guarantee two hex
digits per byte. Replacing this with the hex::encode function (used
elsewhere in transact) corrects the issue.
@@ -203,25 +203,16 @@ fn as_sawtooth_header(header: &TransactionHeader) -> SawtoothTxnHeader {
sawtooth_header.set_family_name(header.family_name().to_owned());
sawtooth_header.set_family_version(header.family_version().to_owned());
- sawtooth_header.set_signer_public_key(to_hex(&header.signer_public_key()));
- sawtooth_header.set_batcher_public_key(to_hex(&header.batcher_public_key()));
- sawtooth_header.set_dependencies(header.dependencies().iter().map(to_hex).collect());
- sawtooth_header.set_inputs(header.inputs().iter().map(to_hex).collect());
- sawtooth_header.set_outputs(header.outputs().iter().map(to_hex).collect());
- sawtooth_header.set_nonce(to_hex(&header.nonce()));
+ sawtooth_header.set_signer_public_key(hex::encode(&header.signer_public_key()));
+ sawtooth_header.set_batcher_public_key(hex::encode(&header.batcher_public_key()));
+ sawtooth_header.set_dependencies(header.dependencies().iter().map(hex::encode).collect());
+ sawtooth_header.set_inputs(header.inputs().iter().map(hex::encode).collect());
+ sawtooth_header.set_outputs(header.outputs().iter().map(hex::encode).collect());
+ sawtooth_header.set_nonce(hex::encode(&header.nonce()));
sawtooth_header
}
-fn to_hex<T: AsRef<[u8]>>(bytes: &T) -> String {
- let bytes = bytes.as_ref();
- let mut buf = String::with_capacity(bytes.len() * 2);
- for b in bytes {
- write!(&mut buf, "{:0x}", b).unwrap(); // this can't fail
- }
- buf
-}
-
fn to_context_error(err: ContextError) -> SawtoothContextError {
SawtoothContextError::ReceiveError(Box::new(err))
}
