-
Notifications
You must be signed in to change notification settings - Fork 55
/
types.ts
97 lines (90 loc) · 3.6 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { Assets } from '../types';
import { Cardano, EraSummary, Reward, StakeSummary, SupplySummary } from '@cardano-sdk/core';
import { GroupedAddress, WitnessedTx } from '@cardano-sdk/key-management';
import { Observable } from 'rxjs';
import { OutgoingOnChainTx, TxInFlight } from '../services';
export interface Destroyable {
destroyed: boolean;
/**
* Clear all resources used by the store.
*
* @returns {Observable} Emits undefined and completes. Completes without emitting if store is already destroyed.
*/
destroy(): Observable<void>;
}
export interface CollectionStore<T> extends Destroyable {
/**
* Similar to getAll, but does not complete. Instead, emits every time the collection is updated (via this store object).
* Emits empty array when no documents are stored.
*/
observeAll(): Observable<T[]>;
/**
* Get all stored documents.
*
* @returns {Observable}
* - When have some documents stored: emits once and completes.
* - When no documents are stored or the store is destroyed: completes without emitting.
*/
getAll(): Observable<T[]>;
/**
* Store the full set of documents.
* getAll() after setAll(docs) should return the same set of 'docs'.
* Should never throw.
*
* @returns {Observable} Emits undefined and completes. Completes without emitting if the store is destroyed.
*/
setAll(docs: T[]): Observable<void>;
}
export type OrderedCollectionStore<T> = CollectionStore<T>;
export interface DocumentStore<T> extends Destroyable {
/**
* Get the stored document.
*
* @returns {Observable}
* - When have some document stored: emits once and completes.
* - When no document is stored or the store is destroyed: completes without emitting.
*/
get(): Observable<T>;
/**
* Store the document. Should never throw.
*
* @returns {Observable} Emits undefined and completes. Completes without emitting if the store is destroyed.
*/
set(doc: T): Observable<void>;
}
export type KeyValueCollection<K, V> = { key: K; value: V };
// getAll is not currently used anywhere for this type of store
export interface KeyValueStore<K, V> extends Omit<CollectionStore<KeyValueCollection<K, V>>, 'getAll' | 'observeAll'> {
/**
* Get the stored documents by keys.
*
* @returns {Observable}
* - When have all requested documents: emits once and completes.
* - When at least one document is missing or the store is destroyed: completes without emitting.
*/
getValues(keys: K[]): Observable<V[]>;
/** Store the document. Should never throw. */
setValue(key: K, value: V): Observable<void>;
}
export interface WalletStores extends Destroyable {
tip: DocumentStore<Cardano.Tip>;
utxo: CollectionStore<Cardano.Utxo>;
unspendableUtxo: CollectionStore<Cardano.Utxo>;
transactions: OrderedCollectionStore<Cardano.HydratedTx>;
inFlightTransactions: DocumentStore<TxInFlight[]>;
volatileTransactions: DocumentStore<OutgoingOnChainTx[]>;
rewardsHistory: KeyValueStore<Cardano.RewardAccount, Reward[]>;
rewardsBalances: KeyValueStore<Cardano.RewardAccount, Cardano.Lovelace>;
stakePools: KeyValueStore<Cardano.PoolId, Cardano.StakePool>;
protocolParameters: DocumentStore<Cardano.ProtocolParameters>;
genesisParameters: DocumentStore<Cardano.CompactGenesis>;
eraSummaries: DocumentStore<EraSummary[]>;
assets: DocumentStore<Assets>;
addresses: DocumentStore<GroupedAddress[]>;
policyIds: DocumentStore<Cardano.PolicyId[]>;
signedTransactions: DocumentStore<WitnessedTx[]>;
}
export interface SupplyDistributionStores extends Destroyable {
stake: DocumentStore<StakeSummary>;
lovelaceSupply: DocumentStore<SupplySummary>;
}