From 8d9947c3f81fd8adde4bba55d501da690dabf134 Mon Sep 17 00:00:00 2001 From: jlvihv Date: Wed, 19 Oct 2022 16:50:44 +0800 Subject: [PATCH 1/2] add public ip field --- frame/provider/src/lib.rs | 8 +++++++- primitives/hamster/src/p_provider.rs | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/frame/provider/src/lib.rs b/frame/provider/src/lib.rs index f05fee0938..82831aedee 100644 --- a/frame/provider/src/lib.rs +++ b/frame/provider/src/lib.rs @@ -166,7 +166,7 @@ pub mod pallet { #[pallet::generate_deposit(pub (super) fn deposit_event)] pub enum Event { /// 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, @@ -177,6 +177,7 @@ pub mod pallet { Vec, Balance, u32, + Vec, ), /// modify the resource unit price successfully [accountId, index, balance] ModifyResourceUnitPrice(T::AccountId, u64, u128), @@ -302,6 +303,7 @@ pub mod pallet { price: BalanceOf, rent_duration_hour: u32, new_index: u64, + public_ip: Vec, ) -> DispatchResult { let who = ensure_signed(account_id)?; @@ -395,6 +397,7 @@ pub mod pallet { statistics, resource_rental_info, ResourceStatus::Unused, + public_ip.clone(), ); //Associate the block number and the resource id to expire @@ -438,6 +441,7 @@ pub mod pallet { cpu_model, T::BalanceToNumber::convert(price), rent_duration_hour, + public_ip, )); Ok(()) @@ -790,6 +794,7 @@ impl ProviderInterface<::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(); T::MarketInterface::change_stake_amount( who.clone(), @@ -837,6 +842,7 @@ impl ProviderInterface<::AccountId> for Pa statistics, resource_rental_info, ResourceStatus::Unused, + public_ip.clone(), ); //Associate the block number and the resource id to expire diff --git a/primitives/hamster/src/p_provider.rs b/primitives/hamster/src/p_provider.rs index 5105772ee4..f71dc8611a 100644 --- a/primitives/hamster/src/p_provider.rs +++ b/primitives/hamster/src/p_provider.rs @@ -28,6 +28,8 @@ pub struct ComputingResource pub rental_info: ResourceRentalInfo, /// resource lease status pub status: ResourceStatus, + /// resource public ip + pub public_ip: Vec, } impl ComputingResource @@ -42,6 +44,7 @@ impl ComputingResource rental_statistics: ResourceRentalStatistics, rental_info: ResourceRentalInfo, status: ResourceStatus, + public_ip: Vec, ) -> Self { ComputingResource { index, @@ -51,6 +54,7 @@ impl ComputingResource rental_statistics, rental_info, status, + public_ip, } } From c3b4ed3fb2f17d12f1e7ca63e28181bc7b3a005f Mon Sep 17 00:00:00 2001 From: jlvihv Date: Thu, 20 Oct 2022 14:55:36 +0800 Subject: [PATCH 2/2] add specification field --- frame/provider/src/lib.rs | 11 +++++++++++ primitives/hamster/src/p_provider.rs | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/frame/provider/src/lib.rs b/frame/provider/src/lib.rs index 82831aedee..ceb179f5a9 100644 --- a/frame/provider/src/lib.rs +++ b/frame/provider/src/lib.rs @@ -178,6 +178,7 @@ pub mod pallet { Balance, u32, Vec, + u32, ), /// modify the resource unit price successfully [accountId, index, balance] ModifyResourceUnitPrice(T::AccountId, u64, u128), @@ -304,6 +305,7 @@ pub mod pallet { rent_duration_hour: u32, new_index: u64, public_ip: Vec, + specification: u32, ) -> DispatchResult { let who = ensure_signed(account_id)?; @@ -388,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, @@ -398,6 +405,7 @@ pub mod pallet { resource_rental_info, ResourceStatus::Unused, public_ip.clone(), + spec, ); //Associate the block number and the resource id to expire @@ -442,6 +450,7 @@ pub mod pallet { T::BalanceToNumber::convert(price), rent_duration_hour, public_ip, + specification, )); Ok(()) @@ -795,6 +804,7 @@ impl ProviderInterface<::AccountId> for Pa 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(), @@ -843,6 +853,7 @@ impl ProviderInterface<::AccountId> for Pa resource_rental_info, ResourceStatus::Unused, public_ip.clone(), + spec, ); //Associate the block number and the resource id to expire diff --git a/primitives/hamster/src/p_provider.rs b/primitives/hamster/src/p_provider.rs index f71dc8611a..97c15ae7e9 100644 --- a/primitives/hamster/src/p_provider.rs +++ b/primitives/hamster/src/p_provider.rs @@ -30,6 +30,16 @@ pub struct ComputingResource pub status: ResourceStatus, /// resource public ip pub public_ip: Vec, + /// 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 ComputingResource @@ -45,6 +55,7 @@ impl ComputingResource rental_info: ResourceRentalInfo, status: ResourceStatus, public_ip: Vec, + specification: Specification, ) -> Self { ComputingResource { index, @@ -55,6 +66,7 @@ impl ComputingResource rental_info, status, public_ip, + specification, } }