Options
All
  • Public
  • Public/Protected
  • All
Menu

Module contexts/DatabaseContext

This file defines context for storing data locally in user's browser IndexedDB and reading it again. The two main use cases are storing data which shouldn't be sent to the contract (for example if they need to remain private) and caching data from the blockchain locally so they don't have to be requested repeatedly. Internally it uses Dexie.js library.

Type aliases

DataEventHandler

DataEventHandler<T>: function

Definition of function which can be bound to the context and handle data events defined by DataEventType

Type parameters

Type declaration

DataEventType

DataEventType: "CREATE" | "UPDATE" | "DELETE"

Event types which can be emitted and listened to regarding any DataModelType object.

DataModelMultiType

DataModelMultiType: "PLAYER" | "ACTION" | "EQUIPMENT" | "MINED" | "ITEM"

Data types which can have multiple instances, identified by their identifiers, and stored in IndexedDB.

DataModelSingleType

DataModelSingleType: "ACCOUNT" | "LATEST_BLOCK" | "TURN_SEED"

Data types which are stored at most once, so they don't need an identifier and are not stored in IndexedDB.

DataModelType

DataType

DataType<T>: T extends "ACCOUNT" ? Address : T extends "LATEST_BLOCK" ? undefined | BlockInfo : T extends "TURN_SEED" ? BigNumber : T extends "EQUIPMENT" ? EquipmentInfo : T extends "PLAYER" ? PlayerInfo : T extends "ACTION" ? ActionInfo : T extends "ITEM" ? ItemInfo : T extends "MINED" ? MinedInfo : never

Type definitions for every possible DataModelType type. Their meaning is following:

  • ACCOUNT - Address of currently logged user in MetaMask
  • LATEST_BLOCK - BlockInfo data of last known mined block in Ethereum blockchain, or undefined, if no block was received so far.
  • TURN_SEED - 256bit number representing current game turn seed.
  • EQUIPMENT - EquipmentInfo representing information about items currently equipped by given user (so it could have one instance for every user account used so far).
  • PLAYER - PlayerInfo representing data regarding given player
  • ACTION - ActionInfo representing pending action of any user account used so far. There should be no more than one pending action for every user account.
  • ITEM - ItemInfo which maps item identifier to the address of its owner (if any)
  • MINED - MinedInfo storing information when and by whom were game tiles mined for the last time.

Type parameters

Functions

Const createDatabaseContext

  • Function for creating global database context. This function should be called exactly once through the whole application.

    Returns DatabaseContext

    Global database context (in form of extended Dexie database)

Generated using TypeDoc