@@ -212,6 +212,10 @@ decl_event!(
212
212
SubmissionReceived ( FeedId , RoundId , Value , AccountId ) ,
213
213
/// The answer for the round was updated. \[feed_id, round_id, new_answer, updated_at_block\]
214
214
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 ) ,
215
219
}
216
220
) ;
217
221
@@ -254,6 +258,10 @@ decl_error! {
254
258
/// The round initiation delay cannot be equal to or greater
255
259
/// than the number of oracles.
256
260
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 ,
257
265
}
258
266
}
259
267
@@ -461,6 +469,44 @@ decl_module! {
461
469
462
470
Ok ( ( ) . into( ) )
463
471
}
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
+ }
464
510
}
465
511
}
466
512
0 commit comments