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"
path = "examples/flow_example.rs"
[[example]]
name = "biz_rhai"
path = "examples/biz_rhai/example.rs"
required-features = ["rhai"]
# [[example]]
# name = "biz_rhai"
# path = "examples/biz_rhai/example.rs"
# required-features = ["rhai"]
[[example]]
name = "postgres_model_example"

View File

@@ -1,26 +1,26 @@
use circles_launcher::{new_launcher};
use heromodels::models::circle::circle::{new_circle};
use secp256k1::{Secp256k1, SecretKey, PublicKey};
use circles_launcher::new_launcher;
use heromodels::models::circle::circle::new_circle;
use rand::rngs::OsRng;
use secp256k1::{PublicKey, Secp256k1, SecretKey};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Generate valid secp256k1 keypairs for testing
let secp = Secp256k1::new();
let mut rng = OsRng;
let secret_key1 = SecretKey::new(&mut rng);
let public_key1 = PublicKey::from_secret_key(&secp, &secret_key1);
let pk1_hex = hex::encode(public_key1.serialize());
let secret_key2 = SecretKey::new(&mut rng);
let public_key2 = PublicKey::from_secret_key(&secp, &secret_key2);
let pk2_hex = hex::encode(public_key2.serialize());
let secret_key3 = SecretKey::new(&mut rng);
let public_key3 = PublicKey::from_secret_key(&secp, &secret_key3);
let pk3_hex = hex::encode(public_key3.serialize());
println!("Generated test public keys:");
println!(" PK1: {}", pk1_hex);
println!(" PK2: {}", pk2_hex);
@@ -36,4 +36,4 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.save();
Ok(())
}
}

View File

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

View File

@@ -43,8 +43,10 @@ fn main() {
// Clean up any existing data to ensure consistent results
println!("Cleaning up existing data...");
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
if let Ok(existing_users) = user_collection.get_all() {
for user in existing_users {

View File

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

View File

@@ -119,4 +119,4 @@ impl Circle {
/// Creates a new circle builder
pub fn new_circle() -> Circle {
Circle::new()
}
}

View File

@@ -1,16 +1,17 @@
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::{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::sync::Arc;
use crate::models::circle::Circle;
type RhaiCircle = Circle;
use crate::db::hero::OurDB;
use crate::db::Collection;
use crate::db::hero::OurDB;
use crate::models::circle::ThemeData;
#[export_module]

View File

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

View File

@@ -1,6 +1,6 @@
use heromodels_core::BaseModelData;
use heromodels_derive::model;
use rhai::CustomType;
use rhai::{CustomType, TypeBuilder};
use serde::{Deserialize, Serialize};
/// Storage device information
@@ -160,19 +160,58 @@ impl ComputeSlice {
}
}
pub fn nodeid(mut self, nodeid: u32) -> Self { self.nodeid = nodeid; self }
pub fn slice_id(mut self, id: i32) -> Self { self.id = id; self }
pub fn mem_gb(mut self, v: f64) -> Self { self.mem_gb = v; 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 }
pub fn nodeid(mut self, nodeid: u32) -> Self {
self.nodeid = nodeid;
self
}
pub fn slice_id(mut self, id: i32) -> Self {
self.id = id;
self
}
pub fn mem_gb(mut self, v: f64) -> Self {
self.mem_gb = v;
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)
@@ -204,11 +243,26 @@ impl StorageSlice {
}
}
pub fn nodeid(mut self, nodeid: u32) -> Self { self.nodeid = nodeid; 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 }
pub fn nodeid(mut self, nodeid: u32) -> Self {
self.nodeid = nodeid;
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
@@ -248,17 +302,41 @@ impl Node {
}
}
pub fn nodegroupid(mut self, v: i32) -> Self { self.nodegroupid = v; self }
pub fn uptime(mut self, v: i32) -> Self { self.uptime = v; 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 }
pub fn nodegroupid(mut self, v: i32) -> Self {
self.nodegroupid = v;
self
}
pub fn uptime(mut self, v: i32) -> Self {
self.uptime = v;
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
pub fn recalc_capacity(mut self) -> Self {
pub fn recalc_capacity(self) -> Self {
// TODO: calculate NodeCapacity out of the devices on the Node
self
}

View File

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

View File

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

View File

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

View File

@@ -1,20 +1,10 @@
// Export all heroledger model modules
pub mod user;
pub mod group;
pub mod money;
pub mod membership;
pub mod dnsrecord;
pub mod group;
pub mod membership;
pub mod money;
pub mod rhai;
pub mod secretbox;
pub mod signature;
pub mod user;
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 serde::{Deserialize, Serialize};
use std::collections::HashMap;
@@ -223,8 +223,6 @@ impl Account {
}
}
/// Represents an asset in the financial system
#[model]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
@@ -342,8 +340,6 @@ impl Asset {
}
}
/// Represents account policies for various operations
#[model]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
@@ -400,8 +396,6 @@ impl AccountPolicy {
}
}
/// Represents a financial transaction
#[model]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
@@ -511,5 +505,3 @@ impl Transaction {
self
}
}

View File

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

View File

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

View File

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

View File

@@ -46,4 +46,4 @@ pub struct IdenfyVerificationData {
pub doc_issuing_country: Option<String>,
#[serde(rename = "manuallyDataChanged")]
pub manually_data_changed: Option<bool>,
}
}

View File

@@ -2,4 +2,4 @@
pub mod kyc;
pub use kyc::*;
pub use kyc::*;

View File

@@ -8,4 +8,4 @@ pub struct Address {
pub postal_code: String,
pub country: String,
pub company: Option<String>,
}
}

View File

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

View File

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

View File

@@ -2,4 +2,4 @@
pub mod stripe;
pub use stripe::*;
pub use stripe::*;

View File

@@ -27,4 +27,4 @@ pub struct StripeEventData {
pub struct StripeEventRequest {
pub id: Option<String>,
pub idempotency_key: Option<String>,
}
}