Skip to content

Commit

Permalink
Added stability_getActiveValidatorList endpoint (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
clostao authored Feb 5, 2024
1 parent c231077 commit 6481f41
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions primitives/stability-rpc-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ sp_api::decl_runtime_apis! {

fn get_validator_list() -> Vec<H160>;

fn get_active_validator_list() -> Vec<H160>;

fn convert_sponsored_transaction(transaction: fp_ethereum::Transaction, meta_trx_sponsor: H160, meta_trx_sponsor_signature: Vec<u8>) -> <Block as BlockT>::Extrinsic;
}
}
10 changes: 10 additions & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,16 @@ impl_runtime_apis! {
}

fn get_validator_list() -> Vec<H160> {
let validators = <pallet_validator_set::Pallet<Runtime>>::approved_validators();
validators
.iter()
.map(|v| <Runtime as pallet_custom_balances::Config>::AccountIdMapping::into_evm_address(v))
.collect()

}


fn get_active_validator_list() -> Vec<H160> {
let validators = <pallet_validator_set::Pallet<Runtime>>::validators();
validators
.iter()
Expand Down
27 changes: 26 additions & 1 deletion stability-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ pub trait StabilityRpcEndpoints<BlockHash> {
#[method(name = "stability_getValidatorList")]
fn get_validator_list(&self, at: Option<BlockHash>) -> RpcResult<StabilityOutput<Vec<H160>>>;

#[method(name = "stability_getActiveValidatorList")]
fn get_active_validator_list(
&self,
at: Option<BlockHash>,
) -> RpcResult<StabilityOutput<Vec<H160>>>;

#[method(name = "stability_sendSponsoredTransaction")]
async fn send_sponsored_transaction(
&self,
Expand Down Expand Up @@ -99,6 +105,21 @@ where
})
}

fn get_active_validator_list(
&self,
at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<StabilityOutput<Vec<H160>>> {
let api = self.client.runtime_api();
let at = at.unwrap_or_else(|| self.client.info().best_hash);
let value = api
.get_active_validator_list(at)
.map_err(runtime_error_into_rpc_err);
Ok(StabilityOutput {
code: 200,
value: value.unwrap(),
})
}

async fn send_sponsored_transaction(
&self,
transaction: Bytes,
Expand Down Expand Up @@ -132,7 +153,11 @@ where
let transaction_hash = transaction.hash();

self.pool
.submit_one(&BlockId::Hash(block_hash), TransactionSource::Local, extrinsic)
.submit_one(
&BlockId::Hash(block_hash),
TransactionSource::Local,
extrinsic,
)
.map_ok(move |_| transaction_hash)
.map_err(|e| {
error::Error::Custom(format!("Unable to submit transaction: {:?}", e).into())
Expand Down

0 comments on commit 6481f41

Please sign in to comment.