LogoLogo
  • Overview
    • 📎What is Interesting?
    • 📐What we do
      • 🏴‍☠️Private Application Networks
      • 🥠Graph Blockchains
      • ✨Extranet
      • 🔮SD-zkUAN
    • 💡Knowledge Graphs are Interesting
    • 🍨Zero Knowledge Graphs
  • 🔐Cryptography
  • 🚡Hybrid Layer 2
  • 🪙Our Platform Token
  • Guides
    • 📪Creating an Account
    • 📎Creating Blockchain Graphs
    • 👽UAP Tracking App
    • 🧠AI Forever Brain
    • 🛫Decentralized Elon Flight Tracker
  • Intermediate Level
    • 🔗JSON Linked Data
    • 🔏Immutable Graphchains
    • 🕸️The Semantic Web3
    • 📔Smart Functions
    • 🎓Advanced Smart Functions
    • ⛓️Graphchain vs. Blockchain
  • Use Cases
    • 🎨For Artists
    • 🖥️For Developers
    • 🕴️For Business
    • 👷‍♂️For Industry
    • 👨‍🌾For Farmers
    • 🪖For Non Profits
Powered by GitBook

Copyright 2023 - the interesting network

On this page
  1. Intermediate Level

Smart Functions

Understanding FlureeDB Smart Functions in the Interesting Network

The Interesting Network, leveraging the FlureeDB framework, integrates the power of FlureeDB's smart functions to offer an advanced and secure data management system. FlureeDB smart functions, known as FlureeQL within the network, are pivotal in facilitating complex data manipulations and enforcing business logic directly within the ledger.

How Projects Work in the Interesting Network

Projects in the Interesting Network transcend traditional data collections, evolving into ecosystems where data integrity, security, and smart functionality are harmoniously intertwined. Each project is a distinct microcosm with its own schema, rules, and smart functions. These functions are critical for managing and transforming data within the ledger.

The Basics of FlureeDB Smart Functions

FlureeDB smart functions are code snippets that operate within the database layer to:

  • Validate transactions based on custom business rules.

  • Ensure data adheres to the defined schema and business logic.

  • Automate processes based on data changes within the ledger.

Creating a Project with Smart Functions

To set up a project in the Interesting Network:

  1. Define Your Schema: Outline the structure of your data, specifying the collections and their relationships.

  2. Incorporate Smart Functions: Embed smart functions into your schema to dictate data interactions.

  3. Deploy Your Project: Launch your schema and smart functions in the network to begin managing your project’s data.

Organizing Your Projects Effectively

Effective project organization involves:

  • Grouping related data into well-defined collections.

  • Writing reusable, modular smart functions.

  • Rigorous testing to ensure expected functionality.

  • Continuously refining smart functions to meet evolving needs.

Clojure Examples of Smart Functions

1. Transaction Validation Function

(defn validate-transaction
  [txn db]
  (let [user-credits (query db {:select ["credits"]
                               :from "user"
                               :where [[:id (:userId txn)]]})
        required-credits (:amount txn)]
    (if (>= user-credits required-credits)
      true
      (throw (Exception. "Insufficient credits")))))

2. Automated Data Updates Function

(defn update-user-status
  [userId db]
  (let [activity-threshold 10
        user-activity (query db {:select ["activity"]
                                :from "userActivity"
                                :where [[:userId userId]]})]
    (when (> user-activity activity-threshold)
      (update db {:update "user"
                  :where [[:id userId]]
                  :set {:status "active"}}))))

3. Complex Business Logic Enforcement Function

(defn access-control-check
  [userId dataId db]
  (let [user-role (query db {:select ["role"]
                            :from "user"
                            :where [[:id userId]]})
        data-classification (query db {:select ["classification"]
                                      :from "data"
                                      :where [[:id dataId]]})]
    (if (authorized? user-role data-classification)
      true
      (throw (Exception. "Access Denied")))))

(defn authorized?
  [role classification]
  ;; Define authorization logic
  (or (= role "admin") (= classification "public")))

By harnessing FlureeDB smart functions within the Interesting Network, you can build robust, secure, and efficient applications tailored to your specific needs. These functions provide advanced data control and automation capabilities, enhancing your project's functionality and efficiency. As you explore these tools, you'll uncover new ways to leverage them for innovative data management and processing solutions.

PreviousThe Semantic Web3NextAdvanced Smart Functions

Last updated 1 year ago

📔