diff --git a/packages/common/src/utils/stream-utils.ts b/packages/common/src/utils/stream-utils.ts index 007eeb7436..c4fdd35abc 100644 --- a/packages/common/src/utils/stream-utils.ts +++ b/packages/common/src/utils/stream-utils.ts @@ -30,11 +30,11 @@ export class StreamUtils { return cloned } - if (StreamUtils.isSignedCommit(cloned)) { + if (StreamUtils.isSignedCommit(commit)) { cloned.link = cloned.link.toString() } - if (StreamUtils.isAnchorCommit(cloned)) { + if (StreamUtils.isAnchorCommit(commit)) { cloned.proof = cloned.proof.toString() } @@ -169,22 +169,22 @@ export class StreamUtils { * @param commit - Commit */ static isSignedCommitContainer(commit: CeramicCommit): boolean { - return (commit as SignedCommitContainer).jws !== undefined + return commit && (commit as SignedCommitContainer).jws !== undefined } /** * Checks if commit is signed * @param commit - Commit */ - static isSignedCommit(commit: CeramicCommit): boolean { - return (commit as SignedCommit).link !== undefined + static isSignedCommit(commit: CeramicCommit): commit is SignedCommit { + return commit && (commit as SignedCommit).link !== undefined } /** * Checks if commit is anchor commit * @param commit - Commit */ - static isAnchorCommit(commit: CeramicCommit): boolean { - return (commit as AnchorCommit).proof !== undefined + static isAnchorCommit(commit: CeramicCommit): commit is AnchorCommit { + return commit && (commit as AnchorCommit).proof !== undefined } } diff --git a/packages/core/src/store/__tests__/state-store-integration.test.ts b/packages/core/src/store/__tests__/state-store-integration.test.ts index c365463698..adabf4bfb1 100644 --- a/packages/core/src/store/__tests__/state-store-integration.test.ts +++ b/packages/core/src/store/__tests__/state-store-integration.test.ts @@ -79,11 +79,11 @@ describe('Level data store', () => { const pinSpy = jest.spyOn(realIpfs.pin, 'add'); await ceramic.pin.add(stream.id); - expect(pinSpy).toBeCalledTimes(4); + expect(pinSpy).toBeCalledTimes(5); const unpinSpy = jest.spyOn(realIpfs.pin, 'rm'); await ceramic.pin.rm(stream.id); - expect(unpinSpy).toBeCalledTimes(4); + expect(unpinSpy).toBeCalledTimes(5); await ceramic.close(); await realIpfs.stop(); diff --git a/packages/core/src/store/pin-store.ts b/packages/core/src/store/pin-store.ts index a9cecd2d7c..aaec3ba4d7 100644 --- a/packages/core/src/store/pin-store.ts +++ b/packages/core/src/store/pin-store.ts @@ -1,5 +1,5 @@ import { StateStore } from "./state-store"; -import { LogEntry, StreamState, PinningBackend, StreamStateHolder } from '@ceramicnetwork/common'; +import { LogEntry, StreamState, PinningBackend, StreamStateHolder, StreamUtils } from '@ceramicnetwork/common'; import CID from "cids" import StreamID from '@ceramicnetwork/streamid' @@ -53,7 +53,7 @@ export class PinStore { points.push(cid) const record = await this.retrieve(cid) - if (record && record.proof) { + if (StreamUtils.isAnchorCommit(record)) { points.push(record.proof) const path = record.path ? "root/" + record.path : "root" @@ -66,6 +66,9 @@ export class PinStore { points.push(subPathResolved) } } + if (StreamUtils.isSignedCommit(record)) { + points.push(record.link) + } } return points }