Skip to content

Commit

Permalink
Merge pull request #219 from Fair-Squares/propose-tenant
Browse files Browse the repository at this point in the history
Pallet Documentation
  • Loading branch information
ndkazu authored Nov 28, 2022
2 parents 9b30aef + f4eb165 commit df26413
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 44 deletions.
1 change: 1 addition & 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 node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ name = "fs-node"

[dependencies]
clap = { version = "3.1.18", features = ["derive"] }
serde_json = { version = "1.0", default-features = false, features = ["alloc"]}

sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", features = ["wasmtime"] , branch = "polkadot-v0.9.29" }
sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.29" }
Expand Down
76 changes: 50 additions & 26 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,52 @@ pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
(get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))
}

pub fn get_endowed_accounts_with_balance() -> Vec<(AccountId, u128)> {
let accounts: Vec<AccountId> =
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),

// All the accounts below have to be manually added to Polkadot.JS using the secret seed obtained with
// for example: `target/release/fs-node key inspect //KillMonger`
// The account balance can then be customised, using the `/seed/balances.json` file

get_account_id_from_seed::<sr25519::Public>("KillMonger"),
get_account_id_from_seed::<sr25519::Public>("Aluman"),
get_account_id_from_seed::<sr25519::Public>("Shikamaru"),
get_account_id_from_seed::<sr25519::Public>("Geraldo"),
get_account_id_from_seed::<sr25519::Public>("Gabriel"),
get_account_id_from_seed::<sr25519::Public>("Henry"),
get_account_id_from_seed::<sr25519::Public>("Hans"),
get_account_id_from_seed::<sr25519::Public>("Obito"),
];

let accounts_with_balance: Vec<(AccountId, u128)> = accounts.iter().cloned().map(|k| (k, 1 << 60)).collect();
let json_data = &include_bytes!("../../seed/balances.json")[..];
let additional_accounts_with_balance: Vec<(AccountId, u128)> = serde_json::from_slice(json_data).unwrap();

let mut accounts = additional_accounts_with_balance.clone();

accounts_with_balance.iter().for_each(|tup1| {
for tup2 in additional_accounts_with_balance.iter() {
if tup1.0 == tup2.0 {
return;
}
}
accounts.push(tup1.to_owned());
});

accounts
}

pub fn development_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

Expand All @@ -54,16 +100,7 @@ pub fn development_config() -> Result<ChainSpec, String> {
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Pre-funded accounts
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Geraldo"),
get_account_id_from_seed::<sr25519::Public>("Hans"),
],
get_endowed_accounts_with_balance(),
true,
)
},
Expand Down Expand Up @@ -98,20 +135,7 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Pre-funded accounts
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
],
get_endowed_accounts_with_balance(),
true,
)
},
Expand All @@ -134,7 +158,7 @@ fn testnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AuraId, GrandpaId)>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
endowed_accounts: Vec<(AccountId,u128)>,
_enable_println: bool,
) -> GenesisConfig {
GenesisConfig {
Expand All @@ -144,7 +168,7 @@ fn testnet_genesis(
},
balances: BalancesConfig {
// Configure endowed accounts with initial balance of 1 << 60.
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
balances: endowed_accounts,
},
aura: AuraConfig {
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
Expand Down
10 changes: 5 additions & 5 deletions pallets/asset_management/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "pallet-asset_management"
version = "4.0.0-dev"
description = "FRAME pallet template for defining custom runtime logic."
authors = ["Substrate DevHub <https://github.com/substrate-developer-hub>"]
homepage = "https://substrate.io"
description = "This pallet is used for management of an asset by its owners."
authors = ["Fair Squares"]
homepage = "https://fair-squares.nl"
edition = "2021"
license = "Unlicense"
license = "Apache 2.0"
publish = false
repository = "https://github.com/substrate-developer-hub/substrate-node-template/"
repository = "https://github.com/Fair-Squares/fair-squares"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
Expand Down
16 changes: 15 additions & 1 deletion pallets/asset_management/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
License: Apache 2.0
# Asset_Management pallet

SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
48 changes: 36 additions & 12 deletions pallets/asset_management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@
//!
//!### Dispatchable Functions
//!
//! * `launch_representative_session` - An Owner creates a referendum for the available proposals:
//! Elect or demote a Representative.
//! * `launch_representative_session` - An Owner creates a referendum for the following available proposals:
//! - Elect a Representative.
//! - Demote a Representative.
//!
//! * `owners_vote` - Each asset owner can vote on ongoing referendum.
//! * `owners_vote` - Each asset owner can vote in an ongoing referendum.
//!
//! * `representative_approval` - Private call used as a proposal for Representative election.
//! * `representative_approval` - Call used as a proposal for Representative election.
//!
//! * `demote_representative` - Private call used as a proposal for Representative demotion.
//! * `demote_representative` - Call used as a proposal for Representative demotion.
//!
//! * `launch_tenant_session` - A Representative creates a referendum for the following available proposals:
//! - Admit a Tenant for a given asset.
//! - Evict a Tenant from a given asset.
//!
//! * `link_tenant_to_asset` - Call used as a proposal to link an accepted tenant with an existing asset.
//!
//! * `unlink_tenant_to_asset` - Call used as a proposal to remove the link between a tenant and an asset.
#![cfg_attr(not(feature = "std"), no_std)]

Expand Down Expand Up @@ -254,8 +263,8 @@ pub mod pallet {
)
.ok();
}
//Create the call

//Create the call
let proposal_call = match proposal {
VoteProposals::Election => {
//Check that the account is in the representative waiting list
Expand Down Expand Up @@ -309,7 +318,10 @@ pub mod pallet {

///The function below allows the owner to vote.
///The balance locked and used for vote conviction corresponds
///to the number of ownership tokens possessed by the voter.
///to the number of ownership tokens possessed by the voter.
/// The origin must be an owner of the asset
/// - referendum_index: index of the referendum the voter is taking part in
/// - vote: aye or nay
#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1).ref_time())]
pub fn owners_vote(
origin: OriginFor<T>,
Expand Down Expand Up @@ -355,8 +367,10 @@ pub mod pallet {
}

///Approval of a Representative role request
///The caller is the virtual account linked
///to the asset
/// The origin must be the virtual account connected to the asset
/// - rep_account: account Of the candidate to the representative account
/// - collection: collection number of the asset.
/// - item: item number of the asset.
#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1).ref_time())]
pub fn representative_approval(
origin: OriginFor<T>,
Expand Down Expand Up @@ -386,8 +400,10 @@ pub mod pallet {
}

///Demotion of a previously elected Representative
///The caller is the virtual account linked
///to the asset
/// The origin must be the virtual account connected to the asset
/// - rep_account: account Of the candidate to the representative account
/// - collection: collection_id of the asset.
/// - item: item_id of the asset.
#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1).ref_time())]
pub fn demote_representative(
origin: OriginFor<T>,
Expand Down Expand Up @@ -521,7 +537,11 @@ pub mod pallet {
Ok(())
}

/// Link a tenant with an asset
/// Link an accepted tenant with an existing asset
/// The origin must be the virtual account connected to the asset
/// - tenant: an account with the tenant role
/// - collection: collection_id of the asset
/// - item: item_id of the asset
#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1).ref_time())]
pub fn link_tenant_to_asset(
origin: OriginFor<T>,
Expand Down Expand Up @@ -549,6 +569,10 @@ pub mod pallet {
}

/// Unlink a tenant with an asset
/// The origin must be the virtual account connected to the asset
/// - tenant: an account with the tenant role linked to the asset
/// - collection: collection_id of the asset
/// - item: item_id of the asset
#[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1).ref_time())]
pub fn unlink_tenant_to_asset(
origin: OriginFor<T>,
Expand Down
14 changes: 14 additions & 0 deletions pallets/share_distributor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Share_Distributor pallet
SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
74 changes: 74 additions & 0 deletions seed/balances.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[
[
"5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw",
50000000000000000000
],
[
"5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL",
40000000000000000000
],
[
"5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
50000000000000000000
],
[
"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
40000000000000000000
],
[
"5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",
50000000000000000000
],
[
"5DAAnrj7VHTznn2AWBemMuyBwZWs6FNFjdyVXUeYum3PTXFy",
40000000000000000000
],
[
"5GNJqTPyNqANBkUVMN1LPPrxXnFouWXoe2wNSmmEoLctxiZY",
50000000000000000000
],
[
"5HpG9w8EBLe5XCrbczpwq5TSXvedjrBGCwqxK1iQ7qUsSWFc",
40000000000000000000
],
[
"5Ck5SLSHYac6WFt5UZRSsdJjwmpSZq85fd5TRNAdZQVzEAPT",
50000000000000000000
],
[
"5HKPmK9GYtE1PSLsS1qiYU9xQ9Si1NcEhdeCq9sw5bqu4ns8",
40000000000000000000
],
[
"5Gj5KmQgRZ9wx83gLhNUVQGqdvZQ9tvfHyzSKui2JCBohRBe",
50000000000000000000
],
[
"5DZnUdFg8yN5fR2eX4nvJHhofMG7qAcsKN16swuAr4XETfRQ",
36000000000000000000
],
[
"5GnT5fsfksWJG1owzDz1Q4buhmf6TXVDzVXCRg9pcZL6tqDj",
22000000000000000000
],
[
"5FWzkMhK4chYGm2D7Pv2W47U3nzByEpLkNYGAMrcKfpEchw3",
25000000000000000000
],
[
"5FU8gDwFrfUHWboXEqc3yA7wN6U4J7WcmLrrAFCu2PniPw3W",
29000000000000000000
],
[
"5FcTxwLAQ8L23HvTa6Y6UUMBKJkYRG42Vg9wVVpZDpE2ZnTZ",
38000000000000000000
],
[
"5CZembCRh7CwbJ7WfNp3vCNtvjb9nev3KHC1YFfZoz8GzGp7",
45000000000000000000
],
[
"5Ei3s8CRc3UfutpZvxrcaHfoHMs9apbnhAYXcRCgSWXVDc88",
55000000000000000000
]
]

0 comments on commit df26413

Please sign in to comment.