use walleth::{Controller, Keychain, Signable};
pub fn main() {
let mut keychain = Keychain::new();
keychain.subscribe(|keychain_state| {
println!(
"> Keychain state changed, accounts: {:?}",
keychain_state.accounts.len()
);
});
let account = match keychain.add_account() {
Ok(key) => key,
Err(e) => {
println!("Error: {}", e);
return;
}
};
println!("> Account: {}", account.address);
keychain.lock("Hello Buterin").unwrap();
println!("> Keychain locked");
keychain.unlock("Hello Buterin").unwrap();
println!("> Keychain unlocked");
let message_to_sign = Signable::from_str("Hello").unwrap();
let signature = keychain
.use_signer(account.address.clone(), |signer| {
let signature = signer.sign(&message_to_sign).unwrap();
signature
})
.unwrap();
println!(
"> Signed message: {:?}\n> Signature: {}",
message_to_sign.to_signable_message(),
signature
);
keychain.lock("Hello Buterin").unwrap();
if keychain.add_account().is_ok() {
panic!("> Error: We added an account while wallet was locked");
}
}