Skip to content
Permalink
Browse files

use named field for output and make input value public

  • Loading branch information...
vincenthz committed Mar 14, 2019
1 parent 8525685 commit f735a4fa8505219ffd47188cedd0c48778cffe4b
Showing with 33 additions and 26 deletions.
  1. +3 −3 chain-impl-mockchain/src/stake.rs
  2. +30 −23 chain-impl-mockchain/src/transaction/transfer.rs
@@ -49,7 +49,7 @@ impl DelegationState {

// We're only interested in "group" addresses
// (i.e. containing a spending key and a stake key).
if let Kind::Group(_spending_key, stake_key) = output.0.kind() {
if let Kind::Group(_spending_key, stake_key) = output.address.kind() {
// Grmbl.
let stake_key = stake_key.clone().into();

@@ -67,13 +67,13 @@ impl DelegationState {
});
// note: unwrap should be safe, the system should have a total less than overflow
stake_pool_dist.total_stake =
(stake_pool_dist.total_stake + output.1).unwrap();
(stake_pool_dist.total_stake + output.value).unwrap();

let member_dist = stake_pool_dist
.member_stake
.entry(stake_key.clone())
.or_insert_with(|| Value::zero());
*member_dist = (*member_dist + output.1).unwrap();
*member_dist = (*member_dist + output.value).unwrap();
}
}
}
@@ -1,4 +1,5 @@
use super::utxo::{TransactionId, UtxoPointer};
use super::utxo::UtxoPointer;
use super::transaction::TransactionId;
use crate::account;
use crate::value::*;
use chain_core::property;
@@ -13,7 +14,7 @@ const INPUT_PTR_SIZE: usize = 32;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Input {
index_or_account: u8,
value: Value,
pub value: Value,
input_ptr: [u8; INPUT_PTR_SIZE],
}

@@ -23,6 +24,27 @@ pub enum InputEnum {
}

impl Input {
pub fn from_utxo(utxo_pointer: UtxoPointer) -> Self {
let mut input_ptr = [0u8; INPUT_PTR_SIZE];
input_ptr.clone_from_slice(utxo_pointer.transaction_id.as_ref());
Input {
index_or_account: utxo_pointer.output_index,
value: utxo_pointer.value,
input_ptr: input_ptr,
}
}

pub fn from_account(id: account::Identifier, value: Value) -> Self {
let pk: PublicKey<account::AccountAlg> = id.into();
let mut input_ptr = [0u8; INPUT_PTR_SIZE];
input_ptr.clone_from_slice(pk.as_ref());
Input {
index_or_account: 0xff,
value: value,
input_ptr: input_ptr,
}
}

pub fn to_enum(&self) -> InputEnum {
if self.index_or_account == 0xff {
let pk =
@@ -39,26 +61,8 @@ impl Input {

pub fn from_enum(ie: InputEnum) -> Input {
match ie {
InputEnum::AccountInput(id, value) => {
let pk: PublicKey<account::AccountAlg> = id.into();
let mut input_ptr = [0u8; INPUT_PTR_SIZE];
input_ptr.clone_from_slice(pk.as_ref());
Input {
index_or_account: 0xff,
value: value,
input_ptr: input_ptr,
}
}

InputEnum::UtxoInput(utxo_pointer) => {
let mut input_ptr = [0u8; INPUT_PTR_SIZE];
input_ptr.clone_from_slice(utxo_pointer.transaction_id.as_ref());
Input {
index_or_account: utxo_pointer.output_index,
value: utxo_pointer.value,
input_ptr: input_ptr,
}
}
InputEnum::AccountInput(id, value) => Self::from_account(id, value),
InputEnum::UtxoInput(utxo_pointer) => Self::from_utxo(utxo_pointer),
}
}
}
@@ -99,4 +103,7 @@ impl property::Deserialize for Input {
/// Information how tokens are spent.
/// A value of tokens is sent to the address.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Output<Address>(pub Address, pub Value);
pub struct Output<Address> {
pub address: Address,
pub value: Value,
}

0 comments on commit f735a4f

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.