MCPcopy Create free account
hub / github.com/ddimaria/rust-blockchain-tutorial / try_into

Method try_into

utils/src/crypto.rs:37–57  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

35 type Error = UtilsError;
36
37 fn try_into(self) -> Result<RecoverableSignature> {
38 let mut signature = [0u8; 64];
39 signature[..32].copy_from_slice(self.r.as_bytes());
40 signature[32..].copy_from_slice(self.s.as_bytes());
41
42 let recovery_id_32 = i32::try_from(self.v).map_err(|e| {
43 UtilsError::ConversionError(format!("could not convert u64 to i32 {}", e))
44 })?;
45 let recovery_id: RecoveryId = RecoveryId::from_i32(recovery_id_32).map_err(|e| {
46 UtilsError::ConversionError(format!("could not convert i32 to RecoveryId {}", e))
47 })?;
48 let recoverable_signature = RecoverableSignature::from_compact(&signature, recovery_id)
49 .map_err(|e| {
50 UtilsError::ConversionError(format!(
51 "could not convert a signature to a RecoverableSignature {}",
52 e
53 ))
54 })?;
55
56 Ok(recoverable_signature)
57 }
58}
59
60impl TryInto<Vec<u8>> for Signature {

Callers 3

parse_block_numberMethod · 0.45
send_transactionMethod · 0.45
send_raw_transactionMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected