cargo fix & fix heroledger

This commit is contained in:
Timur Gordon
2025-08-21 14:15:29 +02:00
parent 130822b69b
commit ce12f26a91
26 changed files with 173 additions and 153 deletions

View File

@@ -53,10 +53,10 @@ path = "examples/finance_example/main.rs"
name = "flow_example" name = "flow_example"
path = "examples/flow_example.rs" path = "examples/flow_example.rs"
[[example]] # [[example]]
name = "biz_rhai" # name = "biz_rhai"
path = "examples/biz_rhai/example.rs" # path = "examples/biz_rhai/example.rs"
required-features = ["rhai"] # required-features = ["rhai"]
[[example]] [[example]]
name = "postgres_model_example" name = "postgres_model_example"

View File

@@ -1,7 +1,7 @@
use circles_launcher::{new_launcher}; use circles_launcher::new_launcher;
use heromodels::models::circle::circle::{new_circle}; use heromodels::models::circle::circle::new_circle;
use secp256k1::{Secp256k1, SecretKey, PublicKey};
use rand::rngs::OsRng; use rand::rngs::OsRng;
use secp256k1::{PublicKey, Secp256k1, SecretKey};
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {

View File

@@ -1,6 +1,6 @@
use heromodels::models::heroledger::rhai::register_heroledger_rhai_modules;
use heromodels_core::db::hero::OurDB; use heromodels_core::db::hero::OurDB;
use rhai::{Dynamic, Engine}; use rhai::{Dynamic, Engine};
use heromodels::models::heroledger::rhai::register_heroledger_rhai_modules;
use std::sync::Arc; use std::sync::Arc;
use std::{fs, path::Path}; use std::{fs, path::Path};

View File

@@ -43,7 +43,9 @@ fn main() {
// Clean up any existing data to ensure consistent results // Clean up any existing data to ensure consistent results
println!("Cleaning up existing data..."); println!("Cleaning up existing data...");
let user_collection = db.collection::<User>().expect("can open user collection"); let user_collection = db.collection::<User>().expect("can open user collection");
let comment_collection = db.collection::<Comment>().expect("can open comment collection"); let comment_collection = db
.collection::<Comment>()
.expect("can open comment collection");
// Clear all existing users and comments // Clear all existing users and comments
if let Ok(existing_users) = user_collection.get_all() { if let Ok(existing_users) = user_collection.get_all() {

View File

@@ -8,8 +8,8 @@ use std::{
collections::HashSet, collections::HashSet,
path::PathBuf, path::PathBuf,
sync::{ sync::{
atomic::{AtomicU32, Ordering},
Arc, Mutex, Arc, Mutex,
atomic::{AtomicU32, Ordering},
}, },
}; };

View File

@@ -1,16 +1,17 @@
use crate::db::Db; use crate::db::Db;
use rhailib_macros::{
register_authorized_create_by_id_fn, register_authorized_delete_by_id_fn, register_authorized_get_by_id_fn,
};
use rhai::plugin::*; use rhai::plugin::*;
use rhai::{Array, Dynamic, Engine, EvalAltResult, Map, Module}; use rhai::{Array, Dynamic, Engine, EvalAltResult, Map, Module};
use rhailib_macros::{
register_authorized_create_by_id_fn, register_authorized_delete_by_id_fn,
register_authorized_get_by_id_fn,
};
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use crate::models::circle::Circle; use crate::models::circle::Circle;
type RhaiCircle = Circle; type RhaiCircle = Circle;
use crate::db::hero::OurDB;
use crate::db::Collection; use crate::db::Collection;
use crate::db::hero::OurDB;
use crate::models::circle::ThemeData; use crate::models::circle::ThemeData;
#[export_module] #[export_module]

View File

@@ -1,16 +1,6 @@
pub mod node; pub mod node;
pub use node::{ pub use node::{
Node, CPUDevice, ComputeSlice, DeviceInfo, GPUDevice, MemoryDevice, NetworkDevice, Node,
DeviceInfo, NodeCapacity, PricingPolicy, SLAPolicy, StorageDevice, StorageSlice,
StorageDevice,
MemoryDevice,
CPUDevice,
GPUDevice,
NetworkDevice,
NodeCapacity,
ComputeSlice,
StorageSlice,
PricingPolicy,
SLAPolicy,
}; };

View File

@@ -1,6 +1,6 @@
use heromodels_core::BaseModelData; use heromodels_core::BaseModelData;
use heromodels_derive::model; use heromodels_derive::model;
use rhai::CustomType; use rhai::{CustomType, TypeBuilder};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// Storage device information /// Storage device information
@@ -160,19 +160,58 @@ impl ComputeSlice {
} }
} }
pub fn nodeid(mut self, nodeid: u32) -> Self { self.nodeid = nodeid; self } pub fn nodeid(mut self, nodeid: u32) -> Self {
pub fn slice_id(mut self, id: i32) -> Self { self.id = id; self } self.nodeid = nodeid;
pub fn mem_gb(mut self, v: f64) -> Self { self.mem_gb = v; self } self
pub fn storage_gb(mut self, v: f64) -> Self { self.storage_gb = v; self } }
pub fn passmark(mut self, v: i32) -> Self { self.passmark = v; self } pub fn slice_id(mut self, id: i32) -> Self {
pub fn vcores(mut self, v: i32) -> Self { self.vcores = v; self } self.id = id;
pub fn cpu_oversubscription(mut self, v: i32) -> Self { self.cpu_oversubscription = v; self } self
pub fn storage_oversubscription(mut self, v: i32) -> Self { self.storage_oversubscription = v; self } }
pub fn price_range(mut self, min_max: Vec<f64>) -> Self { self.price_range = min_max; self } pub fn mem_gb(mut self, v: f64) -> Self {
pub fn gpus(mut self, v: u8) -> Self { self.gpus = v; self } self.mem_gb = v;
pub fn price_cc(mut self, v: f64) -> Self { self.price_cc = v; self } self
pub fn pricing_policy(mut self, p: PricingPolicy) -> Self { self.pricing_policy = p; self } }
pub fn sla_policy(mut self, p: SLAPolicy) -> Self { self.sla_policy = p; self } pub fn storage_gb(mut self, v: f64) -> Self {
self.storage_gb = v;
self
}
pub fn passmark(mut self, v: i32) -> Self {
self.passmark = v;
self
}
pub fn vcores(mut self, v: i32) -> Self {
self.vcores = v;
self
}
pub fn cpu_oversubscription(mut self, v: i32) -> Self {
self.cpu_oversubscription = v;
self
}
pub fn storage_oversubscription(mut self, v: i32) -> Self {
self.storage_oversubscription = v;
self
}
pub fn price_range(mut self, min_max: Vec<f64>) -> Self {
self.price_range = min_max;
self
}
pub fn gpus(mut self, v: u8) -> Self {
self.gpus = v;
self
}
pub fn price_cc(mut self, v: f64) -> Self {
self.price_cc = v;
self
}
pub fn pricing_policy(mut self, p: PricingPolicy) -> Self {
self.pricing_policy = p;
self
}
pub fn sla_policy(mut self, p: SLAPolicy) -> Self {
self.sla_policy = p;
self
}
} }
/// Storage slice (typically 1GB of storage) /// Storage slice (typically 1GB of storage)
@@ -204,11 +243,26 @@ impl StorageSlice {
} }
} }
pub fn nodeid(mut self, nodeid: u32) -> Self { self.nodeid = nodeid; self } pub fn nodeid(mut self, nodeid: u32) -> Self {
pub fn slice_id(mut self, id: i32) -> Self { self.id = id; self } self.nodeid = nodeid;
pub fn price_cc(mut self, v: f64) -> Self { self.price_cc = v; self } self
pub fn pricing_policy(mut self, p: PricingPolicy) -> Self { self.pricing_policy = p; self } }
pub fn sla_policy(mut self, p: SLAPolicy) -> Self { self.sla_policy = p; self } pub fn slice_id(mut self, id: i32) -> Self {
self.id = id;
self
}
pub fn price_cc(mut self, v: f64) -> Self {
self.price_cc = v;
self
}
pub fn pricing_policy(mut self, p: PricingPolicy) -> Self {
self.pricing_policy = p;
self
}
pub fn sla_policy(mut self, p: SLAPolicy) -> Self {
self.sla_policy = p;
self
}
} }
/// Grid4 Node model /// Grid4 Node model
@@ -248,17 +302,41 @@ impl Node {
} }
} }
pub fn nodegroupid(mut self, v: i32) -> Self { self.nodegroupid = v; self } pub fn nodegroupid(mut self, v: i32) -> Self {
pub fn uptime(mut self, v: i32) -> Self { self.uptime = v; self } self.nodegroupid = v;
pub fn add_compute_slice(mut self, s: ComputeSlice) -> Self { self.computeslices.push(s); self } self
pub fn add_storage_slice(mut self, s: StorageSlice) -> Self { self.storageslices.push(s); self } }
pub fn devices(mut self, d: DeviceInfo) -> Self { self.devices = d; self } pub fn uptime(mut self, v: i32) -> Self {
pub fn country(mut self, c: impl ToString) -> Self { self.country = c.to_string(); self } self.uptime = v;
pub fn capacity(mut self, c: NodeCapacity) -> Self { self.capacity = c; self } self
pub fn provisiontime(mut self, t: u32) -> Self { self.provisiontime = t; self } }
pub fn add_compute_slice(mut self, s: ComputeSlice) -> Self {
self.computeslices.push(s);
self
}
pub fn add_storage_slice(mut self, s: StorageSlice) -> Self {
self.storageslices.push(s);
self
}
pub fn devices(mut self, d: DeviceInfo) -> Self {
self.devices = d;
self
}
pub fn country(mut self, c: impl ToString) -> Self {
self.country = c.to_string();
self
}
pub fn capacity(mut self, c: NodeCapacity) -> Self {
self.capacity = c;
self
}
pub fn provisiontime(mut self, t: u32) -> Self {
self.provisiontime = t;
self
}
/// Placeholder for capacity recalculation out of the devices on the Node /// Placeholder for capacity recalculation out of the devices on the Node
pub fn recalc_capacity(mut self) -> Self { pub fn recalc_capacity(self) -> Self {
// TODO: calculate NodeCapacity out of the devices on the Node // TODO: calculate NodeCapacity out of the devices on the Node
self self
} }

View File

@@ -1,4 +1,4 @@
use heromodels_core::{Model, BaseModelData, IndexKey}; use heromodels_core::{BaseModelData, IndexKey, Model};
use heromodels_derive::model; use heromodels_derive::model;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
@@ -297,5 +297,3 @@ impl DNSZone {
self self
} }
} }

View File

@@ -1,4 +1,4 @@
use heromodels_core::{Model, BaseModelData, IndexKey}; use heromodels_core::{BaseModelData, IndexKey, Model};
use heromodels_derive::model; use heromodels_derive::model;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -184,8 +184,6 @@ impl Group {
} }
} }
/// Represents the membership relationship between users and groups /// Represents the membership relationship between users and groups
#[model] #[model]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
@@ -232,5 +230,3 @@ impl UserGroupMembership {
self self
} }
} }

View File

@@ -1,4 +1,4 @@
use heromodels_core::{Model, BaseModelData, IndexKey}; use heromodels_core::{BaseModelData, IndexKey, Model};
use heromodels_derive::model; use heromodels_derive::model;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -111,5 +111,3 @@ impl Member {
self self
} }
} }

View File

@@ -1,20 +1,10 @@
// Export all heroledger model modules // Export all heroledger model modules
pub mod user;
pub mod group;
pub mod money;
pub mod membership;
pub mod dnsrecord; pub mod dnsrecord;
pub mod group;
pub mod membership;
pub mod money;
pub mod rhai;
pub mod secretbox; pub mod secretbox;
pub mod signature; pub mod signature;
pub mod user;
pub mod user_kvs; pub mod user_kvs;
pub mod rhai;
// Re-export key types for convenience
pub use user::{User, UserStatus, UserProfile, KYCInfo, KYCStatus, SecretBox};
pub use group::{Group, UserGroupMembership, GroupStatus, Visibility, GroupConfig};
pub use money::{Account, Asset, AccountPolicy, AccountPolicyItem, Transaction, AccountStatus, TransactionType, Signature as TransactionSignature};
pub use membership::{Member, MemberRole, MemberStatus};
pub use dnsrecord::{DNSZone, DNSRecord, SOARecord, NameType, NameCat, DNSZoneStatus};
pub use secretbox::{Notary, NotaryStatus, SecretBoxCategory};
pub use signature::{Signature, SignatureStatus, ObjectType};
pub use user_kvs::{UserKVS, UserKVSItem};

View File

@@ -1,4 +1,4 @@
use heromodels_core::{Model, BaseModelData, IndexKey}; use heromodels_core::{BaseModelData, IndexKey, Model};
use heromodels_derive::model; use heromodels_derive::model;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
@@ -223,8 +223,6 @@ impl Account {
} }
} }
/// Represents an asset in the financial system /// Represents an asset in the financial system
#[model] #[model]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
@@ -342,8 +340,6 @@ impl Asset {
} }
} }
/// Represents account policies for various operations /// Represents account policies for various operations
#[model] #[model]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
@@ -400,8 +396,6 @@ impl AccountPolicy {
} }
} }
/// Represents a financial transaction /// Represents a financial transaction
#[model] #[model]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
@@ -511,5 +505,3 @@ impl Transaction {
self self
} }
} }

View File

@@ -1,8 +1,13 @@
use ::rhai::plugin::*; use ::rhai::plugin::*;
use ::rhai::{Array, Dynamic, Engine, EvalAltResult, Map, Module}; use ::rhai::{Dynamic, Engine, EvalAltResult, Module};
use std::mem; use std::mem;
use crate::models::heroledger::*; use crate::models::heroledger::{
dnsrecord::DNSZone,
group::{Group, Visibility},
money::Account,
user::{User, UserStatus},
};
// ============================================================================ // ============================================================================
// User Module // User Module
@@ -12,6 +17,8 @@ type RhaiUser = User;
#[export_module] #[export_module]
mod rhai_user_module { mod rhai_user_module {
use crate::models::heroledger::user::User;
use super::RhaiUser; use super::RhaiUser;
#[rhai_fn(name = "new_user", return_raw)] #[rhai_fn(name = "new_user", return_raw)]
@@ -30,30 +37,21 @@ mod rhai_user_module {
} }
#[rhai_fn(name = "add_email", return_raw)] #[rhai_fn(name = "add_email", return_raw)]
pub fn add_email( pub fn add_email(user: &mut RhaiUser, email: String) -> Result<RhaiUser, Box<EvalAltResult>> {
user: &mut RhaiUser,
email: String,
) -> Result<RhaiUser, Box<EvalAltResult>> {
let owned = std::mem::take(user); let owned = std::mem::take(user);
*user = owned.add_email(email); *user = owned.add_email(email);
Ok(user.clone()) Ok(user.clone())
} }
#[rhai_fn(name = "pubkey", return_raw)] #[rhai_fn(name = "pubkey", return_raw)]
pub fn set_pubkey( pub fn set_pubkey(user: &mut RhaiUser, pubkey: String) -> Result<RhaiUser, Box<EvalAltResult>> {
user: &mut RhaiUser,
pubkey: String,
) -> Result<RhaiUser, Box<EvalAltResult>> {
let owned = std::mem::take(user); let owned = std::mem::take(user);
*user = owned.pubkey(pubkey); *user = owned.pubkey(pubkey);
Ok(user.clone()) Ok(user.clone())
} }
#[rhai_fn(name = "status", return_raw)] #[rhai_fn(name = "status", return_raw)]
pub fn set_status( pub fn set_status(user: &mut RhaiUser, status: String) -> Result<RhaiUser, Box<EvalAltResult>> {
user: &mut RhaiUser,
status: String,
) -> Result<RhaiUser, Box<EvalAltResult>> {
let status_enum = match status.as_str() { let status_enum = match status.as_str() {
"Active" => UserStatus::Active, "Active" => UserStatus::Active,
"Inactive" => UserStatus::Inactive, "Inactive" => UserStatus::Inactive,
@@ -115,10 +113,7 @@ mod rhai_group_module {
} }
#[rhai_fn(name = "name", return_raw)] #[rhai_fn(name = "name", return_raw)]
pub fn set_name( pub fn set_name(group: &mut RhaiGroup, name: String) -> Result<RhaiGroup, Box<EvalAltResult>> {
group: &mut RhaiGroup,
name: String,
) -> Result<RhaiGroup, Box<EvalAltResult>> {
let owned = std::mem::take(group); let owned = std::mem::take(group);
*group = owned.name(name); *group = owned.name(name);
Ok(group.clone()) Ok(group.clone())
@@ -263,15 +258,11 @@ mod rhai_dns_zone_module {
Ok(zone.clone()) Ok(zone.clone())
} }
#[rhai_fn(name = "save_dns_zone", return_raw)] #[rhai_fn(name = "save_dns_zone", return_raw)]
pub fn save_dns_zone(zone: &mut RhaiDNSZone) -> Result<RhaiDNSZone, Box<EvalAltResult>> { pub fn save_dns_zone(zone: &mut RhaiDNSZone) -> Result<RhaiDNSZone, Box<EvalAltResult>> {
Ok(zone.clone()) Ok(zone.clone())
} }
// Getters // Getters
#[rhai_fn(name = "get_id")] #[rhai_fn(name = "get_id")]
pub fn get_id(zone: &mut RhaiDNSZone) -> i64 { pub fn get_id(zone: &mut RhaiDNSZone) -> i64 {

View File

@@ -1,4 +1,4 @@
use heromodels_core::{Model, BaseModelData, IndexKey}; use heromodels_core::{BaseModelData, IndexKey, Model};
use heromodels_derive::model; use heromodels_derive::model;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -138,5 +138,3 @@ impl Notary {
self self
} }
} }

View File

@@ -1,4 +1,4 @@
use heromodels_core::{Model, BaseModelData, IndexKey}; use heromodels_core::{BaseModelData, IndexKey, Model};
use heromodels_derive::model; use heromodels_derive::model;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -116,5 +116,3 @@ impl Signature {
self self
} }
} }

View File

@@ -1,4 +1,4 @@
use heromodels_core::{Model, BaseModelData, IndexKey}; use heromodels_core::{BaseModelData, IndexKey, Model};
use heromodels_derive::model; use heromodels_derive::model;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
@@ -366,5 +366,3 @@ impl User {
self self
} }
} }

View File

@@ -1,7 +1,7 @@
use heromodels_core::{Model, BaseModelData, IndexKey}; use super::secretbox::SecretBox;
use heromodels_core::{BaseModelData, IndexKey, Model};
use heromodels_derive::model; use heromodels_derive::model;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::secretbox::SecretBox;
/// Represents a per-user key-value store /// Represents a per-user key-value store
#[model] #[model]
@@ -44,8 +44,6 @@ impl UserKVS {
} }
} }
/// Represents an item in a user's key-value store /// Represents an item in a user's key-value store
#[model] #[model]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
@@ -116,5 +114,3 @@ impl UserKVSItem {
self self
} }
} }

View File

@@ -10,16 +10,16 @@ pub mod contact;
pub mod finance; pub mod finance;
pub mod flow; pub mod flow;
pub mod governance; pub mod governance;
pub mod grid4;
pub mod heroledger; pub mod heroledger;
pub mod identity;
pub mod legal; pub mod legal;
pub mod library; pub mod library;
pub mod location; pub mod location;
pub mod object; pub mod object;
pub mod projects;
pub mod payment; pub mod payment;
pub mod identity; pub mod projects;
pub mod tfmarketplace; // pub mod tfmarketplace;
pub mod grid4;
// Re-export key types for convenience // Re-export key types for convenience
pub use core::Comment; pub use core::Comment;

View File

@@ -1,6 +1,6 @@
use super::Object;
use rhai::plugin::*; use rhai::plugin::*;
use rhai::{CustomType, Dynamic, Engine, EvalAltResult, Module}; use rhai::{CustomType, Dynamic, Engine, EvalAltResult, Module};
use super::Object;
type RhaiObject = Object; type RhaiObject = Object;
@@ -16,10 +16,7 @@ pub mod generated_rhai_module {
/// Set the title of an Object /// Set the title of an Object
#[rhai_fn(name = "object_title")] #[rhai_fn(name = "object_title")]
pub fn object_title( pub fn object_title(object: &mut RhaiObject, title: String) -> RhaiObject {
object: &mut RhaiObject,
title: String,
) -> RhaiObject {
let mut result = object.clone(); let mut result = object.clone();
result.title = title; result.title = title;
result result
@@ -27,10 +24,7 @@ pub mod generated_rhai_module {
/// Set the description of an Object /// Set the description of an Object
#[rhai_fn(name = "object_description")] #[rhai_fn(name = "object_description")]
pub fn object_description( pub fn object_description(object: &mut RhaiObject, description: String) -> RhaiObject {
object: &mut RhaiObject,
description: String,
) -> RhaiObject {
let mut result = object.clone(); let mut result = object.clone();
result.description = description; result.description = description;
result result