Browse Source

Save output before sending extrinsic and normalize ExtrinsicFailed to be errors

Leszek Wiesner 4 years ago
parent
commit
2343b0a690

+ 1 - 1
cli/src/base/ApiCommandBase.ts

@@ -443,7 +443,7 @@ export default abstract class ApiCommandBase extends StateAwareCommandBase {
   async sendAndFollowTx(
     account: KeyringPair,
     tx: SubmittableExtrinsic<'promise'>,
-    warnOnly = true // If specified - only warning will be displayed in case of failure (instead of error beeing thrown)
+    warnOnly = false // If specified - only warning will be displayed in case of failure (instead of error beeing thrown)
   ): Promise<void> {
     try {
       await this.sendExtrinsic(account, tx)

+ 3 - 4
cli/src/commands/content-directory/addClassSchema.ts

@@ -17,6 +17,7 @@ export default class AddClassSchemaCommand extends ContentDirectoryCommandBase {
   async run() {
     const account = await this.getRequiredSelectedAccount()
     await this.requireLead()
+    await this.requestAccountDecoding(account)
 
     const { input, output } = this.parse(AddClassSchemaCommand).flags
 
@@ -69,12 +70,10 @@ export default class AddClassSchemaCommand extends ContentDirectoryCommandBase {
     const confirmed = await this.simplePrompt({ type: 'confirm', message: 'Do you confirm the provided input?' })
 
     if (confirmed) {
-      await this.requestAccountDecoding(account)
+      saveOutputJson(output, `${inputJson.className}Schema.json`, inputJson)
       const inputParser = new InputParser(this.getOriginalApi())
       this.log('Sending the extrinsic...')
-      await this.sendAndFollowTx(account, await inputParser.parseAddClassSchemaExtrinsic(inputJson), true)
-
-      saveOutputJson(output, `${inputJson.className}Schema.json`, inputJson)
+      await this.sendAndFollowTx(account, await inputParser.parseAddClassSchemaExtrinsic(inputJson))
     }
   }
 }

+ 3 - 4
cli/src/commands/content-directory/createClass.ts

@@ -15,6 +15,7 @@ export default class CreateClassCommand extends ContentDirectoryCommandBase {
   async run() {
     const account = await this.getRequiredSelectedAccount()
     await this.requireLead()
+    await this.requestAccountDecoding(account)
 
     const { input, output } = this.parse(CreateClassCommand).flags
     const existingClassnames = (await this.getApi().availableClasses()).map(([, aClass]) => aClass.name.toString())
@@ -40,12 +41,10 @@ export default class CreateClassCommand extends ContentDirectoryCommandBase {
     const confirmed = await this.simplePrompt({ type: 'confirm', message: 'Do you confirm the provided input?' })
 
     if (confirmed) {
-      await this.requestAccountDecoding(account)
+      saveOutputJson(output, `${inputJson.name}Class.json`, inputJson)
       this.log('Sending the extrinsic...')
       const inputParser = new InputParser(this.getOriginalApi())
-      await this.sendAndFollowTx(account, inputParser.parseCreateClassExtrinsic(inputJson), true)
-
-      saveOutputJson(output, `${inputJson.name}Class.json`, inputJson)
+      await this.sendAndFollowTx(account, inputParser.parseCreateClassExtrinsic(inputJson))
     }
   }
 }

+ 2 - 2
cli/src/commands/media/createChannel.ts

@@ -39,6 +39,7 @@ export default class CreateChannelCommand extends ContentDirectoryCommandBase {
     const confirmed = await this.simplePrompt({ type: 'confirm', message: 'Do you confirm the provided input?' })
 
     if (confirmed) {
+      saveOutputJson(output, `${inputJson.title}Channel.json`, inputJson)
       const inputParser = InputParser.createWithKnownSchemas(this.getOriginalApi(), [
         {
           className: 'Channel',
@@ -46,8 +47,7 @@ export default class CreateChannelCommand extends ContentDirectoryCommandBase {
         },
       ])
       const operations = await inputParser.getEntityBatchOperations()
-      await this.sendAndFollowNamedTx(account, 'contentDirectory', 'transaction', [actor, operations], true)
-      saveOutputJson(output, `${inputJson.title}Channel.json`, inputJson)
+      await this.sendAndFollowNamedTx(account, 'contentDirectory', 'transaction', [actor, operations])
     }
   }
 }

+ 2 - 2
cli/src/commands/media/updateChannel.ts

@@ -67,11 +67,11 @@ export default class UpdateChannelCommand extends ContentDirectoryCommandBase {
     const confirmed = await this.simplePrompt({ type: 'confirm', message: 'Do you confirm the provided input?' })
 
     if (confirmed) {
+      saveOutputJson(output, `${inputJson.title}Channel.json`, inputJson)
       const inputParser = InputParser.createWithKnownSchemas(this.getOriginalApi())
       const updateOperation = await inputParser.createEntityUpdateOperation(inputJson, 'Channel', channelId)
       this.log('Sending the extrinsic...')
-      await this.sendAndFollowNamedTx(account, 'contentDirectory', 'transaction', [actor, [updateOperation]], true)
-      saveOutputJson(output, `${inputJson.title}Channel.json`, inputJson)
+      await this.sendAndFollowNamedTx(account, 'contentDirectory', 'transaction', [actor, [updateOperation]])
     }
   }
 }

+ 1 - 1
cli/src/commands/media/uploadVideo.ts

@@ -367,6 +367,6 @@ export default class UploadVideoCommand extends ContentDirectoryCommandBase {
       },
     ])
     const operations = await inputParser.getEntityBatchOperations()
-    await this.sendAndFollowNamedTx(account, 'contentDirectory', 'transaction', [actor, operations], true)
+    await this.sendAndFollowNamedTx(account, 'contentDirectory', 'transaction', [actor, operations])
   }
 }