Skip to content

Commit

Permalink
Merge pull request #258 from Fair-Squares/257-additional-preimage-bug
Browse files Browse the repository at this point in the history
Add `requested_asset` to Registered_Tenant Struct
  • Loading branch information
cuteolaf authored Mar 1, 2023
2 parents 94d908e + d528fe9 commit 6ce97fc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
4 changes: 2 additions & 2 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ fn testnet_genesis(
role_module: RoleModuleConfig {
new_admin: Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
representatives: vec![
get_account_id_from_seed::<sr25519::Public>("Gabriel"),
get_account_id_from_seed::<sr25519::Public>("Henry"),
//get_account_id_from_seed::<sr25519::Public>("Gabriel"),
//get_account_id_from_seed::<sr25519::Public>("Henry"),
],
},
nft_module: NftModuleConfig {
Expand Down
10 changes: 4 additions & 6 deletions pallets/asset_management/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ impl<T: Config> Pallet<T> {
}

if !check0 {
let origin_root: OriginFor<T> = frame_system::RawOrigin::Root.into();
//Set the representative as a registrar
Ident::Pallet::<T>::add_registrar(origin, who2).ok();
Ident::Pallet::<T>::add_registrar(origin_root, who2).ok();

//Set registrar fields
let origin2: OriginFor<T> = RawOrigin::Signed(who).into();
Expand Down Expand Up @@ -224,11 +225,8 @@ impl<T: Config> Pallet<T> {

let proposal_hash = T::Hashing::hash_of(&call_dispatch);
let proposal_encoded: Vec<u8> = call_dispatch.encode();
match Dem::Pallet::<T>::note_preimage(origin, proposal_encoded) {
Ok(_) => (),
Err(x) if x == Error::<T>::DuplicatePreimage.into() => (),
Err(x) => panic!("{x:?}"),
}
Dem::Pallet::<T>::note_preimage(origin, proposal_encoded).ok();

proposal_hash
}

Expand Down
2 changes: 0 additions & 2 deletions pallets/asset_management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ pub mod pallet {
StorageOverflow,
/// The proposal could not be created
FailedToCreateProposal,
/// This Preimage already exists
DuplicatePreimage,
/// Not an owner in the corresponding virtual account
NotAnOwner,
/// The Asset Does not Exists
Expand Down
17 changes: 16 additions & 1 deletion pallets/tenancy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,25 @@ pub mod pallet {
let caller = ensure_signed(origin.clone())?;
// Ensure that the caller has the tenancy role
ensure!(Roles::TenantLog::<T>::contains_key(caller.clone()), Error::<T>::NotATenant);
RegisteredTenant::<T>::new(caller.clone(), info.clone()).ok();



// Ensure that the asset is valid
let collection_id: T::NftCollectionId = asset_type.value().into();
let ownership = Share::Pallet::<T>::virtual_acc(collection_id, asset_id);
ensure!(ownership.is_some(), Error::<T>::NotAnAsset);
let virtual_account = ownership.unwrap().virtual_account;

if !Tenants::<T>::contains_key(caller.clone()){
RegisteredTenant::<T>::new(caller.clone(), info.clone(), Some(virtual_account.clone())).ok();
}else{
let mut val0 = Self::infos(&caller).unwrap();
Tenants::<T>::mutate(&caller,|val|{
val0.asset_requested = Some(virtual_account.clone());
*val = Some(val0);
});
}

Self::request_helper(origin.clone(), virtual_account.clone(), info).ok();
let now = <frame_system::Pallet<T>>::block_number();

Expand Down Expand Up @@ -225,9 +237,12 @@ pub mod pallet {
Error::<T>::NotAValidPayment
);


Self::payment_helper(origin, virtual_account.clone(), collection_id, asset_id).ok();
let now = <frame_system::Pallet<T>>::block_number();



Self::deposit_event(Event::GuarantyDepositPayment {
tenant: caller,
when: now,
Expand Down
6 changes: 5 additions & 1 deletion pallets/tenancy/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@ pub struct RegisteredTenant<T: Config> {
pub infos: Box<IdentityInfo<T::MaxAdditionalFields>>,
///Creation Blocknumber
pub registered_at_block: BlockNumberOf<T>,
///Asset requested by the tenant
pub asset_requested: Option<T::AccountId>,
}

impl<T: Config> RegisteredTenant<T> {
pub fn new(
tenant_id: T::AccountId,
infos: Box<IdentityInfo<T::MaxAdditionalFields>>,
asset_requested: Option<T::AccountId>,

) -> DispatchResult {
let registered_at_block = <frame_system::Pallet<T>>::block_number();
let tenant = RegisteredTenant::<T> { infos, registered_at_block };
let tenant = RegisteredTenant::<T> { infos, registered_at_block,asset_requested};
Tenants::<T>::insert(tenant_id.clone(), tenant);
Roles::TenantLog::<T>::mutate(tenant_id, |val| {
let mut val0 = val.clone().unwrap();
Expand Down

0 comments on commit 6ce97fc

Please sign in to comment.