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

    Interface XOStorage

    Abstract storage adapter interface.

    This interface hides ALL implementation details of the underlying database. All storage implementations (IndexedDB, SQLite, PostgreSQL, etc.) must implement this interface. The implementation details are completely hidden from consumers.

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

    // Use the adapter
    await storage.storeTemplate(template);
    const retrievedTemplate = await storage.getTemplate('template-identifier');
    interface XOStorage {
        close(): Promise<void>;
        deleteUnspentOutputData(
            outpointTransactionHash: string,
            outpointIndex: number,
        ): Promise<void>;
        executeBulkUnspentOutputReservation(
            outpoints: { outpointIndex: number; outpointTransactionHash: string }[],
            shouldBeReserved: boolean,
            invitationIdentifier: string,
        ): Promise<void>;
        getInvitation(invitationIdentifier: string): Promise<StoredInvitation>;
        getLastDerivativeIndexForP2PKH(
            templateIdentifier: string,
            outputIdentifier: string,
            invitationIdentifier?: string,
        ): Promise<string>;
        getScriptHashData(scriptHash: string): Promise<ScriptHashData>;
        getTemplate(templateIdentifier: string): Promise<XOTemplate>;
        getUnspentOutputData(
            outpointTransactionHash: string,
            outpointIndex: number,
        ): Promise<UnspentOutputData>;
        initialize(): Promise<void>;
        listEvents(query: EventDataQuery): Promise<EventData[]>;
        listScriptHashData(query: ScriptHashDataQuery): Promise<ScriptHashData[]>;
        listTemplates(): Promise<XOTemplate[]>;
        listUnspentOutputs(
            query?: UnspentOutputDataQuery,
            filter?: UnspentOutputDataFilter,
        ): Promise<UnspentOutputData[]>;
        storeEvent(
            eventId: string,
            eventType: string,
            data: unknown,
            timestamp?: number,
        ): Promise<void>;
        storeInvitation(
            invitationIdentifier: string,
            invitation: StoredInvitation,
        ): Promise<void>;
        storeScriptHashData(data: ScriptHashData): Promise<void>;
        storeTemplate(template: XOTemplate): Promise<void>;
        storeUnspentOutputData(data: UnspentOutputData): Promise<void>;
        updateUnspentOutputDataStatus(
            outpointTransactionHash: string,
            outpointIndex: number,
            status: UnspentOutputStatus,
        ): Promise<void>;
    }
    Index

    Methods

    • Closes the storage adapter and releases all resources. After closing, this instance cannot be used again. Create a new instance to reopen the database.

      Returns Promise<void>

      Promise that resolves when the storage is closed

    • Deletes unspent output data from storage.

      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, containing an outpointTransactionHash and an outpointIndex

      • 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 storage by its identifier.

      Parameters

      • invitationIdentifier: string

        Identifier for the invitation

      Returns Promise<StoredInvitation>

      Promise that resolves to the invitation data, or undefined if not found

    • Gets the last derivative index used for standard lockingBytecodes. 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 that resolves to the last derivative index as a string, or null if none found

    • Retrieves script hash data from storage by its script hash.

      Parameters

      • scriptHash: string

        The script hash to look up

      Returns Promise<ScriptHashData>

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

    • Retrieves a template from storage by its identifier.

      Parameters

      • templateIdentifier: string

        Identifier for the template

      Returns Promise<XOTemplate>

      Promise that resolves to the template data, or undefined if not found

    • Retrieves unspent output data from storage.

      Parameters

      • outpointTransactionHash: string

        The transaction hash of the outpoint

      • outpointIndex: number

        The index of the outpoint

      Returns Promise<UnspentOutputData>

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

    • Initializes the storage adapter. Must be called before using any other methods.

      Returns Promise<void>

      Promise that resolves when initialization is complete

    • Lists event data matching the provided query.

      Parameters

      Returns Promise<EventData[]>

      Promise that resolves to an array of events matching the query

      if more than one query field is provided

      if the query contains no recognized field

    • Lists script hash data matching the provided query.

      Parameters

      • query: ScriptHashDataQuery

        Query to apply (e.g. templateIdentifier, scriptHash, or invitationIdentifier)

      Returns Promise<ScriptHashData[]>

      Promise that resolves to an array of script hash data matching the query

      if more than one query field is provided

      if the query contains no recognized field

    • Lists all templates stored in the storage.

      Returns Promise<XOTemplate[]>

      Promise that resolves to an array of all templates

    • Stores an event in storage.

      Parameters

      • eventId: string

        Identifier for the event

      • eventType: string

        Type of the event

      • data: unknown

        Event data

      • Optionaltimestamp: number

        Optional timestamp (defaults to current time)

      Returns Promise<void>

      Promise that resolves when the event is stored

    • Stores an invitation in storage.

      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 a template in storage.

      Parameters

      • template: XOTemplate

        The template data to store

      Returns Promise<void>

      Promise that resolves when the template is stored

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

      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