Skip to content

Latest commit

 

History

History
331 lines (260 loc) · 10.2 KB

File metadata and controls

331 lines (260 loc) · 10.2 KB

Enhanced Event Monitor - Implementation Summary

Date: October 6, 2025

Overview

Successfully implemented comprehensive smart contract parameter decoding with human-readable display in the MongoTron event monitoring system. The system now displays full details of smart contract function calls, including all addresses and parameters in an easy-to-understand format.

What Was Implemented

1. Backend Enhancements

New Parser Method (tron_parser.go)

// DecodeSmartContract decodes smart contract call data
func (p *TronParser) DecodeSmartContract(contract *core.Transaction_Contract) *DecodedCall

Features:

  • Returns complete decoded call information
  • Extracts method signature and name
  • Identifies all addresses in parameters
  • Decodes amounts and other parameters
  • Returns nil for non-smart-contract transactions

Enhanced Event Extraction (address_monitor.go)

// Store decoded smart contract info in event data
if decoded := m.parser.DecodeSmartContract(contract); decoded != nil {
    event.EventData["smartContract"] = map[string]interface{}{
        "methodSignature": decoded.MethodSignature,
        "methodName":      decoded.MethodName,
        "addresses":       decoded.Addresses,
        "parameters":      decoded.Parameters,
    }
}

Benefits:

  • All events now include smart contract decoding
  • Data stored in structured format
  • Available via API and WebSocket
  • No breaking changes to existing API

2. Frontend Enhancements

New Display Function (event_monitor.py)

def display_smart_contract_info(self, smart_contract: dict):
    """Display decoded smart contract information in human-readable format"""

Features:

  • Recognizes TRC20 functions (transfer, transferFrom, approve, etc.)
  • Converts hex addresses to base58 (T... format)
  • Formats token amounts with proper decimals
  • Shows operation-specific information
  • Displays both hex and readable addresses

Enhanced Event Display

  • Transaction events now show decoded smart contract info
  • Clear visual sections with emoji indicators
  • Function-specific formatting
  • Full address conversion (hex → base58)

Supported Functions

Function Signature Display
transfer(address,uint256) a9059cbb 💸 TOKEN TRANSFER
transferFrom(address,address,uint256) 23b872dd 💸 TOKEN TRANSFER (Approved)
approve(address,uint256) 095ea7b3 ✅ TOKEN APPROVAL
balanceOf(address) 70a08231 💰 BALANCE QUERY
allowance(address,address) dd62ed3e 🔍 ALLOWANCE QUERY
Generic/Unknown (any) 📋 PARAMETERS (with addresses)

Example Output

Real Event Captured

================================================================================
EVENT #1
================================================================================
TX Hash:      6f2cc36e9105a389ec688b89168d8d6f5bb92367...
Block:        61115147
Type:         TriggerSmartContract
Success:      True

--------------------------------------------------------------------------------
BASIC TRANSACTION:
--------------------------------------------------------------------------------
From (hex):   41a977d20898ed9198d7977864876f6b92e9d53df1
From:         TRRGjkNwoA32ynkQ2UvcHS6vx7vNyh8zCA
To (hex):     41eca9bc828a3005b9a3b909f2cc5c2a54794de05f
To:           TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf

--------------------------------------------------------------------------------
🔍 SMART CONTRACT DECODED:
--------------------------------------------------------------------------------
Function:     transfer(address,uint256)
Signature:    0xa9059cbb

💸 TOKEN TRANSFER:
   To (hex):     4190517a46c051dbe39eaf2418befe71694a570521
   To:           TP8HurAGMeJpx3SXLdK3mV31rEFe7TqUBQ
   Amount:       1.100000 tokens
   Amount (raw): 1100000

What This Shows

  1. Transaction Layer:

    • From: TRRGjkNwoA32ynkQ2UvcHS6vx7vNyh8zCA (sender wallet)
    • To: TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf (USDT contract)
  2. Smart Contract Layer (NEW!):

    • Function: transfer(address,uint256)
    • Recipient: TP8HurAGMeJpx3SXLdK3mV31rEFe7TqUBQ
    • Amount: 1.1 USDT

Key Insight: The recipient address (TP8...) was inside the function parameters, not in the transaction fields! This is exactly what was missing before.

API Response Format

Events now include smartContract in the data:

{
  "eventId": "evt_...",
  "type": "TriggerSmartContract",
  "data": {
    "from": "41a977d20898ed9198d7977864876f6b92e9d53df1",
    "to": "41eca9bc828a3005b9a3b909f2cc5c2a54794de05f",
    "eventData": {
      "smartContract": {
        "methodName": "transfer(address,uint256)",
        "methodSignature": "a9059cbb",
        "addresses": [
          "4190517a46c051dbe39eaf2418befe71694a570521"
        ],
        "amount": "1100000",
        "parameters": {
          "to": "4190517a46c051dbe39eaf2418befe71694a570521",
          "amount": "1100000"
        }
      }
    }
  }
}

Files Modified

Backend (Go)

  1. internal/blockchain/parser/tron_parser.go

    • Added: DecodeSmartContract() method (lines 30-62)
    • Purpose: Return decoded smart contract information
  2. internal/blockchain/monitor/address_monitor.go

    • Modified: extractEvent() function (lines ~340-360)
    • Added: Smart contract decoding and storage in event data

Frontend (Python)

  1. event_monitor.py
    • Added: display_smart_contract_info() function (~120 lines)
    • Modified: display_event() to call smart contract display
    • Modified: display_transaction_event() to show decoded info

Documentation

  1. SMART_CONTRACT_DECODING_MONITOR.md (NEW)

    • Complete guide to the feature
    • Examples and usage instructions
    • Technical details and extension guide
  2. test_smart_contract_display.py (NEW)

    • Test script to demonstrate the feature
    • Fetches recent events and displays decoded info

Testing Results

Backend: Successfully decoding smart contract calls

  • Method signatures identified correctly
  • Addresses extracted from parameters
  • Amounts decoded properly
  • Data stored in events

Frontend: Human-readable display working

  • Function names displayed clearly
  • Addresses shown in both hex and base58
  • Amounts formatted with decimals
  • Clear visual sections

Integration: Complete end-to-end flow

  • Events captured with decoded data
  • WebSocket delivers complete information
  • Monitor displays everything correctly

Verification

API Check

curl -s http://localhost:8080/api/v1/events?limit=1 | jq '.events[0].data.eventData.smartContract'

Output:

{
  "addresses": ["41c5945cb070af231b0fc7e752ef846d923ed5cb50"],
  "amount": "10000000",
  "methodName": "transfer(address,uint256)",
  "methodSignature": "a9059cbb",
  "parameters": {
    "amount": "10000000",
    "to": "41c5945cb070af231b0fc7e752ef846d923ed5cb50"
  }
}

Monitor Check

source .venv/bin/activate
python test_smart_contract_display.py

Result: ✅ All events display with decoded smart contract information

Benefits

For Users

  1. Complete Visibility: See all addresses involved in a transaction

    • Transaction-level addresses (from/to)
    • Parameter-level addresses (recipients, spenders, etc.)
  2. Human-Readable Format: Everything in T... format

    • No need to manually convert hex addresses
    • Clear operation descriptions
  3. Amount Clarity: Token amounts with proper decimals

    • Raw amounts: 1100000
    • Formatted: 1.100000 tokens
  4. Context Understanding: Know what function was called

    • Transfer vs TransferFrom vs Approve
    • Clear operation labels with emojis

For Developers

  1. Complete Data: Full event structure preserved

    • Raw data still available in JSON
    • Decoded data added as enhancement
  2. Easy Integration: Standard API response

    • No breaking changes
    • Additional fields optional to use
  3. Debugging: Clear visibility into contract calls

    • See method signatures
    • Inspect all parameters
    • Verify address extraction
  4. Extensibility: Easy to add new functions

    • Add signature to abi_decoder.go
    • Add decoder function
    • Add display format to monitor

Performance Impact

  • Minimal overhead: Simple byte parsing
  • Already running: ABI decoder was implemented previously
  • No additional API calls: Decoding happens during event extraction
  • Memory efficient: Only stores decoded data, not raw calldata

Next Steps (Future Enhancements)

  1. Additional Contract Types

    • TRC721 (NFT transfers)
    • TRC1155 (Multi-token)
    • DEX-specific functions (swap, addLiquidity)
    • Staking contracts
  2. Event Log Decoding

    • Decode emitted events (Transfer events from logs)
    • Extract indexed topics
    • Parse event data fields
  3. Enhanced Amount Formatting

    • Auto-detect token decimals
    • Display token symbols (USDT, USDC, etc.)
    • Show USD values if available
  4. Query Support

    • Filter by function name
    • Search by parameter values
    • Find transactions with specific addresses in parameters

Summary

Backend: Smart contract decoding integrated into event extraction ✅ Frontend: Human-readable display with address conversion ✅ Testing: Verified with real transactions ✅ Documentation: Complete guides created ✅ Production: Deployed and actively processing events

The system now provides complete visibility into smart contract interactions, solving the original issue where addresses in function parameters were not detected. Every USDT transfer, approval, or other TRC20 operation is now fully decoded and displayed in an easy-to-understand format.

Usage

# Start monitoring
source .venv/bin/activate

# Watch all events with smart contract decoding
python event_monitor.py

# Watch specific address
python event_monitor.py --address THpjvxomBhvZUodJ3FHFY1szQxAidxejy8

# Test the display
python test_smart_contract_display.py

Every smart contract interaction will now show:

  • 📝 Function name and signature
  • 💸 Operation type (Transfer, Approval, etc.)
  • 👤 All addresses (hex + readable)
  • 💰 Token amounts (formatted)
  • 📋 All parameters

Result: Complete transparency into blockchain smart contract activity! 🎉