Skip to content

Commit

Permalink
chore: Renamee AccountRoles::None to Unregistered (#4208)
Browse files Browse the repository at this point in the history
  • Loading branch information
syan095 authored Nov 13, 2023
1 parent 1de7247 commit fc200c1
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions api/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl StateChainApi {
scope,
&state_chain_settings.ws_endpoint,
&state_chain_settings.signing_key_file,
AccountRole::None,
AccountRole::Unregistered,
false,
None,
)
Expand Down Expand Up @@ -192,7 +192,7 @@ pub trait OperatorApi: SignedExtrinsicApi + RotateSessionKeysApi + AuctionPhaseA
RuntimeCall::from(pallet_cf_swapping::Call::register_as_broker {}),
AccountRole::LiquidityProvider =>
RuntimeCall::from(pallet_cf_lp::Call::register_lp_account {}),
AccountRole::None => bail!("Cannot register account role None"),
AccountRole::Unregistered => bail!("Cannot register account role None"),
};

let (tx_hash, ..) = self
Expand Down
2 changes: 1 addition & 1 deletion api/lib/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl QueryApi {
scope,
&state_chain_settings.ws_endpoint,
&state_chain_settings.signing_key_file,
AccountRole::None,
AccountRole::Unregistered,
false,
None,
)
Expand Down
6 changes: 4 additions & 2 deletions engine/src/state_chain_observer/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,11 @@ impl SignedExtrinsicClientBuilderTrait for SignedExtrinsicClientBuilder {
.await?
{
Some(role) =>
if self.required_role == AccountRole::None || self.required_role == role {
if self.required_role == AccountRole::Unregistered ||
self.required_role == role
{
break
} else if self.wait_for_required_role && role == AccountRole::None {
} else if self.wait_for_required_role && role == AccountRole::Unregistered {
warn!("Your Chainflip account {} does not have an assigned account role. WAITING for the account role to be set to '{:?}' at block: {block_hash}", signer.account_id, self.required_role);
} else {
bail!("Your Chainflip account {} has the wrong account role '{role:?}'. The '{:?}' account role is required", signer.account_id, self.required_role);
Expand Down
2 changes: 1 addition & 1 deletion engine/src/state_chain_observer/sc_observer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ async fn run_the_sc_observer() {
scope,
&settings.state_chain.ws_endpoint,
&settings.state_chain.signing_key_file,
AccountRole::None,
AccountRole::Unregistered,
false,
None,
)
Expand Down
2 changes: 1 addition & 1 deletion engine/src/witness/eth/key_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ mod tests {
scope,
"ws://localhost:9944",
PathBuf::from_str("/some/sc/key/bashful-key").unwrap().as_path(),
AccountRole::None,
AccountRole::Unregistered,
false,
None,
)
Expand Down
14 changes: 8 additions & 6 deletions state-chain/custom-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl TryFrom<(Asset, Option<ForeignChain>)> for RpcAsset {
#[derive(Serialize, Deserialize)]
#[serde(tag = "role", rename_all = "snake_case")]
pub enum RpcAccountInfo {
None {
Unregistered {
flip_balance: NumberOrHex,
},
Broker {
Expand Down Expand Up @@ -120,8 +120,8 @@ pub enum RpcAccountInfo {
}

impl RpcAccountInfo {
fn none(balance: u128) -> Self {
Self::None { flip_balance: balance.into() }
fn unregistered(balance: u128) -> Self {
Self::Unregistered { flip_balance: balance.into() }
}

fn broker(balance: u128) -> Self {
Expand Down Expand Up @@ -644,9 +644,9 @@ where
match api
.cf_account_role(hash, account_id.clone())
.map_err(to_rpc_error)?
.unwrap_or(AccountRole::None)
.unwrap_or(AccountRole::Unregistered)
{
AccountRole::None => RpcAccountInfo::none(balance),
AccountRole::Unregistered => RpcAccountInfo::unregistered(balance),
AccountRole::Broker => RpcAccountInfo::broker(balance),
AccountRole::LiquidityProvider => {
let info = api
Expand Down Expand Up @@ -1158,7 +1158,9 @@ mod test {

#[test]
fn test_no_account_serialization() {
insta::assert_display_snapshot!(serde_json::to_value(RpcAccountInfo::none(0)).unwrap());
insta::assert_display_snapshot!(
serde_json::to_value(RpcAccountInfo::unregistered(0)).unwrap()
);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: state-chain/custom-rpc/src/lib.rs
expression: "serde_json::to_value(RpcAccountInfo::none(0)).unwrap()"
expression: "serde_json::to_value(RpcAccountInfo::unregistered(0)).unwrap()"
---
{"flip_balance":"0x0","role":"none"}
{"flip_balance":"0x0","role":"unregistered"}
4 changes: 2 additions & 2 deletions state-chain/pallets/cf-account-roles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<T: Config> Pallet<T> {
) -> DispatchResult {
AccountRoles::<T>::try_mutate(account_id, |old_account_role| {
match old_account_role.replace(account_role) {
Some(AccountRole::None) => {
Some(AccountRole::Unregistered) => {
Self::deposit_event(Event::AccountRoleRegistered {
account_id: account_id.clone(),
role: account_role,
Expand Down Expand Up @@ -174,7 +174,7 @@ impl<T: Config> AccountRoleRegistry<T> for Pallet<T> {
role: AccountRole,
) -> Result<T::AccountId, BadOrigin> {
match role {
AccountRole::None => Err(BadOrigin),
AccountRole::Unregistered => Err(BadOrigin),
AccountRole::Validator => ensure_validator::<T>(origin),
AccountRole::LiquidityProvider => ensure_liquidity_provider::<T>(origin),
AccountRole::Broker => ensure_broker::<T>(origin),
Expand Down
2 changes: 1 addition & 1 deletion state-chain/pallets/cf-account-roles/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn cannot_register_swapping_roles_if_swapping_disabled() {
assert!(!SwappingEnabled::<Test>::get());

// As if the account is already funded.
AccountRoles::<Test>::insert(ALICE, AccountRole::None);
AccountRoles::<Test>::insert(ALICE, AccountRole::Unregistered);

assert_noop!(Pallet::<Test>::register_as_broker(&ALICE), Error::<Test>::SwappingDisabled);
assert_noop!(
Expand Down
6 changes: 3 additions & 3 deletions state-chain/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::Account
/// the chain.
///
/// Each account can only be associated with a single role, and the role can only be updated from
/// the initial [AccountRole::None] state.
/// the initial [AccountRole::Unregistered] state.
#[derive(
PartialEq,
Eq,
Expand All @@ -128,9 +128,9 @@ pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::Account
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! See AccountRoles storage item !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
pub enum AccountRole {
/// The default account type - indicates a bare account with no special role or permissions.
/// The default account type - account not yet assigned with special role or permissions.
#[default]
None,
Unregistered,
/// Validators are responsible for the maintenance and operation of the Chainflip network. This
/// role is required for any node that wishes to participate in auctions.
Validator,
Expand Down
6 changes: 3 additions & 3 deletions state-chain/traits/src/mocks/account_role_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<T: Config> AccountRoleRegistry<T> for MockAccountRoleRegistry {

fn has_account_role(who: &<T as Config>::AccountId, role: AccountRole) -> bool {
<Self as MockPalletStorage>::get_storage::<_, AccountRole>(ACCOUNT_ROLES, who)
.unwrap_or(AccountRole::None) ==
.unwrap_or(AccountRole::Unregistered) ==
role
}

Expand All @@ -42,7 +42,7 @@ impl<T: Config> AccountRoleRegistry<T> for MockAccountRoleRegistry {
ACCOUNT_ROLES,
account_id.clone(),
)
.unwrap_or(AccountRole::None);
.unwrap_or(AccountRole::Unregistered);
if account_role == role {
Ok(account_id)
} else {
Expand All @@ -58,6 +58,6 @@ impl<T: Config> AccountRoleRegistry<T> for MockAccountRoleRegistry {

#[cfg(feature = "runtime-benchmarks")]
fn get_account_role(_account_id: T::AccountId) -> AccountRole {
AccountRole::None
AccountRole::Unregistered
}
}

0 comments on commit fc200c1

Please sign in to comment.