Hi everyone,
As my first project on Rust i'm trying to build a simple blockchain, but i'm stumbling into some stones along the way hahaha.
I've created a struct:
pub struct Output {
pub sender: String,
pub receiver: String,
pub amount: u64,
pub signature: String,
pub spent: Cell<bool>,
}
but when i'm trying to make the signature, the unwrap() method always fails on me:
Error:
thread 'main' panicked at src\output.rs:32:79:
called `Result::unwrap()` on an `Err` value: InvalidMessage
//signs the message
fn sign(&mut self, secret_key: &SecretKey) {
let secp = Secp256k1::new();
let message = self.create_message();
let signature = secp.sign_ecdsa(&Message::from_digest_slice(&message).unwrap(), secret_key); //error happens here
self.signature = signature.to_string();
}
//creates a message in bytes
fn create_message(&self) -> Vec<u8> {
let mut bytes = Vec::new();
bytes.extend(self.sender.as_bytes());
bytes.extend(self.receiver.as_bytes());
bytes.extend(self.amount.to_le_bytes());
bytes
}
i'm not quite getting why. Sorry for any newbie stuff, i'm actually newbie.