diff --git a/do.sql b/do.sql new file mode 100644 index 0000000..9def15d --- /dev/null +++ b/do.sql @@ -0,0 +1,246 @@ +-- -------------------------------------------------------------- +-- do.sql – create tables for HeroLedger models (PostgreSQL) +-- -------------------------------------------------------------- +BEGIN; + +-- 1. DNSZONE +CREATE TABLE dnszone ( + id SERIAL PRIMARY KEY, + created BIGINT, + updated BIGINT, + deleted BOOLEAN, + version INTEGER, + domain TEXT, -- @[index] + administrators INTEGER[], -- array of user ids + status TEXT, + metadata JSONB, + soarecord JSONB, -- store array of SOARecord structs as JSONB + data JSONB NOT NULL +); +CREATE INDEX idx_dnszone_domain ON dnszone(domain); + +-- 2. DNSRECORD +CREATE TABLE dnsrecord ( + id SERIAL PRIMARY KEY, + created BIGINT, + updated BIGINT, + deleted BOOLEAN, + version INTEGER, + subdomain TEXT, + record_type TEXT, + value TEXT, + priority INTEGER, + ttl INTEGER, + is_active BOOLEAN, + cat TEXT, + is_wildcard BOOLEAN, + data JSONB NOT NULL +); +-- No explicit index required – rarely queried alone + +-- 3. GROUP +CREATE TABLE "group" ( + id SERIAL PRIMARY KEY, + created BIGINT, + updated BIGINT, + deleted BOOLEAN, + version INTEGER, + name TEXT NOT NULL, + description TEXT, + dnsrecords INTEGER[], -- FK → dnsrecord.id (array) + administrators INTEGER[], + config JSONB, -- embedded GroupConfig struct + status TEXT, + visibility TEXT, + created_ts BIGINT, + updated_ts BIGINT, + data JSONB NOT NULL +); +CREATE UNIQUE INDEX idx_group_name ON "group"(name); + +-- 4. USER_GROUP_MEMBERSHIP +CREATE TABLE user_group_membership ( + id SERIAL PRIMARY KEY, + created BIGINT, + updated BIGINT, + deleted BOOLEAN, + version INTEGER, + user_id INTEGER NOT NULL, + group_ids INTEGER[], -- array of group ids + data JSONB NOT NULL +); +CREATE INDEX idx_ugm_user_id ON user_group_membership(user_id); +CREATE INDEX idx_ugm_group_ids ON user_group_membership USING GIN (group_ids); + +-- 5. MEMBER (circle/member.v) +CREATE TABLE member ( + id SERIAL PRIMARY KEY, + created BIGINT, + updated BIGINT, + deleted BOOLEAN, + version INTEGER, + user_id INTEGER NOT NULL, + role TEXT, + status TEXT, + joined_at BIGINT, + invited_by INTEGER, + permissions TEXT[], + data JSONB NOT NULL +); +CREATE INDEX idx_member_user_id ON member(user_id); + +-- 6. ACCOUNT +CREATE TABLE account ( + id SERIAL PRIMARY KEY, + created BIGINT, + updated BIGINT, + deleted BOOLEAN, + version INTEGER, + owner_id INTEGER, + address TEXT NOT NULL, + balance DOUBLE PRECISION, + currency TEXT, + assetid INTEGER, + last_activity BIGINT, + administrators INTEGER[], + accountpolicy INTEGER, + data JSONB NOT NULL +); +CREATE UNIQUE INDEX idx_account_address ON account(address); +CREATE INDEX idx_account_assetid ON account(assetid); + +-- 7. ASSET +CREATE TABLE asset ( + id SERIAL PRIMARY KEY, + created BIGINT, + updated BIGINT, + deleted BOOLEAN, + version INTEGER, + address TEXT NOT NULL, + assetid INTEGER NOT NULL, + asset_type TEXT, + issuer INTEGER, + supply DOUBLE PRECISION, + decimals SMALLINT, + is_frozen BOOLEAN, + metadata JSONB, + administrators INTEGER[], + min_signatures INTEGER, + data JSONB NOT NULL +); +CREATE UNIQUE INDEX idx_asset_address ON asset(address); +CREATE UNIQUE INDEX idx_asset_assetid ON asset(assetid); +CREATE INDEX idx_asset_issuer ON asset(issuer); + +-- 8. ACCOUNT_POLICY (holds three AccountPolicyItem JSONB blobs) +CREATE TABLE account_policy ( + id SERIAL PRIMARY KEY, + created BIGINT, + updated BIGINT, + deleted BOOLEAN, + version INTEGER, + transferpolicy JSONB, + adminpolicy JSONB, + clawbackpolicy JSONB, + freezepolicy JSONB, + data JSONB NOT NULL +); + +-- 9. ACCOUNT_POLICY_ITEM (stand‑alone if you ever need a table) +-- (optional – we store it as JSONB inside account_policy, so not created) + +-- 10. TRANSACTION +CREATE TABLE transaction ( + id SERIAL PRIMARY KEY, + created BIGINT, + updated BIGINT, + deleted BOOLEAN, + version INTEGER, + txid INTEGER NOT NULL, + source INTEGER, + destination INTEGER, + assetid INTEGER, + amount DOUBLE PRECISION, + timestamp BIGINT, + status TEXT, + memo TEXT, + tx_type TEXT, + signatures JSONB, -- array of Signature JSON objects + data JSONB NOT NULL +); +CREATE UNIQUE INDEX idx_transaction_txid ON transaction(txid); +CREATE INDEX idx_transaction_source ON transaction(source); +CREATE INDEX idx_transaction_destination ON transaction(destination); +CREATE INDEX idx_transaction_assetid ON transaction(assetid); + +-- 11. SIGNATURE +CREATE TABLE signature ( + id SERIAL PRIMARY KEY, + created BIGINT, + updated BIGINT, + deleted BOOLEAN, + version INTEGER, + signature_id INTEGER NOT NULL, + user_id INTEGER NOT NULL, + value TEXT, + objectid INTEGER, + objecttype TEXT, + status TEXT, + timestamp BIGINT, + data JSONB NOT NULL +); +CREATE INDEX idx_signature_signature_id ON signature(signature_id); +CREATE INDEX idx_signature_user_id ON signature(user_id); +CREATE INDEX idx_signature_objectid ON signature(objectid); + +-- 12. USER_KVS +CREATE TABLE user_kvs ( + id SERIAL PRIMARY KEY, + created BIGINT, + updated BIGINT, + deleted BOOLEAN, + version INTEGER, + userid INTEGER NOT NULL, + name TEXT, + data JSONB NOT NULL +); +CREATE INDEX idx_userkvs_userid ON user_kvs(userid); + +-- 13. USER_KVS_ITEM +CREATE TABLE user_kvs_item ( + id SERIAL PRIMARY KEY, + created BIGINT, + updated BIGINT, + deleted BOOLEAN, + version INTEGER, + userkvs_id INTEGER NOT NULL, + key TEXT NOT NULL, + value TEXT, + secretbox JSONB, + timestamp BIGINT, + data JSONB NOT NULL +); +CREATE INDEX idx_userkvs_item_userkvs_id ON user_kvs_item(userkvs_id); +CREATE INDEX idx_userkvs_item_key ON user_kvs_item(key); + +-- 14. USER +CREATE TABLE "user" ( + id SERIAL PRIMARY KEY, + created BIGINT, + updated BIGINT, + deleted BOOLEAN, + version INTEGER, + username TEXT NOT NULL, + pubkey TEXT NOT NULL, + email TEXT[] NOT NULL, + status TEXT, + userprofile JSONB, + kyc JSONB, + data JSONB NOT NULL +); +CREATE UNIQUE INDEX idx_user_username ON "user"(username); +CREATE UNIQUE INDEX idx_user_pubkey ON "user"(pubkey); +-- Email array index – use GIN for fast containment queries +CREATE INDEX idx_user_email ON "user" USING GIN (email); + +COMMIT; \ No newline at end of file diff --git a/specs/models_heroledger/main/money.v b/specs/models_heroledger/main/money.v index e86796d..143edb5 100644 --- a/specs/models_heroledger/main/money.v +++ b/specs/models_heroledger/main/money.v @@ -10,7 +10,7 @@ pub mut: address string // Blockchain address for this wallet @[index] balance f64 // Current balance in the wallet currency string // Currency type (e.g., "USD", "BTC", "ETH") - assetid u32 + assetid u32 @[index] last_activity u64 // Unix timestamp of last transaction administrators []u32 // List of user IDs who are super admins, they have all rights, without any treashold accountpolicy u32 // Policy for signing transactions, 0 means none @@ -21,9 +21,9 @@ pub struct Asset { core.Base pub mut: address string // Blockchain address for this asset @[index] - assetid u32 // Unique identifier for the asset (e.g., "USD", "BTC", "ETH") + assetid u32 @[index] // Unique identifier for the asset (e.g., "USD", "BTC", "ETH") asset_type string // "fiat", "crypto", "stablecoin", etc. - issuer u32 // Issuer account + issuer u32 @[index] // Issuer account supply f64 // Total circulating supply decimals u8 // Decimal precision (e.g., 2 for cents) is_frozen bool // Whether the asset is frozen globally @@ -50,7 +50,7 @@ pub mut: min_signatures u32 // Minimum number of signatures required for a transaction enabled bool // Whether clawback is enabled for this account threshold f64 // Threshold amount for triggering clawback - recipient u32 // Account ID of the recipient for clawback funds + recipient u32 @[index] // Account ID of the recipient for clawback funds } pub enum AccountStatus { @@ -65,10 +65,10 @@ pub enum AccountStatus { pub struct Transaction { core.Base pub mut: - txid u32 // Unique identifier for the transaction - source u32 - destination u32 - assetid u32 + txid u32 @[index] // Unique identifier for the transaction + source u32 @[index] + destination u32 @[index] + assetid u32 @[index] amount f64 timestamp u64 status string // pending, confirmed, failed diff --git a/specs/models_marketplace/core/base.v b/specs/models_marketplace/core/base.v new file mode 100644 index 0000000..b7f04d7 --- /dev/null +++ b/specs/models_marketplace/core/base.v @@ -0,0 +1,11 @@ +module core + +// BaseData provides common fields for all models +pub struct Base { +pub mut: + id u32 + created u64 // Unix timestamp of creation + updated u64 // Unix timestamp of last update + deleted bool + version u32 +} diff --git a/specs/models_marketplace/core/mod.v b/specs/models_marketplace/core/mod.v new file mode 100644 index 0000000..1566dd2 --- /dev/null +++ b/specs/models_marketplace/core/mod.v @@ -0,0 +1 @@ +module core diff --git a/specs/models_marketplace/main/config.v b/specs/models_marketplace/main/config.v new file mode 100644 index 0000000..361fa90 --- /dev/null +++ b/specs/models_marketplace/main/config.v @@ -0,0 +1,23 @@ +module main + +import freeflowuniverse.herolib.hero.models.marketplace.core + + +pub struct MarketplaceCurrencyConfig { +pub mut: + base_currency string + supported_currencies []string + default_display_currency string + auto_update_rates bool + update_interval_minutes u32 + fallback_rates map[string]f64 // Using f64 for Decimal +} + + +// User currency preferences +pub struct UserCurrencyPreference { +pub mut: + user_id string + preferred_currency string + updated_at u64 // Unix timestamp +} diff --git a/specs/models_marketplace/main/currency.v b/specs/models_marketplace/main/currency.v new file mode 100644 index 0000000..1c54e89 --- /dev/null +++ b/specs/models_marketplace/main/currency.v @@ -0,0 +1,64 @@ +module main + +import freeflowuniverse.herolib.hero.models.marketplace.core + +// Configurable currency support for any currency type +pub struct Currency { + core.Base +pub mut: + code string // USD, EUR, BTC, ETH, etc. + name string + symbol string + currency_type CurrencyType + exchange_rate_to_base f64 // Using f64 for Decimal + is_base_currency bool + decimal_places u8 + is_active bool +} + +pub enum CurrencyType { + fiat + cryptocurrency + token + points + custom +} + +pub struct Price { +pub mut: + base_amount f64 // Using f64 for Decimal + base_currency string + display_currency string + display_amount f64 // Using f64 for Decimal + formatted_display string + conversion_rate f64 // Using f64 for Decimal + conversion_timestamp u64 // Unix timestamp +} + +pub struct MarketplaceCurrencyConfig { +pub mut: + base_currency string + supported_currencies []string + default_display_currency string + auto_update_rates bool + update_interval_minutes u32 + fallback_rates map[string]f64 // Using f64 for Decimal +} + +// Exchange rate history for tracking changes over time +pub struct ExchangeRateHistory { +pub mut: + from_currency string + to_currency string + rate f64 // Using f64 for Decimal + timestamp u64 // Unix timestamp + provider string +} + +// User currency preferences +pub struct UserCurrencyPreference { +pub mut: + user_id string + preferred_currency string + updated_at u64 // Unix timestamp +} diff --git a/specs/models_marketplace/main/order.v b/specs/models_marketplace/main/order.v new file mode 100644 index 0000000..2bb42af --- /dev/null +++ b/specs/models_marketplace/main/order.v @@ -0,0 +1,115 @@ +module main + +import freeflowuniverse.herolib.hero.models.marketplace.core + +pub struct Order { + core.Base +pub mut: + id string + user_id string + items []OrderItem + subtotal_base f64 // Using f64 for Decimal + total_base f64 // Using f64 for Decimal + base_currency string + currency_used string + currency_total f64 // Using f64 for Decimal + conversion_rate f64 // Using f64 for Decimal + status OrderStatus + payment_method string + payment_details PaymentDetails + billing_address Address + shipping_address Address + notes string + purchase_type PurchaseType + created_at u64 // Unix timestamp + updated_at u64 // Unix timestamp +} + +pub struct OrderItem { +pub mut: + product_id string + product_name string + product_category string + quantity u32 + unit_price_base f64 // Using f64 for Decimal + total_price_base f64 // Using f64 for Decimal + specifications map[string]string // Using map[string]string for HashMap + provider_id string + provider_name string +} + +pub enum OrderStatus { + pending + confirmed + processing + deployed + completed + cancelled + refunded + failed +} + +// Purchase type to distinguish between cart-based and instant purchases +pub enum PurchaseType { + cart + instant +} + +pub struct PaymentDetails { +pub mut: + payment_id string + payment_method PaymentMethod + transaction_id string + payment_status PaymentStatus + payment_timestamp u64 // Unix timestamp + failure_reason string +} + +pub enum PaymentMethod { + credit_card // CreditCard { last_four: String, card_type: String } + bank_transfer // BankTransfer { bank_name: String, account_last_four: String } + cryptocurrency // Cryptocurrency { currency: String, wallet_address: String } + token // Token { token_type: String, wallet_address: String } + mock // Mock { method_name: String } +} + +pub struct Address { +pub mut: + street string + city string + state string + postal_code string + country string + company string +} + +// Shopping Cart Models +pub struct CartItem { +pub mut: + product_id string + quantity u32 + selected_specifications map[string]string // Using map[string]string for HashMap + added_at u64 // Unix timestamp + updated_at u64 // Unix timestamp +} + +pub struct Cart { +pub mut: + user_id string + items []CartItem + session_id string + created_at u64 // Unix timestamp + updated_at u64 // Unix timestamp +} + +// Order summary for display purposes +pub struct OrderSummary { +pub mut: + subtotal f64 // Using f64 for Decimal + tax f64 // Using f64 for Decimal + shipping f64 // Using f64 for Decimal + discount f64 // Using f64 for Decimal + total f64 // Using f64 for Decimal + currency string + item_count u32 +} diff --git a/specs/models_marketplace/main/pool.v b/specs/models_marketplace/main/pool.v new file mode 100644 index 0000000..c43159f --- /dev/null +++ b/specs/models_marketplace/main/pool.v @@ -0,0 +1,93 @@ +module main + +import freeflowuniverse.herolib.hero.models.marketplace.core + +pub struct LiquidityPool { + core.Base +pub mut: + id string + name string + token_a string + token_b string + reserve_a f64 // Using f64 for Decimal + reserve_b f64 // Using f64 for Decimal + exchange_rate f64 // Using f64 for Decimal + liquidity f64 // Using f64 for Decimal + volume_24h f64 // Using f64 for Decimal + fee_percentage f64 // Using f64 for Decimal + status PoolStatus +} + +pub enum PoolStatus { + active + paused + maintenance +} + +pub struct ExchangeRequest { +pub mut: + pool_id string + from_token string + to_token string + amount f64 // Using f64 for Decimal + min_receive f64 // Using f64 for Decimal + slippage_tolerance f64 // Using f64 for Decimal +} + +pub struct ExchangeResponse { +pub mut: + success bool + message string + transaction_id string + from_amount f64 // Using f64 for Decimal + to_amount f64 // Using f64 for Decimal + exchange_rate f64 // Using f64 for Decimal + fee f64 // Using f64 for Decimal +} + +pub struct StakeRequest { +pub mut: + amount f64 // Using f64 for Decimal + duration_months u32 +} + +pub struct StakePosition { + core.Base +pub mut: + id string + user_id string + amount f64 // Using f64 for Decimal + start_date u64 // Unix timestamp + end_date u64 // Unix timestamp + discount_percentage f64 // Using f64 for Decimal + reputation_bonus int + status StakeStatus +} + +pub enum StakeStatus { + active + completed + withdrawn +} + +// Pool analytics data +pub struct PoolAnalytics { +pub mut: + price_history []PricePoint + volume_history []VolumePoint + liquidity_distribution map[string]f64 // Using f64 for Decimal + staking_distribution map[string]int +} + +pub struct PricePoint { +pub mut: + timestamp u64 // Unix timestamp + price f64 // Using f64 for Decimal + volume f64 // Using f64 for Decimal +} + +pub struct VolumePoint { +pub mut: + date string + volume f64 // Using f64 for Decimal +} diff --git a/specs/models_marketplace/main/product.v b/specs/models_marketplace/main/product.v new file mode 100644 index 0000000..cbebdb2 --- /dev/null +++ b/specs/models_marketplace/main/product.v @@ -0,0 +1,177 @@ +module main + +import freeflowuniverse.herolib.hero.models.marketplace.core + +// Generic product structure that can represent any marketplace item +pub struct Product { + core.Base +pub mut: + id string + name string + category_id string // References ProductCategory config + description string + base_price f64 // Using f64 for Decimal + base_currency string + attributes map[string]ProductAttribute // Generic attributes + provider_id string + provider_name string + availability ProductAvailability + metadata ProductMetadata // Extensible metadata + created_at u64 // Unix timestamp + updated_at u64 // Unix timestamp +} + +// Configurable product categories +pub struct ProductCategory { +pub mut: + id string + name string + display_name string + description string + attribute_schema []AttributeDefinition // Defines allowed attributes + parent_category string + is_active bool +} + +// Generic attribute system for any product type +pub struct ProductAttribute { +pub mut: + key string + value string // Using string for serde_json::Value, consider map[string]string or specific types + attribute_type AttributeType + is_searchable bool + is_filterable bool + display_order u32 +} + +pub enum AttributeType { + text + number + slice_configuration + boolean + select // Select(Vec) + multi_select // MultiSelect(Vec) + range // Range { min: f64, max: f64 } + custom +} + +pub struct AttributeDefinition { +pub mut: + key string + name string + attribute_type AttributeType + is_required bool + is_searchable bool + is_filterable bool + validation_rules []ValidationRule +} + +pub enum ValidationRule { + min_length // MinLength(usize) + max_length // MaxLength(usize) + min_value // MinValue(f64) + max_value // MaxValue(f64) + pattern // Pattern(String) + custom +} + +pub enum ProductAvailability { + available + limited + unavailable + pre_order + custom +} + +pub struct ProductMetadata { +pub mut: + tags []string + location string + rating f32 + review_count u32 + featured bool + custom_fields map[string]string // Using map[string]string for HashMap +} + +// Support for different pricing models +pub enum PricingModel { + one_time + recurring // Recurring { interval: String } + usage_based // UsageBased { unit: String } + tiered // Tiered(Vec) + custom +} + +pub struct PriceTier { +pub mut: + min_quantity u32 + max_quantity u32 + price_per_unit f64 // Using f64 for Decimal + discount_percentage f32 +} + +// Slice configuration data structure for product attributes +pub struct SliceConfiguration { +pub mut: + cpu_cores int + memory_gb int + storage_gb int + bandwidth_mbps int + min_uptime_sla f32 + public_ips int + node_id string + slice_type SliceType + pricing SlicePricing +} + +// Enhanced pricing structure for slices with multiple time periods +pub struct SlicePricing { +pub mut: + hourly f64 // Using f64 for Decimal + daily f64 // Using f64 for Decimal + monthly f64 // Using f64 for Decimal + yearly f64 // Using f64 for Decimal +} + +pub enum SliceType { + basic + standard + premium + custom +} + +// Placeholder for SliceAllocation and SliceCombination +// These are not directly from product.rs but are referenced in user.rs +pub struct SliceAllocation { +pub mut: + slice_id string + node_id string + user_id string + allocated_cpu_cores int + allocated_memory_gb int + allocated_storage_gb int + allocated_bandwidth_mbps int + start_time u64 + end_time u64 +} + +pub struct SliceCombination { +pub mut: + cpu_cores int + memory_gb int + storage_gb int + bandwidth_mbps int + price_per_hour f64 +} + +// Placeholder for DefaultSliceFormat +// This is not directly from product.rs but is referenced in user.rs +pub struct DefaultSliceFormat { +pub mut: + name string + cpu_cores int + memory_gb int + storage_gb int + bandwidth_mbps int + price_per_hour f64 +} diff --git a/specs/models_marketplace/main/user.v b/specs/models_marketplace/main/user.v new file mode 100644 index 0000000..3126dc3 --- /dev/null +++ b/specs/models_marketplace/main/user.v @@ -0,0 +1,730 @@ +module main + +import freeflowuniverse.herolib.hero.models.marketplace.core + +// Represents a user in the system +pub struct User { + core.Base +pub mut: + id u32 // Unique identifier for the user, using u32 for consistency with VLang + name string // User's full name + email string // User's email address + role UserRole // User's role in the system + country string // User's country + timezone string // User's timezone + created_at u64 // Unix timestamp of creation + updated_at u64 // Unix timestamp of last update + mock_data MockUserData // Mock data for dashboard +} + +// Represents the possible roles a user can have +pub enum UserRole { + user + admin +} + +// Represents user login credentials +pub struct LoginCredentials { +pub mut: + email string + password string +} + +// Represents user registration data +pub struct RegistrationData { +pub mut: + name string + email string + password string + password_confirmation string +} + +// Mock user data for testing +pub struct MockUserData { +pub mut: + active_deployments int + active_slices int + current_cost int + balance int + wallet_balance_usd f64 // Using f64 for Decimal, consider string for high precision + owned_product_ids []string + active_rentals []string + transaction_history []Transaction + resource_utilization ResourceUtilization + usd_usage_trend []int + user_activity UserActivityStats + recent_activities []RecentActivity + deployment_distribution DeploymentDistribution + farmer_data FarmerData // Farmer-specific data + app_provider_data AppProviderData // App Provider-specific data + service_provider_data ServiceProviderData // Service Provider-specific data + customer_service_data CustomerServiceData // Customer Service-specific data +} + +pub struct ResourceUtilization { +pub mut: + cpu int + memory int + storage int + network int +} + +pub struct UserActivityStats { +pub mut: + deployments []int + resource_reservations []int +} + +pub struct RecentActivity { +pub mut: + date string + action string + status string + details string +} + +pub struct DeploymentDistribution { +pub mut: + regions []RegionDeployments +} + +pub struct RegionDeployments { +pub mut: + region string + nodes int + slices int + apps int + gateways int +} + +// Farmer-specific data +pub struct FarmerData { +pub mut: + total_nodes int + online_nodes int + total_capacity NodeCapacity + used_capacity NodeCapacity + monthly_earnings_usd int + total_earnings_usd int + uptime_percentage f32 + nodes []FarmNode + earnings_history []EarningsRecord + slice_templates []Product + active_slices int +} + +pub struct NodeCapacity { +pub mut: + cpu_cores int + memory_gb int + storage_gb int + bandwidth_mbps int + ssd_storage_gb int + hdd_storage_gb int +} + +// Enhanced Node structure for farmer dashboard with modern types +pub struct FarmNode { +pub mut: + id string + name string + location string + status NodeStatus + capacity NodeCapacity + used_capacity NodeCapacity + uptime_percentage f32 + earnings_today_usd f64 // Using f64 for Decimal + last_seen u64 // Unix timestamp + health_score f32 + region string + node_type string + slice_formats []string + rental_options NodeRentalOptions + availability_status NodeAvailabilityStatus + grid_node_id u32 + grid_data GridNodeData + node_group_id string + group_assignment_date u64 // Unix timestamp + group_slice_format string + group_slice_price f64 // Using f64 for Decimal + staking_options NodeStakingOptions + marketplace_sla MarketplaceSLA + total_base_slices u32 + allocated_base_slices u32 + slice_allocations []SliceAllocation // Assuming SliceAllocation is defined elsewhere or will be translated + available_combinations []SliceCombination // Assuming SliceCombination is defined elsewhere or will be translated + slice_pricing SlicePricing // Assuming SlicePricing is defined elsewhere or will be translated + slice_last_calculated u64 // Unix timestamp +} + +pub struct EarningsRecord { +pub mut: + date string + amount int + source string +} + +pub enum NodeStatus { + online + offline + maintenance + error + standby +} + +pub struct FarmerSettings { +pub mut: + auto_accept_deployments bool + maintenance_window string + notification_preferences NotificationSettings + minimum_deployment_duration int + preferred_regions []string + default_slice_customizations map[string]DefaultSliceFormat // Assuming DefaultSliceFormat is defined elsewhere or will be translated +} + +pub struct NotificationSettings { +pub mut: + email_enabled bool + sms_enabled bool + push bool + node_offline_alerts bool + earnings_reports bool + maintenance_reminders bool +} + +// Marketplace SLA configuration - what the farmer promises to customers +pub struct MarketplaceSLA { +pub mut: + uptime_guarantee_percentage f32 + bandwidth_guarantee_mbps int + base_slice_price f64 // Using f64 for Decimal + last_updated u64 // Unix timestamp +} + +// Node rental options that farmers can configure +pub struct NodeRentalOptions { +pub mut: + slice_rental_enabled bool + full_node_rental_enabled bool + full_node_pricing FullNodePricing + minimum_rental_days u32 + maximum_rental_days u32 + auto_renewal_enabled bool +} + +// Node staking options that farmers can configure +pub struct NodeStakingOptions { +pub mut: + staking_enabled bool + staked_amount f64 // Using f64 for Decimal + staking_start_date u64 // Unix timestamp + staking_period_months u32 + early_withdrawal_allowed bool + early_withdrawal_penalty_percent f32 +} + +// Full node rental pricing configuration with auto-calculation support +pub struct FullNodePricing { +pub mut: + hourly f64 // Using f64 for Decimal + daily f64 // Using f64 for Decimal + monthly f64 // Using f64 for Decimal + yearly f64 // Using f64 for Decimal + auto_calculate bool + daily_discount_percent f32 + monthly_discount_percent f32 + yearly_discount_percent f32 +} + +// Node availability status for rental management +pub enum NodeAvailabilityStatus { + available + partially_rented + fully_rented + unavailable + reserved +} + +// Individual node rental record +pub struct NodeRental { +pub mut: + id string + node_id string + renter_email string + rental_type NodeRentalType + monthly_cost f64 // Using f64 for Decimal + start_date u64 // Unix timestamp + end_date u64 // Unix timestamp + status NodeRentalStatus + auto_renewal bool + payment_method string + metadata map[string]string // Using map[string]string for HashMap +} + +// Type of node rental +pub enum NodeRentalType { + slice // Slice { slice_ids: Vec, total_cpu_cores: u32, total_memory_gb: u32, total_storage_gb: u32 } + full_node +} + +// Status of a node rental +pub enum NodeRentalStatus { + active + pending + expired + cancelled + suspended +} + +// Farmer earnings from node rentals +pub struct FarmerRentalEarning { +pub mut: + id string + node_id string + rental_id string + renter_email string + amount f64 // Using f64 for Decimal + currency string + earning_date u64 // Unix timestamp + rental_type NodeRentalType + payment_status PaymentStatus +} + +pub enum PaymentStatus { + pending + completed + failed + refunded +} + +// User Activity Tracking +pub struct UserActivity { +pub mut: + id string + activity_type ActivityType + description string + timestamp u64 // Unix timestamp + metadata map[string]string // Using map[string]string for HashMap + category string + importance ActivityImportance +} + +pub enum ActivityType { + login + purchase + deployment + service_created + app_published + node_added + node_updated + wallet_transaction + profile_update + settings_change + marketplace_view + slice_created + slice_allocated + slice_released + slice_rental_started + slice_rental_stopped + slice_rental_restarted + slice_rental_cancelled +} + +pub enum ActivityImportance { + low + medium + high + critical +} + +// Enhanced User Statistics +pub struct UsageStatistics { +pub mut: + total_deployments int + active_services int + total_spent f64 // Using f64 for Decimal + favorite_categories []string + usage_trends []UsageTrend + login_frequency f32 + preferred_regions []string + account_age_days int + last_activity u64 // Unix timestamp +} + +pub struct UsageTrend { +pub mut: + period string + metric string + value f32 + change_percentage f32 +} + +pub struct UserPreferences { +pub mut: + preferred_currency string + preferred_language string + timezone string + dashboard_layout string + notification_settings NotificationSettings + privacy_settings PrivacySettings + theme string + last_payment_method string +} + +pub struct PrivacySettings { +pub mut: + profile_visibility string + activity_tracking bool + marketing_emails bool + data_sharing bool +} + +// ThreeFold Grid Node Data fetched from gridproxy/graphql +pub struct GridNodeData { +pub mut: + grid_node_id u32 + city string + country string + farm_name string + farm_id u32 + public_ips u32 + total_resources NodeCapacity + used_resources NodeCapacity + certification_type string + farming_policy_id u32 + last_updated u64 // Unix timestamp +} + +// Node Group for managing multiple nodes together +pub struct NodeGroup { + core.Base +pub mut: + id string + name string + description string + group_type NodeGroupType + node_ids []string + group_config NodeGroupConfig + created_at u64 // Unix timestamp + updated_at u64 // Unix timestamp +} + +// Type of node group - default or custom +pub enum NodeGroupType { + default_compute + default_storage + default_ai_gpu + custom +} + +// Configuration for node groups +pub struct NodeGroupConfig { +pub mut: + preferred_slice_formats []string + default_pricing map[string]f64 // Using f64 for Decimal + resource_optimization ResourceOptimization + auto_scaling bool +} + +// Resource optimization settings for groups +pub enum ResourceOptimization { + balanced + performance + efficiency + custom +} + +// Statistics for a node group +pub struct GroupStatistics { +pub mut: + group_id string + total_nodes int + online_nodes int + total_capacity NodeCapacity + average_uptime f32 + group_type NodeGroupType +} + +// Enhanced User Dashboard Data +pub struct UserDashboardData { +pub mut: + user_info UserInfo + recent_activities []UserActivity + usage_statistics UsageStatistics + active_services []Service // Assuming Service is defined elsewhere or will be translated + active_deployments int + wallet_summary WalletSummary + recommendations []Recommendation + quick_actions []QuickAction +} + +pub struct UserInfo { +pub mut: + name string + email string + member_since string + account_type string + verification_status string +} + +pub struct WalletSummary { +pub mut: + balance f64 // Using f64 for Decimal + currency string + recent_transactions int + pending_transactions int +} + +pub struct Recommendation { +pub mut: + id string + title string + description string + action_url string + priority string + category string +} + +pub struct QuickAction { +pub mut: + id string + title string + description string + action_url string + icon string + enabled bool +} + +// App Provider-specific data +pub struct AppProviderData { +pub mut: + published_apps int + total_deployments int + active_deployments int + monthly_revenue_usd int + total_revenue_usd int + apps []PublishedApp + deployment_stats []DeploymentStat + revenue_history []RevenueRecord +} + +pub struct PublishedApp { +pub mut: + id string + name string + category string + version string + status string + deployments int + rating f32 + monthly_revenue_usd int + last_updated string + auto_healing bool +} + +pub struct DeploymentStat { +pub mut: + app_name string + region string + instances int + status string + resource_usage ResourceUtilization + customer_name string + deployed_date string + deployment_id string + auto_healing bool +} + +pub struct RevenueRecord { +pub mut: + date string + amount int + app_name string +} + +// Service Provider-specific data +pub struct ServiceProviderData { +pub mut: + active_services int + total_clients int + monthly_revenue_usd int + total_revenue_usd int + service_rating f32 + services []Service + client_requests []ServiceRequest + revenue_history []RevenueRecord +} + +pub struct Service { +pub mut: + id string + name string + category string + description string + price_per_hour_usd int + status string + clients int + rating f32 + total_hours int +} + +pub struct ServiceRequest { +pub mut: + id string + client_name string + service_name string + status string + requested_date string + estimated_hours int + budget int + priority string + progress int + completed_date string + client_email string + client_phone string + description string + created_date string +} + +// Service booking record for customers who purchase services +pub struct ServiceBooking { +pub mut: + id string + service_id string + service_name string + provider_email string + customer_email string + budget int + estimated_hours int + status string + requested_date string + priority string + description string + booking_date string + client_phone string + progress int + completed_date string +} + +// Customer Service-specific data (for users who book services) +pub struct CustomerServiceData { +pub mut: + active_bookings int + completed_bookings int + total_spent int + monthly_spending int + average_rating_given f32 + service_bookings []ServiceBooking + favorite_providers []string + spending_history []SpendingRecord +} + +pub struct SpendingRecord { +pub mut: + date string + amount int + service_name string + provider_name string +} + +// Transaction record for wallet operations +pub struct Transaction { +pub mut: + id string + user_id string + transaction_type TransactionType + amount f64 // Using f64 for Decimal + timestamp u64 // Unix timestamp + status TransactionStatus +} + +// Types of transactions +pub enum TransactionType { + purchase + rental + transfer + earning + instant_purchase + exchange + stake + unstake + auto_top_up + credits_purchase + credits_sale + credits_transfer +} + +// Transaction status +pub enum TransactionStatus { + pending + completed + failed + cancelled +} + +// Rental record +pub struct Rental { +pub mut: + id string + user_id string + product_id string + start_date u64 // Unix timestamp + end_date u64 // Unix timestamp + status RentalStatus + monthly_cost f64 // Using f64 for Decimal +} + +// Rental status +pub enum RentalStatus { + active + expired + cancelled + pending +} + +// User deployment information for dashboard +pub struct UserDeployment { +pub mut: + id string + app_name string + status DeploymentStatus + cost_per_month f64 // Using f64 for Decimal + deployed_at u64 // Unix timestamp + provider string + region string + resource_usage ResourceUtilization +} + +// Deployment status enum +pub enum DeploymentStatus { + active + pending + stopped + error + maintenance +} + +// Comprehensive user metrics for dashboard +pub struct UserMetrics { +pub mut: + total_spent_this_month f64 // Using f64 for Decimal + active_deployments_count int + resource_utilization ResourceUtilization + cost_trend []int + wallet_balance f64 // Using f64 for Decimal + total_transactions int +} + +// User compute resource for dashboard display +pub struct UserComputeResource { +pub mut: + id string + resource_type string + specs string + location string + status string + sla string + monthly_cost f64 // Using f64 for Decimal + provider string + resource_usage ResourceUtilization +} diff --git a/specs/models_marketplace/mod.v b/specs/models_marketplace/mod.v new file mode 100644 index 0000000..a2cb557 --- /dev/null +++ b/specs/models_marketplace/mod.v @@ -0,0 +1,4 @@ +module models_marketplace + +import models_marketplace.core +import models_marketplace.main diff --git a/specs/models_threefold/aiinstruct.md b/specs/models_threefold/aiinstruct.md new file mode 100644 index 0000000..4075370 --- /dev/null +++ b/specs/models_threefold/aiinstruct.md @@ -0,0 +1,7 @@ +make SQL script to populate DB + +only models with base class are put in tables + +the data itself is in data field + +the fields marked with @index go as separate fields in tables \ No newline at end of file diff --git a/specs/models_threefold/core b/specs/models_threefold/core new file mode 120000 index 0000000..6f98b7c --- /dev/null +++ b/specs/models_threefold/core @@ -0,0 +1 @@ +../models_heroledger/core \ No newline at end of file diff --git a/specs/models_threefold/main/secretbox.v b/specs/models_threefold/main/secretbox.v new file mode 100644 index 0000000..9f23887 --- /dev/null +++ b/specs/models_threefold/main/secretbox.v @@ -0,0 +1,31 @@ +module main + +pub struct SecretBox { +pub mut: + notary_id u32 // person who is allowed to decrypt this info + value string //the actual incrypted value + version u16 //version of the schema used to encrypt this value + timestamp u64 + cat SecretBoxCategory //category of the secret box, e.g. profile +} + +pub enum SecretBoxCategory { + profile +} + +pub struct Notary { + core.Base +pub mut: + userid u32 // Reference to the user entity @[index] + status NotaryStatus // Current user status + myceliumaddress string // Mycelium address of the notary + pubkey string // Public key for cryptographic operations @[index] +} + +pub enum NotaryStatus { + active + inactive + suspended + archived + error +} diff --git a/specs/models_threefold/main/signature.v b/specs/models_threefold/main/signature.v new file mode 100644 index 0000000..7eb627b --- /dev/null +++ b/specs/models_threefold/main/signature.v @@ -0,0 +1,32 @@ +module circle + +import freeflowuniverse.herolib.hero.models.core + +// Wallet represents a wallet associated with a circle for financial operations +pub struct Signature { + core.Base +pub mut: + signature_id u32 // Reference to the user who created the signature @[index] + user_id u32 // Reference to the user who created the signature @[index] + value string // The actual signature value + objectid u32 // Reference to the user who created the signature @[index] + objecttype ObjectType // Type of object being signed (e.g., + status SignatureStatus + timestamp u64 +} + +pub enum SignatureStatus { + active + inactive + pending + revoked +} + +pub enum ObjectType { + account + dnsrecord + membership + user + transaction + kyc +} \ No newline at end of file diff --git a/specs/models_threefold/main/user.v b/specs/models_threefold/main/user.v new file mode 100644 index 0000000..1dcd811 --- /dev/null +++ b/specs/models_threefold/main/user.v @@ -0,0 +1,29 @@ +module circle + +import freeflowuniverse.herolib.hero.models.core + +//is a user in the system, most of info is in models_heroledger + + +pub struct User { + core.Base +pub mut: + username string // Unique username for the user @[index] + pubkey string // Public key for cryptographic operations @[index] + status UserStatus // Current user status + kyc KYCStatus // Know Your Customer status + } + + +pub enum UserStatus { + active + inactive + suspended + archived +} + +pub enum KYCStatus { + pending + approved + rejected +} \ No newline at end of file diff --git a/specs/models_threefold/main/user_kvs.v b/specs/models_threefold/main/user_kvs.v new file mode 100644 index 0000000..7c072ed --- /dev/null +++ b/specs/models_threefold/main/user_kvs.v @@ -0,0 +1,22 @@ +module circle + +import freeflowuniverse.herolib.hero.models.core + +//a per user db +pub struct UserKVS { + core.Base +pub mut: + userid u32 // Reference to the user entity @[index] + name string // Name of the key-value store + } + +pub struct UserKVSItem { + core.Base +pub mut: + userkvs_id u32 // Reference to the user entity @[index] + key string + value string // Value associated with the key + secretbox []SecretBox // Optional secret boxes for sensitive data + timestamp u64 // Timestamp when the item was created or last updated + } +