diff --git a/storage-node/packages/cli/bin/cli.js b/storage-node/packages/cli/bin/cli.js index 4ec3132626..c8f078d07d 100755 --- a/storage-node/packages/cli/bin/cli.js +++ b/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) }) diff --git a/storage-node/packages/cli/package.json b/storage-node/packages/cli/package.json index 42f197ae34..680bf69807 100644 --- a/storage-node/packages/cli/package.json +++ b/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", diff --git a/storage-node/packages/cli/src/commands/upload.ts b/storage-node/packages/cli/src/commands/upload.ts index 7a1ff8cfec..f0a9f7c34a 100644 --- a/storage-node/packages/cli/src/commands/upload.ts +++ b/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, diff --git a/storage-node/packages/colossus/bin/cli.js b/storage-node/packages/colossus/bin/cli.js index 75390191a4..2a56d9d893 100755 --- a/storage-node/packages/colossus/bin/cli.js +++ b/storage-node/packages/colossus/bin/cli.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -/* es-lint disable*/ +/* es-lint disable */ 'use strict' diff --git a/storage-node/packages/colossus/lib/sync.js b/storage-node/packages/colossus/lib/sync.js index 450a4487b8..60b6ef002b 100644 --- a/storage-node/packages/colossus/lib/sync.js +++ b/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()}`) diff --git a/storage-node/packages/colossus/paths/asset/v0/{id}.js b/storage-node/packages/colossus/paths/asset/v0/{id}.js index a0e83219f9..993070870f 100644 --- a/storage-node/packages/colossus/paths/asset/v0/{id}.js +++ b/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 } }, diff --git a/storage-node/packages/runtime-api/balances.js b/storage-node/packages/runtime-api/balances.js index 89b4fae724..575eac0ee5 100644 --- a/storage-node/packages/runtime-api/balances.js +++ b/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 } /* diff --git a/storage-node/packages/runtime-api/identities.js b/storage-node/packages/runtime-api/identities.js index 2896be5fd2..09ec680ce9 100644 --- a/storage-node/packages/runtime-api/identities.js +++ b/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', diff --git a/storage-node/packages/runtime-api/index.js b/storage-node/packages/runtime-api/index.js index 61f517157f..52ec01822e 100644 --- a/storage-node/packages/runtime-api/index.js +++ b/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 }) } } } diff --git a/storage-node/packages/runtime-api/package.json b/storage-node/packages/runtime-api/package.json index 0889cc312c..9356c5e408 100644 --- a/storage-node/packages/runtime-api/package.json +++ b/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" diff --git a/storage-node/packages/runtime-api/workers.js b/storage-node/packages/runtime-api/workers.js index 4e45288d3a..47ed43e782 100644 --- a/storage-node/packages/runtime-api/workers.js +++ b/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 } diff --git a/storage-node/packages/storage/storage.js b/storage-node/packages/storage/storage.js index bc5117d6d4..f3e3f0764d 100644 --- a/storage-node/packages/storage/storage.js +++ b/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 } diff --git a/yarn.lock b/yarn.lock index 6f75c9758d..e3d6e9ab29 100644 --- a/yarn.lock +++ b/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" @@ -11565,7 +11564,7 @@ find-babel-config@^1.2.0: json5 "^0.5.1" path-exists "^3.0.0" -find-cache-dir@^2.1.0: +find-cache-dir@^2.0.0, find-cache-dir@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-2.1.0.tgz#8d0f94cd13fe43c6c7c261a0d86115ca918c05f7" integrity sha512-Tq6PixE0w/VMFfCgbONnkiQIVol/JJL7nRMi20fqzA4NRs9AfeqMGeRdPi3wIhYkxjeBaWh2rxwapn5Tu3IqOQ== @@ -19164,7 +19163,7 @@ pirates@^3.0.2: dependencies: node-modules-regexp "^1.0.0" -pirates@^4.0.1: +pirates@^4.0.0, pirates@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.1.tgz#643a92caf894566f91b2b986d2c66950a8e2fb87" integrity sha512-WuNqLTbMI3tmfef2TKxlQmAiLHKtFhlsCZnPIpuv2Ow0RDVO8lfy1Opf4NUzlMXLjPl+Men7AuVdX6TA+s+uGA==