move repos into monorepo

This commit is contained in:
Timur Gordon
2025-11-13 20:44:00 +01:00
commit 4b23e5eb7f
204 changed files with 33737 additions and 0 deletions

View File

@@ -0,0 +1,129 @@
/// Legal Contract Object
///
/// Simple contract object with signatures for legal agreements
use crate::store::{BaseData, Object};
use serde::{Deserialize, Serialize};
/// Contract status
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum ContractStatus {
Draft,
Active,
Completed,
Cancelled,
}
impl Default for ContractStatus {
fn default() -> Self {
ContractStatus::Draft
}
}
/// Legal contract with signatures
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, crate::DeriveObject)]
pub struct Contract {
/// Base data for object storage
pub base_data: BaseData,
/// Contract title
pub title: String,
/// Contract content/terms
pub content: String,
/// Contract status
pub status: ContractStatus,
/// List of signature IDs (references to Signature objects)
pub signatures: Vec<u32>,
/// Creator user ID
pub creator_id: u32,
/// Expiry timestamp (optional)
pub expires_at: Option<u64>,
}
impl Contract {
/// Create a new contract
pub fn new(id: u32) -> Self {
let base_data = BaseData::with_id(id, String::new());
Self {
base_data,
title: String::new(),
content: String::new(),
status: ContractStatus::default(),
signatures: Vec::new(),
creator_id: 0,
expires_at: None,
}
}
/// Set the title (fluent)
pub fn title(mut self, title: impl ToString) -> Self {
self.title = title.to_string();
self
}
/// Set the content (fluent)
pub fn content(mut self, content: impl ToString) -> Self {
self.content = content.to_string();
self
}
/// Set the status (fluent)
pub fn status(mut self, status: ContractStatus) -> Self {
self.status = status;
self
}
/// Set the creator ID (fluent)
pub fn creator_id(mut self, creator_id: u32) -> Self {
self.creator_id = creator_id;
self
}
/// Set the expiry timestamp (fluent)
pub fn expires_at(mut self, expires_at: u64) -> Self {
self.expires_at = Some(expires_at);
self
}
/// Add a signature (fluent)
pub fn add_signature(mut self, signature_id: u32) -> Self {
if !self.signatures.contains(&signature_id) {
self.signatures.push(signature_id);
}
self
}
/// Remove a signature (fluent)
pub fn remove_signature(mut self, signature_id: u32) -> Self {
self.signatures.retain(|&id| id != signature_id);
self
}
/// Check if all required signatures are present
pub fn is_fully_signed(&self, required_count: usize) -> bool {
self.signatures.len() >= required_count
}
/// Activate the contract
pub fn activate(mut self) -> Self {
self.status = ContractStatus::Active;
self
}
/// Complete the contract
pub fn complete(mut self) -> Self {
self.status = ContractStatus::Completed;
self
}
/// Cancel the contract
pub fn cancel(mut self) -> Self {
self.status = ContractStatus::Cancelled;
self
}
}

View File

@@ -0,0 +1,7 @@
/// Legal module for contracts and legal documents
pub mod contract;
pub mod rhai;
pub use contract::{Contract, ContractStatus};
pub use rhai::register_legal_modules;

View File

@@ -0,0 +1,150 @@
/// Rhai bindings for Legal objects (Contract)
use ::rhai::plugin::*;
use ::rhai::{CustomType, Dynamic, Engine, EvalAltResult, Module, TypeBuilder};
use super::{Contract, ContractStatus};
/// Register legal modules with the Rhai engine
pub fn register_legal_modules(parent_module: &mut Module) {
// Register custom types
parent_module.set_custom_type::<Contract>("Contract");
parent_module.set_custom_type::<ContractStatus>("ContractStatus");
// Merge contract functions
let contract_module = exported_module!(rhai_contract_module);
parent_module.merge(&contract_module);
}
// ============================================================================
// Contract Module
// ============================================================================
type RhaiContract = Contract;
type RhaiContractStatus = ContractStatus;
#[export_module]
mod rhai_contract_module {
use super::{RhaiContract, RhaiContractStatus};
use super::super::{Contract, ContractStatus};
use ::rhai::EvalAltResult;
// Contract constructor
#[rhai_fn(name = "new_contract", return_raw)]
pub fn new_contract(id: i64) -> Result<RhaiContract, Box<EvalAltResult>> {
Ok(Contract::new(id as u32))
}
// Builder methods
#[rhai_fn(name = "title", return_raw)]
pub fn set_title(
contract: RhaiContract,
title: String,
) -> Result<RhaiContract, Box<EvalAltResult>> {
Ok(contract.title(title))
}
#[rhai_fn(name = "content", return_raw)]
pub fn set_content(
contract: RhaiContract,
content: String,
) -> Result<RhaiContract, Box<EvalAltResult>> {
Ok(contract.content(content))
}
#[rhai_fn(name = "creator_id", return_raw)]
pub fn set_creator_id(
contract: RhaiContract,
creator_id: i64,
) -> Result<RhaiContract, Box<EvalAltResult>> {
Ok(contract.creator_id(creator_id as u32))
}
#[rhai_fn(name = "expires_at", return_raw)]
pub fn set_expires_at(
contract: RhaiContract,
expires_at: i64,
) -> Result<RhaiContract, Box<EvalAltResult>> {
Ok(contract.expires_at(expires_at as u64))
}
#[rhai_fn(name = "add_signature", return_raw)]
pub fn add_signature(
contract: RhaiContract,
signature_id: i64,
) -> Result<RhaiContract, Box<EvalAltResult>> {
Ok(contract.add_signature(signature_id as u32))
}
#[rhai_fn(name = "remove_signature", return_raw)]
pub fn remove_signature(
contract: RhaiContract,
signature_id: i64,
) -> Result<RhaiContract, Box<EvalAltResult>> {
Ok(contract.remove_signature(signature_id as u32))
}
// State management methods
#[rhai_fn(name = "activate", return_raw)]
pub fn activate(contract: RhaiContract) -> Result<RhaiContract, Box<EvalAltResult>> {
Ok(contract.activate())
}
#[rhai_fn(name = "complete", return_raw)]
pub fn complete(contract: RhaiContract) -> Result<RhaiContract, Box<EvalAltResult>> {
Ok(contract.complete())
}
#[rhai_fn(name = "cancel", return_raw)]
pub fn cancel(contract: RhaiContract) -> Result<RhaiContract, Box<EvalAltResult>> {
Ok(contract.cancel())
}
// Query methods
#[rhai_fn(name = "is_fully_signed", pure)]
pub fn is_fully_signed(contract: &mut RhaiContract, required_count: i64) -> bool {
contract.is_fully_signed(required_count as usize)
}
// Getters
#[rhai_fn(name = "title", pure)]
pub fn get_title(contract: &mut RhaiContract) -> String {
contract.title.clone()
}
#[rhai_fn(name = "content", pure)]
pub fn get_content(contract: &mut RhaiContract) -> String {
contract.content.clone()
}
#[rhai_fn(name = "status", pure)]
pub fn get_status(contract: &mut RhaiContract) -> String {
format!("{:?}", contract.status)
}
#[rhai_fn(name = "creator_id", pure)]
pub fn get_creator_id(contract: &mut RhaiContract) -> i64 {
contract.creator_id as i64
}
#[rhai_fn(name = "signature_count", pure)]
pub fn get_signature_count(contract: &mut RhaiContract) -> i64 {
contract.signatures.len() as i64
}
}
// ============================================================================
// CustomType Implementations
// ============================================================================
impl CustomType for Contract {
fn build(mut builder: TypeBuilder<Self>) {
builder.with_name("Contract");
}
}
impl CustomType for ContractStatus {
fn build(mut builder: TypeBuilder<Self>) {
builder.with_name("ContractStatus");
}
}