AI Network
  • What is AI Network
  • AIN Blockchain
    • Architecture
      • Design Principles
      • Event-driven Architectures
      • Blockchain Database
        • States
          • State Types
          • Operations
          • Predefined Structures
        • Rules and Owners
          • Rule Configs
          • Owner Configs
        • Functions
          • Built-in Functions
      • Instant Execution, and Eventual Consistency
      • Network ID and Chain ID
      • Transactions
        • Structure
        • Nonce
        • Read Concern
        • Propagation
      • Block Structure
      • Account and Keys
      • Consensus
      • Scalability
      • Apps
    • Developer Guide
      • Quick Start
      • AI Network Products
        • AI Network Worker
        • AI Network Insight
        • Testnet Server Node
        • Ainize Trigger
          • Project user
          • Project deployer
          • Why do we have to use Ainize Trigger?
      • Token Bridge
      • Trouble Shooting
    • Developer Reference
      • Blockchain API
        • JSON RPC API
        • Node Client API
      • Blockchain SDK
        • ain-js
        • ain-py
      • Validators
    • Staking
  • AIN DAO
    • What is AIN DAO
      • Runo (Run Your Node)
      • GPU Sponsorship Program
    • Onboarding & Participation
    • Governance
    • Tokenomics
      • AI Network Tokenomics
      • AINFT Tokenomics
  • AI Agents
    • AINFT
    • AINFT Factory
    • AINFT Projects
      • 🍳MiniEggs
      • 🦈Baby Shark
      • 🛸Soul Fiction
      • 🎻NFT Classics Society
    • Developer Reference
      • Ainft-Js
      • AINFT tutorial
        • Create AINFT object and Mint
        • Transfer AINFT
        • Set metadata of AINFT
        • Search and Retrieve AINFT
  • AIN Wallet
    • What is AIN Wallet?
    • AIN Wallet API
  • PROPOSAL DOCUMENTS
    • AIN Improvement Memos (AIMs)
    • AIN Improvement Proposals (AIPs)
Powered by GitBook
On this page
  • Built-in Functions
  • Transfer
  • Deposit
  • Withdraw

Was this helpful?

  1. AIN Blockchain
  2. Architecture
  3. Blockchain Database
  4. Functions

Built-in Functions

Built-in Functions

To apply predefined system operations, built-in functions are defined. For example, account value transfer is implemented using transfer built-in function. Each built-in function consists of triggering conditions and a function. The triggering condition is given by a database path pattern and whenever a new value is written on the path patten, the function is called. If the function fails, the transaction triggered the function call also fails.

Transfer

{
  '/transfer/{from_addr}/{to_addr}/{transfer_id}/value': _transfer(value, context) {
    // Check (the balance of from_addr) >= value
    // Decrement the balance of from_addr by value
    // Increment the balance of to_addr by value
  }
}

Deposit

{
  '/deposit/{service_id}/{addr}/{deposit_id}/value': _deposit(value, context) {
    // Check (the balance of addr) >= value
    // Decrement the balance of addr by value
    // Increment the value of /deposit_accounts/$service_id/$addr by value
    // Set /deposit_accounts/$service_id/$addr/expire_at as
    // transaction's timestamp + service's deposit lockup time, which is
    // configured at /deposit_accounts/$service_id/config/lockup_duration
  }
}

Withdraw

{
  '/withdraw/{service_id}/{addr}/{withdraw_id}/value': _withdraw(value, context) {
    // Check the value at (/deposit_accounts/$service_id/$addr/value) >= value
    // Check (deposit_accounts/$service_id/$addr/expire_at) >= current time
    // Decrement the value of /deposit_accounts/$service_id/$addr by value
    // Increment the balance of addr by value
  }
}
PreviousFunctionsNextInstant Execution, and Eventual Consistency

Last updated 5 years ago

Was this helpful?