Skip to content

Commit

Permalink
use separate env var controlling ipfs storage
Browse files Browse the repository at this point in the history
  • Loading branch information
smrz2001 committed Mar 27, 2024
1 parent 4632026 commit be4afde
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions src/services/anchor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ export class AnchorService {
logger.debug('Creating anchor commits')
const anchors = await this._createAnchorCommits(ipfsProofCid, merkleTree)

// Do not use IPFS by default
if (process.env['CAS_USE_IPFS']) {
// Do not store CAR file in IPFS by default
if (process.env['CAS_USE_IPFS_STORAGE']) {
try {
await this.ipfsService.importCAR(merkleTree.car)
} catch (e) {
Expand Down Expand Up @@ -504,37 +504,31 @@ export class AnchorService {
cid: anchorCid,
}

// Do not use IPFS by default
if (process.env['CAS_USE_IPFS']) {
try {
try {
// Do not store in IPFS by default
if (process.env['CAS_USE_IPFS_STORAGE']) {
await this.ipfsService.storeRecord(ipfsAnchorCommit)

// Do not publish to pubsub by default
if (process.env['CAS_PUBSUB_PUBLISH']) {
// TODO: Remove this case entirely after js-ceramic no longer supports pubsub
await this.ipfsService.publishAnchorCommit(anchorCid, candidate.streamId)
logger.debug(
`Created anchor commit with CID ${anchorCid} for commit ${candidate.cid} of stream ${candidate.streamId} and published it to pubsub`
)
} else {
logger.debug(
`Created anchor commit with CID ${anchorCid} for commit ${candidate.cid} of stream ${candidate.streamId}`
)
}

return anchor
} catch (err) {
const msg = `Error publishing anchor commit of commit ${
candidate.cid
} for stream ${candidate.streamId.toString()}: ${err}`
logger.err(msg)
Metrics.count(METRIC_NAMES.ERROR_IPFS, 1)
return anchor
}
} else {
logger.debug(
`Created anchor commit with CID ${anchorCid} for commit ${candidate.cid} of stream ${candidate.streamId}`
)
// Do not publish to pubsub by default
if (process.env['CAS_PUBSUB_PUBLISH']) {
// TODO: Remove this case entirely after js-ceramic no longer supports pubsub
await this.ipfsService.publishAnchorCommit(anchorCid, candidate.streamId)
logger.debug(
`Created anchor commit with CID ${anchorCid} for commit ${candidate.cid} of stream ${candidate.streamId} and published it to pubsub`
)
} else {
logger.debug(
`Created anchor commit with CID ${anchorCid} for commit ${candidate.cid} of stream ${candidate.streamId}`
)
}

return anchor
} catch (err) {
const msg = `Error publishing anchor commit of commit ${
candidate.cid
} for stream ${candidate.streamId.toString()}: ${err}`
logger.err(msg)
Metrics.count(METRIC_NAMES.ERROR_IPFS, 1)
return anchor
}
}
Expand Down

0 comments on commit be4afde

Please sign in to comment.