@satellite-earth/epoch v2.0.0
View full documentation at https://docs.satellite.earth/
Usage
const Epoch = require('@satellite-earth/epoch');
// . . .
const epoch = new Epoch(meta);Constructor
Object- Epoch meta dataname-String- typeof options.name === 'undefined' ? this.name : options.name,number-Number- Ordinal epoch numberancestor-String- Previous epoch'suuidalpha-Number- Ethereum block number at which epoch beganomega-Number- Ethereum block number at which epoch ended (only defined if loading previously finalized epoch)
Properties
signals
epoch.signalsArray - Signal objects contained within the epoch
states
epoch.statesArray - State objects built from epoch's signals
initial
epoch.initialArray - States that existed at the beginning of epoch
ancestor
epoch.ancestor // '4ab983d73d502bd027e97cdba7fcad7e695fd514'String - Previous epoch's uuid ('genesis' if epoch number 0)
signer
epoch.signer // 'alice'String - Alias name of epoch signer
number
epoch.number // 3Number - Ordinal epoch number
alpha
epoch.alpha // 10190026Number - Ethereum block number at which epoch began
omega
epoch.omega // 10363972Number - Ethereum block number at which epoch ended
finalized
epoch.finalized // trueBoolean - If the epoch has ended
compressed
epoch.compressedUint8Array - Compressed epoch data
Methods
data
await epoch.data(data);Inflate epoch with compressed data. Overrides method on Torrent superclass.
Parameters
Uint8Array- Epoch torrent data
Returns
Promise returns this - Reference to self allows method chaining
include
epoch.include(signal);Include a signal in the epoch.
Parameters
Signal- Signal to be included
loadState
await epoch.loadState(meta, get);Create a new state model or initialize an existing state from compressed data.
Parameters
Object- Meta data for state as defined bypayloadon State classFunction- (optional) async function, if provided, is called with state model and expected to return compressed data to initialize state.
Returns
Promise returns this - Reference to self allows method chaining
build
await epoch.build({
initial: [ myState, myOtherState, ... ],
signals: [ signal1, signal2, ... ]
});Build epoch from initial states and signals.
Parameters
Object- Content of the epochinitial-Array- Meta data for epochs initial statessignals-Array- Signals to include in the epoch
Function- (optional) async function, if provided, is called with state model and expected to return compressed data to initialize state.
Returns
Promise returns this - Reference to self allows method chaining
drop
const dropped = await epoch.drop('1cf5fc421006a70d06a11fe8c5441f1b8a97a28d');Remove a signal from the epoch. States are automatically rebuilt without dropped signal.
Parameters
Signal|Array-uuid(s) of signal(s) to dropFunction- (optional) async function, if provided, is called with state model and expected to return compressed data to initialize state.
Returns
Promise returns Array - Signals that were dropped
finalize
await epoch.finalize(10363972);Finalize the epoch, build states and compute data params in preparation for a new epoch.
Parameters
Number- Final block number
Returns
Promise returns this - Reference to self allows method chaining
next
console.log(epoch.number); // 3
const nextEpoch = await epoch.next();
console.log(nextEpoch.number); // 4Create a successive epoch.
Parameters
Object- Optionsname-String- Alias name of the new epoch singer. By default, inherit from immediate ancestor.
Returns
Promise returns Epoch - The new epoch