StateManager primarily handles incoming transactions that modify the current and historical state. StateManager effectively acts as a wrapper around StateDB but also makes some calls to HistoryManager.


Data Structures


interface StateQuery {
  plasmaContract: string
  predicateAddress: string
  start?: number
  end?: number
  method: string
  params: string[]
  filter: Expression

Represents a query for some information about the current state.

  1. plasmaContract - string: Address of the plasma contract to query. Clients may track multiple plasma contracts, so this parameter is necessary to resolve the correct data.
  2. predicateAddress - string: Address of the predicate to query.
  3. start - number: Start of the range to query. If not provided, will default to the 0.
  4. end - number: End of the range to query. If not provided, will default to the max range value.
  5. method - string: Name of the method to call.
  6. params - string[]: List of parameters to the call.
  7. filter? - Expression: An Expression to use to filter results. May be omitted to return all results.


interface StateQueryResult {
  stateUpdate: StateUpdate
  result: string[]

Element of the list of results returned when a client makes a state query.

  1. stateUpdate - StateUpdate: StateUpdate object to which the result pertains.
  2. result - string[]: Result values of the query corresponding to the output values described in the Predicate API.



async function executeTransaction(
  transaction: Transaction
): Promise<{ stateUpdate: StateUpdate, validRanges: Range[] }>

Executes a `transaction`_ against the current verified state and returns the resulting state update.

Transactions reference a range of state objects that they’re attempting to modify. It’s possible that we only have the full valid history for some of the referenced state objects but not others. This behavior is allowed by construction. As a result, this method also returns the list of ranges over which the transaction can be considered “valid”.

For example, we may have a valid history for the ranges (0, 50) and a transaction that sends (0, 100). We can assert that the transaction is valid for (0, 50) but cannot make the same assertion for (50, 100).

  1. transaction - Transaction: `Transaction`_ to execute against the verified state.

Promise<{ stateUpdate: StateUpdate, validRanges: Range[] }>: The StateUpdate created as a result of the transaction and the list of ranges over which the state update has been validated.


async function ingestHistoryProof(
  historyProof: HistoryProof
): Promise<void>

Validates a given HistoryProof, which consists of elements that are either deposits (“Deposit Proof Elements”), transactions (“State Update Proof Elements”), or state updates that prove a given range was not included in a specific block (“Exclusion Proof Elements”).

  1. historyProof - HistoryProof: A HistoryProof to validate.

Promise<void>: Promise that resolves once the proof has been applied or rejected.


async function queryState(query: StateQuery): Promise<StateQueryResult[]>

Performs a query on the local state.

  1. query - StateQuery: A StateQuery object with information about what state to query.

Promise<StateQueryResult[]>: A StateQueryResult object for each state update that passed the filter provided in the query.