Explorar el Código

Merge branch 'iznik' into pioneer-upgrade-final

Leszek Wiesner hace 4 años
padre
commit
1fa5f3e5da

+ 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/upload.ts

@@ -96,7 +96,7 @@ export class UploadCommand extends BaseCommand {
     return {
       accountId,
       ipfsCid: await this.computeIpfsHash(),
-      contentId: ContentId.generate(),
+      contentId: ContentId.generate(this.api.api.registry),
       fileSize: new BN(this.getFileSize()),
       dataObjectTypeId,
       memberId,

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

@@ -1,5 +1,5 @@
 #!/usr/bin/env node
-/* es-lint disable*/
+/* es-lint disable  */
 
 'use strict'
 

+ 0 - 1
storage-node/packages/colossus/lib/sync.js

@@ -70,7 +70,6 @@ async function syncCallback(api, storage) {
         await api.assets.toggleStorageRelationshipReady(roleAddress, providerId, relationshipId, true)
       } catch (err) {
         debug(`Error creating new storage relationship ${contentId.encode()}: ${err.stack}`)
-        return
       }
     } else if (!relationship.ready) {
       debug(`Updating storage relationship to ready for ${contentId.encode()}`)

+ 1 - 2
storage-node/packages/colossus/paths/asset/v0/{id}.js

@@ -121,7 +121,7 @@ module.exports = function (storage, runtime) {
 
             // Filter
             const filterResult = filter({}, req.headers, info.mimeType)
-            if (200 !== filterResult.code) {
+            if (filterResult.code !== 200) {
               debug('Rejecting content', filterResult.message)
               stream.end()
               res.status(filterResult.code).send({ message: filterResult.message })
@@ -181,7 +181,6 @@ module.exports = function (storage, runtime) {
         req.pipe(stream)
       } catch (err) {
         errorHandler(res, err)
-        return
       }
     },
 

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

@@ -51,7 +51,7 @@ class BalancesApi {
    */
   async freeBalance(accountId) {
     const decoded = this.base.identities.keyring.decodeAddress(accountId, true)
-    return this.base.api.query.balances.freeBalance(decoded)
+    return (await this.base.api.derive.balances.all(decoded)).availableBalance
   }
 
   /*

+ 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',

+ 15 - 16
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
 
@@ -209,7 +208,7 @@ class RuntimeApi {
 
     // object used to communicate back information from the tx updates handler
     const out = {
-      lastResult: undefined,
+      lastResult: { status: {} },
     }
 
     // synchronize access to nonce
@@ -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"

+ 7 - 24
storage-node/packages/runtime-api/workers.js

@@ -121,31 +121,14 @@ class WorkersApi {
    * Returns the set of ids and Worker instances of providers enrolled on the network
    */
   async getAllProviders() {
-    // const workerEntries = await this.base.api.query.storageWorkingGroup.workerById()
-    // can't rely on .isEmpty or isNone property to detect empty map
-    // return workerEntries.isNone ? [] : workerEntries[0]
-    // return workerEntries.isEmpty ? [] : workerEntries[0]
-    // So we iterate over possible ids which may or may not exist, by reading directly
-    // from storage value
-    const nextWorkerId = (await this.base.api.query.storageWorkingGroup.nextWorkerId()).toNumber()
     const ids = []
     const providers = {}
-    for (let id = 0; id < nextWorkerId; id++) {
-      // We get back an Option. Will be None if value doesn't exist
-      // eslint-disable-next-line no-await-in-loop
-      let value = await this.base.api.rpc.state.getStorage(this.base.api.query.storageWorkingGroup.workerById.key(id))
-
-      if (!value.isNone) {
-        // no need to read from storage again!
-        // const worker = (await this.base.api.query.storageWorkingGroup.workerById(id))[0]
-        value = value.unwrap()
-        // construct the Worker type from raw data
-        // const worker = createType('WorkerOf', value)
-        // const worker = new Worker(value)
-        ids.push(id)
-        providers[id] = new Worker(value)
-      }
-    }
+    const entries = await this.base.api.query.storageWorkingGroup.workerById.entries()
+    entries.forEach(([storageKey, worker]) => {
+      const id = storageKey.args[0].toNumber()
+      ids.push(id)
+      providers[id] = worker
+    })
 
     return { ids, providers }
   }
@@ -155,7 +138,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
   }

+ 1 - 1
storage-node/packages/storage/storage.js

@@ -169,7 +169,7 @@ class StorageWriteStream extends Transform {
   cleanup() {
     debug('Cleaning up temporary file: ', this.temp.path)
     fs.unlink(this.temp.path, () => {
-      /* Ignore errors.*/
+      /* Ignore errors. */
     })
     delete this.temp
   }

+ 13 - 14
yarn.lock

@@ -2196,20 +2196,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:
@@ -2983,6 +2969,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"