Special case sending money to self

In the genesis block, let matching 'from' and 'to' keys be used
to mint new coin.
This commit is contained in:
Greg Fitzgerald 2018-03-03 20:27:09 -07:00
parent cebcb5b92d
commit ce60b960c0
2 changed files with 5 additions and 7 deletions

View File

@ -40,7 +40,7 @@ pub enum Event<T> {
impl<T> Event<T> {
pub fn new_claim(to: PublicKey, data: T, sig: Signature) -> Self {
Event::Transaction {
from: None,
from: Some(to),
to,
data,
sig,
@ -81,9 +81,7 @@ pub fn sign_transaction_data<T: Serialize>(
/// Return a signature for the given data using the private key from the given keypair.
pub fn sign_claim_data<T: Serialize>(data: &T, keypair: &Ed25519KeyPair) -> Signature {
let to = get_pubkey(keypair);
let from: Option<PublicKey> = None;
sign_serialized(&(&from, &to, data), keypair)
sign_transaction_data(data, keypair, &get_pubkey(keypair))
}
/// Verify a signed message with the given public key.

View File

@ -1,6 +1,6 @@
//! A library for generating the chain's genesis block.
use event::{generate_keypair, get_pubkey, sign_claim_data, sign_transaction_data, Event, PublicKey};
use event::{generate_keypair, get_pubkey, sign_transaction_data, Event, PublicKey};
use ring::rand::SystemRandom;
use ring::signature::Ed25519KeyPair;
use untrusted::Input;
@ -55,9 +55,9 @@ impl Genesis {
pub fn create_events(&self) -> Vec<Event<u64>> {
let org_keypair = Ed25519KeyPair::from_pkcs8(Input::from(&self.pkcs8)).unwrap();
let sig = sign_claim_data(&self.tokens, &org_keypair);
let event0 = Event::Tick;
let event1 = Event::new_claim(get_pubkey(&org_keypair), self.tokens, sig);
let treasury = Creator::new("Treasury", self.tokens);
let event1 = treasury.create_transaction(&org_keypair);
let mut events = vec![event0, event1];
for creator in &self.creators {