RAILGUN Reloaded
    Preparing search index...

    Type Alias ChainStorage

    Chain-wide storage operations.

    type ChainStorage = {
        nullifierExists(
            nullifier: Uint8Array,
            treeNumber: number,
        ): Promise<boolean>;
        insertNullifiersBatch(nullifierBatch: any[]): Promise<number>;
        getNullifiersByBlockRange(
            fromBlock: bigint,
            toBlock: bigint,
        ): Promise<any[]>;
        getAllNullifiers(): Promise<any[]>;
        getNullifiersFromBlock(fromBlock: bigint): Promise<any[]>;
        insertCommitmentBatch(commitmentBatch: any[]): Promise<number>;
        getCommitmentsByLeafRange(
            treeNumber: number,
            startLeafIndex: number,
            endLeafIndex: number,
        ): Promise<any[]>;
        getCommitmentsByBlockRange(
            fromBlock: bigint,
            toBlock: bigint,
        ): Promise<any[]>;
        getMerkleTree(treeNumber: number): Promise<any>;
        getAllMerkleTrees(): Promise<any[]>;
        setMerkleTree(tree: any): Promise<number>;
        getSyncState(chainID: number): Promise<any>;
        updateSyncState(chainID: number, lastBlockHeight: bigint): Promise<number>;
        getSnapshotCheckpoint(chainID: number): Promise<any>;
        getPendingSnapshotCheckpoint(chainID: number): Promise<any>;
        rollbackChain(chainID: number, merkleTrees: any[]): Promise<void>;
        getTxidSyncCursor(chainID: number): Promise<bigint>;
        setTxidSyncCursor(chainID: number, blockHeight: bigint): Promise<number>;
        getTxidMerkletree(
            chainID: number,
        ): Promise<TxidMerkletreeState | undefined>;
        setTxidMerkletree(
            chainID: number,
            state: TxidMerkletreeState,
        ): Promise<void>;
        countRailgunTransactionsThroughBlock(toBlock: bigint): Promise<number>;
        insertRailgunTransactions(rows: any[]): Promise<number>;
        getRailgunTransactionByTxid(railgunTxid: Uint8Array): Promise<any>;
        getRailgunTransactionsByBlockRange(
            fromBlock: bigint,
            toBlock: bigint,
        ): Promise<any[]>;
        getRailgunTransactionsByTreeRange(
            utxoTreeOut: number,
            startPosition: number,
            endPosition: number,
        ): Promise<any[]>;
        findRailgunTransactionForCommitment(
            commitment: Pick<
                DBCommitment,
                "hash"
                | "transactionHash"
                | "blockNumber",
            >,
        ): Promise<any>;
        insertUnshieldBatch(unshieldsBatch: any[]): Promise<number>;
        getUnshieldsByTransactionHash(transactionHash: Uint8Array): Promise<any[]>;
        insertScanBatch(batch: ScanBatch): Promise<void>;
    }
    Index
    • Determine whether a given nullifier exists.

      Parameters

      • nullifier: Uint8Array

        The nullifier value to look up.

      • treeNumber: number

        Tree number of the nullifier.

      Returns Promise<boolean>

      true if the nullifier is present, otherwise false.

    • Insert a batch of nullifiers, updating existing records on conflict. An empty batch is a no-op and returns 0.

      Parameters

      • nullifierBatch: any[]

        Array of nullifiers to upsert.

      Returns Promise<number>

      Normalized count of affected rows.

    • Retrieve nullifiers whose block numbers fall within an inclusive range, ordered ascending by block number.

      Parameters

      • fromBlock: bigint

        Starting block height (inclusive).

      • toBlock: bigint

        Ending block height (inclusive).

      Returns Promise<any[]>

      Nullifiers ordered by block number.

    • Retrieve all nullifiers, ordered ascending by block number.

      Returns Promise<any[]>

      All nullifier records.

    • Retrieve nullifiers at or after a block number, ordered ascending by block.

      Parameters

      • fromBlock: bigint

        Starting block height (inclusive).

      Returns Promise<any[]>

      Nullifier records from the block onward.

    • Insert or update a batch of commitments. An empty batch is a no-op and returns 0.

      Parameters

      • commitmentBatch: any[]

        Array of commitment records to upsert.

      Returns Promise<number>

      Normalized count of affected rows.

    • Get commitments within an inclusive leaf range of a Merkle tree, ordered ascending by tree position.

      Parameters

      • treeNumber: number

        Tree identifier.

      • startLeafIndex: number

        Starting leaf index (inclusive).

      • endLeafIndex: number

        Ending leaf index (inclusive).

      Returns Promise<any[]>

      Commitments ordered by leaf index.

    • Retrieve commitments within an inclusive block range, ordered ascending by block number.

      Parameters

      • fromBlock: bigint

        Start block height (inclusive).

      • toBlock: bigint

        End block height (inclusive).

      Returns Promise<any[]>

      Commitments ordered by block number.

    • Fetch the serialized Merkle tree for a given tree number.

      Parameters

      • treeNumber: number

        Identifier of the Merkle tree.

      Returns Promise<any>

      The Merkle tree record, or undefined when absent.

    • Fetch all Merkle trees, ordered ascending by tree number.

      Returns Promise<any[]>

      All Merkle tree records.

    • Insert or update a Merkle tree record.

      Parameters

      • tree: any

        Merkle tree data to persist.

      Returns Promise<number>

      Normalized count of affected rows.

    • Retrieve the synchronization state for a chain.

      Parameters

      • chainID: number

        Identifier of the chain.

      Returns Promise<any>

      The sync state, or undefined when absent.

    • Insert or update the commitment synchronization cursor for a chain.

      Parameters

      • chainID: number

        Identifier of the chain.

      • lastBlockHeight: bigint

        Last synced block height.

      Returns Promise<number>

      Normalized count of affected rows.

    • Read the validated snapshot checkpoint of a chain.

      Parameters

      • chainID: number

        Identifier of the chain.

      Returns Promise<any>

      The checkpoint, or undefined when the chain has no checkpoint.

    • Read the pending snapshot checkpoint of a chain. A pending checkpoint marks the chain rows as snapshot data that no validation has confirmed.

      Parameters

      • chainID: number

        Identifier of the chain.

      Returns Promise<any>

      The pending checkpoint, or undefined when the chain has none.

    • Return the chain database to its validated snapshot checkpoint, or to the empty chain when it has none, atomically. With a checkpoint: delete the rows above its height, write merkleTrees, delete the trees the checkpoint does not hold, delete the TXID trees, set last_block_height to the checkpoint height and lower the TXID sync cursor to it. Every stored tree must match the checkpoint leaf count and root. Without a checkpoint: delete every chain row, the sync state and the pending checkpoint of the chain. A rollback with a checkpoint keeps the stored reorg epoch. The caller stops the scan and the TXID sync of the chain first.

      Parameters

      • chainID: number

        Identifier of the chain.

      • merkleTrees: any[]

        UTXO trees cut back to the checkpoint leaf counts. Empty when the chain has no checkpoint.

      Returns Promise<void>

      When a tree does not match the checkpoint, or when trees are given and the chain has no checkpoint. No row changes.

    • Read the independent Railgun TXID sync cursor for a chain.

      Parameters

      • chainID: number

        Identifier of the chain.

      Returns Promise<bigint>

      Last block height whose Railgun TXID rows were persisted, or 0n.

    • Update the Railgun TXID sync cursor without changing the commitment cursor.

      Parameters

      • chainID: number

        Identifier of the chain.

      • blockHeight: bigint

        Last PPOI-complete block persisted for TXID state.

      Returns Promise<number>

      Normalized count of affected rows.

    • Read the persisted RAILGUN TXID Merkle tree. TXID trees live apart from the UTXO trees of getAllMerkleTrees.

      Parameters

      • chainID: number

        Identifier of the chain.

      Returns Promise<TxidMerkletreeState | undefined>

      All TXID trees ordered by tree number with the stored position, or undefined when no TXID tree was persisted.

    • Persist the given RAILGUN TXID trees and the sync position atomically. Trees not in state.trees stay unchanged.

      Parameters

      • chainID: number

        Identifier of the chain.

      • state: TxidMerkletreeState

        Changed trees and the position they cover.

      Returns Promise<void>

      When state.syncedThroughBlock is above the TXID sync cursor. No row changes.

    • Count the Railgun transactions at or below a block.

      Parameters

      • toBlock: bigint

        End block height, inclusive.

      Returns Promise<number>

      Number of stored Railgun transactions through toBlock.

    • Insert Railgun transactions, ignoring already-seen Railgun TXIDs. An empty batch is a no-op and returns 0.

      Parameters

      • rows: any[]

        Railgun transaction rows to insert.

      Returns Promise<number>

      Normalized count of inserted rows.

    • Fetch one Railgun transaction by its canonical Railgun TXID.

      Parameters

      • railgunTxid: Uint8Array

        Canonical Railgun transaction ID.

      Returns Promise<any>

      The matching transaction, or undefined.

    • Fetch Railgun transactions within an inclusive block range, ordered ascending by block number, then by graphID.

      Parameters

      • fromBlock: bigint

        Start block height (inclusive).

      • toBlock: bigint

        End block height (inclusive).

      Returns Promise<any[]>

      Transactions ordered by block number and graphID.

    • Fetch Railgun transactions whose output batch starts in a tree range, ordered ascending by output batch start position, then by graphID.

      Parameters

      • utxoTreeOut: number

        Output UTXO tree number.

      • startPosition: number

        Inclusive output start position.

      • endPosition: number

        Inclusive output end position.

      Returns Promise<any[]>

      Transactions ordered by output batch start position and graphID.

    • Find the Railgun transaction whose output leaves contain a commitment. The lookup matches the commitment hash inside its chain transaction.

      Parameters

      • commitment: Pick<DBCommitment, "hash" | "transactionHash" | "blockNumber">

        Stored commitment row to locate.

      Returns Promise<any>

      The transaction that produced the commitment, or undefined.

    • Insert or update a batch of unshield events. An empty batch is a no-op and returns 0.

      Parameters

      • unshieldsBatch: any[]

        Array of unshield records to upsert.

      Returns Promise<number>

      Normalized count of affected rows.

    • Retrieve the unshield records of one EVM transaction, ordered ascending by event log index.

      Parameters

      • transactionHash: Uint8Array

        Hash of the EVM transaction.

      Returns Promise<any[]>

      Unshield records ordered by event log index.

    • Persist one scan batch atomically: nullifiers, commitments, unshields, Railgun transactions, serialized Merkle trees, and the sync cursors either all commit or all roll back together. The Railgun TXID cursor advances only when at least one new Railgun transaction row was inserted; the commitment sync cursor always advances. Absent or empty members are skipped.

      Parameters

      Returns Promise<void>