Skip to content

Commit

Permalink
epoch node translation
Browse files Browse the repository at this point in the history
  • Loading branch information
teamdandelion committed Feb 18, 2020
1 parent 38a83e5 commit f7e65aa
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/core/markovProcessGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,29 @@ export type EpochNodeAddress = {|
+epochStart: TimestampMs,
|};

function epochNodeAddressToRaw(addr: EpochNodeAddress) {
export function epochNodeAddressToRaw(addr: EpochNodeAddress): NodeAddressT {
return NodeAddress.append(
EPOCH_PREFIX,
String(addr.epochStart),
...NodeAddress.toParts(addr.owner)
);
}

export function epochNodeAddressFromRaw(addr: NodeAddressT): EpochNodeAddress {
if (!NodeAddress.hasPrefix(addr, EPOCH_PREFIX)) {
throw new Error("not epochNodeAddress");
}
const epochPrefixLength = NodeAddress.toParts(EPOCH_PREFIX).length;
const parts = NodeAddress.toParts(addr);
const epochStart = +parts[epochPrefixLength];
const owner = NodeAddress.fromParts(parts.slice(epochPrefixLength + 1));
return {
type: "EPOCH_NODE",
owner,
epochStart,
};
}

// STOPSHIP document these parameters
export type FibrationOptions = {|
+what: $ReadOnlyArray<NodeAddressT>,
Expand Down

0 comments on commit f7e65aa

Please sign in to comment.