diff --git a/Cargo.lock b/Cargo.lock index ca00eecf..2681d850 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1002,9 +1002,9 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "1.2.2" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" +checksum = "83827793632c72fa4f73c2edb31e7a997527dd8ffe7077344621fc62c5478157" dependencies = [ "cache-padded", ] @@ -1268,9 +1268,9 @@ dependencies = [ [[package]] name = "crypto-common" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ccfd8c0ee4cce11e45b3fd6f9d5e69e0cc62912aa6a0cb1bf4617b0eba5a12f" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array 0.14.5", "typenum", @@ -1820,7 +1820,7 @@ dependencies = [ [[package]] name = "ethers" version = "0.13.0" -source = "git+https://github.com/gakonst/ethers-rs#ba00f549dd05e72fed7f00703f29752324645172" +source = "git+https://github.com/gakonst/ethers-rs#13ce18fd3b0f995183ce5cc14a85133e28f994dc" dependencies = [ "ethers-addressbook", "ethers-contract", @@ -1835,7 +1835,7 @@ dependencies = [ [[package]] name = "ethers-addressbook" version = "0.13.0" -source = "git+https://github.com/gakonst/ethers-rs#ba00f549dd05e72fed7f00703f29752324645172" +source = "git+https://github.com/gakonst/ethers-rs#13ce18fd3b0f995183ce5cc14a85133e28f994dc" dependencies = [ "ethers-core", "once_cell", @@ -1846,7 +1846,7 @@ dependencies = [ [[package]] name = "ethers-contract" version = "0.13.0" -source = "git+https://github.com/gakonst/ethers-rs#ba00f549dd05e72fed7f00703f29752324645172" +source = "git+https://github.com/gakonst/ethers-rs#13ce18fd3b0f995183ce5cc14a85133e28f994dc" dependencies = [ "ethers-contract-abigen", "ethers-contract-derive", @@ -1864,7 +1864,7 @@ dependencies = [ [[package]] name = "ethers-contract-abigen" version = "0.13.0" -source = "git+https://github.com/gakonst/ethers-rs#ba00f549dd05e72fed7f00703f29752324645172" +source = "git+https://github.com/gakonst/ethers-rs#13ce18fd3b0f995183ce5cc14a85133e28f994dc" dependencies = [ "Inflector", "cfg-if", @@ -1886,7 +1886,7 @@ dependencies = [ [[package]] name = "ethers-contract-derive" version = "0.13.0" -source = "git+https://github.com/gakonst/ethers-rs#ba00f549dd05e72fed7f00703f29752324645172" +source = "git+https://github.com/gakonst/ethers-rs#13ce18fd3b0f995183ce5cc14a85133e28f994dc" dependencies = [ "ethers-contract-abigen", "ethers-core", @@ -1900,7 +1900,7 @@ dependencies = [ [[package]] name = "ethers-core" version = "0.13.0" -source = "git+https://github.com/gakonst/ethers-rs#ba00f549dd05e72fed7f00703f29752324645172" +source = "git+https://github.com/gakonst/ethers-rs#13ce18fd3b0f995183ce5cc14a85133e28f994dc" dependencies = [ "arrayvec 0.7.2", "bytes", @@ -1931,7 +1931,7 @@ dependencies = [ [[package]] name = "ethers-etherscan" version = "0.13.0" -source = "git+https://github.com/gakonst/ethers-rs#ba00f549dd05e72fed7f00703f29752324645172" +source = "git+https://github.com/gakonst/ethers-rs#13ce18fd3b0f995183ce5cc14a85133e28f994dc" dependencies = [ "ethers-core", "getrandom 0.2.7", @@ -1947,7 +1947,7 @@ dependencies = [ [[package]] name = "ethers-middleware" version = "0.13.0" -source = "git+https://github.com/gakonst/ethers-rs#ba00f549dd05e72fed7f00703f29752324645172" +source = "git+https://github.com/gakonst/ethers-rs#13ce18fd3b0f995183ce5cc14a85133e28f994dc" dependencies = [ "async-trait", "ethers-contract", @@ -1971,7 +1971,7 @@ dependencies = [ [[package]] name = "ethers-providers" version = "0.13.0" -source = "git+https://github.com/gakonst/ethers-rs#ba00f549dd05e72fed7f00703f29752324645172" +source = "git+https://github.com/gakonst/ethers-rs#13ce18fd3b0f995183ce5cc14a85133e28f994dc" dependencies = [ "async-trait", "auto_impl", @@ -2005,7 +2005,7 @@ dependencies = [ [[package]] name = "ethers-signers" version = "0.13.0" -source = "git+https://github.com/gakonst/ethers-rs#ba00f549dd05e72fed7f00703f29752324645172" +source = "git+https://github.com/gakonst/ethers-rs#13ce18fd3b0f995183ce5cc14a85133e28f994dc" dependencies = [ "async-trait", "coins-bip32", @@ -2022,7 +2022,7 @@ dependencies = [ [[package]] name = "ethers-solc" version = "0.13.0" -source = "git+https://github.com/gakonst/ethers-rs#ba00f549dd05e72fed7f00703f29752324645172" +source = "git+https://github.com/gakonst/ethers-rs#13ce18fd3b0f995183ce5cc14a85133e28f994dc" dependencies = [ "cfg-if", "colored", @@ -2716,9 +2716,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.26.1" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" dependencies = [ "fallible-iterator", "indexmap", @@ -2827,9 +2827,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "607c8a29735385251a339424dd462993c0fed8fa09d378f259377df08c126022" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ "ahash", ] @@ -3127,7 +3127,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", - "hashbrown 0.12.2", + "hashbrown 0.12.3", "serde", ] @@ -4485,7 +4485,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6566c70c1016f525ced45d7b7f97730a2bafb037c788211d0c186ef5b2189f0a" dependencies = [ "hash-db", - "hashbrown 0.12.2", + "hashbrown 0.12.3", "parity-util-mem", ] @@ -4713,19 +4713,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" -[[package]] -name = "multisig-serai" -version = "0.1.0" -dependencies = [ - "ink_env", - "ink_lang", - "ink_metadata", - "ink_primitives", - "ink_storage", - "parity-scale-codec", - "scale-info", -] - [[package]] name = "multistream-select" version = "0.11.0" @@ -4870,9 +4857,9 @@ checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" [[package]] name = "nix" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f17df307904acd05aa8e32e97bb20f2a0df1728bbc2d771ae8f9a90463441e9" +checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" dependencies = [ "bitflags", "cfg-if", @@ -5085,9 +5072,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.1.0" +version = "6.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" +checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" [[package]] name = "owning_ref" @@ -5337,7 +5324,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c32561d248d352148124f036cac253a644685a21dc9fea383eb4907d7bd35a8f" dependencies = [ "cfg-if", - "hashbrown 0.12.2", + "hashbrown 0.12.3", "impl-trait-for-tuples", "parity-util-mem-derive", "parking_lot 0.12.1", @@ -7520,6 +7507,28 @@ dependencies = [ "tokio", ] +[[package]] +name = "serai-extension" +version = "0.1.0" +dependencies = [ + "ink_env", + "ink_lang", +] + +[[package]] +name = "serai-multisig" +version = "0.1.0" +dependencies = [ + "ink_env", + "ink_lang", + "ink_metadata", + "ink_primitives", + "ink_storage", + "parity-scale-codec", + "scale-info", + "serai-extension", +] + [[package]] name = "serai-node" version = "0.1.0" @@ -8982,19 +8991,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "token-serai" -version = "0.1.0" -dependencies = [ - "ink_env", - "ink_lang", - "ink_metadata", - "ink_primitives", - "ink_storage", - "parity-scale-codec", - "scale-info", -] - [[package]] name = "tokio" version = "1.20.0" @@ -9185,7 +9181,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d32d034c0d3db64b43c31de38e945f15b40cd4ca6d2dcfc26d4798ce8de4ab83" dependencies = [ "hash-db", - "hashbrown 0.12.2", + "hashbrown 0.12.3", "log", "rustc-hex", "smallvec", diff --git a/Cargo.toml b/Cargo.toml index 52fb9cfb..bca305b2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ members = [ "substrate/consensus", "substrate/node", + "contracts/extension", "contracts/multisig", ] diff --git a/contracts/extension/Cargo.toml b/contracts/extension/Cargo.toml new file mode 100644 index 00000000..f0f0c23d --- /dev/null +++ b/contracts/extension/Cargo.toml @@ -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 "] +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 = [] diff --git a/contracts/extension/src/lib.rs b/contracts/extension/src/lib.rs new file mode 100644 index 00000000..a29cb754 --- /dev/null +++ b/contracts/extension/src/lib.rs @@ -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 = ::MAX_EVENT_TOPICS; + + type AccountId = ::AccountId; + type Balance = ::Balance; + type Hash = ::Hash; + type BlockNumber = ::BlockNumber; + type Timestamp = ::Timestamp; + + type ChainExtension = SeraiExtension; +} diff --git a/contracts/multisig/Cargo.toml b/contracts/multisig/Cargo.toml index 488a045d..3b74ad5a 100644 --- a/contracts/multisig/Cargo.toml +++ b/contracts/multisig/Cargo.toml @@ -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 "] 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 = [] diff --git a/contracts/multisig/lib.rs b/contracts/multisig/lib.rs index f0da67f6..9ba129c3 100644 --- a/contracts/multisig/lib.rs +++ b/contracts/multisig/lib.rs @@ -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 = ::MAX_EVENT_TOPICS; - - type AccountId = ::AccountId; - type Balance = ::Balance; - type Hash = ::Hash; - type BlockNumber = ::BlockNumber; - type Timestamp = ::Timestamp; - - type ChainExtension = ValidatorsExtension; -} - -#[ink::contract(env = crate::ValidatorEnvironment)] +#[ink::contract(env = serai_extension::SeraiEnvironment)] mod multisig { use scale::Encode;