96 lines
3.5 KiB
Plaintext
96 lines
3.5 KiB
Plaintext
// 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");
|