Переглянути джерело

storage-node: cli: Modify keyfilea and passphrase as optional params.

Shamil Gadelshin 4 роки тому
батько
коміт
8b784324e8

+ 12 - 6
storage-node/packages/cli/src/commands/upload.ts

@@ -8,6 +8,7 @@ import { BaseCommand } from './base'
 import { discover } from '@joystream/service-discovery/discover'
 import Debug from 'debug'
 import chalk from 'chalk'
+import {aliceKeyPair} from './dev'
 const debug = Debug('joystream:storage-cli:upload')
 
 // Defines maximum content length for the assets (files). Limits the upload.
@@ -57,10 +58,6 @@ export class UploadCommand extends BaseCommand {
       this.mediaSourceFilePath !== '' &&
       this.dataObjectTypeId &&
       this.dataObjectTypeId !== '' &&
-      this.keyFile &&
-      this.keyFile !== '' &&
-      this.passPhrase &&
-      this.passPhrase !== '' &&
       this.memberId &&
       this.memberId !== ''
     )
@@ -174,6 +171,14 @@ export class UploadCommand extends BaseCommand {
 
   // Loads and unlocks the runtime identity using the key file and pass phrase.
   private async loadIdentity(): Promise<any> {
+    const noKeyFileProvided = !this.keyFile || this.keyFile === ''
+    const useAlice = noKeyFileProvided && await this.api.system.isDevelopmentChain()
+
+    if (useAlice) {
+      debug('Discovered \'development\' chain.')
+      return aliceKeyPair(this.api)
+    }
+
     try {
       await fs.promises.access(this.keyFile)
     } catch (error) {
@@ -187,8 +192,9 @@ export class UploadCommand extends BaseCommand {
   protected showUsage() {
     console.log(
       chalk.yellow(`
-        Usage:   storage-cli upload mediaSourceFilePath dataObjectTypeId memberId keyFilePath passPhrase
-        Example: storage-cli upload ./movie.mp4 1 1 ./keyFile.json secretPhrase
+        Usage:       storage-cli upload mediaSourceFilePath dataObjectTypeId memberId [keyFilePath] [passPhrase]
+        Example:     storage-cli upload ./movie.mp4 1 1 ./keyFile.json secretPhrase
+        Development: storage-cli upload ./movie.mp4 1 0
       `)
     )
   }

+ 2 - 0
storage-node/packages/runtime-api/index.js

@@ -28,6 +28,7 @@ const { BalancesApi } = require('@joystream/storage-runtime-api/balances')
 const { WorkersApi } = require('@joystream/storage-runtime-api/workers')
 const { AssetsApi } = require('@joystream/storage-runtime-api/assets')
 const { DiscoveryApi } = require('@joystream/storage-runtime-api/discovery')
+const { SystemApi } = require('@joystream/storage-runtime-api/system')
 const AsyncLock = require('async-lock')
 const { newExternallyControlledPromise } = require('@joystream/storage-utils/externalPromise')
 
@@ -72,6 +73,7 @@ class RuntimeApi {
     this.workers = await WorkersApi.create(this)
     this.assets = await AssetsApi.create(this)
     this.discovery = await DiscoveryApi.create(this)
+    this.system = await SystemApi.create(this)
   }
 
   disconnect() {

+ 33 - 0
storage-node/packages/runtime-api/system.js

@@ -0,0 +1,33 @@
+'use strict'
+
+const debug = require('debug')('joystream:runtime:system')
+
+/*
+ * Add system functionality to the substrate API.
+ */
+class SystemApi {
+  static async create(base) {
+    const ret = new SystemApi()
+    ret.base = base
+    await SystemApi.init()
+    return ret
+  }
+
+  static async init() {
+    debug('Init')
+  }
+
+  /*
+   * Check the running chain for the development setup.
+   */
+  async isDevelopmentChain() {
+    const developmentChainName = 'Development'
+    const runningChainName = await this.base.api.rpc.system.chain()
+
+    return runningChainName.toString() === developmentChainName
+  }
+}
+
+module.exports = {
+  SystemApi,
+}