Wallet operation to burn some coins (#172)
* Burn transaction for testing * Burn bug fixes, embed burn key in keychain * Better error logging in API, wallet fee calc fix
This commit is contained in:
@@ -135,6 +135,12 @@ impl Identifier {
|
||||
Identifier(identifier)
|
||||
}
|
||||
|
||||
pub fn from_pubkey(secp: &Secp256k1, pubkey: &PublicKey) -> Identifier {
|
||||
let bytes = pubkey.serialize_vec(secp, true);
|
||||
let identifier = blake2b(20, &[], &bytes[..]);
|
||||
Identifier::from_bytes(&identifier.as_bytes())
|
||||
}
|
||||
|
||||
fn from_hex(hex: &str) -> Result<Identifier, Error> {
|
||||
// TODO - error handling, don't unwrap here
|
||||
let bytes = util::from_hex(hex.to_string()).unwrap();
|
||||
@@ -245,9 +251,7 @@ impl ExtendedKey {
|
||||
// corresponding to the underlying SecretKey
|
||||
pub fn identifier(&self, secp: &Secp256k1) -> Result<Identifier, Error> {
|
||||
let pubkey = PublicKey::from_secret_key(secp, &self.key)?;
|
||||
let bytes = pubkey.serialize_vec(secp, true);
|
||||
let identifier = blake2b(20, &[], &bytes[..]);
|
||||
Ok(Identifier::from_bytes(&identifier.as_bytes()))
|
||||
Ok(Identifier::from_pubkey(secp, &pubkey))
|
||||
}
|
||||
|
||||
/// Derive an extended key from an extended key
|
||||
|
||||
@@ -48,6 +48,10 @@ impl From<extkey::Error> for Error {
|
||||
pub struct Keychain {
|
||||
secp: Secp256k1,
|
||||
extkey: extkey::ExtendedKey,
|
||||
|
||||
/// for tests and burn only, associate the zero fingerprint to a known
|
||||
/// dummy private key
|
||||
pub enable_burn_key: bool,
|
||||
}
|
||||
|
||||
impl Keychain {
|
||||
@@ -61,6 +65,7 @@ impl Keychain {
|
||||
let keychain = Keychain {
|
||||
secp: secp,
|
||||
extkey: extkey,
|
||||
enable_burn_key: false,
|
||||
};
|
||||
Ok(keychain)
|
||||
}
|
||||
@@ -82,6 +87,13 @@ impl Keychain {
|
||||
// TODO - smarter lookups - can we cache key_id/fingerprint -> derivation
|
||||
// number somehow?
|
||||
fn derived_key(&self, pubkey: &Identifier) -> Result<SecretKey, Error> {
|
||||
if self.enable_burn_key {
|
||||
// for tests and burn only, associate the zero fingerprint to a known
|
||||
// dummy private key
|
||||
if pubkey.fingerprint().to_string() == "00000000" {
|
||||
return Ok(SecretKey::from_slice(&self.secp, &[1; 32])?);
|
||||
}
|
||||
}
|
||||
for i in 1..10000 {
|
||||
let extkey = self.extkey.derive(&self.secp, i)?;
|
||||
if extkey.identifier(&self.secp)? == *pubkey {
|
||||
|
||||
Reference in New Issue
Block a user