Skip to content

Trunks is a rust program to listen event result and make bet claimable for Sightbet Users πŸ“‘πŸŒ

Notifications You must be signed in to change notification settings

AkiraaCorp/Trunks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Trunks πŸ—‘οΈ

Trunks Logo

Trunks is a Rust-based blockchain event listener and processor specifically designed to interact with the StarkNet blockchain. It listens for EventFinished events emitted from smart contracts, parses them, and updates a PostgreSQL database accordingly. Trunks helps developers monitor and react to smart contract events on StarkNet, providing an efficient way to build real-time data pipelines for decentralized applications.


Features

  • Event Listening: Monitors EventFinished events on specified StarkNet smart contracts.
  • Database Updates:
    • Updates the events table by setting is_active to FALSE and recording the event outcome.
    • Updates the bets table by setting is_claimable to TRUE for bets with the correct outcome.
  • Block Synchronization: Automatically syncs from the last processed block to ensure no events are missed.
  • Efficient Processing: Handles large volumes of events with robust error handling.
  • Configurable: Easily adjust RPC endpoints and contract addresses.

Requirements

Before starting, ensure you have the following installed:

  • Rust (latest stable version)
  • PostgreSQL (version 12 or higher)
  • Docker (optional, for database setup)

Setup

1. Clone the Repository

git clone https://github.com/AkiraaCorp/trunks.git
cd trunks

2. Install Dependencies

Make sure you have Rust installed. If not, install it using rustup:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

3. Set Up Environment Variables

Create a .env file in the root directory and add the following:

DATABASE_URL=postgres://username:password@localhost:5432/your_database
RPC_ENDPOINT=https://your-starknet-rpc-endpoint

Replace username, password, and your_database with your PostgreSQL credentials.
Replace https://your-starknet-rpc-endpoint with your StarkNet RPC endpoint.

4. Set Up the Database

Ensure PostgreSQL is running, and the database specified in DATABASE_URL exists. You can create the database using:

createdb your_database

Configuration

  • RPC Endpoint: Modify the RPC_ENDPOINT in your .env file to point to the desired StarkNet RPC endpoint.
  • Contract Addresses: Trunks fetches contract addresses from the events table in your database where is_active = true. Ensure this table is populated with the contracts you want to monitor.

Running the Program

1. Build and Run Trunks

Use Cargo to build and run the program:

cargo run

2. Program Workflow

When you run Trunks, it will:

  1. Connect to the Specified RPC Endpoint: Ensure your RPC provider is accessible.
  2. Set Up the Database:
    • Creates necessary tables if they don’t exist.
    • Initializes the block_state_gotenk table to track the last processed block.
  3. Fetch Contract Addresses: Retrieves active contract addresses from the events table.
  4. Start Listening for Events:
    • Processes new blocks starting from the last processed block.
    • Listens for EventFinished events in each block.
  5. Update the Database:
    • Updates the events table by setting is_active to FALSE and recording the event outcome.
    • Updates the bets table by setting is_claimable to TRUE for bets matching the event outcome.
  6. Logging: Outputs informative logs to the console for monitoring.

Manual Setup for Specific Use Cases

Changing Contracts

To monitor different contracts, update the events table in your PostgreSQL database:

-- Insert a new contract address
INSERT INTO events (address, is_active)
VALUES ('0xYourContractAddress', TRUE);

Replace '0xYourContractAddress' with the desired contract address.

Starting from a Specific Block

To avoid processing from the genesis block, set the last_processed_block in the block_state_gotenk table:

UPDATE block_state_gotenk
SET last_processed_block = YOUR_DESIRED_BLOCK_NUMBER
WHERE id = 1;

Replace YOUR_DESIRED_BLOCK_NUMBER with the block number you want to start from.


Troubleshooting

Database Connection Error

  • Ensure your PostgreSQL instance is running and accessible at the specified DATABASE_URL.
  • Check for firewall or connection issues if using a remote PostgreSQL instance.
  • Verify that the database user has the necessary permissions.

Event Parsing Issues

If event parsing fails, ensure that the event structure in your smart contract matches the parsing logic in Trunks.

To enable more verbose logging for debugging, adjust the log level in main.rs:

env_logger::Builder::from_env(Env::default().default_filter_or("debug")).init();

RPC Endpoint Errors

  • Ensure the RPC endpoint is correct and accessible.
  • Check for network connectivity issues.

License

This project is licensed under the MIT License – see the LICENSE file for details.


Contributing

Feel free to submit issues or pull requests if you have any improvements or suggestions!


Author

Trunks was developed by [AkiraaCorp].
For inquiries, contact: contact@sightbet.com

About

Trunks is a rust program to listen event result and make bet claimable for Sightbet Users πŸ“‘πŸŒ

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages