Skip to content

Commit 1a804b8

Browse files
committed
add admin transfer functions
1 parent 930dbcc commit 1a804b8

File tree

2 files changed

+311
-252
lines changed

2 files changed

+311
-252
lines changed

pallet-chainlink-feed/src/lib.rs

+46
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ decl_event!(
212212
SubmissionReceived(FeedId, RoundId, Value, AccountId),
213213
/// The answer for the round was updated. \[feed_id, round_id, new_answer, updated_at_block\]
214214
AnswerUpdated(FeedId, RoundId, Value, BlockNumber),
215+
/// An admin change was requested for the given oracle. \[oracle, admin, pending_admin\]
216+
OracleAdminUpdateRequested(AccountId, AccountId, AccountId),
217+
/// The admin change was executed. \[oracle, new_admin\]
218+
OracleAdminUpdated(AccountId, AccountId),
215219
}
216220
);
217221

@@ -254,6 +258,10 @@ decl_error! {
254258
/// The round initiation delay cannot be equal to or greater
255259
/// than the number of oracles.
256260
DelayExceededTotal,
261+
/// Sender is not admin. Admin privilege can only be transfered by the admin.
262+
NotAdmin,
263+
/// Only the pending admin can accept the transfer.
264+
NotPendingAdmin,
257265
}
258266
}
259267

@@ -461,6 +469,44 @@ decl_module! {
461469

462470
Ok(().into())
463471
}
472+
473+
#[weight = 100]
474+
pub fn transfer_admin(
475+
origin,
476+
oracle: T::AccountId,
477+
new_admin: T::AccountId,
478+
) -> DispatchResultWithPostInfo {
479+
let old_admin = ensure_signed(origin)?;
480+
let mut oracle_meta = Self::oracle(&oracle).ok_or(Error::<T>::OracleNotFound)?;
481+
482+
ensure!(oracle_meta.admin == old_admin, Error::<T>::NotAdmin);
483+
484+
oracle_meta.pending_admin = Some(new_admin.clone());
485+
Oracles::<T>::insert(&oracle, oracle_meta);
486+
487+
Self::deposit_event(RawEvent::OracleAdminUpdateRequested(oracle, old_admin, new_admin));
488+
489+
Ok(().into())
490+
}
491+
492+
#[weight = 100]
493+
pub fn accept_admin(
494+
origin,
495+
oracle: T::AccountId,
496+
) -> DispatchResultWithPostInfo {
497+
let new_admin = ensure_signed(origin)?;
498+
let mut oracle_meta = Self::oracle(&oracle).ok_or(Error::<T>::OracleNotFound)?;
499+
500+
ensure!(oracle_meta.pending_admin.filter(|p| p == &new_admin).is_some(), Error::<T>::NotPendingAdmin);
501+
502+
oracle_meta.pending_admin = None;
503+
oracle_meta.admin = new_admin.clone();
504+
Oracles::<T>::insert(&oracle, oracle_meta);
505+
506+
Self::deposit_event(RawEvent::OracleAdminUpdated(oracle, new_admin));
507+
508+
Ok(().into())
509+
}
464510
}
465511
}
466512

0 commit comments

Comments
 (0)