Skip to content

Commit

Permalink
Feat(cli): Clean up pinning CLI flags (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer T Brody authored Feb 17, 2021
1 parent c2707f2 commit 8cf3a0b
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/__tests__/ceramic-daemon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ describe('Ceramic interop: core <> http-client', () => {
// performed yet by the time the test checks. To eliminate this race condition we should set
// anchorOnRequest to false in the config for the InMemoryAnchorService and anchor manually
// throughout the tests.
const pinsetDirectory = tmpFolder.path
core = await Ceramic.create(ipfs, {pubsubTopic: topic, pinsetDirectory})
const stateStoreDirectory = tmpFolder.path
core = await Ceramic.create(ipfs, {pubsubTopic: topic, stateStoreDirectory})

const doctypeHandler = new TileDoctypeHandler()
doctypeHandler.verifyJWS = (): Promise<void> => { return }
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/bin/ceramic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ program
.option('--ethereum-rpc <url>', 'The Ethereum RPC URL used for communicating with Ethereum blockchain')
.option('--anchor-service-api <url>', 'The anchor service URL to use')
.option('--validate-docs', 'Validate documents according to their schemas. It is enabled by default')
.option('--pinning-endpoint <url...>', 'Pinning endpoints')
.option('--pinset-directory <string>', `The directory path used for pinning service. Defaults to HOME_DIR/.ceramic/pinset`)
.option('--ipfs-pinning-endpoint <url...>', 'Ipfs pinning endpoints')
.option('--state-store-directory <string>', `The directory path used for storing pinned document state. Defaults to HOME_DIR/.ceramic/pinset`)
.option('--gateway', 'Makes read only endpoints available. It is disabled by default')
.option('--port <int>', 'Port daemon is available. Default is 7007')
.option('--debug', 'Enable debug logging level. Default is false')
Expand All @@ -26,8 +26,8 @@ program
ethereumRpc,
anchorServiceApi,
validateDocs,
pinningEndpoint,
pinsetDirectory,
ipfsPinningEndpoint,
stateStoreDirectory,
gateway,
port,
debug,
Expand All @@ -44,8 +44,8 @@ program
ethereumRpc,
anchorServiceApi,
validateDocs,
pinningEndpoint,
pinsetDirectory,
ipfsPinningEndpoint,
stateStoreDirectory,
gateway,
port,
debug,
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/ceramic-cli-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class CeramicCliUtils {
* @param ethereumRpc - Ethereum RPC URL
* @param anchorServiceApi - Anchor service API URL
* @param validateDocs - Validate docs according to schemas or not
* @param pinningEndpoints - Pinning endpoints
* @param pinsetDirectory - Path to the directory that will be used for storing pinned document state
* @param ipfsPinningEndpoints - Ipfs pinning endpoints
* @param stateStoreDirectory - Path to the directory that will be used for storing pinned document state
* @param gateway - read only endpoints available. It is disabled by default
* @param port - port daemon is availabe. Default is 7007
* @param debug - Enable debug logging level
Expand All @@ -57,8 +57,8 @@ export class CeramicCliUtils {
ethereumRpc: string,
anchorServiceApi: string,
validateDocs: boolean,
pinningEndpoints: string[],
pinsetDirectory: string,
ipfsPinningEndpoints: string[],
stateStoreDirectory: string,
gateway: boolean,
port: number,
debug: boolean,
Expand All @@ -78,9 +78,9 @@ export class CeramicCliUtils {
const config: CreateOpts = {
ethereumRpcUrl: ethereumRpc,
anchorServiceUrl: anchorServiceApi,
pinsetDirectory,
stateStoreDirectory,
validateDocs,
pinningEndpoints,
ipfsPinningEndpoints,
gateway,
port,
debug,
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/ceramic-daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export interface CreateOpts {

ethereumRpcUrl?: string;
anchorServiceUrl?: string;
pinsetDirectory?: string;
stateStoreDirectory?: string;

validateDocs?: boolean;
pinningEndpoints?: string[];
ipfsPinningEndpoints?: string[];
gateway?: boolean;
debug: boolean;
logToFiles?: boolean;
Expand Down Expand Up @@ -93,12 +93,12 @@ const makeCeramicConfig = function (opts: CreateOpts): CeramicConfig {
ceramicConfig.pubsubTopic = opts.pubsubTopic
}

if (opts.pinsetDirectory) {
ceramicConfig.pinsetDirectory = opts.pinsetDirectory
if (opts.stateStoreDirectory) {
ceramicConfig.stateStoreDirectory = opts.stateStoreDirectory
}

if (opts.pinningEndpoints) {
ceramicConfig.pinningEndpoints = opts.pinningEndpoints
if (opts.ipfsPinningEndpoints) {
ceramicConfig.ipfsPinningEndpoints = opts.ipfsPinningEndpoints
}

if (opts.logToFiles) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/ceramic-anchor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const seed = u8a.fromString('6e34b2e1a9624113d81ece8a8a22e6e97f0e145c25c1d4d2d0e

const createCeramic = async (ipfs: IpfsApi, anchorManual: boolean): Promise<Ceramic> => {
const ceramic = await Ceramic.create(ipfs, {
pinsetDirectory: await tmp.tmpName(),
stateStoreDirectory: await tmp.tmpName(),
anchorOnRequest: !anchorManual,
restoreDocuments: false,
pubsubTopic: "/ceramic/inmemory/test" // necessary so Ceramic instances can talk to each other
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/__tests__/ceramic-pinning.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { createIPFS } from './ipfs-util';

const seed = u8a.fromString('6e34b2e1a9624113d81ece8a8a22e6e97f0e145c25c1d4d2d0e62753b4060c83', 'base16')

const createCeramic = async (ipfs: IpfsApi, pinsetDirectory, anchorOnRequest = false): Promise<Ceramic> => {
const createCeramic = async (ipfs: IpfsApi, stateStoreDirectory, anchorOnRequest = false): Promise<Ceramic> => {
const ceramic = await Ceramic.create(ipfs, {
pinsetDirectory,
stateStoreDirectory,
anchorOnRequest,
pubsubTopic: "/ceramic/inmemory/test" // necessary so Ceramic instances can talk to each other
})
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/__tests__/ceramic-recover-documents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function registerChangeListener (doc: Doctype): Promise<void> {
})
}

async function createCeramic(ipfs: IpfsApi, pinsetDirectory: string) {
async function createCeramic(ipfs: IpfsApi, stateStoreDirectory: string) {
const ceramic = await Ceramic.create(ipfs, {
pinsetDirectory: pinsetDirectory,
stateStoreDirectory,
anchorOnRequest: false,
pubsubTopic: PUBSUB_TOPIC, // necessary so Ceramic instances can talk to each other
});
Expand All @@ -57,10 +57,10 @@ afterEach(async () => {
});

it("re-request anchors on #recoverDocuments", async () => {
const pinsetDirectory = await tmp.tmpName();
const stateStoreDirectory = await tmp.tmpName();

// Store
const ceramic1 = await createCeramic(ipfs1, pinsetDirectory);
const ceramic1 = await createCeramic(ipfs1, stateStoreDirectory);
const controller = ceramic1.context.did.id;

const doc1 = await ceramic1.createDocument(
Expand All @@ -73,7 +73,7 @@ it("re-request anchors on #recoverDocuments", async () => {
await ceramic1.close();

// Retrieve after being closed
const ceramic2 = await createCeramic(ipfs2, pinsetDirectory);
const ceramic2 = await createCeramic(ipfs2, stateStoreDirectory);

const doc2 = await ceramic2.loadDocument(doc1.id);
expect(doc2.state.anchorStatus).toEqual(AnchorStatus.PENDING);
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/__tests__/ceramic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function delay(mills: number): Promise<void> {

const createCeramic = async (ipfs: IpfsApi, anchorOnRequest = false, docCacheLimit = 100, cacheDocumentCommits = true): Promise<Ceramic> => {
const ceramic = await Ceramic.create(ipfs, {
pinsetDirectory: await tmp.tmpName(),
stateStoreDirectory: await tmp.tmpName(),
anchorOnRequest,
docCacheLimit,
cacheDocCommits: cacheDocumentCommits,
Expand Down Expand Up @@ -66,33 +66,33 @@ describe('Ceramic integration', () => {
})

it('can create Ceramic instance on default network', async () => {
const pinsetDirectory = await tmp.tmpName()
const ceramic = await Ceramic.create(ipfs1, {pinsetDirectory, restoreDocuments: false})
const stateStoreDirectory = await tmp.tmpName()
const ceramic = await Ceramic.create(ipfs1, {stateStoreDirectory, restoreDocuments: false})
await delay(1000)
const supportedChains = await ceramic.getSupportedChains()
expect(supportedChains).toEqual(['inmemory:12345'])
await ceramic.close()
})

it('can create Ceramic instance explicitly on inmemory network', async () => {
const pinsetDirectory = await tmp.tmpName()
const ceramic = await Ceramic.create(ipfs1, { networkName: 'inmemory', pinsetDirectory, restoreDocuments: false })
const stateStoreDirectory = await tmp.tmpName()
const ceramic = await Ceramic.create(ipfs1, { networkName: 'inmemory', stateStoreDirectory, restoreDocuments: false })
await delay(1000)
const supportedChains = await ceramic.getSupportedChains()
expect(supportedChains).toEqual(['inmemory:12345'])
await ceramic.close()
})

it('cannot create Ceramic instance on network not supported by our anchor service', async () => {
const pinsetDirectory = await tmp.tmpName()
await expect(Ceramic.create(ipfs1, { networkName: 'local', pinsetDirectory, restoreDocuments: false })).rejects.toThrow(
const stateStoreDirectory = await tmp.tmpName()
await expect(Ceramic.create(ipfs1, { networkName: 'local', stateStoreDirectory, restoreDocuments: false })).rejects.toThrow(
"No usable chainId for anchoring was found. The ceramic network 'local' supports the chains: ['eip155:1337'], but the configured anchor service 'inmemory' only supports the chains: ['inmemory:12345']")
await delay(1000)
})

it('cannot create Ceramic instance on invalid network', async () => {
const pinsetDirectory = await tmp.tmpName()
await expect(Ceramic.create(ipfs1, { networkName: 'fakenetwork', pinsetDirectory, restoreDocuments: false })).rejects.toThrow("Unrecognized Ceramic network name: 'fakenetwork'. Supported networks are: 'mainnet', 'testnet-clay', 'dev-unstable', 'local', 'inmemory'")
const stateStoreDirectory = await tmp.tmpName()
await expect(Ceramic.create(ipfs1, { networkName: 'fakenetwork', stateStoreDirectory, restoreDocuments: false })).rejects.toThrow("Unrecognized Ceramic network name: 'fakenetwork'. Supported networks are: 'mainnet', 'testnet-clay', 'dev-unstable', 'local', 'inmemory'")
await delay(1000)
})

Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/ceramic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ const TESTING = process.env.NODE_ENV == 'test'
export interface CeramicConfig {
ethereumRpcUrl?: string;
anchorServiceUrl?: string;
pinsetDirectory?: string;
stateStoreDirectory?: string;

didResolver?: Resolver;
didProvider?: DIDProvider;

validateDocs?: boolean;
pinningEndpoints?: string[];
ipfsPinningEndpoints?: string[];
pinningBackends?: PinningBackendStatic[];

logLevel?: string;
Expand Down Expand Up @@ -293,8 +293,8 @@ class Ceramic implements CeramicApi {

const pinStoreProperties = {
networkName: networkOptions.name,
pinsetDirectory: config.pinsetDirectory,
pinningEndpoints: config.pinningEndpoints,
pinsetDirectory: config.stateStoreDirectory,
pinningEndpoints: config.ipfsPinningEndpoints,
pinningBackends: config.pinningBackends
}
const pinStoreFactory = new PinStoreFactory(context, pinStoreProperties)
Expand Down

0 comments on commit 8cf3a0b

Please sign in to comment.