Skip to content

Commit

Permalink
fix: Pin dag-jose contents (#1451)
Browse files Browse the repository at this point in the history
  • Loading branch information
ukstv authored Jun 2, 2021
1 parent fbd0dd1 commit a598c10
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
14 changes: 7 additions & 7 deletions packages/common/src/utils/stream-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/store/pin-store.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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"
Expand All @@ -66,6 +66,9 @@ export class PinStore {
points.push(subPathResolved)
}
}
if (StreamUtils.isSignedCommit(record)) {
points.push(record.link)
}
}
return points
}
Expand Down

0 comments on commit a598c10

Please sign in to comment.