hydra
Search…
Context interfaces
A closer look at the Context types passed to the mappers

StoreContext

StoreContext is a type indicating that the mappings context is aware of the store property of type DatabaseManager . DatabaseManager is a wrapper interface incapsulating the persistence layer:
1
export interface StoreContext {
2
store: DatabaseManager
3
}
4
5
/**
6
* Database access interface. Use typeorm transactional entity manager to perform get/save/remove operations.
7
*/
8
export default interface DatabaseManager {
9
/**
10
* Save given entity instance, if entity is exists then just update
11
* @param entity
12
*/
13
save<T>(entity: DeepPartial<T>): Promise<void>;
14
15
/**
16
* Removes a given entity from the database.
17
* @param entity: DeepPartial<T>
18
*/
19
remove<T>(entity: DeepPartial<T>): Promise<void>;
20
21
/**
22
* Finds first entity that matches given options.
23
* @param entity: T
24
* @param options: FindOneOptions<T>
25
*/
26
get<T>(entity: { new (...args: any[]): T }, options: FindOneOptions<T>): Promise<T | undefined>;
27
28
/**
29
* Finds entities that match given options.
30
* @param entity: T
31
* @param options: FindOneOptions<T>
32
*/
33
getMany<T>(entity: { new (...args: any[]): T }, options: FindOneOptions<T>): Promise<T[]>;
34
}
Copied!

BlockContext

Contains information about the block: timestamp, height, hash, as well as the list of all events and extrinsics.
1
export interface BlockContext {
2
block: SubstrateBlock
3
}
Copied!

EventContext

Contains info about the event being handled and the extrinsic emitted the event. Since some events are emitted without an extrinsic (system event), the extrinsic parameter is optional.
1
export interface EventContext extends BlockContext {
2
event: SubstrateEvent
3
extrinsic?: SubstrateExtrinsic
4
}
Copied!

ExtrinsicContext

Passed to extrinsic handlers. Similar to EventContext but extrinsic is now a mandatory property.
1
export interface ExtrinsicContext extends BlockContext {
2
event: SubstrateEvent
3
extrinsic: SubstrateExtrinsic
4
}
Copied!
Last modified 7mo ago