bitbadgesjs-sdk - v0.22.7
    Preparing search index...

    Class StatusDoc<T>

    // Create a new StatusDoc with transaction tracking
    const statusDoc = new StatusDoc({
    _docId: 'status',
    block: { height: 1000, txIndex: 5, timestamp: Date.now() },
    nextCollectionId: 123,
    gasPrice: 0.001,
    lastXGasAmounts: [0.001, 0.002, 0.0015],
    lastXGasLimits: [100000, 150000, 120000],
    lastXTxs: []
    });

    // Add transactions with timestamps
    statusDoc.addTransaction(0.001, 100000); // Uses current timestamp
    statusDoc.addTransaction(0.002, 150000, Date.now() - 60000); // 1 minute ago

    // Get transactions in the last 5 minutes
    const recentTxs = statusDoc.getTransactionsInWindow(5 * 60 * 1000);

    // Calculate average gas price in the last hour
    const avgGasPrice = statusDoc.getAverageGasPriceInWindow(60 * 60 * 1000);

    // Get transaction statistics
    const stats = statusDoc.getTransactionStats(24 * 60 * 60 * 1000); // Last 24 hours
    console.log(`Total transactions: ${stats.count}`);
    console.log(`Average amount: ${stats.averageAmount}`);

    // Clean up old transactions (older than 1 day)
    const removed = statusDoc.cleanupOldTransactions(24 * 60 * 60 * 1000);
    console.log(`Removed ${removed} old transactions`);

    Type Parameters

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    _docId: string

    A unique stringified document ID

    _id?: string

    A unique document ID (Mongo DB ObjectID)

    The latest synced block status (i.e. height, txIndex, timestamp)

    gasPrice: number

    The current gas price based on the average of recent transactions

    lastXTxs?: TransactionEntry<T>[]

    The last X transactions with timestamps for dynamic reset functionality

    nextCollectionId: T

    The next collection ID to be used

    Methods

    • Add a new transaction entry to the lastXTxs array

      Parameters

      • amount: T

        The transaction amount

      • limit: T

        The gas limit

      • Optionaltimestamp: number

        The timestamp (optional, defaults to current time)

      • maxEntries: number = 100

        Maximum number of entries to keep (optional, defaults to 100)

      Returns void

    • Get transaction statistics in a time window

      Parameters

      • windowMs: number

        Time window in milliseconds

      • OptionalcurrentTime: number

        Current timestamp (optional, defaults to Date.now())

      Returns {
          averageAmount: number;
          averageLimit: number;
          count: number;
          maxAmount: number;
          minAmount: number;
          totalAmount: number;
          totalLimit: number;
      }

      Object with transaction statistics