Skip to content

Commit a6d6628

Browse files
authored
Merge pull request #2 from Karuzzzo/master
minor fixes
2 parents afb2a9a + 6ade02a commit a6d6628

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ Current proof-of-concept runtime includes functions:
3030
# Build and run
3131

3232
```bash
33+
# install rust and all required dependencies
34+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
35+
3336
# clone project from repo
3437
git clone https://github.com/DistributedSky/distributed-sky-substrate.git
3538
cd distributed-sky-substrate

node/src/chain_spec.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use node_dsky_runtime::{
44
};
55
use sc_service::ChainType;
66
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
7-
use sp_core::{crypto::Ss58Codec, sr25519, Pair, Public};
7+
use sp_core::{sr25519, Pair, Public};
88
use sp_finality_grandpa::AuthorityId as GrandpaId;
99
use sp_runtime::traits::{IdentifyAccount, Verify};
1010

@@ -47,10 +47,6 @@ pub fn development_config() -> Result<ChainSpec, String> {
4747
"dev",
4848
ChainType::Development,
4949
move || {
50-
let master_account_id: AccountId =
51-
Ss58Codec::from_ss58check("5Gn6YMyoNZVZx9jCpANYDRPMB2p4FwyUTy1tKgfPTZz4vQFL").unwrap();
52-
let registrar_account_id: AccountId =
53-
Ss58Codec::from_ss58check("5GQvJoe3uQFFKPjCQLLfdf1nTPbPP6NKRHtEeRtvLBDBpMuX").unwrap();
5450
testnet_genesis(
5551
wasm_binary,
5652
// Initial PoA authorities
@@ -59,8 +55,6 @@ pub fn development_config() -> Result<ChainSpec, String> {
5955
get_account_id_from_seed::<sr25519::Public>("Alice"),
6056
// Pre-funded accounts
6157
vec![
62-
master_account_id,
63-
registrar_account_id,
6458
get_account_id_from_seed::<sr25519::Public>("Alice"),
6559
get_account_id_from_seed::<sr25519::Public>("Bob"),
6660
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
@@ -93,8 +87,6 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
9387
"local_testnet",
9488
ChainType::Local,
9589
move || {
96-
let master_account_id: AccountId =
97-
Ss58Codec::from_ss58check("5Gn6YMyoNZVZx9jCpANYDRPMB2p4FwyUTy1tKgfPTZz4vQFL").unwrap();
9890
testnet_genesis(
9991
wasm_binary,
10092
// Initial PoA authorities
@@ -103,11 +95,9 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
10395
authority_keys_from_seed("Bob"),
10496
],
10597
// Sudo account
106-
// get_account_id_from_seed::<sr25519::Public>("Alice"),
107-
master_account_id.clone(),
98+
get_account_id_from_seed::<sr25519::Public>("Alice"),
10899
// Pre-funded accounts
109100
vec![
110-
master_account_id,
111101
get_account_id_from_seed::<sr25519::Public>("Alice"),
112102
get_account_id_from_seed::<sr25519::Public>("Bob"),
113103
get_account_id_from_seed::<sr25519::Public>("Charlie"),

pallets/ds-accounts/src/lib.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ decl_event!(
173173
AccountId = <T as frame_system::Config>::AccountId,
174174
Balance = BalanceOf<T>,
175175
AccountRole = <T as Trait>::AccountRole,
176+
MetaIPFS = <T as Trait>::MetaIPFS,
176177
{
177178
// Event documentation should end with an array that provides descriptive names for event parameters.
178179
/// New account has been created [who, account, role]
@@ -181,10 +182,10 @@ decl_event!(
181182
AccountDisabled(AccountId, AccountId),
182183
/// Lock balance [who, balance]
183184
BalanceLocked(AccountId, Balance),
184-
/// Pilot has been registered [who, account]
185-
PilotRegistered(AccountId, AccountId),
186-
/// UAV has been registered [who, account] (do we need ipfs link here?)
187-
UAVRegistred(AccountId, AccountId),
185+
/// Pilot has been registered [who, account, license_ipfs_hash]
186+
PilotRegistered(AccountId, AccountId, MetaIPFS),
187+
/// UAV has been registered [who, account, license_ipfs_hash]
188+
UAVRegistred(AccountId, AccountId, MetaIPFS),
188189
// add other events here
189190
}
190191
);
@@ -256,7 +257,7 @@ decl_module! {
256257

257258
/// Register an entry in account registry with PILOT role.
258259
#[weight = <T as Trait>::WeightInfo::register_pilot()]
259-
pub fn register_pilot(origin, account: T::AccountId) -> dispatch::DispatchResult {
260+
pub fn register_pilot(origin, account: T::AccountId, metadata_ipfs_hash: T::MetaIPFS) -> dispatch::DispatchResult {
260261
let who = ensure_signed(origin)?;
261262
ensure!(Self::account_is(&who, REGISTRAR_ROLE.into()), Error::<T>::NotAuthorized);
262263
ensure!(!UAVRegistry::<T>::contains_key(&account), Error::<T>::AddressAlreadyUsed);
@@ -274,7 +275,7 @@ decl_module! {
274275
});
275276

276277
if update_storage_result.is_ok() {
277-
Self::deposit_event(RawEvent::PilotRegistered(who, account));
278+
Self::deposit_event(RawEvent::PilotRegistered(who, account, metadata_ipfs_hash));
278279
}
279280

280281
update_storage_result
@@ -289,9 +290,9 @@ decl_module! {
289290
ensure!(Self::account_is(&who, (REGISTRAR_ROLE | PILOT_ROLE).into()), Error::<T>::NotAuthorized);
290291
ensure!(!AccountRegistry::<T>::contains_key(&uav_address), Error::<T>::AddressAlreadyUsed);
291292

292-
UAVRegistry::<T>::insert(&uav_address, UAVOf::<T>::new(serial_number, meta, &who));
293+
UAVRegistry::<T>::insert(&uav_address, UAVOf::<T>::new(serial_number, meta.clone(), &who));
293294

294-
Self::deposit_event(RawEvent::UAVRegistred(who, uav_address));
295+
Self::deposit_event(RawEvent::UAVRegistred(who, uav_address, meta));
295296
Ok(())
296297
}
297298

pallets/ds-accounts/src/tests.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ fn it_register_pilot_by_registrar() {
152152
));
153153
assert_ok!(DSAccountsModule::register_pilot(
154154
Origin::signed(REGISTRAR_1_ACCOUNT_ID),
155-
PILOT_1_ACCOUNT_ID
155+
PILOT_1_ACCOUNT_ID,
156+
vec![0],
156157
));
157158

158159
let account = DSAccountsModule::account_registry(PILOT_1_ACCOUNT_ID);
@@ -169,7 +170,8 @@ fn it_try_register_pilot_not_by_registrar() {
169170
assert_noop!(
170171
DSAccountsModule::register_pilot(
171172
Origin::signed(ADMIN_ACCOUNT_ID),
172-
PILOT_1_ACCOUNT_ID
173+
PILOT_1_ACCOUNT_ID,
174+
vec![0],
173175
),
174176
Error::NotAuthorized
175177
);
@@ -189,7 +191,8 @@ fn it_try_register_same_pilot_twice() {
189191

190192
assert_ok!(DSAccountsModule::register_pilot(
191193
Origin::signed(REGISTRAR_1_ACCOUNT_ID),
192-
PILOT_1_ACCOUNT_ID
194+
PILOT_1_ACCOUNT_ID,
195+
vec![0],
193196
));
194197

195198
let account = DSAccountsModule::account_registry(PILOT_1_ACCOUNT_ID);
@@ -207,7 +210,8 @@ fn it_try_register_same_pilot_twice() {
207210
assert_noop!(
208211
DSAccountsModule::register_pilot(
209212
Origin::signed(REGISTRAR_2_ACCOUNT_ID),
210-
PILOT_1_ACCOUNT_ID
213+
PILOT_1_ACCOUNT_ID,
214+
vec![0],
211215
),
212216
Error::AlreadyRegistered,
213217
);
@@ -226,6 +230,7 @@ fn it_try_to_add_admin_account_role_pilot() {
226230
DSAccountsModule::register_pilot(
227231
Origin::signed(REGISTRAR_1_ACCOUNT_ID),
228232
ADMIN_ACCOUNT_ID,
233+
vec![0],
229234
)
230235
);
231236
});
@@ -299,6 +304,7 @@ fn it_try_to_add_new_uav_with_allowed_roles() {
299304
assert_ok!(DSAccountsModule::register_pilot(
300305
Origin::signed(REGISTRAR_1_ACCOUNT_ID),
301306
PILOT_1_ACCOUNT_ID,
307+
vec![0],
302308
));
303309

304310
assert_ok!(DSAccountsModule::register_uav(
@@ -345,6 +351,7 @@ fn it_try_register_uav_on_wrong_addr() {
345351
assert_ok!(DSAccountsModule::register_pilot(
346352
Origin::signed(REGISTRAR_1_ACCOUNT_ID),
347353
PILOT_1_ACCOUNT_ID,
354+
vec![0],
348355
));
349356
assert_noop!(
350357
DSAccountsModule::register_uav(
@@ -386,6 +393,7 @@ fn it_try_register_user_on_uav_addr() {
386393
DSAccountsModule::register_pilot(
387394
Origin::signed(REGISTRAR_1_ACCOUNT_ID),
388395
UAV_1_ACCOUNT_ID,
396+
vec![0],
389397
),
390398
Error::AddressAlreadyUsed
391399
);

pallets/ds-maps/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use sp_std::{
2525
use dsky_utils::{CastToType, FromRaw, IntDiv, Signed, ToBigCoord, FromBigCoord, GetEpsilon};
2626
use frame_system::ensure_signed;
2727
use pallet_ds_accounts as accounts;
28-
use accounts::REGISTRAR_ROLE;
28+
use accounts::{REGISTRAR_ROLE, PILOT_ROLE};
2929

3030
mod default_weight;
3131
#[cfg(test)]
@@ -1767,7 +1767,7 @@ decl_module! {
17671767
root_id: RootId) -> dispatch::DispatchResult {
17681768
let who = ensure_signed(origin)?;
17691769
// TODO consider role for route addition
1770-
ensure!(<accounts::Module<T>>::account_is(&who, REGISTRAR_ROLE.into()), Error::<T>::NotAuthorized);
1770+
ensure!(<accounts::Module<T>>::account_is(&who, (PILOT_ROLE | REGISTRAR_ROLE).into()), Error::<T>::NotAuthorized);
17711771
ensure!(RootBoxes::<T>::contains_key(root_id), Error::<T>::RootDoesNotExist);
17721772
ensure!(waypoints.len() >= 2, Error::<T>::InvalidData);
17731773
let start_waypoint = &waypoints.first().unwrap();

0 commit comments

Comments
 (0)