diff --git a/core/child/src/mvp.rs b/core/child/src/mvp.rs index 9ff1305010..37a28343b3 100644 --- a/core/child/src/mvp.rs +++ b/core/child/src/mvp.rs @@ -193,6 +193,8 @@ mod tests { type TimeLock = Self::BlockNumber; type Value = u64; + type OnNewAccount = (); + type Event = TestEvent; } diff --git a/core/parent/src/mvp.rs b/core/parent/src/mvp.rs index 349b15d540..563677fa28 100644 --- a/core/parent/src/mvp.rs +++ b/core/parent/src/mvp.rs @@ -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; @@ -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)); diff --git a/core/utxo/src/mvp.rs b/core/utxo/src/mvp.rs index 59dcdf0857..9510557229 100644 --- a/core/utxo/src/mvp.rs +++ b/core/utxo/src/mvp.rs @@ -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}; @@ -76,6 +76,8 @@ pub trait Trait: system::Trait { type TimeLock: Parameter + Zero + Default; type Value: Parameter + Member + SimpleArithmetic + Codec + Default + Copy + As + As + MaybeSerializeDebug; + type OnNewAccount: OnNewAccount; + /// The overarching event type. type Event: From> + Into<::Event>; } @@ -175,6 +177,9 @@ impl WritableUtxoTrait, T::AccountId, (T::Hash, u32)> for let identify = (hash.clone(), i as u32); >::insert(identify.clone(), out.clone()); for key in out.keys.iter() { + if !>::exists(key) { // if unexits outputs finder, create accounts. + T::OnNewAccount::on_new_account(key); + } >::mutate(key, |v| { match v.as_mut() { Some(vc) => vc.push(identify.clone()), @@ -452,6 +457,8 @@ mod tests { type TimeLock = Self::BlockNumber; type Value = u64; + type OnNewAccount = (); + type Event = (); } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 89de2c0f07..51792437a9 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -195,6 +195,8 @@ impl utxo_mvp::Trait for Runtime { type Value = u128; type TimeLock = BlockNumber; + type OnNewAccount = Indices; + type Event = Event; } diff --git a/runtime/wasm/target/wasm32-unknown-unknown/release/plasm_runtime_wasm.compact.wasm b/runtime/wasm/target/wasm32-unknown-unknown/release/plasm_runtime_wasm.compact.wasm index 1da732d902..23536bede3 100644 Binary files a/runtime/wasm/target/wasm32-unknown-unknown/release/plasm_runtime_wasm.compact.wasm and b/runtime/wasm/target/wasm32-unknown-unknown/release/plasm_runtime_wasm.compact.wasm differ