TallyBox Tutorial - Database Structure

by shahiN Noursalehi

You are here: Home / Tutorials / TallyBox Payment Processor - Database Structure

Note: This tutorial is structured to be AI-Friendly. An AI can generate code or database schemas in any programming language or database system based on the content of this URL, thanks to its clear explanations, schema details, and examples.

TallyBox Database Structure

This tutorial guides developers through the SQL Server database structure for the TallyBox Windows desktop application. The `net_mixoftix_tallybox` database supports transaction processing, wallet management, and archiving for a decentralized ledger system. This tutorial explains the database setup, table purposes, relationships, and provides a downloadable SQL script with copy-to-clipboard functionality.

Step 1: Database Setup

The `net_mixoftix_tallybox` database is created with specific configurations for performance and reliability. The setup involves:

This step ensures the database is optimized for transaction processing.

Pseudo-Code: Database Creation

CREATE DATABASE net_mixoftix_tallybox
    PRIMARY_FILE = 'C:\shahin_root\dbs\net_mixoftix_tallybox.mdf', SIZE = 10304KB, MAXSIZE = UNLIMITED
    LOG_FILE = 'C:\shahin_root\dbs\net_mixoftix_tallybox_log.ldf', SIZE = 8192KB, MAXSIZE = 2048GB
    COMPATIBILITY_LEVEL = 160
    QUERY_STORE = ON (STALE_QUERY_THRESHOLD_DAYS = 30, MAX_STORAGE_SIZE_MB = 1000)
    RECOVERY = FULL
    PAGE_VERIFY = CHECKSUM
    DISABLE ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS
END
                


Example Setup:

Database Name: net_mixoftix_tallybox
Data File: C:\shahin_root\dbs\net_mixoftix_tallybox.mdf (10MB)
Log File: C:\shahin_root\dbs\net_mixoftix_tallybox_log.ldf (8MB)
Query Store: Enabled
Recovery Model: FULL

References:
CREATE DATABASE (Microsoft Docs)
SQL Server (Wikipedia)

Step 2: Download SQL Script

Below is the complete SQL script for creating the `net_mixoftix_tallybox` database and its tables. You can copy it to your clipboard.

References:
Generate Scripts in SSMS (Microsoft Docs)
SQL (Wikipedia)

Step 3: Transaction Processing Tables

These tables handle incoming transactions and their processing. They include:

These tables are used by `timer_engine_Tick` and `sql_ods_processor` to process transactions.

Schema Example: tbl_order_ods

CREATE TABLE tbl_order_ods (
    graph_from VARCHAR(50) NULL,
    graph_to VARCHAR(50) NULL,
    wallet_from VARCHAR(64) NOT NULL,
    wallet_to VARCHAR(64) NOT NULL,
    order_currency VARCHAR(10) NULL,
    order_amount DECIMAL(18,8) NOT NULL,
    order_utc_unix BIGINT NOT NULL,
    order_id VARCHAR(20) NULL,
    public_key VARCHAR(50) NULL,
    the_sign VARCHAR(100) NOT NULL,
    local_utc_unix BIGINT NULL,
    CONSTRAINT PK_tbl_order_ods PRIMARY KEY (the_sign)
)
                


Example Data:

Table: tbl_order_ods
graph_from: tallybox.mixoftix.net
wallet_from: boxB2bbc15c8c135...
order_currency: 2ZR
order_amount: 3500.00000000
order_id: 778844
the_sign: MEYCIQCxzNKhOUXijLr+z2mI9npu/+KZijiEv3//W7Ya3VpvzgIhAI1m7wJLJ9ldP2m5jmYfUreuvoKTjoZmFQmt5e6foakp
local_utc_unix: 1741675600

References:
CREATE TABLE (Microsoft Docs)
Database Sharding (Wikipedia)

Step 4: System Configuration Tables

These tables store configuration and validation data for the TallyBox system. They include:

These tables support validation in `sql_ods_processor`.

Schema Example: tbl_system_currency

CREATE TABLE tbl_system_currency (
    currency_id INT NULL,
    currency_name VARCHAR(10) NOT NULL,
    currency_title VARCHAR(50) NULL,
    currency_image VARCHAR(15) NULL,
    CONSTRAINT PK_tbl_system_currency PRIMARY KEY (currency_name)
)
                


Example Data:

Table: tbl_system_currency
currency_id: 1
currency_name: IRR
currency_title: Iranian Rial
currency_image: irr.png

currency_id: 2
currency_name: 2ZR
currency_title: TallyBox Token
currency_image: 2zr.png

References:
Primary Key Constraints (Microsoft Docs)
Database Normalization (Wikipedia)

Step 5: Ledger and Wallet Tables

These tables manage wallets and ledger entries for transactions in the TallyBox system. They are critical for tracking wallet identities, public keys, and transaction records. The tables include:

These tables are updated by the `sql_ods_processor` stored procedure during transaction processing, ensuring accurate ledger updates and signature validation.

Schema Example: tbl_tallybox_book

CREATE TABLE tbl_tallybox_book (
    tnx_id_dag DECIMAL(18,7) NULL,
    tnx_id DECIMAL(18,7) NULL,
    tnx_type TINYINT NULL,
    graph_id INT NULL,
    wallet_id BIGINT NULL,
    currency_id INT NULL,
    currency_amount DECIMAL(18,8) NULL,
    left_amount DECIMAL(18,8) NULL,
    tally_hash_dag VARCHAR(64) NULL,
    tally_hash VARCHAR(64) NOT NULL,
    CONSTRAINT PK_tbl_tallybox_book PRIMARY KEY (tally_hash)
)
                


Example Data:

Table: tbl_tallybox_book
tnx_id_dag: 1741675599.1000000
tnx_id: 1741675600.1000000
tnx_type: 0
graph_id: 123
wallet_id: 1001
currency_id: 1
currency_amount: 750.00000000
left_amount: 250.00000000
tally_hash_dag: a1b2c3d4e5f67890123456789abcdef0123456789abcdef0123456789abcdef
tally_hash: 7c4a8d09ca3762af61e59520943dc26494f8941b

References:
Primary Key Constraints (Microsoft Docs)
Cryptographic Hash Functions (Wikipedia)

Step 6: Buffer and Archive Tables

Buffer and archive tables manage temporary storage and long-term archiving of transaction and wallet data. These tables include:

The `timer_buffer_Tick` process moves data from buffer tables to archive tables based on the `archive_id` value.

Schema Example: tbl_tallybox_wallet_buffer

CREATE TABLE tbl_tallybox_wallet_buffer (
    the_wallet VARCHAR(64) NOT NULL,
    wallet_id BIGINT NOT NULL,
    archive_id TINYINT NULL
)
                


Example Data:

Table: tbl_tallybox_wallet_buffer
the_wallet: boxB2bbc15c8c135a7b8f8e7a8b6c7d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8
wallet_id: 1001
archive_id: 1

References:
Temporal Tables (Microsoft Docs)
Data Archiving (Wikipedia)

Step 7: Optimization and Monitoring

The database includes features for optimization and monitoring:

These features ensure efficient transaction processing and data retrieval.

Schema Example: tbl_optimize_row_counts

CREATE TABLE tbl_optimize_row_counts (
    table_name VARCHAR(30) NOT NULL,
    row_count BIGINT NOT NULL DEFAULT (0),
    last_updated DATETIME NOT NULL DEFAULT (GETDATE()),
    CONSTRAINT PK_tbl_row_counts PRIMARY KEY (table_name)
)
                


Example Data:

Table: tbl_optimize_row_counts
table_name: tbl_tallybox_book
row_count: 15000
last_updated: 2025-08-02 05:47:00

References:
Indexes (Microsoft Docs)
Performance Monitoring (Microsoft Docs)

Step 8: Data Flow and Relationships

The data flow in the TallyBox database follows a structured process:

  1. Incoming transactions are stored in one of the sharded `tbl_order_dispatcher_X` tables (0-9), identified by `the_sign`.
  2. The `timer_engine_Tick` process moves transactions to `tbl_order_ods` for processing.
  3. The `sql_ods_processor` validates transactions using `tbl_system_currency`, `tbl_system_graph`, and `tbl_tallybox_wallet`, then updates `tbl_tallybox_book` and `tbl_tallybox_sign`.
  4. For group transactions, `tbl_order_ods_multiple` stores multiple recipients linked by `the_sign_md5`.
  5. Periodically, `timer_buffer_Tick` moves records from buffer tables (`tbl_tallybox_wallet_buffer`, etc.) to archive tables (`tbl_tallybox_wallet_archive_1`, etc.) based on `archive_id`.
  6. `tbl_system_treasury` and `tbl_system_gazette` log treasury and blockchain-related data.
Relationships:

Pseudo-Code: Transaction Processing

BEGIN
    SELECT * FROM tbl_order_dispatcher_X WHERE the_sign = 'signature'
    INSERT INTO tbl_order_ods SELECT * FROM tbl_order_dispatcher_X
    EXEC sql_ods_processor @the_sign
        VALIDATE wallet_from, wallet_to IN tbl_tallybox_wallet
        VALIDATE order_currency IN tbl_system_currency
        INSERT INTO tbl_tallybox_book (tnx_id, wallet_id, currency_amount, tally_hash)
        INSERT INTO tbl_tallybox_sign (tnx_id, the_sign, the_sign_md5)
    MOVE TO tbl_tallybox_book_buffer WHERE archive_id = 1
    EXEC timer_buffer_Tick
        INSERT INTO tbl_tallybox_book_archive_1 SELECT * FROM tbl_tallybox_book_buffer
END
                

References:
Stored Procedures (Microsoft Docs)
Database Design (Wikipedia)

Conclusion

The `net_mixoftix_tallybox` database is designed for efficient transaction processing, wallet management, and data archiving in the TallyBox application. Its sharded dispatcher tables, system configuration tables, ledger and wallet tables, and buffer/archive system ensure scalability and performance. Non-clustered indexes and the Query Store optimize query performance, while constraints maintain data integrity. By following this tutorial, developers can set up the database, understand its structure, and integrate it with the TallyBox application.

For further assistance, refer to the provided SQL script and Microsoft SQL Server documentation. If you have questions, contact the TallyBox support team.

References:
SQL Server Documentation
Blockchain (Wikipedia)