Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop-2.0' into develop-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mohaijiang committed Oct 11, 2023
2 parents d18cfd6 + 04fad0c commit a0fb76e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
19 changes: 18 additions & 1 deletion frame/provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub mod pallet {
#[pallet::generate_deposit(pub (super) fn deposit_event)]
pub enum Event<T: Config> {
/// successfully registered resources
/// [accountId, index, peerId, cpu, memory, system, cpu_model, price_hour, rent_duration_hour]
/// [accountId, index, peerId, cpu, memory, system, cpu_model, price_hour, rent_duration_hour, public_ip]
RegisterResourceSuccess(
T::AccountId,
u64,
Expand All @@ -177,6 +177,8 @@ pub mod pallet {
Vec<u8>,
Balance,
u32,
Vec<u8>,
u32,
),
/// modify the resource unit price successfully [accountId, index, balance]
ModifyResourceUnitPrice(T::AccountId, u64, u128),
Expand Down Expand Up @@ -302,6 +304,8 @@ pub mod pallet {
price: BalanceOf<T>,
rent_duration_hour: u32,
new_index: u64,
public_ip: Vec<u8>,
specification: u32,
) -> DispatchResult {
let who = ensure_signed(account_id)?;

Expand Down Expand Up @@ -386,6 +390,11 @@ pub mod pallet {
rent_blocks,
end_of_block,
);
let spec = match specification {
1 => Specification::Enhanced,
2 => Specification::HighRanking,
_ => Specification::General,
};
// create the computing resource: include all the info(resource, statistics, rental_info, and source status)
let computing_resource = ComputingResource::new(
index,
Expand All @@ -395,6 +404,8 @@ pub mod pallet {
statistics,
resource_rental_info,
ResourceStatus::Unused,
public_ip.clone(),
spec,
);

//Associate the block number and the resource id to expire
Expand Down Expand Up @@ -438,6 +449,8 @@ pub mod pallet {
cpu_model,
T::BalanceToNumber::convert(price),
rent_duration_hour,
public_ip,
specification,
));

Ok(())
Expand Down Expand Up @@ -790,6 +803,8 @@ impl<T: Config> ProviderInterface<<T as frame_system::Config>::AccountId> for Pa
let price = T::NumberToBalance::convert(1_000_000_000_000);
let rent_duration_hour = 3 as u32;
let staking_amount = T::NumberToBalance::convert(200_000_000_000_000);
let public_ip = "127.0.0.1".as_bytes().to_vec();
let spec = Specification::General;

T::MarketInterface::change_stake_amount(
who.clone(),
Expand Down Expand Up @@ -837,6 +852,8 @@ impl<T: Config> ProviderInterface<<T as frame_system::Config>::AccountId> for Pa
statistics,
resource_rental_info,
ResourceStatus::Unused,
public_ip.clone(),
spec,
);

//Associate the block number and the resource id to expire
Expand Down
16 changes: 16 additions & 0 deletions primitives/hamster/src/p_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ pub struct ComputingResource<BlockNumber, AccountId>
pub rental_info: ResourceRentalInfo<BlockNumber>,
/// resource lease status
pub status: ResourceStatus,
/// resource public ip
pub public_ip: Vec<u8>,
/// resource specification
pub specification: Specification,
}

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub enum Specification {
General,
Enhanced,
HighRanking,
}

impl<BlockNumber, AccountId> ComputingResource<BlockNumber, AccountId>
Expand All @@ -42,6 +54,8 @@ impl<BlockNumber, AccountId> ComputingResource<BlockNumber, AccountId>
rental_statistics: ResourceRentalStatistics,
rental_info: ResourceRentalInfo<BlockNumber>,
status: ResourceStatus,
public_ip: Vec<u8>,
specification: Specification,
) -> Self {
ComputingResource {
index,
Expand All @@ -51,6 +65,8 @@ impl<BlockNumber, AccountId> ComputingResource<BlockNumber, AccountId>
rental_statistics,
rental_info,
status,
public_ip,
specification,
}
}

Expand Down

0 comments on commit a0fb76e

Please sign in to comment.