Pārlūkot izejas kodu

storage-node: Fix dev-init command

Shamil Gadelshin 4 gadi atpakaļ
vecāks
revīzija
48ecb1c587

+ 2 - 1
storage-node/packages/cli/bin/cli.js

@@ -8,6 +8,7 @@ main()
     process.exit(0)
   })
   .catch((err) => {
-    console.error(chalk.red(err.stack))
+    console.error(chalk.red(`Error: ${JSON.stringify(err)}`))
+    console.error(chalk.red(`Stack: ${err.stack}`))
     process.exit(-1)
   })

+ 1 - 1
storage-node/packages/cli/package.json

@@ -44,7 +44,7 @@
     "@joystream/storage-runtime-api": "^0.1.0",
     "@joystream/service-discovery": "^0.1.0",
     "@joystream/storage-utils": "^0.1.0",
-    "@joystream/types": "^0.12.0",
+    "@joystream/types": "^0.13.0",
     "axios": "^0.19.2",
     "chalk": "^2.4.2",
     "lodash": "^4.17.11",

+ 1 - 1
storage-node/packages/cli/src/commands/dev.ts

@@ -188,7 +188,7 @@ const init = async (api: RuntimeApi): Promise<any> => {
   debug('Making Alice the storage Lead.')
   const leadOpeningId = await api.workers.devAddStorageLeadOpening()
   const leadApplicationId = await api.workers.devApplyOnOpening(leadOpeningId, aliceMemberId, alice, alice)
-  api.workers.devBeginLeadOpeningReview(leadOpeningId)
+  await api.workers.devBeginLeadOpeningReview(leadOpeningId)
   await api.workers.devFillLeadOpening(leadOpeningId, leadApplicationId)
 
   const leadAccount = await api.workers.getLeadRoleAccount()

+ 1 - 1
storage-node/packages/runtime-api/identities.js

@@ -183,7 +183,7 @@ class IdentitiesApi {
    * using default policy 0, returns new member id
    */
   async registerMember(accountId, userInfo) {
-    const tx = this.base.api.tx.members.buyMembership(0, userInfo)
+    const tx = this.base.api.tx.members.buyMembership(0, userInfo.handle, userInfo.avatarUri, userInfo.about)
 
     return this.base.signAndSendThenGetEventResult(accountId, tx, {
       module: 'members',

+ 22 - 23
storage-node/packages/runtime-api/index.js

@@ -21,7 +21,7 @@
 const debug = require('debug')('joystream:runtime:base')
 const debugTx = require('debug')('joystream:runtime:base:tx')
 
-const { registerJoystreamTypes } = require('@joystream/types')
+const { types } = require('@joystream/types')
 const { ApiPromise, WsProvider } = require('@polkadot/api')
 const { IdentitiesApi } = require('@joystream/storage-runtime-api/identities')
 const { BalancesApi } = require('@joystream/storage-runtime-api/balances')
@@ -54,13 +54,10 @@ class RuntimeApi {
 
     options = options || {}
 
-    // Register joystream types
-    registerJoystreamTypes()
-
     const provider = new WsProvider(options.provider_url || 'ws://localhost:9944')
 
     // Create the API instrance
-    this.api = await ApiPromise.create({ provider })
+    this.api = await ApiPromise.create({ provider, types: types })
 
     this.asyncLock = new AsyncLock()
 
@@ -158,7 +155,9 @@ class RuntimeApi {
     const cachedNonce = this.nonces[accountId]
     // In future use this rpc method to take the pending tx pool into account when fetching the nonce
     // const nonce = await this.api.rpc.system.accountNextIndex(accountId)
-    const systemNonce = await this.api.query.system.accountNonce(accountId)
+    const { nonce } = await this.api.query.system.account(accountId)
+
+    const systemNonce = nonce
 
     const bestNonce = cachedNonce && cachedNonce.gte(systemNonce) ? cachedNonce : systemNonce
 
@@ -233,11 +232,11 @@ class RuntimeApi {
         // Elaboration: when the tx is rejected and therefore the tx isn't added
         // to the tx pool ready queue status is not updated and
         // .send() throws, so we don't reach this code.
-        if (out.lastResult.status.isFuture) {
-          debugTx(`Warning: Submitted Tx with future nonce: ${serialized}`)
-        } else {
-          debugTx(`Submitted: ${serialized}`)
-        }
+        // if (out.lastResult.status.isFuture) {
+        //   debugTx(`Warning: Submitted Tx with future nonce: ${serialized}`)
+        // } else {
+        //   debugTx(`Submitted: ${serialized}`)
+        // }
 
         // transaction submitted successfully, increment and save nonce.
         this.incrementAndSaveNonce(accountId)
@@ -251,9 +250,9 @@ class RuntimeApi {
     // Here again we assume that the transaction has been accepted into the tx pool
     // and status was updated.
     // We cannot get tx updates for a future tx so return now to avoid blocking caller
-    if (out.lastResult.status.isFuture) {
-      return {}
-    }
+    // if (out.lastResult.status.isFuture) {
+    //   return {}
+    // }
 
     // Return a promise that will resolve when the transaction finalizes.
     // On timeout it will be rejected. Timeout is a workaround for dealing with the
@@ -337,7 +336,7 @@ class RuntimeApi {
 
         onFinalizedFailed &&
           onFinalizedFailed({ err: status.type, result, tx: status.isUsurped ? status.asUsurped : undefined })
-      } else if (result.isFinalized) {
+      } else if (result.isCompleted) {
         unsubscribe()
 
         debugTx('Finalized', txinfo())
@@ -357,7 +356,7 @@ class RuntimeApi {
             err: 'ExtrinsicFailed',
             mappedEvents,
             result,
-            block: status.asFinalized,
+            block: status.asCompleted,
             dispatchError, // we get module number/id and index into the Error enum
           })
         } else if (success) {
@@ -365,20 +364,20 @@ class RuntimeApi {
           // console, we cannot get it in the events
           if (sudid) {
             const dispatchSuccess = sudid.event.data[0]
-            if (dispatchSuccess.isTrue) {
-              onFinalizedSuccess({ mappedEvents, result, block: status.asFinalized })
+            if (dispatchSuccess.isOk) {
+              onFinalizedSuccess({ mappedEvents, result, block: status.asCompleted })
             } else {
-              onFinalizedFailed({ err: 'SudoFailed', mappedEvents, result, block: status.asFinalized })
+              onFinalizedFailed({ err: 'SudoFailed', mappedEvents, result, block: status.asCompleted })
             }
           } else if (sudoAsDone) {
             const dispatchSuccess = sudoAsDone.event.data[0]
-            if (dispatchSuccess.isTrue) {
-              onFinalizedSuccess({ mappedEvents, result, block: status.asFinalized })
+            if (dispatchSuccess.isOk) {
+              onFinalizedSuccess({ mappedEvents, result, block: status.asCompleted })
             } else {
-              onFinalizedFailed({ err: 'SudoAsFailed', mappedEvents, result, block: status.asFinalized })
+              onFinalizedFailed({ err: 'SudoAsFailed', mappedEvents, result, block: status.asCompleted })
             }
           } else {
-            onFinalizedSuccess({ mappedEvents, result, block: status.asFinalized })
+            onFinalizedSuccess({ mappedEvents, result, block: status.asCompleted })
           }
         }
       }

+ 2 - 2
storage-node/packages/runtime-api/package.json

@@ -46,8 +46,8 @@
   },
   "dependencies": {
     "@joystream/storage-utils": "^0.1.0",
-    "@joystream/types": "^0.12.0",
-    "@polkadot/api": "^0.96.1",
+    "@joystream/types": "^0.13.0",
+    "@polkadot/api": "^1.26.1",
     "async-lock": "^1.2.0",
     "lodash": "^4.17.11",
     "password-prompt": "^1.1.2"

+ 1 - 1
storage-node/packages/runtime-api/workers.js

@@ -155,7 +155,7 @@ class WorkersApi {
     if (currentLead.isSome) {
       const leadWorkerId = currentLead.unwrap()
       const worker = await this.base.api.query.storageWorkingGroup.workerById(leadWorkerId)
-      return worker[0].role_account_id
+      return worker.role_account_id
     }
     return null
   }

+ 13 - 14
yarn.lock

@@ -2008,20 +2008,6 @@
     "@types/yargs" "^15.0.0"
     chalk "^4.0.0"
 
-"@joystream/types@^0.12.0", "@nicaea/types@npm:@joystream/types@^0.12.0":
-  name "@nicaea/types"
-  version "0.12.0"
-  resolved "https://registry.yarnpkg.com/@joystream/types/-/types-0.12.0.tgz#4033967ae2ac111f894fb4100e414f7cdbe95611"
-  integrity sha512-pHHYTbIa6V1C4k9aj+M6Fkwa2I2Br+4x7cuvREmrVh21GHjGuzoIwB74MfqFajdSTDQDZbjdixcYDES6uo3sUg==
-  dependencies:
-    "@polkadot/keyring" "^1.7.0-beta.5"
-    "@polkadot/types" "^0.96.1"
-    "@types/lodash" "^4.14.157"
-    "@types/vfile" "^4.0.0"
-    ajv "^6.11.0"
-    lodash "^4.17.15"
-    moment "^2.24.0"
-
 "@joystream/types@link:types":
   version "0.13.0"
   dependencies:
@@ -2790,6 +2776,19 @@
     call-me-maybe "^1.0.1"
     glob-to-regexp "^0.3.0"
 
+"@nicaea/types@npm:@joystream/types@^0.12.0":
+  version "0.12.0"
+  resolved "https://registry.yarnpkg.com/@joystream/types/-/types-0.12.0.tgz#4033967ae2ac111f894fb4100e414f7cdbe95611"
+  integrity sha512-pHHYTbIa6V1C4k9aj+M6Fkwa2I2Br+4x7cuvREmrVh21GHjGuzoIwB74MfqFajdSTDQDZbjdixcYDES6uo3sUg==
+  dependencies:
+    "@polkadot/keyring" "^1.7.0-beta.5"
+    "@polkadot/types" "^0.96.1"
+    "@types/lodash" "^4.14.157"
+    "@types/vfile" "^4.0.0"
+    ajv "^6.11.0"
+    lodash "^4.17.15"
+    moment "^2.24.0"
+
 "@nodelib/fs.scandir@2.1.3":
   version "2.1.3"
   resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz#3a582bdb53804c6ba6d146579c46e52130cf4a3b"