@xo-cash/state
    Preparing search index...

    Class State

    State class responsible for managing the state of the XO Engine.

    • Manages the state of the templates, invitations, script hashes, unspent outputs, and events.
    • Interacts with remote servers to sync the state and maintain consistency.
    • Manages blockchain and invitation state and events.
    import { createStorageAdapter, StorageType, State } from '@xo-cash/state';

    // Create storage
    const storage = await createStorageAdapter({
    storageType: StorageType.INDEXEDDB,
    databasePath: './',
    databaseFilename: 'XO',
    });

    // Create state
    const state = new State(storage);

    // Use state
    await state.storeTemplate(template);
    const retrievedTemplate = await state.getTemplate('template-identifier');
    Index

    Constructors

    Methods

    • Deletes unspent output data from the state.

      Parameters

      • outpointTransactionHash: string

        The transaction hash of the outpoint

      • outpointIndex: number

        The index of the outpoint

      Returns Promise<void>

      Promise that resolves when the unspent output data is deleted

    • Sets the reservation status of an unspent output for a specific invitation.

      Parameters

      • outpoints: { outpointIndex: number; outpointTransactionHash: string }[]

        The outpoints to reserve

      • shouldBeReserved: boolean

        Whether the output should be reserved

      • invitationIdentifier: string

        The invitation identifier to associate with the reservation

      Returns Promise<void>

      Promise that resolves when the output reservation status is set

      if the output doesn't exist

      if the output is already reserved by another invitation

    • Retrieves an invitation from the state by its identifier.

      Parameters

      • invitationIdentifier: string

        Identifier for the invitation

      Returns Promise<StoredInvitation>

      Promise resolving to the stored invitation data, or undefined if not found

    • TODO: This needs a different implementation, this function is focused on p2pkh.

      Gets the last derivative index used for standard locking bytecodes. Filters by templateIdentifier and outputIdentifier, and optionally by invitationIdentifier.

      Parameters

      • templateIdentifier: string

        The template identifier to filter by

      • outputIdentifier: string

        The output identifier to filter by

      • OptionalinvitationIdentifier: string

        Optional invitation identifier to filter by (if provided, only looks at locking bytecodes for that invitation)

      Returns Promise<string>

      Promise resolving to the last derivative index as a string, or null if none found

    • Retrieves script hash data from the state by its script hash.

      Parameters

      • scriptHash: string

        The script hash to look up

      Returns Promise<ScriptHashData>

      Promise resolving to the script hash data, or undefined if not found

    • Retrieves a template from the state by its identifier.

      Parameters

      • templateIdentifier: string

        Identifier for the template

      Returns Promise<XOTemplate>

      Promise resolving to the template data, or undefined if not found

    • Retrieves unspent output data from the state.

      Parameters

      • outpointTransactionHash: string

        The transaction hash of the outpoint

      • outpointIndex: number

        The index of the outpoint

      Returns Promise<UnspentOutputData>

      Promise resolving to the unspent output data, or undefined if not found

    • Lists all templates stored in the state.

      Returns Promise<XOTemplate[]>

      Promise resolving to an array of all templates

    • Stores an event in the state.

      Parameters

      • eventId: string

        Identifier for the event

      • eventType: string

        Type of the event

      • data: unknown

        Event data

      • Optionaltimestamp: number

        Optional timestamp

      Returns Promise<void>

      Promise that resolves when the event is stored

    • Stores an invitation in the state.

      Parameters

      • invitationIdentifier: string

        Identifier for the invitation

      • invitation: StoredInvitation

        The invitation data to store

      Returns Promise<void>

      Promise that resolves when the invitation is stored

    • Stores script hash data in the state.

      Parameters

      Returns Promise<void>

      Promise that resolves when the script hash data is stored

    • Stores a template in the state.

      Parameters

      • template: XOTemplate

        The template data to store

      Returns Promise<void>

      Promise that resolves when the template is stored

    • Stores unspent output data in the state.

      Parameters

      Returns Promise<void>

      Promise that resolves when the unspent output data is stored

    • Updates the status of existing unspent output data in the state.

      Parameters

      • outpointTransactionHash: string

        The transaction hash of the outpoint

      • outpointIndex: number

        The index of the outpoint

      • status: UnspentOutputStatus

        The new status to set ('confirmed' or 'pending')

      Returns Promise<void>

      Promise that resolves when the status is updated

      if the output doesn't exist