108 lines
3.3 KiB
Rust
108 lines
3.3 KiB
Rust
// This example demonstrates the basic functionality of the circle models
|
|
// without using the database functionality
|
|
|
|
use herodb::models::circle::{Circle, Member, Name, Wallet, Role, Record, RecordType};
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
println!("Circle Module Basic Demo");
|
|
|
|
// Create a circle
|
|
let circle = Circle::new(
|
|
1,
|
|
"ThreeFold Community".to_string(),
|
|
"A circle for ThreeFold community members".to_string(),
|
|
);
|
|
|
|
println!("Created circle: {:?}", circle);
|
|
|
|
// Create members
|
|
let mut alice = Member::new(
|
|
1,
|
|
"Alice".to_string(),
|
|
"Core contributor".to_string(),
|
|
Role::Admin,
|
|
);
|
|
alice.add_email("alice@example.com".to_string());
|
|
|
|
let mut bob = Member::new(
|
|
2,
|
|
"Bob".to_string(),
|
|
"Community member".to_string(),
|
|
Role::Member,
|
|
);
|
|
bob.add_email("bob@example.com".to_string());
|
|
|
|
println!("Created members: {:?}, {:?}", alice, bob);
|
|
|
|
// Create a domain name
|
|
let mut domain = Name::new(
|
|
1,
|
|
"threefold.io".to_string(),
|
|
"ThreeFold main domain".to_string(),
|
|
);
|
|
|
|
let record = Record {
|
|
name: "www".to_string(),
|
|
text: "ThreeFold Website".to_string(),
|
|
category: RecordType::A,
|
|
addr: vec!["192.168.1.1".to_string()],
|
|
};
|
|
|
|
domain.add_record(record);
|
|
domain.add_admin("alice_pubkey".to_string());
|
|
|
|
println!("Created domain: {:?}", domain);
|
|
|
|
// Create wallets
|
|
let mut alice_wallet = Wallet::new(
|
|
1,
|
|
"Alice's TFT Wallet".to_string(),
|
|
"Main TFT wallet".to_string(),
|
|
"Stellar".to_string(),
|
|
"GALICE...".to_string(),
|
|
);
|
|
|
|
alice_wallet.set_asset("TFT".to_string(), 1000.0);
|
|
alice_wallet.set_asset("XLM".to_string(), 100.0);
|
|
|
|
let mut bob_wallet = Wallet::new(
|
|
2,
|
|
"Bob's TFT Wallet".to_string(),
|
|
"Main TFT wallet".to_string(),
|
|
"Stellar".to_string(),
|
|
"GBOB...".to_string(),
|
|
);
|
|
|
|
bob_wallet.set_asset("TFT".to_string(), 500.0);
|
|
|
|
println!("Created wallets: {:?}, {:?}", alice_wallet, bob_wallet);
|
|
|
|
// Link wallets to members
|
|
alice.link_wallet(alice_wallet.id);
|
|
bob.link_wallet(bob_wallet.id);
|
|
|
|
println!("Linked wallets to members");
|
|
|
|
// Demonstrate wallet operations
|
|
println!("\nDemonstrating wallet operations:");
|
|
|
|
println!("Alice's wallet before transfer: {:?}", alice_wallet);
|
|
println!("Alice's wallet total value: {}", alice_wallet.total_value());
|
|
|
|
println!("Bob's wallet before transfer: {:?}", bob_wallet);
|
|
println!("Bob's wallet total value: {}", bob_wallet.total_value());
|
|
|
|
// Simulate a transfer of 100 TFT from Alice to Bob
|
|
alice_wallet.set_asset("TFT".to_string(), 900.0); // Decrease Alice's TFT by 100
|
|
bob_wallet.set_asset("TFT".to_string(), 600.0); // Increase Bob's TFT by 100
|
|
|
|
println!("Alice's wallet after transfer: {:?}", alice_wallet);
|
|
println!("Alice's wallet total value: {}", alice_wallet.total_value());
|
|
|
|
println!("Bob's wallet after transfer: {:?}", bob_wallet);
|
|
println!("Bob's wallet total value: {}", bob_wallet.total_value());
|
|
|
|
println!("\nCircle basic demo completed successfully!");
|
|
|
|
Ok(())
|
|
} |