Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Feature/add relayer authority #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

# These are backup files generated by rustfmt
**/*.rs.bk

.idea/
runtime/Cargo.lock
23 changes: 22 additions & 1 deletion runtime/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ decl_storage! {

ParentSupply get(parent_supply): T::TokenBalance;
ChildSupplies get(child_supply_of): map T::ChildChainId => T::TokenBalance;

RelayersIndex: map T::AccountId => u64;
RelayersCount get(all_relayers_count): u64;
// FIXME: jkcomment
// とりあえずT::AccountIdにしているが、
// 今後他の型にする必要があるのでは?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここのRelayersはこのTokenに対するRelayersを管理するだけで、例えばEthereumからみたRelayersのアカウントはEthereum上のコントラクトで管理することになるので、T::AccountIdのままで良いと思います

RelayersArray get(relayer_by_index): map u64 => T::AccountId;
}
}

Expand Down Expand Up @@ -79,14 +86,22 @@ decl_module! {
Ok(())
}

fn set_parent(_origin, parent_supply: u128) -> Result {
fn set_parent(_origin, parent_supply: u128, relayer_account: T::AccountId) -> Result {
let sender = ensure_signed(_origin)?;
ensure!(Self::owner() == sender, "Only owner can set parent chain");
ensure!(Self::is_root(), "This chain already has parent chain");

let supply = <T::TokenBalance as As<u128>>::sa(parent_supply);
let zero = <T::TokenBalance as As<u128>>::sa(0);

let all_relayers_count = Self::all_relayers_count();
let new_all_relayers_count = all_relayers_count.checked_add(1)
.ok_or("Overflow adding a new relayer to total supply")?;

<RelayersArray<T>>::insert(all_relayers_count, relayer_account.clone());
<RelayersCount<T>>::put(new_all_relayers_count);
<RelayersIndex<T>>::insert(relayer_account, all_relayers_count);

<TotalSupply<T>>::put(supply);
<LocalSupply<T>>::put(zero);
<ParentSupply<T>>::put(supply);
Expand Down Expand Up @@ -299,6 +314,12 @@ decl_event!(
}
);

impl<T: Trait> Module<T> {
fn _is_relayer(relayer_account: T::AccountId) -> bool {
<RelayersIndex<T>>::exists(relayer_account)
}
}

/// tests for this module
#[cfg(test)]
mod tests {
Expand Down