wip
This commit is contained in:
53
examples/engine/01_note.rhai
Normal file
53
examples/engine/01_note.rhai
Normal file
@@ -0,0 +1,53 @@
|
||||
// Example 1: Creating and working with Notes
|
||||
|
||||
print("=== Note Example ===\n");
|
||||
|
||||
// Get a context to work with
|
||||
print("1. Getting context...");
|
||||
let ctx = get_context(["alice", "bob"]);
|
||||
print(" ✓ Context created: " + ctx.context_id());
|
||||
|
||||
// Create notes with builder pattern
|
||||
print("\n2. Creating notes...");
|
||||
|
||||
let meeting_note = note("notes")
|
||||
.title("Meeting Notes")
|
||||
.content("Discussed OSIRIS integration and Rhai packages")
|
||||
.tag("category", "work")
|
||||
.tag("priority", "high")
|
||||
.mime("text/markdown");
|
||||
|
||||
print(" ✓ Created meeting note with tags and mime type");
|
||||
|
||||
let quick_note = note("notes")
|
||||
.title("Quick Reminder")
|
||||
.content("Remember to push changes")
|
||||
.tag("category", "personal");
|
||||
|
||||
print(" ✓ Created quick reminder note");
|
||||
|
||||
let project_note = note("notes")
|
||||
.title("Project Plan")
|
||||
.content("1. Design\n2. Implement\n3. Test")
|
||||
.tag("project", "osiris")
|
||||
.tag("status", "in-progress");
|
||||
|
||||
print(" ✓ Created project plan note");
|
||||
|
||||
// Save notes to context
|
||||
print("\n3. Saving notes to context...");
|
||||
ctx.save(meeting_note);
|
||||
print(" ✓ Saved meeting note");
|
||||
|
||||
ctx.save(quick_note);
|
||||
print(" ✓ Saved quick note");
|
||||
|
||||
ctx.save(project_note);
|
||||
print(" ✓ Saved project note");
|
||||
|
||||
// List all notes in context
|
||||
print("\n4. Listing notes in context...");
|
||||
let note_ids = ctx.list("notes");
|
||||
print(" ✓ Found " + note_ids.len() + " notes in context");
|
||||
|
||||
print("\n=== Note Example Complete ===");
|
||||
44
examples/engine/02_event.rhai
Normal file
44
examples/engine/02_event.rhai
Normal file
@@ -0,0 +1,44 @@
|
||||
// Example 2: Creating and working with Events
|
||||
|
||||
print("=== Event Example ===\n");
|
||||
|
||||
// Get a context to work with
|
||||
print("1. Getting context...");
|
||||
let ctx = get_context(["alice", "charlie"]);
|
||||
print(" ✓ Context created: " + ctx.context_id());
|
||||
|
||||
// Create events with builder pattern
|
||||
print("\n2. Creating events...");
|
||||
|
||||
let standup = event("calendar", "Daily Standup")
|
||||
.description("Quick sync on progress and blockers");
|
||||
|
||||
print(" ✓ Created daily standup event");
|
||||
|
||||
let review = event("calendar", "Sprint Review")
|
||||
.description("Demo completed features to stakeholders");
|
||||
|
||||
print(" ✓ Created sprint review event");
|
||||
|
||||
let workshop = event("calendar", "OSIRIS Workshop")
|
||||
.description("Deep dive into OSIRIS architecture and Rhai integration");
|
||||
|
||||
print(" ✓ Created workshop event");
|
||||
|
||||
// Save events to context
|
||||
print("\n3. Saving events to context...");
|
||||
ctx.save(standup);
|
||||
print(" ✓ Saved standup event");
|
||||
|
||||
ctx.save(review);
|
||||
print(" ✓ Saved review event");
|
||||
|
||||
ctx.save(workshop);
|
||||
print(" ✓ Saved workshop event");
|
||||
|
||||
// List all events in context
|
||||
print("\n4. Listing events in context...");
|
||||
let event_ids = ctx.list("calendar");
|
||||
print(" ✓ Found " + event_ids.len() + " events in context");
|
||||
|
||||
print("\n=== Event Example Complete ===");
|
||||
54
examples/engine/03_user.rhai
Normal file
54
examples/engine/03_user.rhai
Normal file
@@ -0,0 +1,54 @@
|
||||
// Example 3: Creating and working with Users
|
||||
|
||||
print("=== User Example ===\n");
|
||||
|
||||
// Get a context to work with
|
||||
print("1. Getting context...");
|
||||
let ctx = get_context(["alice", "bob"]);
|
||||
print(" ✓ Context created: " + ctx.context_id());
|
||||
|
||||
// Create users with builder pattern
|
||||
print("\n2. Creating users...");
|
||||
|
||||
let alice = new_user()
|
||||
.username("alice")
|
||||
.add_email("alice@example.com");
|
||||
|
||||
print(" ✓ Created user: alice");
|
||||
|
||||
let bob = new_user()
|
||||
.username("bob")
|
||||
.add_email("bob@example.com");
|
||||
|
||||
print(" ✓ Created user: bob");
|
||||
|
||||
let charlie = new_user()
|
||||
.username("charlie")
|
||||
.add_email("charlie@example.com");
|
||||
|
||||
print(" ✓ Created user: charlie");
|
||||
|
||||
// Display user info
|
||||
print("\n3. User information...");
|
||||
print(" Alice ID: " + alice.get_id());
|
||||
print(" Alice username: " + alice.get_username());
|
||||
print(" Alice email: " + alice.get_email());
|
||||
|
||||
print(" Bob ID: " + bob.get_id());
|
||||
print(" Bob username: " + bob.get_username());
|
||||
|
||||
print(" Charlie ID: " + charlie.get_id());
|
||||
print(" Charlie username: " + charlie.get_username());
|
||||
|
||||
// Save users to context
|
||||
print("\n4. Saving users to context...");
|
||||
let alice_id = ctx.save(alice);
|
||||
print(" ✓ Saved alice with ID: " + alice_id);
|
||||
|
||||
let bob_id = ctx.save(bob);
|
||||
print(" ✓ Saved bob with ID: " + bob_id);
|
||||
|
||||
let charlie_id = ctx.save(charlie);
|
||||
print(" ✓ Saved charlie with ID: " + charlie_id);
|
||||
|
||||
print("\n=== User Example Complete ===");
|
||||
54
examples/engine/04_group.rhai
Normal file
54
examples/engine/04_group.rhai
Normal file
@@ -0,0 +1,54 @@
|
||||
// Example 4: Creating and working with Groups
|
||||
|
||||
print("=== Group Example ===\n");
|
||||
|
||||
// Get a context to work with
|
||||
print("1. Getting context...");
|
||||
let ctx = get_context(["alice", "bob"]);
|
||||
print(" ✓ Context created: " + ctx.context_id());
|
||||
|
||||
// Create groups with builder pattern
|
||||
print("\n2. Creating groups...");
|
||||
|
||||
let dev_team = new_group()
|
||||
.name("Development Team")
|
||||
.description("Core development team members");
|
||||
|
||||
print(" ✓ Created group: Development Team");
|
||||
|
||||
let ops_team = new_group()
|
||||
.name("Operations Team")
|
||||
.description("Infrastructure and operations team");
|
||||
|
||||
print(" ✓ Created group: Operations Team");
|
||||
|
||||
let admin_group = new_group()
|
||||
.name("Administrators")
|
||||
.description("System administrators with full access");
|
||||
|
||||
print(" ✓ Created group: Administrators");
|
||||
|
||||
// Display group info
|
||||
print("\n3. Group information...");
|
||||
print(" Dev Team ID: " + dev_team.get_id());
|
||||
print(" Dev Team name: " + dev_team.get_name());
|
||||
print(" Dev Team description: " + dev_team.get_description());
|
||||
|
||||
print(" Ops Team ID: " + ops_team.get_id());
|
||||
print(" Ops Team name: " + ops_team.get_name());
|
||||
|
||||
print(" Admin Group ID: " + admin_group.get_id());
|
||||
print(" Admin Group name: " + admin_group.get_name());
|
||||
|
||||
// Save groups to context
|
||||
print("\n4. Saving groups to context...");
|
||||
let dev_id = ctx.save(dev_team);
|
||||
print(" ✓ Saved Development Team with ID: " + dev_id);
|
||||
|
||||
let ops_id = ctx.save(ops_team);
|
||||
print(" ✓ Saved Operations Team with ID: " + ops_id);
|
||||
|
||||
let admin_id = ctx.save(admin_group);
|
||||
print(" ✓ Saved Administrators with ID: " + admin_id);
|
||||
|
||||
print("\n=== Group Example Complete ===");
|
||||
55
examples/engine/05_account.rhai
Normal file
55
examples/engine/05_account.rhai
Normal file
@@ -0,0 +1,55 @@
|
||||
// Example 5: Creating and working with Accounts
|
||||
|
||||
print("=== Account Example ===\n");
|
||||
|
||||
// Get a context to work with
|
||||
print("1. Getting context...");
|
||||
let ctx = get_context(["alice", "bob"]);
|
||||
print(" ✓ Context created: " + ctx.context_id());
|
||||
|
||||
// Create accounts with builder pattern
|
||||
print("\n2. Creating accounts...");
|
||||
|
||||
let checking = new_account()
|
||||
.address("checking_001")
|
||||
.currency("USD");
|
||||
|
||||
print(" ✓ Created checking account");
|
||||
|
||||
let savings = new_account()
|
||||
.address("savings_001")
|
||||
.currency("USD");
|
||||
|
||||
print(" ✓ Created savings account");
|
||||
|
||||
let crypto = new_account()
|
||||
.address("0x1234567890abcdef")
|
||||
.currency("ETH");
|
||||
|
||||
print(" ✓ Created crypto account");
|
||||
|
||||
// Display account info
|
||||
print("\n3. Account information...");
|
||||
print(" Checking ID: " + checking.get_id());
|
||||
print(" Checking address: " + checking.get_address());
|
||||
print(" Checking currency: " + checking.get_currency());
|
||||
|
||||
print(" Savings ID: " + savings.get_id());
|
||||
print(" Savings address: " + savings.get_address());
|
||||
|
||||
print(" Crypto ID: " + crypto.get_id());
|
||||
print(" Crypto address: " + crypto.get_address());
|
||||
print(" Crypto currency: " + crypto.get_currency());
|
||||
|
||||
// Save accounts to context
|
||||
print("\n4. Saving accounts to context...");
|
||||
let checking_id = ctx.save(checking);
|
||||
print(" ✓ Saved checking account with ID: " + checking_id);
|
||||
|
||||
let savings_id = ctx.save(savings);
|
||||
print(" ✓ Saved savings account with ID: " + savings_id);
|
||||
|
||||
let crypto_id = ctx.save(crypto);
|
||||
print(" ✓ Saved crypto account with ID: " + crypto_id);
|
||||
|
||||
print("\n=== Account Example Complete ===");
|
||||
50
examples/engine/06_dnszone.rhai
Normal file
50
examples/engine/06_dnszone.rhai
Normal file
@@ -0,0 +1,50 @@
|
||||
// Example 6: Creating and working with DNS Zones
|
||||
|
||||
print("=== DNS Zone Example ===\n");
|
||||
|
||||
// Get a context to work with
|
||||
print("1. Getting context...");
|
||||
let ctx = get_context(["alice", "bob"]);
|
||||
print(" ✓ Context created: " + ctx.context_id());
|
||||
|
||||
// Create DNS zones with builder pattern
|
||||
print("\n2. Creating DNS zones...");
|
||||
|
||||
let example_zone = new_dns_zone()
|
||||
.domain("example.com");
|
||||
|
||||
print(" ✓ Created DNS zone: example.com");
|
||||
|
||||
let test_zone = new_dns_zone()
|
||||
.domain("test.org");
|
||||
|
||||
print(" ✓ Created DNS zone: test.org");
|
||||
|
||||
let dev_zone = new_dns_zone()
|
||||
.domain("dev.local");
|
||||
|
||||
print(" ✓ Created DNS zone: dev.local");
|
||||
|
||||
// Display DNS zone info
|
||||
print("\n3. DNS Zone information...");
|
||||
print(" Example Zone ID: " + example_zone.get_id());
|
||||
print(" Example Zone domain: " + example_zone.get_domain());
|
||||
|
||||
print(" Test Zone ID: " + test_zone.get_id());
|
||||
print(" Test Zone domain: " + test_zone.get_domain());
|
||||
|
||||
print(" Dev Zone ID: " + dev_zone.get_id());
|
||||
print(" Dev Zone domain: " + dev_zone.get_domain());
|
||||
|
||||
// Save DNS zones to context
|
||||
print("\n4. Saving DNS zones to context...");
|
||||
let example_id = ctx.save(example_zone);
|
||||
print(" ✓ Saved example.com with ID: " + example_id);
|
||||
|
||||
let test_id = ctx.save(test_zone);
|
||||
print(" ✓ Saved test.org with ID: " + test_id);
|
||||
|
||||
let dev_id = ctx.save(dev_zone);
|
||||
print(" ✓ Saved dev.local with ID: " + dev_id);
|
||||
|
||||
print("\n=== DNS Zone Example Complete ===");
|
||||
104
examples/engine/07_kyc.rhai
Normal file
104
examples/engine/07_kyc.rhai
Normal file
@@ -0,0 +1,104 @@
|
||||
// Example 7: KYC Info and Session Management
|
||||
|
||||
print("=== KYC Example ===\n");
|
||||
|
||||
// Get a context to work with
|
||||
print("1. Getting context...");
|
||||
let ctx = get_context(["alice", "bob"]);
|
||||
print(" ✓ Context created: " + ctx.context_id());
|
||||
|
||||
// Create KYC info objects with builder pattern
|
||||
print("\n2. Creating KYC info objects...");
|
||||
|
||||
let john_info = new_kyc_info()
|
||||
.client_id("CLIENT_001")
|
||||
.first_name("John")
|
||||
.last_name("Doe")
|
||||
.email("john.doe@example.com")
|
||||
.phone("+1234567890")
|
||||
.date_of_birth("1990-01-15")
|
||||
.nationality("US")
|
||||
.address("123 Main Street")
|
||||
.city("New York")
|
||||
.country("US")
|
||||
.postal_code("10001")
|
||||
.provider("idenfy");
|
||||
|
||||
print(" ✓ Created KYC info for John Doe");
|
||||
|
||||
let jane_info = new_kyc_info()
|
||||
.client_id("CLIENT_002")
|
||||
.first_name("Jane")
|
||||
.last_name("Smith")
|
||||
.email("jane.smith@example.com")
|
||||
.phone("+9876543210")
|
||||
.date_of_birth("1985-05-20")
|
||||
.nationality("GB")
|
||||
.provider("idenfy");
|
||||
|
||||
print(" ✓ Created KYC info for Jane Smith");
|
||||
|
||||
// Display info
|
||||
print("\n3. KYC information...");
|
||||
print(" John - ID: " + john_info.get_id());
|
||||
print(" John - Client ID: " + john_info.get_client_id());
|
||||
print(" John - Name: " + john_info.get_first_name() + " " + john_info.get_last_name());
|
||||
print(" John - Email: " + john_info.get_email());
|
||||
print(" John - Provider: " + john_info.get_provider());
|
||||
|
||||
print(" Jane - ID: " + jane_info.get_id());
|
||||
print(" Jane - Client ID: " + jane_info.get_client_id());
|
||||
print(" Jane - Name: " + jane_info.get_first_name() + " " + jane_info.get_last_name());
|
||||
|
||||
// Save KYC info to context
|
||||
print("\n4. Saving KYC info to context...");
|
||||
let john_id = ctx.save(john_info);
|
||||
print(" ✓ Saved John's KYC info with ID: " + john_id);
|
||||
|
||||
let jane_id = ctx.save(jane_info);
|
||||
print(" ✓ Saved Jane's KYC info with ID: " + jane_id);
|
||||
|
||||
// Create KYC verification sessions
|
||||
print("\n5. Creating KYC verification sessions...");
|
||||
|
||||
let john_session = new_kyc_session("CLIENT_001", "idenfy")
|
||||
.callback_url("https://example.com/kyc/callback")
|
||||
.success_url("https://example.com/kyc/success")
|
||||
.error_url("https://example.com/kyc/error")
|
||||
.locale("en");
|
||||
|
||||
print(" ✓ Created verification session for John");
|
||||
|
||||
let jane_session = new_kyc_session("CLIENT_002", "idenfy")
|
||||
.callback_url("https://example.com/kyc/callback")
|
||||
.success_url("https://example.com/kyc/success")
|
||||
.error_url("https://example.com/kyc/error")
|
||||
.locale("en");
|
||||
|
||||
print(" ✓ Created verification session for Jane");
|
||||
|
||||
// Display session info
|
||||
print("\n6. Session information...");
|
||||
print(" John's session - ID: " + john_session.get_id());
|
||||
print(" John's session - Client ID: " + john_session.get_client_id());
|
||||
print(" John's session - Provider: " + john_session.get_provider());
|
||||
|
||||
// Save KYC sessions to context
|
||||
print("\n7. Saving KYC sessions to context...");
|
||||
let john_session_id = ctx.save(john_session);
|
||||
print(" ✓ Saved John's session with ID: " + john_session_id);
|
||||
|
||||
let jane_session_id = ctx.save(jane_session);
|
||||
print(" ✓ Saved Jane's session with ID: " + jane_session_id);
|
||||
|
||||
// List all KYC clients in context
|
||||
print("\n8. Listing KYC clients in context...");
|
||||
let client_ids = ctx.list("kyc_clients");
|
||||
print(" ✓ Found " + client_ids.len() + " KYC clients in context");
|
||||
|
||||
// List all KYC sessions in context
|
||||
print("\n9. Listing KYC sessions in context...");
|
||||
let session_ids = ctx.list("kyc_sessions");
|
||||
print(" ✓ Found " + session_ids.len() + " KYC sessions in context");
|
||||
|
||||
print("\n=== KYC Example Complete ===");
|
||||
90
examples/engine/08_flow.rhai
Normal file
90
examples/engine/08_flow.rhai
Normal file
@@ -0,0 +1,90 @@
|
||||
// Example 8: Flow Template and Instance Management
|
||||
|
||||
print("=== Flow Example ===\n");
|
||||
|
||||
// Get a context to work with
|
||||
print("1. Getting context...");
|
||||
let ctx = get_context(["alice", "bob"]);
|
||||
print(" ✓ Context created: " + ctx.context_id());
|
||||
|
||||
// Create a registration flow template
|
||||
print("\n2. Creating registration flow template...");
|
||||
|
||||
let registration_flow = new_flow()
|
||||
.name("registration_flow")
|
||||
.description("User Registration Flow with KYC");
|
||||
|
||||
registration_flow.add_step("registration", "User PK Registration");
|
||||
registration_flow.add_step("kyc", "KYC Verification");
|
||||
registration_flow.add_step("email", "Email Verification");
|
||||
|
||||
print(" ✓ Created registration flow template");
|
||||
print(" Template: " + registration_flow.get_name());
|
||||
print(" Description: " + registration_flow.get_description());
|
||||
|
||||
// Save the template
|
||||
print("\n3. Saving flow template to context...");
|
||||
let template_id = ctx.save(registration_flow.build());
|
||||
print(" ✓ Saved template with ID: " + template_id);
|
||||
|
||||
// Create a flow instance for a user
|
||||
print("\n4. Creating flow instance for user...");
|
||||
let user_id = "user_123";
|
||||
|
||||
let flow_instance = new_flow_instance(
|
||||
"registration_flow_user_123",
|
||||
"registration_flow",
|
||||
user_id
|
||||
);
|
||||
|
||||
// Initialize steps (in real scenario, would get from template)
|
||||
flow_instance.start();
|
||||
|
||||
print(" ✓ Created and started flow instance");
|
||||
print(" Instance name: " + flow_instance.get_name());
|
||||
print(" Template: " + flow_instance.get_template_name());
|
||||
print(" Entity ID: " + flow_instance.get_entity_id());
|
||||
print(" Status: " + flow_instance.get_status());
|
||||
|
||||
// Save the instance
|
||||
print("\n5. Saving flow instance to context...");
|
||||
let instance_id = ctx.save(flow_instance);
|
||||
print(" ✓ Saved instance with ID: " + instance_id);
|
||||
|
||||
// Simulate completing steps
|
||||
print("\n6. Simulating step completion...");
|
||||
|
||||
// Complete registration step
|
||||
flow_instance.complete_step("registration");
|
||||
print(" ✓ Completed 'registration' step");
|
||||
|
||||
// Save updated instance
|
||||
ctx.save(flow_instance);
|
||||
|
||||
// Complete KYC step
|
||||
flow_instance.complete_step("kyc");
|
||||
print(" ✓ Completed 'kyc' step");
|
||||
|
||||
// Save updated instance
|
||||
ctx.save(flow_instance);
|
||||
|
||||
// Complete email step
|
||||
flow_instance.complete_step("email");
|
||||
print(" ✓ Completed 'email' step");
|
||||
|
||||
// Save final instance
|
||||
ctx.save(flow_instance);
|
||||
|
||||
print(" Final status: " + flow_instance.get_status());
|
||||
|
||||
// List all flow templates
|
||||
print("\n7. Listing flow templates in context...");
|
||||
let template_ids = ctx.list("flow_templates");
|
||||
print(" ✓ Found " + template_ids.len() + " flow templates");
|
||||
|
||||
// List all flow instances
|
||||
print("\n8. Listing flow instances in context...");
|
||||
let instance_ids = ctx.list("flow_instances");
|
||||
print(" ✓ Found " + instance_ids.len() + " flow instances");
|
||||
|
||||
print("\n=== Flow Example Complete ===");
|
||||
119
examples/engine/09_money.rhai
Normal file
119
examples/engine/09_money.rhai
Normal file
@@ -0,0 +1,119 @@
|
||||
// Example 9: Money - Accounts, Assets, and Transactions
|
||||
|
||||
print("=== Money Example ===\n");
|
||||
|
||||
// Get a context to work with
|
||||
print("1. Getting context...");
|
||||
let ctx = get_context(["alice", "bob", "charlie"]);
|
||||
print(" ✓ Context created: " + ctx.context_id());
|
||||
|
||||
// Create an asset (e.g., a token)
|
||||
print("\n2. Creating a digital asset...");
|
||||
|
||||
let tft_asset = new_asset()
|
||||
.address("TFT_ASSET_001")
|
||||
.asset_type("utility_token")
|
||||
.issuer(1)
|
||||
.supply(1000000.0);
|
||||
|
||||
print(" ✓ Created TFT asset");
|
||||
print(" Address: " + tft_asset.get_address());
|
||||
print(" Type: " + tft_asset.get_asset_type());
|
||||
print(" Supply: " + tft_asset.get_supply());
|
||||
|
||||
// Save the asset
|
||||
print("\n3. Saving asset to context...");
|
||||
let asset_id = ctx.save(tft_asset);
|
||||
print(" ✓ Saved asset with ID: " + asset_id);
|
||||
|
||||
// Create accounts for users
|
||||
print("\n4. Creating user accounts...");
|
||||
|
||||
let alice_account = new_account()
|
||||
.owner_id(100)
|
||||
.address("ALICE_TFT_ACCOUNT")
|
||||
.balance(10000.0)
|
||||
.currency("TFT")
|
||||
.assetid(1);
|
||||
|
||||
print(" ✓ Created Alice's account");
|
||||
print(" Owner ID: " + alice_account.get_owner_id());
|
||||
print(" Address: " + alice_account.get_address());
|
||||
print(" Balance: " + alice_account.get_balance() + " " + alice_account.get_currency());
|
||||
|
||||
let bob_account = new_account()
|
||||
.owner_id(101)
|
||||
.address("BOB_TFT_ACCOUNT")
|
||||
.balance(5000.0)
|
||||
.currency("TFT")
|
||||
.assetid(1);
|
||||
|
||||
print(" ✓ Created Bob's account");
|
||||
print(" Owner ID: " + bob_account.get_owner_id());
|
||||
print(" Address: " + bob_account.get_address());
|
||||
print(" Balance: " + bob_account.get_balance() + " " + bob_account.get_currency());
|
||||
|
||||
// Save accounts
|
||||
print("\n5. Saving accounts to context...");
|
||||
let alice_account_id = ctx.save(alice_account);
|
||||
print(" ✓ Saved Alice's account with ID: " + alice_account_id);
|
||||
|
||||
let bob_account_id = ctx.save(bob_account);
|
||||
print(" ✓ Saved Bob's account with ID: " + bob_account_id);
|
||||
|
||||
// Create a transaction
|
||||
print("\n6. Creating a transaction...");
|
||||
|
||||
let transaction = new_transaction()
|
||||
.source(100)
|
||||
.destination(101)
|
||||
.amount(500.0)
|
||||
.assetid(1);
|
||||
|
||||
print(" ✓ Created transaction");
|
||||
print(" From: " + transaction.get_source());
|
||||
print(" To: " + transaction.get_destination());
|
||||
print(" Amount: " + transaction.get_amount());
|
||||
print(" Asset ID: " + transaction.get_assetid());
|
||||
|
||||
// Save transaction
|
||||
print("\n7. Saving transaction to context...");
|
||||
let tx_id = ctx.save(transaction);
|
||||
print(" ✓ Saved transaction with ID: " + tx_id);
|
||||
|
||||
// Create a multi-currency account
|
||||
print("\n8. Creating multi-currency account...");
|
||||
|
||||
let charlie_usd_account = new_account()
|
||||
.owner_id(102)
|
||||
.address("CHARLIE_USD_ACCOUNT")
|
||||
.balance(25000.0)
|
||||
.currency("USD")
|
||||
.assetid(2);
|
||||
|
||||
print(" ✓ Created Charlie's USD account");
|
||||
print(" Balance: " + charlie_usd_account.get_balance() + " " + charlie_usd_account.get_currency());
|
||||
|
||||
let charlie_id = ctx.save(charlie_usd_account);
|
||||
print(" ✓ Saved Charlie's account with ID: " + charlie_id);
|
||||
|
||||
// List all accounts
|
||||
print("\n9. Listing all accounts in context...");
|
||||
let account_ids = ctx.list("accounts");
|
||||
print(" ✓ Found " + account_ids.len() + " accounts");
|
||||
|
||||
// List all assets
|
||||
print("\n10. Listing all assets in context...");
|
||||
let asset_ids = ctx.list("assets");
|
||||
print(" ✓ Found " + asset_ids.len() + " assets");
|
||||
|
||||
// List all transactions
|
||||
print("\n11. Listing all transactions in context...");
|
||||
let tx_ids = ctx.list("transactions");
|
||||
print(" ✓ Found " + tx_ids.len() + " transactions");
|
||||
|
||||
print("\n=== Money Example Complete ===");
|
||||
print("Summary:");
|
||||
print(" - Created 1 asset (TFT)");
|
||||
print(" - Created 3 accounts (Alice TFT, Bob TFT, Charlie USD)");
|
||||
print(" - Created 1 transaction (Alice → Bob: 500 TFT)");
|
||||
103
examples/engine/10_email.rhai
Normal file
103
examples/engine/10_email.rhai
Normal file
@@ -0,0 +1,103 @@
|
||||
// Example 10: Communication - Email Verification
|
||||
|
||||
print("=== Communication & Email Verification Example ===\n");
|
||||
|
||||
// Get a context to work with
|
||||
print("1. Getting context...");
|
||||
let ctx = get_context(["alice", "bob"]);
|
||||
print(" ✓ Context created: " + ctx.context_id());
|
||||
|
||||
// Create verification for a user
|
||||
print("\n2. Creating verification...");
|
||||
|
||||
let verification = new_verification(
|
||||
"user_123",
|
||||
"alice@example.com"
|
||||
)
|
||||
.callback_url("https://example.com/verify");
|
||||
|
||||
print(" ✓ Created verification");
|
||||
print(" Entity ID: " + verification.get_entity_id());
|
||||
print(" Contact: " + verification.get_contact());
|
||||
print(" Code: " + verification.get_code());
|
||||
print(" Nonce: " + verification.get_nonce());
|
||||
print(" Verification URL: " + verification.get_verification_url());
|
||||
print(" Status: " + verification.get_status());
|
||||
|
||||
// Create email client
|
||||
print("\n3. Creating email client...");
|
||||
let email_client = new_email_client();
|
||||
print(" ✓ Email client created");
|
||||
|
||||
// Send verification email with link
|
||||
print("\n4. Sending verification email...");
|
||||
email_client.send_verification_link(verification);
|
||||
verification.mark_sent();
|
||||
print(" ✓ Verification email sent");
|
||||
print(" Status: " + verification.get_status());
|
||||
|
||||
// Save the verification
|
||||
print("\n5. Saving verification to context...");
|
||||
let verification_id = ctx.save(verification);
|
||||
print(" ✓ Saved verification with ID: " + verification_id);
|
||||
|
||||
// Simulate user clicking link (nonce verification)
|
||||
print("\n6. Simulating URL click verification...");
|
||||
let nonce = verification.get_nonce();
|
||||
print(" User clicks: " + verification.get_verification_url());
|
||||
verification.verify_nonce(nonce);
|
||||
print(" ✓ Verification successful via URL!");
|
||||
print(" Status: " + verification.get_status());
|
||||
|
||||
// Save verified status
|
||||
ctx.save(verification);
|
||||
|
||||
// Create another verification for code-based flow
|
||||
print("\n7. Creating code-based verification for Bob...");
|
||||
|
||||
let bob_verification = new_verification(
|
||||
"user_456",
|
||||
"bob@example.com"
|
||||
);
|
||||
|
||||
print(" ✓ Created verification for Bob");
|
||||
print(" Contact: " + bob_verification.get_contact());
|
||||
print(" Code: " + bob_verification.get_code());
|
||||
|
||||
// Send code via email
|
||||
print("\n8. Sending code-based verification email...");
|
||||
email_client.send_verification_code(bob_verification);
|
||||
bob_verification.mark_sent();
|
||||
print(" ✓ Code sent");
|
||||
|
||||
// Save Bob's verification
|
||||
let bob_verification_id = ctx.save(bob_verification);
|
||||
print(" ✓ Saved with ID: " + bob_verification_id);
|
||||
|
||||
// Simulate user entering wrong code
|
||||
print("\n9. Simulating code verification attempts...");
|
||||
print(" Attempt 1 with wrong code...");
|
||||
try {
|
||||
bob_verification.verify_code("000000");
|
||||
print(" ✗ Unexpected success");
|
||||
} catch(err) {
|
||||
print(" ✗ Verification failed (expected): " + err);
|
||||
print(" Attempts: " + bob_verification.get_attempts());
|
||||
}
|
||||
|
||||
// Verify with correct code
|
||||
print("\n10. Verifying with correct code...");
|
||||
let correct_code = bob_verification.get_code();
|
||||
print(" Using code: " + correct_code);
|
||||
bob_verification.verify_code(correct_code);
|
||||
print(" ✓ Verification successful!");
|
||||
print(" Status: " + bob_verification.get_status());
|
||||
|
||||
ctx.save(bob_verification);
|
||||
|
||||
// List all verifications
|
||||
print("\n11. Listing all verifications in context...");
|
||||
let verification_ids = ctx.list("verifications");
|
||||
print(" ✓ Found " + verification_ids.len() + " verifications");
|
||||
|
||||
print("\n=== Communication & Email Verification Example Complete ===");
|
||||
104
examples/engine/11_payments.rhai
Normal file
104
examples/engine/11_payments.rhai
Normal file
@@ -0,0 +1,104 @@
|
||||
// Example 11: Payment Provider - Pesapal Integration
|
||||
|
||||
print("=== Payment Provider & Pesapal Example ===\n");
|
||||
|
||||
// Get a context to work with
|
||||
print("1. Getting context...");
|
||||
let ctx = get_context(["alice", "bob"]);
|
||||
print(" ✓ Context created: " + ctx.context_id());
|
||||
|
||||
// Create Pesapal payment client (sandbox mode for testing)
|
||||
print("\n2. Creating Pesapal payment client (sandbox)...");
|
||||
let payment_client = new_payment_client_pesapal_sandbox(
|
||||
1, // Client ID
|
||||
"qkio1BGGYAXTu2JOfm7XSXNruoZsrqEW", // Consumer key
|
||||
"osGQ364R49cXKeOYSpaOnT++rHs=" // Consumer secret
|
||||
);
|
||||
print(" ✓ Payment client created");
|
||||
|
||||
// Create a payment request
|
||||
print("\n3. Creating payment request...");
|
||||
let payment_request = new_payment_request(
|
||||
"ORDER_" + timestamp(), // Merchant reference
|
||||
2500.00, // Amount
|
||||
"KES", // Currency (Kenyan Shillings)
|
||||
"Payment for Premium Subscription", // Description
|
||||
"https://example.com/payment/callback" // Callback URL
|
||||
);
|
||||
|
||||
// Add customer details
|
||||
payment_request
|
||||
.customer_email("customer@example.com")
|
||||
.customer_phone("+254712345678")
|
||||
.customer_name("John", "Doe")
|
||||
.redirect_url("https://example.com/payment/success");
|
||||
|
||||
print(" ✓ Payment request created");
|
||||
print(" Merchant Reference: ORDER_" + timestamp());
|
||||
print(" Amount: 2500.00 KES");
|
||||
print(" Description: Payment for Premium Subscription");
|
||||
|
||||
// Create payment link
|
||||
print("\n4. Creating payment link...");
|
||||
let payment_response = payment_client.create_payment_link(payment_request);
|
||||
print(" ✓ Payment link created successfully!");
|
||||
print(" Payment URL: " + payment_response.get_payment_url());
|
||||
print(" Order Tracking ID: " + payment_response.get_order_tracking_id());
|
||||
print(" Merchant Reference: " + payment_response.get_merchant_reference());
|
||||
print(" Status: " + payment_response.get_status());
|
||||
|
||||
// In a real scenario, you would:
|
||||
// 1. Redirect the user to payment_response.get_payment_url()
|
||||
// 2. User completes payment on Pesapal
|
||||
// 3. Pesapal sends callback to your callback URL
|
||||
// 4. You check payment status using the order tracking ID
|
||||
|
||||
// Simulate checking payment status
|
||||
print("\n5. Checking payment status...");
|
||||
let order_tracking_id = payment_response.get_order_tracking_id();
|
||||
let payment_status = payment_client.get_payment_status(order_tracking_id);
|
||||
print(" ✓ Payment status retrieved");
|
||||
print(" Order Tracking ID: " + order_tracking_id);
|
||||
print(" Status: " + payment_status.get_status());
|
||||
print(" Amount: " + payment_status.get_amount() + " " + payment_status.get_currency());
|
||||
print(" Payment Method: " + payment_status.get_payment_method());
|
||||
print(" Transaction ID: " + payment_status.get_transaction_id());
|
||||
|
||||
// Create another payment for a different scenario
|
||||
print("\n6. Creating another payment (smaller amount)...");
|
||||
let small_payment = new_payment_request(
|
||||
"ORDER_SMALL_" + timestamp(),
|
||||
150.00,
|
||||
"KES",
|
||||
"Coffee Purchase",
|
||||
"https://example.com/payment/callback"
|
||||
);
|
||||
|
||||
small_payment
|
||||
.customer_email("coffee@example.com")
|
||||
.customer_phone("+254798765432");
|
||||
|
||||
let small_payment_response = payment_client.create_payment_link(small_payment);
|
||||
print(" ✓ Small payment link created");
|
||||
print(" Amount: 150.00 KES");
|
||||
print(" Payment URL: " + small_payment_response.get_payment_url());
|
||||
|
||||
// Example with production client (commented out - requires real credentials)
|
||||
print("\n7. Production client example (not executed)...");
|
||||
print(" // For production, use:");
|
||||
print(" // let prod_client = new_payment_client_pesapal(");
|
||||
print(" // \"your_production_consumer_key\",");
|
||||
print(" // \"your_production_consumer_secret\"");
|
||||
print(" // );");
|
||||
|
||||
print("\n=== Payment Provider & Pesapal Example Complete ===");
|
||||
print("\nNote: This example makes REAL API calls to Pesapal sandbox.");
|
||||
print("The credentials used are for testing purposes only.");
|
||||
print("\nPesapal Payment Flow:");
|
||||
print("1. Create payment request with amount, currency, and customer details");
|
||||
print("2. Get payment URL from Pesapal");
|
||||
print("3. Redirect customer to payment URL");
|
||||
print("4. Customer completes payment (M-PESA, Card, etc.)");
|
||||
print("5. Pesapal sends callback to your server");
|
||||
print("6. Check payment status using order tracking ID");
|
||||
print("7. Fulfill order if payment is successful");
|
||||
95
examples/engine/12_contract.rhai
Normal file
95
examples/engine/12_contract.rhai
Normal file
@@ -0,0 +1,95 @@
|
||||
// Example 12: Legal Contract with Signatures
|
||||
|
||||
print("=== Legal Contract Example ===\n");
|
||||
|
||||
// Get a context to work with
|
||||
print("1. Getting context...");
|
||||
let ctx = get_context(["alice", "bob", "charlie"]);
|
||||
print(" ✓ Context created: " + ctx.context_id());
|
||||
|
||||
// Create a contract
|
||||
print("\n2. Creating a new contract...");
|
||||
let contract = new_contract(1)
|
||||
.title("Service Agreement")
|
||||
.content("This agreement is made between Party A and Party B for the provision of software development services...")
|
||||
.creator_id(101);
|
||||
|
||||
print(" ✓ Contract created");
|
||||
print(" Title: " + contract.title());
|
||||
print(" Status: " + contract.status());
|
||||
print(" Creator ID: " + contract.creator_id());
|
||||
|
||||
// Add signature IDs to contract (signatures would be created separately)
|
||||
print("\n3. Adding signature IDs to contract...");
|
||||
print(" (In practice, signatures would be created separately and their IDs referenced here)");
|
||||
|
||||
contract = contract
|
||||
.add_signature(1001) // Alice's signature ID
|
||||
.add_signature(1002); // Bob's signature ID
|
||||
|
||||
print(" ✓ Signature IDs added");
|
||||
print(" Total signatures: " + contract.signature_count());
|
||||
|
||||
// Check if contract is fully signed
|
||||
print("\n4. Checking signature status...");
|
||||
let required_signatures = 2;
|
||||
if contract.is_fully_signed(required_signatures) {
|
||||
print(" ✓ Contract is fully signed!");
|
||||
print(" Activating contract...");
|
||||
contract = contract.activate();
|
||||
print(" ✓ Contract status: " + contract.status());
|
||||
} else {
|
||||
print(" ⚠ Contract needs more signatures");
|
||||
print(" Current: " + contract.signature_count() + " / Required: " + required_signatures);
|
||||
}
|
||||
|
||||
// Store the contract
|
||||
print("\n5. Storing contract in context...");
|
||||
ctx.save(contract);
|
||||
print(" ✓ Contract stored");
|
||||
|
||||
// Simulate contract completion
|
||||
print("\n6. Completing contract...");
|
||||
contract = contract.complete();
|
||||
print(" ✓ Contract status: " + contract.status());
|
||||
|
||||
// Example: Contract cancellation (alternative flow)
|
||||
print("\n7. Example: Creating a contract that gets cancelled...");
|
||||
let cancelled_contract = new_contract(2)
|
||||
.title("Cancelled Agreement")
|
||||
.content("This contract was cancelled before completion")
|
||||
.creator_id(101);
|
||||
|
||||
print(" ✓ Contract created");
|
||||
cancelled_contract = cancelled_contract.cancel();
|
||||
print(" ✓ Contract cancelled");
|
||||
print(" Status: " + cancelled_contract.status());
|
||||
|
||||
// Example: Removing a signature
|
||||
print("\n8. Example: Removing a signature...");
|
||||
let test_contract = new_contract(3)
|
||||
.title("Test Contract")
|
||||
.add_signature(2001)
|
||||
.add_signature(2002)
|
||||
.add_signature(2003);
|
||||
|
||||
print(" ✓ Contract with 3 signatures created");
|
||||
print(" Signatures before removal: " + test_contract.signature_count());
|
||||
|
||||
test_contract = test_contract.remove_signature(2002);
|
||||
print(" ✓ Signature 2002 removed");
|
||||
print(" Signatures after removal: " + test_contract.signature_count());
|
||||
|
||||
print("\n=== Legal Contract Example Complete ===");
|
||||
print("\nContract Workflow:");
|
||||
print("1. Create contract with title, content, and metadata");
|
||||
print("2. Parties create signatures for the contract");
|
||||
print("3. Add signatures to contract using signature IDs");
|
||||
print("4. Check if contract is fully signed");
|
||||
print("5. Activate contract when all signatures are collected");
|
||||
print("6. Complete or cancel contract based on outcome");
|
||||
print("\nContract Statuses:");
|
||||
print("- Draft: Initial state, collecting signatures");
|
||||
print("- Active: Fully signed and in effect");
|
||||
print("- Completed: Successfully fulfilled");
|
||||
print("- Cancelled: Terminated before completion");
|
||||
84
examples/engine/main.rs
Normal file
84
examples/engine/main.rs
Normal file
@@ -0,0 +1,84 @@
|
||||
/// OSIRIS Engine Example
|
||||
///
|
||||
/// Demonstrates how to create an OSIRIS engine with the package
|
||||
/// and execute multiple Rhai scripts
|
||||
|
||||
use osiris::register_osiris_full;
|
||||
use rhai::Engine;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("=== OSIRIS Engine Example ===\n");
|
||||
|
||||
// Get all .rhai files in the current directory
|
||||
let example_dir = Path::new(file!()).parent().unwrap();
|
||||
let mut rhai_files: Vec<_> = fs::read_dir(example_dir)?
|
||||
.filter_map(|entry| entry.ok())
|
||||
.filter(|entry| {
|
||||
entry.path().extension()
|
||||
.and_then(|ext| ext.to_str())
|
||||
.map(|ext| ext == "rhai")
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Sort files alphabetically for consistent execution order
|
||||
rhai_files.sort_by_key(|entry| entry.file_name());
|
||||
|
||||
if rhai_files.is_empty() {
|
||||
println!("No .rhai files found in examples/engine/");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
println!("Found {} Rhai script(s):\n", rhai_files.len());
|
||||
|
||||
// Execute each Rhai script with a fresh engine
|
||||
for entry in rhai_files {
|
||||
let path = entry.path();
|
||||
let filename = path.file_name().unwrap().to_string_lossy();
|
||||
|
||||
println!("─────────────────────────────────────");
|
||||
println!("Running: {}", filename);
|
||||
println!("─────────────────────────────────────");
|
||||
|
||||
// Create a new raw engine and register all OSIRIS components
|
||||
let mut engine = Engine::new_raw();
|
||||
register_osiris_full(&mut engine);
|
||||
|
||||
// Set up context tags with SIGNATORIES for get_context
|
||||
let mut tag_map = rhai::Map::new();
|
||||
let signatories: rhai::Array = vec![
|
||||
rhai::Dynamic::from("alice".to_string()),
|
||||
rhai::Dynamic::from("bob".to_string()),
|
||||
rhai::Dynamic::from("charlie".to_string()),
|
||||
];
|
||||
tag_map.insert("SIGNATORIES".into(), rhai::Dynamic::from(signatories));
|
||||
tag_map.insert("DB_PATH".into(), "/tmp/osiris_example".to_string().into());
|
||||
tag_map.insert("CONTEXT_ID".into(), "example_context".to_string().into());
|
||||
engine.set_default_tag(rhai::Dynamic::from(tag_map));
|
||||
|
||||
// Read and execute the script
|
||||
let script_content = fs::read_to_string(&path)?;
|
||||
|
||||
match engine.eval::<rhai::Dynamic>(&script_content) {
|
||||
Ok(result) => {
|
||||
println!("\n✓ Success!");
|
||||
if !result.is_unit() {
|
||||
println!("Result: {}", result);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
println!("\n✗ Error: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
println!();
|
||||
}
|
||||
|
||||
println!("─────────────────────────────────────");
|
||||
println!("All scripts executed!");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
365
examples/freezone/freezone.rhai
Normal file
365
examples/freezone/freezone.rhai
Normal file
@@ -0,0 +1,365 @@
|
||||
// ============================================================================
|
||||
// FREEZONE REGISTRATION FLOW
|
||||
// ============================================================================
|
||||
// Complete registration flow for new freezone members including:
|
||||
// 0. Freezone initialization and configuration
|
||||
// 1. Public key registration
|
||||
// 2. User profile creation & email verification
|
||||
// 3. Terms & Conditions signing
|
||||
// 4. Crypto wallet creation (TFT + ETH)
|
||||
// 5. Payment processing
|
||||
// 6. KYC verification with info collection
|
||||
|
||||
print("=== FREEZONE REGISTRATION FLOW ===\n");
|
||||
|
||||
// ============================================================================
|
||||
// KEYPAIRS AND IDENTITIES
|
||||
// ============================================================================
|
||||
|
||||
// Freezone Organization (Keypair 1)
|
||||
let freezone_pubkey = "04d0aea7f0a48bcab4389753ddc2e61623dd89d800652b11d0a383eb3ea74561d730bdd06e0ca8f4cd4013907d95782a0a584313e1d91ae5ad09b663de36bfac44";
|
||||
|
||||
// User: Timur (Keypair 2)
|
||||
let timur_pubkey = "04090636d0a15854c4c0b73f65b6de5f6a27a7b22d6fbf5f6d97c45476a0384fe50781444c33f5af577e017599e4b432373fbcdcd844d8783c5e52240a14b63dc3";
|
||||
|
||||
print("Identities:");
|
||||
print(" Freezone: " + freezone_pubkey);
|
||||
print(" Timur: " + timur_pubkey);
|
||||
print();
|
||||
|
||||
// ============================================================================
|
||||
// INITIALIZATION: Freezone Configuration
|
||||
// ============================================================================
|
||||
|
||||
print("Initialization: Freezone Configuration");
|
||||
print("─────────────────────────────────────────────────────────────");
|
||||
|
||||
// Create context with freezone as the signatory
|
||||
let freezone_ctx = get_context([freezone_pubkey]);
|
||||
print("✓ Freezone context created");
|
||||
print(" Context ID: " + freezone_ctx.context_id());
|
||||
print(" Signatory: Freezone (" + freezone_pubkey + ")");
|
||||
|
||||
// Configure Email Client
|
||||
print("\nConfiguring Email Client...");
|
||||
let freezone_email_client = new_email_client()
|
||||
.smtp_host("smtp.freezone.example")
|
||||
.smtp_port(587)
|
||||
.from_email("noreply@freezone.example")
|
||||
.from_name("Freezone Platform");
|
||||
|
||||
print("✓ Email client configured");
|
||||
print(" SMTP Host: smtp.freezone.example");
|
||||
print(" From: noreply@freezone.example");
|
||||
|
||||
// Configure Payment Provider (Pesapal)
|
||||
print("\nConfiguring Payment Provider...");
|
||||
let freezone_payment_client = new_payment_client_pesapal_sandbox(
|
||||
1,
|
||||
"qkio1BGGYAXTu2JOfm7XSXNruoZsrqEW",
|
||||
"osGQ364R49cXKeOYSpaOnT++rHs="
|
||||
);
|
||||
|
||||
print("✓ Payment provider configured (Pesapal Sandbox)");
|
||||
print(" Provider: Pesapal");
|
||||
print(" Environment: Sandbox");
|
||||
|
||||
// Configure KYC Provider
|
||||
print("\nConfiguring KYC Provider...");
|
||||
print("✓ KYC provider configured");
|
||||
print(" Provider: Freezone KYC");
|
||||
print(" Callback URL: https://freezone.example/kyc/callback");
|
||||
|
||||
// Create Freezone's own Ethereum wallet
|
||||
print("\nCreating Freezone Ethereum Wallet...");
|
||||
let freezone_eth_wallet = new_ethereum_wallet()
|
||||
.owner_id(999) // Freezone organization ID
|
||||
.network("mainnet");
|
||||
|
||||
print("✓ Freezone Ethereum wallet created");
|
||||
print(" Address: " + freezone_eth_wallet.get_address());
|
||||
print(" Network: " + freezone_eth_wallet.get_network());
|
||||
print(" Owner: Freezone Organization (ID: 999)");
|
||||
|
||||
// Save Freezone's Ethereum account
|
||||
let freezone_eth_account = new_account()
|
||||
.owner_id(999)
|
||||
.address(freezone_eth_wallet.get_address())
|
||||
.currency("ETH")
|
||||
.balance(0.0);
|
||||
|
||||
freezone_ctx.save(freezone_eth_account);
|
||||
print("✓ Freezone Ethereum account saved");
|
||||
|
||||
print("\n✓ Freezone initialization complete\n");
|
||||
|
||||
// ============================================================================
|
||||
// STEP 0: Registration Flow Setup
|
||||
// ============================================================================
|
||||
|
||||
print("Step 0: Registration Flow Setup");
|
||||
print("─────────────────────────────────────────────────────────────");
|
||||
|
||||
// Define registration flow steps
|
||||
print("\nRegistration Flow Steps:");
|
||||
print(" 1. Public key registration");
|
||||
print(" 2. User profile creation & email verification");
|
||||
print(" 3. Terms & Conditions signing");
|
||||
print(" 4. Crypto wallet creation (TFT + ETH)");
|
||||
print(" 5. Payment processing");
|
||||
print(" 6. KYC verification with info collection");
|
||||
print();
|
||||
|
||||
// ============================================================================
|
||||
// STEP 1: Public Key Registration
|
||||
// ============================================================================
|
||||
|
||||
print("Step 1: Public Key Registration");
|
||||
print("─────────────────────────────────────────────────────────────");
|
||||
|
||||
// User (Timur) provides their public key
|
||||
print("User public key received: " + timur_pubkey);
|
||||
print("✓ Public key validated and stored\n");
|
||||
|
||||
// ============================================================================
|
||||
// STEP 2: User Profile Creation & Email Verification
|
||||
// ============================================================================
|
||||
|
||||
print("Step 2: User Profile Creation & Email Verification");
|
||||
print("─────────────────────────────────────────────────────────────");
|
||||
|
||||
// Collect basic user information
|
||||
let user_name = "Timur Gordon";
|
||||
let user_email = "timur@freezone.example";
|
||||
print("Collecting user information:");
|
||||
print(" Name: " + user_name);
|
||||
print(" Email: " + user_email);
|
||||
|
||||
// Create user profile
|
||||
let user_profile = new_user()
|
||||
.username(user_name)
|
||||
.pubkey(timur_pubkey)
|
||||
.add_email(user_email);
|
||||
|
||||
print("✓ User profile created");
|
||||
freezone_ctx.save(user_profile);
|
||||
print("✓ Profile saved");
|
||||
|
||||
// Email Verification
|
||||
print("\nInitiating email verification...");
|
||||
let verification = new_verification("user_1", user_email);
|
||||
|
||||
print("✓ Email verification created");
|
||||
print(" Verification code: " + verification.get_code());
|
||||
print(" Nonce: " + verification.get_nonce());
|
||||
|
||||
// Prepare verification email
|
||||
let verification_link = "https://freezone.example/verify?nonce=" + verification.get_nonce();
|
||||
print(" Verification link: " + verification_link);
|
||||
print(" (Email sent to: " + user_email + ")");
|
||||
|
||||
// Simulate user clicking verification link and verifying
|
||||
print("\n✓ User clicks verification link and verifies email");
|
||||
verification.verify_nonce(verification.get_nonce());
|
||||
print("✓ Email verified: " + verification.get_status());
|
||||
|
||||
freezone_ctx.save(verification);
|
||||
print("✓ Verification saved\n");
|
||||
|
||||
// ============================================================================
|
||||
// STEP 3: Terms & Conditions Signing
|
||||
// ============================================================================
|
||||
|
||||
print("Step 3: Terms & Conditions Signing");
|
||||
print("─────────────────────────────────────────────────────────────");
|
||||
|
||||
// Create Terms & Conditions contract
|
||||
let terms_contract = new_contract(1)
|
||||
.title("Freezone Membership Terms & Conditions")
|
||||
.content("By signing this agreement, you agree to abide by all freezone rules and regulations...")
|
||||
.creator_id(999); // Freezone admin
|
||||
|
||||
print("✓ Terms & Conditions contract created");
|
||||
print(" Title: " + terms_contract.title());
|
||||
|
||||
// User signs the contract (add their signature ID)
|
||||
let user_signature_id = 1001;
|
||||
terms_contract = terms_contract.add_signature(user_signature_id);
|
||||
print("✓ User signature added (ID: " + user_signature_id + ")");
|
||||
|
||||
// Activate contract once signed
|
||||
if terms_contract.is_fully_signed(1) {
|
||||
terms_contract = terms_contract.activate();
|
||||
print("✓ Contract activated: " + terms_contract.status());
|
||||
}
|
||||
|
||||
freezone_ctx.save(terms_contract);
|
||||
print("✓ Signed contract saved\n");
|
||||
|
||||
// ============================================================================
|
||||
// STEP 4: Crypto Wallet Creation
|
||||
// ============================================================================
|
||||
|
||||
print("Step 4: Crypto Wallet Creation");
|
||||
print("─────────────────────────────────────────────────────────────");
|
||||
|
||||
// Create TFT crypto account for user
|
||||
let tft_account = new_account()
|
||||
.owner_id(1)
|
||||
.currency("TFT") // ThreeFold Token
|
||||
.balance(0.0);
|
||||
|
||||
print("✓ TFT account created");
|
||||
print(" Owner ID: 1");
|
||||
print(" Currency: TFT");
|
||||
print(" Initial balance: 0");
|
||||
|
||||
freezone_ctx.save(tft_account);
|
||||
|
||||
// Create Ethereum wallet for user
|
||||
print("\nCreating Ethereum wallet...");
|
||||
let eth_wallet = new_ethereum_wallet()
|
||||
.owner_id(1)
|
||||
.network("mainnet");
|
||||
|
||||
print("✓ Ethereum wallet created");
|
||||
print(" Address: " + eth_wallet.get_address());
|
||||
print(" Network: mainnet");
|
||||
print(" Balance: 0 ETH");
|
||||
|
||||
// Save as account
|
||||
let eth_account = new_account()
|
||||
.owner_id(1)
|
||||
.address(eth_wallet.get_address())
|
||||
.currency("ETH")
|
||||
.balance(0.0);
|
||||
|
||||
freezone_ctx.save(eth_account);
|
||||
print("✓ Ethereum account saved\n");
|
||||
|
||||
// ============================================================================
|
||||
// STEP 5: Payment Processing
|
||||
// ============================================================================
|
||||
|
||||
print("Step 5: Payment Processing");
|
||||
print("─────────────────────────────────────────────────────────────");
|
||||
|
||||
print("Using configured Pesapal payment client...");
|
||||
|
||||
// Create payment request for registration fee
|
||||
print("\nCreating payment session...");
|
||||
let payment_request = new_payment_request()
|
||||
.amount(100.0)
|
||||
.currency("USD")
|
||||
.description("Freezone Registration Fee")
|
||||
.callback_url("https://freezone.example/payment/callback")
|
||||
.merchant_reference("REG_USER_1_" + timestamp());
|
||||
|
||||
print("✓ Payment request created");
|
||||
print(" Amount: $100 USD");
|
||||
print(" Description: Freezone Registration Fee");
|
||||
|
||||
// Initiate payment with Pesapal (this would return a payment URL)
|
||||
print("\nInitiating payment session with Pesapal...");
|
||||
print(" Payment URL: https://pay.pesapal.com/iframe/PesapalIframe3/Index/?OrderTrackingId=abc123");
|
||||
print(" (User would be redirected to Pesapal payment page)");
|
||||
|
||||
// Simulate user completing payment
|
||||
print("\n✓ User clicks payment link and completes payment");
|
||||
print(" Payment Status: COMPLETED");
|
||||
print(" Transaction ID: TXN_" + timestamp());
|
||||
|
||||
// Create payment transaction record
|
||||
let payment_tx = new_transaction()
|
||||
.source(0) // External payment
|
||||
.destination(1) // Freezone account
|
||||
.amount(100.0)
|
||||
.assetid(1);
|
||||
|
||||
print("✓ Payment transaction recorded");
|
||||
|
||||
freezone_ctx.save(payment_tx);
|
||||
print("✓ Transaction saved\n");
|
||||
|
||||
// ============================================================================
|
||||
// STEP 6: KYC Verification
|
||||
// ============================================================================
|
||||
|
||||
print("Step 6: KYC Verification");
|
||||
print("─────────────────────────────────────────────────────────────");
|
||||
|
||||
// Create KYC session
|
||||
let kyc_session = new_kyc_session("user_1", "freezone_kyc")
|
||||
.callback_url("https://freezone.example/kyc/callback")
|
||||
.success_url("https://freezone.example/kyc/success")
|
||||
.error_url("https://freezone.example/kyc/error");
|
||||
|
||||
print("✓ KYC session created");
|
||||
print(" Client ID: " + kyc_session.get_client_id());
|
||||
print(" Provider: " + kyc_session.get_provider());
|
||||
|
||||
// Generate KYC verification URL
|
||||
print("\nKYC Verification URL generated:");
|
||||
print(" https://kyc.provider.com/verify?session=kyc_session_" + timestamp());
|
||||
print(" (User would be redirected to KYC provider)");
|
||||
|
||||
// Simulate user clicking KYC link and completing verification
|
||||
print("\n✓ User clicks KYC link and completes verification");
|
||||
print(" - Uploads identity document (Passport)");
|
||||
print(" - Takes selfie for liveness check");
|
||||
print(" - Provides address proof");
|
||||
|
||||
// Simulate KYC callback with verification results
|
||||
print("\n✓ KYC Provider callback received:");
|
||||
print(" - Identity verification: PASSED");
|
||||
print(" - Liveness check: PASSED");
|
||||
print(" - Address verification: PASSED");
|
||||
print(" - Sanctions screening: CLEAR");
|
||||
print(" - PEP check: NOT FOUND");
|
||||
print(" - Overall Status: VERIFIED");
|
||||
|
||||
// Create KYC info with verified data from callback
|
||||
print("\nStoring verified KYC information...");
|
||||
let kyc_info_verified = new_kyc_info()
|
||||
.first_name("Timur")
|
||||
.last_name("Gordon")
|
||||
.email(user_email)
|
||||
.phone("+1-555-0123")
|
||||
.country("US")
|
||||
.date_of_birth("1990-05-15")
|
||||
.document_type("passport")
|
||||
.document_number("P123456789")
|
||||
.verified(true);
|
||||
|
||||
freezone_ctx.save(kyc_info_verified);
|
||||
freezone_ctx.save(kyc_session);
|
||||
print("✓ KYC verification data saved");
|
||||
print("✓ KYC verification completed\n");
|
||||
|
||||
// ============================================================================
|
||||
// SUMMARY
|
||||
// ============================================================================
|
||||
|
||||
print("═══════════════════════════════════════════════════════════════");
|
||||
print("REGISTRATION COMPLETE");
|
||||
print("═══════════════════════════════════════════════════════════════");
|
||||
print("\nUser Summary:");
|
||||
print(" Name: " + user_name);
|
||||
print(" Email: " + user_email);
|
||||
print(" Public Key: " + timur_pubkey);
|
||||
print(" TFT Account: Created");
|
||||
print(" ETH Account: Created");
|
||||
print(" KYC Status: Verified");
|
||||
print(" Payment Status: Completed ($100 USD)");
|
||||
print(" Contract: Signed and Active");
|
||||
print("\nRegistration Flow:");
|
||||
print(" ✓ Freezone initialization (Email, Payment, KYC providers configured)");
|
||||
print(" ✓ Freezone Ethereum wallet created");
|
||||
print(" ✓ Public key registration");
|
||||
print(" ✓ User profile creation & email verification");
|
||||
print(" ✓ Terms & Conditions signed");
|
||||
print(" ✓ Crypto wallets created (TFT + ETH)");
|
||||
print(" ✓ Payment processed ($100 USD)");
|
||||
print(" ✓ KYC verification completed with verified info");
|
||||
print("\n" + user_name + " is now a verified Freezone member!");
|
||||
print("═══════════════════════════════════════════════════════════════\n");
|
||||
48
examples/freezone/main.rs
Normal file
48
examples/freezone/main.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
/// OSIRIS Freezone Registration Flow Example
|
||||
///
|
||||
/// Demonstrates a complete freezone registration flow with all steps
|
||||
|
||||
use osiris::register_osiris_full;
|
||||
use rhai::Engine;
|
||||
use std::fs;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("=== OSIRIS Freezone Registration Flow ===\n");
|
||||
|
||||
// Create a new raw engine and register all OSIRIS components
|
||||
let mut engine = Engine::new_raw();
|
||||
register_osiris_full(&mut engine);
|
||||
|
||||
// Set up context tags with SIGNATORIES for get_context
|
||||
let mut tag_map = rhai::Map::new();
|
||||
let signatories: rhai::Array = vec![
|
||||
rhai::Dynamic::from("freezone_admin".to_string()),
|
||||
rhai::Dynamic::from("kyc_officer".to_string()),
|
||||
rhai::Dynamic::from("payment_processor".to_string()),
|
||||
];
|
||||
tag_map.insert("SIGNATORIES".into(), rhai::Dynamic::from(signatories));
|
||||
tag_map.insert("DB_PATH".into(), "/tmp/osiris_freezone".to_string().into());
|
||||
tag_map.insert("CONTEXT_ID".into(), "freezone_context".to_string().into());
|
||||
engine.set_default_tag(rhai::Dynamic::from(tag_map));
|
||||
|
||||
// Read and execute the freezone script
|
||||
let script_path = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/freezone/freezone.rhai");
|
||||
let script_content = fs::read_to_string(script_path)?;
|
||||
|
||||
match engine.eval::<rhai::Dynamic>(&script_content) {
|
||||
Ok(result) => {
|
||||
println!("\n✓ Freezone registration flow completed successfully!");
|
||||
if !result.is_unit() {
|
||||
println!("Result: {}", result);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("\n✗ Error: {}", e);
|
||||
eprintln!("Error details: {:?}", e);
|
||||
return Err(e.into());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user