TallyBox Tutorial - Buffer Archiving

by shahiN Noursalehi

You are here: Home / Toturials / TallyBox Payment Processor - Buffer Archiving

Note: This tutorial is structured to be AI-Friendly. An AI can generate code in any programming language based on the content of this URL, thanks to its clear steps, pseudo-code, and examples.

Moving Buffered Records to Archive Tables

This tutorial guides developers through a TallyBox Windows desktop application that monitors buffered records in database tables and moves them to their respective archive tables using the `timer_buffer_Tick` function. The function periodically checks buffer tables for records and transfers them to archive tables based on an archive ID. This tutorial explains the logic, algorithm, and data flow, with pseudo-code to aid implementation in a C# Windows Forms environment.

Step 1: Check Buffer Status

The `timer_buffer_Tick` function begins by checking the status of buffer tables using `Program.buffer_stats()`. The process involves:

This step determines whether there are records to process.

Pseudo-Code: Check Buffer Status

FUNCTION check_buffer_status():
    buffer_stats = Program.buffer_stats()
    update_ui(txt_buffer_jobs, buffer_stats)
    IF buffer_stats == "empty" THEN
        // Optionally log empty state
        RETURN null
    END IF
    RETURN buffer_stats
END FUNCTION
                


Example Process:

buffer_stats: 1~1741675600.1
UI Update: txt_buffer_jobs = 1~1741675600.1
Result: Proceed to parse buffer status

References:
Timer Class (Microsoft Docs)
Database (Wikipedia)

Step 2: Parse Buffer Status

If the buffer is not empty, parse the status string to extract `archive_id` and `tnx_id`. The process involves:

This step prepares the identifiers needed to move records to the correct archive tables.

Pseudo-Code: Parse Buffer Status

FUNCTION parse_buffer_status(buffer_stats):
    IF buffer_stats != "empty" THEN
        parts = split(buffer_stats, "~")
        archive_id = parts[0]
        tnx_id = parts[1]
        RETURN archive_id, tnx_id
    END IF
    RETURN null, null
END FUNCTION
                


Example Process:

buffer_stats: 1~1741675600.1
Parsed Output:
archive_id: 1
tnx_id: 1741675600.1

Result: Proceed to move records

References:
String.Split Method (Microsoft Docs)
Delimiter-Separated Values (Wikipedia)

Step 3: Move Records to Archive Tables

Move records from buffer tables to their respective archive tables based on `archive_id` and `tnx_id`. The process involves:

This step ensures buffered records are archived for long-term storage.

Pseudo-Code: Move Records to Archive

FUNCTION move_records_to_archive(archive_id, tnx_id):
    jobs_affected = 0
    jobs_affected += sql_move_records("tbl_tallybox_wallet_buffer",
                                     "tbl_tallybox_wallet_archive_" + archive_id,
                                     "the_wallet,wallet_id",
                                     "archive_id='" + archive_id + "'")
    jobs_affected += sql_move_records("tbl_tallybox_wallet_pubkey_buffer",
                                     "tbl_tallybox_wallet_pubkey_archive_" + archive_id,
                                     "public_key,wallet_id",
                                     "archive_id='" + archive_id + "'")
    jobs_affected += sql_move_records("tbl_tallybox_book_buffer",
                                     "tbl_tallybox_book_archive_" + archive_id,
                                     "tnx_id_dag,tnx_id,tnx_type,graph_id,wallet_id,currency_id,currency_amount,left_amount,tally_hash_dag,tally_hash",
                                     "archive_id='" + archive_id + "' AND tnx_id='" + tnx_id + "'")
    jobs_affected += sql_move_records("tbl_tallybox_sign_buffer",
                                     "tbl_tallybox_sign_archive_" + archive_id,
                                     "tree_id,branch_id,tnx_id,order_id,utc_unix_order,the_sign,the_sign_md5,the_tnx_md5",
                                     "archive_id='" + archive_id + "' AND tnx_id='" + tnx_id + "'")
    log_message("buffer channel [" + archive_id + "][" + tnx_id + "] moved to archive [" + archive_id + "]..")
    RETURN jobs_affected
END FUNCTION
                


Example Process:

archive_id: 1
tnx_id: 1741675600.1
Wallet Move: 2 records moved to tbl_tallybox_wallet_archive_1
Pubkey Move: 1 record moved to tbl_tallybox_wallet_pubkey_archive_1
Book Move: 3 records moved to tbl_tallybox_book_archive_1
Sign Move: 1 record moved to tbl_tallybox_sign_archive_1

Log Output:
buffer channel [1][1741675600.1] moved to archive [1]..

References:
SQL INSERT Statement (Microsoft Docs)
Database Sharding (Wikipedia)

Step 4: Update UI with Results

Update the Windows Forms UI to reflect the movement of records to archive tables. The process involves:

This step keeps the user informed of archiving activity.

Pseudo-Code: Update UI

FUNCTION update_ui(buffer_stats, archive_id, tnx_id):
    update_ui(txt_buffer_jobs, buffer_stats)
    IF buffer_stats != "empty" THEN
        log_message("buffer channel [" + archive_id + "][" + tnx_id + "] moved to archive [" + archive_id + "]..", rtb_buffer_monitor)
    END IF
END FUNCTION
                


Example Output:

References:
RichTextBox Class (Microsoft Docs)
Windows Forms (Wikipedia)

Acknowledgments

Special thanks to Grok, for its invaluable assistance in creating this TallyBox buffer to archive processing tutorial.