Skip to content

Commit

Permalink
Add onNewAccount on utxo (#37)
Browse files Browse the repository at this point in the history
* add onNewAccount on utxo

* fix wasm
  • Loading branch information
satellitex authored May 23, 2019
1 parent d010698 commit c2f5444
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions core/child/src/mvp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ mod tests {
type TimeLock = Self::BlockNumber;
type Value = u64;

type OnNewAccount = ();

type Event = TestEvent;
}

Expand Down
4 changes: 2 additions & 2 deletions core/parent/src/mvp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rstd::marker::PhantomData;

/// plasm
use merkle::{ProofTrait, MerkleProof};
use utxo::mvp::{Transaction};
use utxo::mvp::Transaction;


/// Utxo is H: Hash, V: ChildValue, K: AccountId, B: BlockNumber;
Expand Down Expand Up @@ -631,7 +631,7 @@ mod tests {
assert_eq!(2, Parent::total_deposit()); // 1(deposit) + 1(fee)

// check unfinalize exits
assert_eq!(vec!{exit_id.clone()}, Parent::unfinalized_exits());
assert_eq!(vec! {exit_id.clone()}, Parent::unfinalized_exits());

// error finalized before expired.
assert_ne!(Ok(()), Parent::exit_finalize(Origin::signed(1), exit_id));
Expand Down
9 changes: 8 additions & 1 deletion core/utxo/src/mvp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;
use serde_derive::{Serialize, Deserialize};

use support::{decl_module, decl_storage, decl_event, StorageValue, StorageMap, Parameter, dispatch::Result};
use system::ensure_signed;
use system::{ensure_signed, OnNewAccount};
use sr_primitives::traits::{Member, MaybeSerializeDebug, Hash, SimpleArithmetic, Verify, As, Zero, CheckedAdd, CheckedSub};

use parity_codec::{Encode, Decode, Codec};
Expand Down Expand Up @@ -76,6 +76,8 @@ pub trait Trait: system::Trait {
type TimeLock: Parameter + Zero + Default;
type Value: Parameter + Member + SimpleArithmetic + Codec + Default + Copy + As<usize> + As<u64> + MaybeSerializeDebug;

type OnNewAccount: OnNewAccount<Self::AccountId>;

/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
}
Expand Down Expand Up @@ -175,6 +177,9 @@ impl<T: Trait> WritableUtxoTrait<SignedTx<T>, T::AccountId, (T::Hash, u32)> for
let identify = (hash.clone(), i as u32);
<UnspentOutputs<T>>::insert(identify.clone(), out.clone());
for key in out.keys.iter() {
if !<UnspentOutputsFinder<T>>::exists(key) { // if unexits outputs finder, create accounts.
T::OnNewAccount::on_new_account(key);
}
<UnspentOutputsFinder<T>>::mutate(key, |v| {
match v.as_mut() {
Some(vc) => vc.push(identify.clone()),
Expand Down Expand Up @@ -452,6 +457,8 @@ mod tests {
type TimeLock = Self::BlockNumber;
type Value = u64;

type OnNewAccount = ();

type Event = ();
}

Expand Down
2 changes: 2 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ impl utxo_mvp::Trait for Runtime {
type Value = u128;
type TimeLock = BlockNumber;

type OnNewAccount = Indices;

type Event = Event;
}

Expand Down
Binary file not shown.

0 comments on commit c2f5444

Please sign in to comment.