Skip to content
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
6 changes: 6 additions & 0 deletions substrate/client/serai/src/genesis_liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ impl State<'_> {
pub async fn genesis_completed(&self) -> Result<bool, RpcError> {
self.call::<bool>("genesis-liquidity/completed", "").await
}

/// Returns the time economic security is achieved first time for all networks.
/// Returns `0` if it hasn't happen yet.
pub async fn economic_security_time(&self) -> Result<u64, RpcError> {
self.call::<u64>("genesis-liquidity/economic-security", "").await
}
}
6 changes: 6 additions & 0 deletions substrate/genesis-liquidity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ mod pallet {
pub fn completed() -> bool {
Oraclized::<T>::get().is_some()
}

/// Returns the time economic security was achieved, represented in milliseconds since the epoch.
/// Returns `0` if it isn't achieved yet.
pub fn economic_security_time() -> u64 {
EconomicSecurityAchieved::<T>::get().unwrap_or(0)
}
}

#[pallet::call]
Expand Down
14 changes: 14 additions & 0 deletions substrate/node/src/rpc/genesis_liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,19 @@ pub(crate) fn module(
},
)?;

module.register_method(
"genesis-liquidity/economic-security",
|params, client, _ext| -> Result<_, Error> {
let Some(block_hash) = block_hash(client, &params)? else {
Err(Error::InvalidStateReference)?
};

let Ok(time) = client.runtime_api().economic_security_time(block_hash) else {
Err(Error::Internal("couldn't fetch genesis period status"))?
};
Ok(time)
},
)?;

Ok(module)
}
4 changes: 4 additions & 0 deletions substrate/runtime/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,9 @@ sp_api::decl_runtime_apis! {

/// Next nonce to be used for this account.
fn account_nonce(of: SeraiAddress) -> u32;

/// Returns the time economic security was achieved, represented in milliseconds since the epoch.
/// Returns `0` if it isn't achieved yet.
fn economic_security_time() -> u64;
}
}
4 changes: 4 additions & 0 deletions substrate/runtime/src/std_runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,9 @@ sp_api::impl_runtime_apis! {
fn account_nonce(of: SeraiAddress) -> u32 {
unimplemented!("runtime is only implemented when WASM")
}

fn economic_security_time() -> u64 {
unimplemented!("runtime is only implemented when WASM")
}
}
}
4 changes: 4 additions & 0 deletions substrate/runtime/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ sp_api::impl_runtime_apis! {
fn account_nonce(of: SeraiAddress) -> u32 {
Core::next_nonce(&of)
}

fn economic_security_time() -> u64 {
GenesisLiquidity::economic_security_time()
}
}
}

Expand Down
Loading