mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Create a dedicated crate for the extension
This commit is contained in:
16
contracts/extension/Cargo.toml
Normal file
16
contracts/extension/Cargo.toml
Normal file
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "serai-extension"
|
||||
version = "0.1.0"
|
||||
description = "An ink! extension for exposing Serai to ink"
|
||||
license = "AGPL-3.0-only"
|
||||
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
ink_env = { version = "3", default-features = false }
|
||||
ink_lang = { version = "3", default-features = false }
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = ["ink_env/std"]
|
||||
ink-as-dependency = []
|
||||
35
contracts/extension/src/lib.rs
Normal file
35
contracts/extension/src/lib.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use ink_lang as ink;
|
||||
use ink_env::{Environment, DefaultEnvironment, AccountId};
|
||||
|
||||
#[ink::chain_extension]
|
||||
pub trait SeraiExtension {
|
||||
type ErrorCode = ();
|
||||
|
||||
/// Returns the amount of active validators on the current chain.
|
||||
#[ink(extension = 0, handle_status = false, returns_result = false)]
|
||||
fn active_validators_len() -> u16;
|
||||
|
||||
/// Returns the ID for the current validator set for the current chain.
|
||||
// TODO: Decide if this should be an increasing unsigned integer instead of a hash.
|
||||
#[ink(extension = 1, handle_status = false, returns_result = false)]
|
||||
fn validator_set_id() -> [u8; 32];
|
||||
|
||||
/// Returns if the specified account is an active validator for the current chain.
|
||||
#[ink(extension = 2, handle_status = false, returns_result = false)]
|
||||
fn is_active_validator(account: &AccountId) -> bool;
|
||||
}
|
||||
|
||||
pub struct SeraiEnvironment;
|
||||
impl Environment for SeraiEnvironment {
|
||||
const MAX_EVENT_TOPICS: usize = <DefaultEnvironment as Environment>::MAX_EVENT_TOPICS;
|
||||
|
||||
type AccountId = <DefaultEnvironment as Environment>::AccountId;
|
||||
type Balance = <DefaultEnvironment as Environment>::Balance;
|
||||
type Hash = <DefaultEnvironment as Environment>::Hash;
|
||||
type BlockNumber = <DefaultEnvironment as Environment>::BlockNumber;
|
||||
type Timestamp = <DefaultEnvironment as Environment>::Timestamp;
|
||||
|
||||
type ChainExtension = SeraiExtension;
|
||||
}
|
||||
Reference in New Issue
Block a user