Skip to content

Commit

Permalink
Merge pull request #265 from peaqnetwork/bug/1207512530452118_without…
Browse files Browse the repository at this point in the history
…_storage_info

Bug/1207512530452118 without storage info
  • Loading branch information
sfffaaa authored Aug 7, 2024
2 parents 24add78 + 3a01866 commit e7f47d2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 32 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

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

27 changes: 15 additions & 12 deletions precompiles/peaq-did/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use fp_evm::PrecompileHandle;

use pallet_evm::AddressMapping;

use peaq_pallet_did::did::Did as PeaqDidT;
use peaq_pallet_did::{
did::Did as PeaqDidT,
pallet::{MAX_NAME_SIZE as MAX_DID_NAME_SIZE, MAX_VALUE_SIZE as MAX_DID_VALUE_SIZE},
};
use precompile_utils::{
keccak256,
prelude::{
Expand All @@ -25,6 +28,8 @@ use precompile_utils::{
solidity, EvmResult,
};

type MaxValueSize = ConstU32<{ MAX_DID_VALUE_SIZE as u32 }>;
type MaxNameSize = ConstU32<{ MAX_DID_NAME_SIZE as u32 }>;
type AccountIdOf<Runtime> = <Runtime as frame_system::Config>::AccountId;
type BlockNumberOf<Runtime> = <Runtime as frame_system::Config>::BlockNumber;
type MomentOf<Runtime> = <Runtime as pallet_timestamp::Config>::Moment;
Expand Down Expand Up @@ -78,8 +83,8 @@ where
let did_account = Runtime::AddressMapping::into_account_id(did_account.into());
match peaq_pallet_did::Pallet::<Runtime>::read(&did_account, &Vec::<u8>::from(name)) {
Some(v) => Ok(EVMAttribute {
name: v.name.into(),
value: v.value.into(),
name: v.name.to_vec().into(),
value: v.value.to_vec().into(),
validity: v.validity.into(),
created: v.created.into(),
}),
Expand Down Expand Up @@ -107,11 +112,10 @@ where
_ => Some(valid_for.into()),
};

let name_vec = BoundedVec::<u8, ConstU32<64>>::try_from(name.as_bytes().to_vec())
let name_vec = BoundedVec::<u8, MaxNameSize>::try_from(name.as_bytes().to_vec())
.map_err(|_| Revert::new(RevertReason::custom("Name too long")))?;
let value_vec =
BoundedVec::<u8, <Runtime>::BoundedDataLen>::try_from(value.as_bytes().to_vec())
.map_err(|_| Revert::new(RevertReason::custom("Value too long")))?;
let value_vec = BoundedVec::<u8, MaxValueSize>::try_from(value.as_bytes().to_vec())
.map_err(|_| Revert::new(RevertReason::custom("Value too long")))?;

RuntimeHelper::<Runtime>::try_dispatch(
handle,
Expand Down Expand Up @@ -160,11 +164,10 @@ where
0 => None,
_ => Some(valid_for.into()),
};
let name_vec = BoundedVec::<u8, ConstU32<64>>::try_from(name.as_bytes().to_vec())
let name_vec = BoundedVec::<u8, MaxNameSize>::try_from(name.as_bytes().to_vec())
.map_err(|_| Revert::new(RevertReason::custom("Name too long")))?;
let value_vec =
BoundedVec::<u8, <Runtime>::BoundedDataLen>::try_from(value.as_bytes().to_vec())
.map_err(|_| Revert::new(RevertReason::custom("Value too long")))?;
let value_vec = BoundedVec::<u8, MaxValueSize>::try_from(value.as_bytes().to_vec())
.map_err(|_| Revert::new(RevertReason::custom("Value too long")))?;

RuntimeHelper::<Runtime>::try_dispatch(
handle,
Expand Down Expand Up @@ -206,7 +209,7 @@ where
let caller: AccountIdOf<Runtime> =
Runtime::AddressMapping::into_account_id(handle.context().caller);

let name_vec = BoundedVec::<u8, ConstU32<64>>::try_from(name.as_bytes().to_vec())
let name_vec = BoundedVec::<u8, MaxNameSize>::try_from(name.as_bytes().to_vec())
.map_err(|_| Revert::new(RevertReason::custom("Name too long")))?;
let did_account_addr = Runtime::AddressMapping::into_account_id(did_account.into());
RuntimeHelper::<Runtime>::try_dispatch(
Expand Down
17 changes: 10 additions & 7 deletions precompiles/peaq-rbac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ where

match peaq_pallet_rbac::Pallet::<Runtime>::get_role(&owner_account, entity_id) {
Err(_e) => Err(Revert::new(RevertReason::custom(err2str(&_e))).into()),
Ok(v) => Ok(Entity { id: v.id.into(), name: v.name.into(), enabled: v.enabled }),
Ok(v) =>
Ok(Entity { id: v.id.into(), name: v.name.to_vec().into(), enabled: v.enabled }),
}
}

Expand All @@ -101,7 +102,7 @@ where
.iter()
.map(|entity| Entity {
id: entity.id.into(),
name: entity.name.clone().into(),
name: entity.name.to_vec().into(),
enabled: entity.enabled,
})
.collect::<Vec<Entity>>()),
Expand Down Expand Up @@ -307,7 +308,8 @@ where

match peaq_pallet_rbac::Pallet::<Runtime>::get_permission(&owner, permission_id) {
Err(_e) => Err(Revert::new(RevertReason::custom(err2str(&_e))).into()),
Ok(v) => Ok(Entity { id: v.id.into(), name: v.name.into(), enabled: v.enabled }),
Ok(v) =>
Ok(Entity { id: v.id.into(), name: v.name.to_vec().into(), enabled: v.enabled }),
}
}

Expand All @@ -327,7 +329,7 @@ where
.iter()
.map(|entity| Entity {
id: entity.id.into(),
name: entity.name.clone().into(),
name: entity.name.to_vec().into(),
enabled: entity.enabled,
})
.collect::<Vec<Entity>>()),
Expand Down Expand Up @@ -547,7 +549,8 @@ where

match peaq_pallet_rbac::Pallet::<Runtime>::get_group(&owner, group_id) {
Err(_e) => Err(Revert::new(RevertReason::custom(err2str(&_e))).into()),
Ok(v) => Ok(Entity { id: v.id.into(), name: v.name.into(), enabled: v.enabled }),
Ok(v) =>
Ok(Entity { id: v.id.into(), name: v.name.to_vec().into(), enabled: v.enabled }),
}
}

Expand Down Expand Up @@ -846,7 +849,7 @@ where
.iter()
.map(|val| Entity {
id: val.id.into(),
name: val.name.clone().into(),
name: val.name.to_vec().into(),
enabled: val.enabled,
})
.collect::<Vec<Entity>>()),
Expand Down Expand Up @@ -874,7 +877,7 @@ where
.iter()
.map(|val| Entity {
id: val.id.into(),
name: val.name.clone().into(),
name: val.name.to_vec().into(),
enabled: val.enabled,
})
.collect::<Vec<Entity>>()),
Expand Down
1 change: 0 additions & 1 deletion runtime/krest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,6 @@ impl peaq_pallet_did::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Time = pallet_timestamp::Pallet<Runtime>;
type WeightInfo = peaq_pallet_did::weights::WeightInfo<Runtime>;
type BoundedDataLen = ConstU32<2560>;
type Currency = Balances;
type StorageDepositBase = DidStorageDepositBase;
type StorageDepositPerByte = DidStorageDepositPerByte;
Expand Down
1 change: 0 additions & 1 deletion runtime/peaq-dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ impl peaq_pallet_did::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Time = pallet_timestamp::Pallet<Runtime>;
type WeightInfo = peaq_pallet_did::weights::WeightInfo<Runtime>;
type BoundedDataLen = ConstU32<2560>;
type Currency = Balances;
type StorageDepositBase = DidStorageDepositBase;
type StorageDepositPerByte = DidStorageDepositPerByte;
Expand Down
1 change: 0 additions & 1 deletion runtime/peaq/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ impl peaq_pallet_did::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Time = pallet_timestamp::Pallet<Runtime>;
type WeightInfo = peaq_pallet_did::weights::WeightInfo<Runtime>;
type BoundedDataLen = ConstU32<2560>;
type Currency = Balances;
type StorageDepositBase = DidStorageDepositBase;
type StorageDepositPerByte = DidStorageDepositPerByte;
Expand Down

0 comments on commit e7f47d2

Please sign in to comment.