UNPKG

@ceramicnetwork/stream-handler-common

Version:

Ceramic stream handler common types and utilities

36 lines 1.16 kB
import { AnchorStatus, EventType, StreamUtils, } from '@ceramicnetwork/common'; function applyAnchorTimestampsToLog(state) { let timestamp; for (let i = state.log.length - 1; i >= 0; i--) { const logEntry = state.log[i]; if (logEntry.type == EventType.TIME) { timestamp = logEntry.timestamp; } else { logEntry.timestamp = timestamp; } } } export async function applyAnchorCommit(commitData, state) { StreamUtils.assertCommitLinksToState(state, commitData.commit); if (commitData.anchorValidationError) { throw commitData.anchorValidationError; } state.anchorStatus = AnchorStatus.ANCHORED; state.anchorProof = commitData.proof; state.log.push({ cid: commitData.cid, type: EventType.TIME, timestamp: commitData.timestamp, }); applyAnchorTimestampsToLog(state); if (state.next?.content) { state.content = state.next.content; } if (state.next?.metadata) { state.metadata = state.next.metadata; } delete state.next; return state; } //# sourceMappingURL=anchor-commit-utils.js.map