Skip to content

Commit

Permalink
pallet skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
SkymanOne committed Jul 30, 2022
1 parent da48668 commit 174deac
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 10 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
"node",
"pallets/template",
"pallets/slashing-voting",
"runtime",
]
[profile.release]
Expand Down
4 changes: 2 additions & 2 deletions INSTR.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Substrate Node Template
# Substrate Node

[![Try on playground](https://img.shields.io/badge/Playground-Node_Template-brightgreen?logo=Parity%20Substrate)](https://docs.substrate.io/playground/) [![Matrix](https://img.shields.io/matrix/substrate-technical:matrix.org)](https://matrix.to/#/#substrate-technical:matrix.org)

A fresh FRAME-based [Substrate](https://www.substrate.io/) node, ready for hacking :rocket:
A FRAME-based [Substrate](https://www.substrate.io/) node, ready for hacking :rocket:

## Getting Started

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ Polkadot Blockchain Academy 2022 Cohort Final Exam Project.
- [ ] Staking
- [ ] Slashing

## Resources

[Commit - reveal](https://karl.tech/learning-solidity-part-2-voting/)

Potential idea for anonymous voting
## Potential idea for anonymous voting

1. Author creates a proposal and generates a keypair for this proposal
2. The public key of the proposer is distributed to voters
Expand All @@ -24,8 +20,12 @@ If the proposer reveals results before the timeout -> slashing
If the proposer tries to inside-trade the intermediate vote results -> no solution, might be worth using nominating random voters
to generate keypairs and use multi-sigs to collectively reveal the results

Potential idea for anonymous voting 2
## Potential idea for anonymous voting 2
1. Author publishes a proposal
2. The voters commit their decision
3. Once timeout is out, the voters have some time to reveal their choices
4. If the voters does not reveal their results -> slashing

## Resources

[Commit - reveal](https://karl.tech/learning-solidity-part-2-voting/)
37 changes: 37 additions & 0 deletions pallets/slashing-voting/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "pallet-slashing-voting"
version = "0.1.0"
description = "FRAME pallet template for conducting voting with slashing mechanism."
authors = ["German Nikolishin <[email protected]> "]
edition = "2021"
repository = "https://github.com/SkymanOne/vote-pray-love"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
"derive",
] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
frame-support = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.26"}
frame-system = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.26" }
frame-benchmarking = { default-features = false, version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.26", optional = true }

[dev-dependencies]
sp-core = { default-features = false, version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.26" }
sp-io = { default-features = false, version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.26" }
sp-runtime = { default-features = false, version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.26" }

[features]
default = ["std"]
std = [
"codec/std",
"scale-info/std",
"frame-support/std",
"frame-system/std",
"frame-benchmarking/std",
]

runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
try-runtime = ["frame-support/try-runtime"]
36 changes: 36 additions & 0 deletions pallets/slashing-voting/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;

#[frame_support::pallet]
pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
//use sp_std::vec::Vec; // Step 3.1 will include this in `Cargo.toml`

#[pallet::config] // <-- Step 2. code block will replace this.
pub trait Config: frame_system::Config {
type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
}

#[pallet::event] // <-- Step 3. code block will replace this.
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {}

#[pallet::error] // <-- Step 4. code block will replace this.
pub enum Error<T> {
UndefinedBehaviour,
}

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet<T>(_);

//#[pallet::storage] // <-- Step 5. code block will replace this.

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}

#[pallet::call] // <-- Step 6. code block will replace this.
impl<T: Config> Pallet<T> {}
}
4 changes: 3 additions & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ hex-literal = { version = "0.3.4", optional = true }

# Local Dependencies
pallet-template = { version = "4.0.0-dev", default-features = false, path = "../pallets/template" }
pallet-slashing-voting = { default-features = false, path = "../pallets/slashing-voting" }

[build-dependencies]
substrate-wasm-builder = { version = "5.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.26" }
Expand Down Expand Up @@ -87,7 +88,8 @@ std = [
"sp-version/std",

"pallet-collective/std",
"pallet-identity/std"
"pallet-identity/std",
"pallet-slashing-voting/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
7 changes: 6 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ impl pallet_identity::Config for Runtime {
type WeightInfo = pallet_identity::weights::SubstrateWeight<Runtime>;
}

impl pallet_slashing_voting::Config for Runtime {
type Event = Event;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime where
Expand All @@ -385,7 +389,8 @@ construct_runtime!(
// Include the custom logic from the pallet-template in the runtime.
TemplateModule: pallet_template,
Collective: pallet_collective,
Identity: pallet_identity
Identity: pallet_identity,
QuadraticVoting: pallet_slashing_voting
}
);

Expand Down

0 comments on commit 174deac

Please sign in to comment.