Create a dedicated crate for the extension

This commit is contained in:
Luke Parker
2022-07-17 20:56:10 -04:00
parent 5583bf3447
commit 43c4487804
6 changed files with 115 additions and 97 deletions

View File

@@ -1,5 +1,5 @@
[package]
name = "multisig-serai"
name = "serai-multisig"
version = "0.1.0"
description = "An ink! tracker for Serai's current multisig"
license = "AGPL-3.0-only"
@@ -7,31 +7,33 @@ authors = ["Luke Parker <lukeparker5132@gmail.com>"]
edition = "2021"
[dependencies]
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }
ink_primitives = { version = "3", default-features = false }
ink_metadata = { version = "3", default-features = false, features = ["derive"], optional = true }
ink_env = { version = "3", default-features = false }
ink_storage = { version = "3", default-features = false }
ink_lang = { version = "3", default-features = false }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }
serai-extension = { path = "../extension", default-features = false }
[lib]
name = "multisig"
name = "serai_multisig"
path = "lib.rs"
crate-type = [
# Used for normal contract Wasm blobs.
"cdylib",
]
crate-type = ["cdylib"]
[features]
default = ["std"]
std = [
"scale/std",
"scale-info/std",
"ink_primitives/std",
"ink_metadata/std",
"ink_env/std",
"ink_storage/std",
"ink_primitives/std",
"scale/std",
"scale-info/std",
"serai-extension/std",
]
ink-as-dependency = []

View File

@@ -1,40 +1,8 @@
#![cfg_attr(not(feature = "std"), no_std)]
use ink_lang as ink;
use ink_env::{Environment, DefaultEnvironment, AccountId};
#[ink::chain_extension]
pub trait ValidatorsExtension {
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 ValidatorEnvironment;
impl Environment for ValidatorEnvironment {
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 = ValidatorsExtension;
}
#[ink::contract(env = crate::ValidatorEnvironment)]
#[ink::contract(env = serai_extension::SeraiEnvironment)]
mod multisig {
use scale::Encode;