Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ p2p_secret
# Python
__pycache__/
*.py[cod]

# ink!
contracts/addresses.json
10 changes: 4 additions & 6 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ source contracts/env/dev && ./contracts/scripts/deploy.sh

Specifically it will:

- Deploy the token contracts.
- Deploy the game contracts.
- Set access control.
- Transfer token balances to the game contracts.
- Whitelist accounts for playing the games.
- Deploy the contracts.
- Set access control on them.
- Make neccessary token transfers.

Third `test.sh` script plays the game from two well-known dev addresses.

Expand All @@ -86,5 +84,5 @@ Third `test.sh` script plays the game from two well-known dev addresses.

It will:

- Interact with the games from the whitelisted accounts.
- Interact with the games from known accounts.
- Wait past the game deadline, trigger the game end and reward distribution.
18 changes: 9 additions & 9 deletions contracts/access_control/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod access_control {
};
use scale::{Decode, Encode};

// address placeholder, set in the bytecode
// address placeholder, to be set in the bytecode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: privileges on line 90.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 43 as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I found just one typo, could you comment on the line?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pub priviledges: Mapping<(AccountId, Role), ()>,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And later uses. I do not see the second typo as well, so must have mixed up files. Will find it in a sec.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It crops up a couple of times in 3 files contracts/button/lib.rs (

/// Returned if a call is made from an account with missing access control priviledges
), contracts/access_control/lib.rs (these are the ones you have probably already fixed) and contracts/scripts/deploy.sh (in comments).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, should be fixed now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deploy.sh still has a couple in comments, upper case. Other than that, fixed.

// 4465614444656144446561444465614444656144446561444465614444656144 => 5DcPEG9AQ4Y9Lo9C5WXuKJDDawens77jWxZ6zGChnm8y8FUX
pub const ACCESS_CONTROL_PUBKEY: [u8; 32] = *b"DeaDDeaDDeaDDeaDDeaDDeaDDeaDDeaD";
pub const HAS_ROLE_SELECTOR: [u8; 4] = [0, 0, 0, 3];
Expand All @@ -40,7 +40,7 @@ mod access_control {
#[derive(SpreadAllocate)]
pub struct AccessControl {
/// Stores a de-facto hashset of user accounts and their roles
pub priviledges: Mapping<(AccountId, Role), ()>,
pub privileges: Mapping<(AccountId, Role), ()>,
}

#[ink(event)]
Expand Down Expand Up @@ -87,12 +87,12 @@ mod access_control {

/// Initializes the contract.
///
/// caller is granted admin and owner piviledges
/// caller is granted admin and owner privileges
fn new_init(&mut self) {
let caller = Self::env().caller();
let this = Self::env().account_id();
self.priviledges.insert((caller, Role::Admin(this)), &());
self.priviledges.insert((caller, Role::Owner(this)), &());
self.privileges.insert((caller, Role::Admin(this)), &());
self.privileges.insert((caller, Role::Owner(this)), &());
}

/// Gives a role to an account
Expand All @@ -101,11 +101,11 @@ mod access_control {
#[ink(message, selector = 1)]
pub fn grant_role(&mut self, account: AccountId, role: Role) -> Result<()> {
let key = (account, role);
if !self.priviledges.contains(key) {
if !self.privileges.contains(key) {
let caller = self.env().caller();
let this = self.env().account_id();
self.check_role(caller, Role::Admin(this))?;
self.priviledges.insert(key, &());
self.privileges.insert(key, &());

let event = Event::RoleGranted(RoleGranted {
by: caller,
Expand All @@ -126,7 +126,7 @@ mod access_control {
let caller = self.env().caller();
let this = self.env().account_id();
self.check_role(caller, Role::Admin(this))?;
self.priviledges.remove((account, role));
self.privileges.remove((account, role));

let event = Event::RoleRevoked(RoleRevoked {
by: caller,
Expand All @@ -141,7 +141,7 @@ mod access_control {
/// Returns true if account has a role
#[ink(message, selector = 3)]
pub fn has_role(&self, account: AccountId, role: Role) -> bool {
self.priviledges.contains((account, role))
self.privileges.contains((account, role))
}

/// Terminates the contract.
Expand Down
94 changes: 86 additions & 8 deletions contracts/back_to_the_future/Cargo.lock

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

4 changes: 2 additions & 2 deletions contracts/back_to_the_future/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ scale = { package = "parity-scale-codec", version = "3", default-features = fals
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }

button = { path = "../button", default-features = false }
game_token = { path = "../game_token", default-features = false, features = ["ink-as-dependency"] }
access_control = { path = "../access_control", default-features = false, features = ["ink-as-dependency"] }

[lib]
Expand All @@ -32,9 +31,10 @@ crate-type = [
[features]
default = ["std"]
std = [
"access_control/std",
"button/std",
"game_token/std",
"ink_env/std",
"ink_lang/std",
"ink_lang_codegen/std",
"ink_metadata/std",
"ink_prelude/std",
Expand Down
Loading