Skip to content

Commit

Permalink
guess the number (#1608)
Browse files Browse the repository at this point in the history
* init new pallet. C&P

* initial round timing logic and tests

* new randomness trait and crate (from raffle PR) to use in pallets and runtime

* build works

* add cli and PublicGetter

* broken approach with own trait. trying to just extend traits now

* empty on_initialize and on_finalize builds now

* on_initialize executes on_timestamp_set which starts a new round and draws a random lucky number which can be queried by cli

* cant make BoundedVec work reasonably. will use vec

* refactored to Vec

* fix recursion loop

* add unit tests

* limit number of guess attempts

* flow works with cli

* add total issuance getter

* nested guess-the-number subcommand and other cosmetics

* fmt

* better error logging

* remove set-balance command which was deprecated long ago

* cargo fix

* fmt

* clippy

* taplo fmt

* fix enclave test

* bump lockfile

* review comments fixed

* re-inject set-balance TC but feature gate for test

* fix cargo test

* make CI scripts use shielding via vault instead of set-balance

* restore enum order for TC to make cargo test work again

* fmt

* shuffle TC enum

* fmt

* pin TC,TG,PG enum encoding for upgrade compatibility

* explicit enum pin type

* use Charlie instead of Alice for sidechain demo to avoid genesis funds change

* fix clippy

* tiny alignment

* fix demo script bug

* fix some more

* align CI tests and use non-prefunded Charlie too

* charge fees to guess
  • Loading branch information
brenzi authored Oct 5, 2024
1 parent 1b60092 commit 9bab2c3
Show file tree
Hide file tree
Showing 56 changed files with 1,658 additions and 132 deletions.
31 changes: 31 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2799,9 +2799,11 @@ dependencies = [
"frame-executive",
"frame-support",
"frame-system",
"itp-randomness",
"itp-sgx-runtime-primitives",
"pallet-balances",
"pallet-evm",
"pallet-guess-the-number",
"pallet-parentchain",
"pallet-sudo",
"pallet-timestamp",
Expand Down Expand Up @@ -2837,6 +2839,7 @@ dependencies = [
"pallet-balances",
"pallet-parentchain",
"pallet-sudo",
"pallet-timestamp",
"parity-scale-codec",
"rlp",
"sgx_tstd",
Expand Down Expand Up @@ -3361,6 +3364,13 @@ dependencies = [
"thiserror 1.0.9",
]

[[package]]
name = "itp-randomness"
version = "0.1.0"
dependencies = [
"sgx_rand",
]

[[package]]
name = "itp-rpc"
version = "0.9.0"
Expand Down Expand Up @@ -5154,6 +5164,27 @@ dependencies = [
"sp-std",
]

[[package]]
name = "pallet-guess-the-number"
version = "0.11.0"
dependencies = [
"env_logger 0.9.3",
"frame-support",
"frame-system",
"itp-randomness",
"log 0.4.20",
"pallet-balances",
"pallet-timestamp",
"parity-scale-codec",
"scale-info",
"serde 1.0.193",
"sp-core",
"sp-io 7.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42)",
"sp-keyring",
"sp-runtime",
"sp-std",
]

[[package]]
name = "pallet-parentchain"
version = "0.11.0"
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ members = [
"app-libs/oracle",
"app-libs/parentchain-interface",
"app-libs/sgx-runtime",
"app-libs/sgx-runtime/pallets/parentchain",
"app-libs/sgx-runtime/pallets/guess-the-number",
"app-libs/stf",
"cli",
"core/direct-rpc-server",
Expand Down Expand Up @@ -37,6 +39,7 @@ members = [
"core-primitives/ocall-api",
"core-primitives/pallet-storage",
"core-primitives/primitives-cache",
"core-primitives/randomness",
"core-primitives/rpc",
"core-primitives/settings",
"core-primitives/sgx/crypto",
Expand Down
6 changes: 5 additions & 1 deletion app-libs/sgx-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features =
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }

# local dependencies
itp-randomness = { path = "../../core-primitives/randomness", default-features = false }
itp-sgx-runtime-primitives = { path = "../../core-primitives/sgx-runtime-primitives", default-features = false }
pallet-guess-the-number = { default-features = false, path = "pallets/guess-the-number" }
pallet-parentchain = { default-features = false, path = "pallets/parentchain" }

# Substrate dependencies
Expand All @@ -36,7 +38,9 @@ pallet-evm = { default-features = false, optional = true, git = "https://github.
default = ["std"]
# Compile the sgx-runtime with evm support.
evm = ["pallet-evm"]

sgx = [
"itp-randomness/sgx",
]
std = [
"codec/std",
"scale-info/std",
Expand Down
50 changes: 50 additions & 0 deletions app-libs/sgx-runtime/pallets/guess-the-number/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[package]
name = "pallet-guess-the-number"
description = "a little game that only works with confidentiality"
version = "0.11.0"
authors = ["Integritee AG <[email protected]>"]
homepage = "https://integritee.network/"
repository = "https://github.com/integritee-network/pallets/"
license = "Apache-2.0"
edition = "2021"

[dependencies]
codec = { version = "3.0.0", default-features = false, features = ["derive"], package = "parity-scale-codec" }
log = { version = "0.4.14", default-features = false }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
serde = { version = "1.0.13", features = ["derive"], optional = true }

# substrate dependencies
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }

itp-randomness = { path = "../../../../core-primitives/randomness" }

[dev-dependencies]
env_logger = "0.9.0"
sp-keyring = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }

[features]
default = ["std"]
std = [
"codec/std",
"log/std",
"scale-info/std",
"serde",
# substrate dependencies
"frame-support/std",
"frame-system/std",
"pallet-balances/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
]

try-runtime = ["frame-support/try-runtime"]
Loading

0 comments on commit 9bab2c3

Please sign in to comment.