Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion storage-node/packages/cli/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
2 changes: 1 addition & 1 deletion storage-node/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion storage-node/packages/cli/src/commands/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion storage-node/packages/colossus/bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
/* es-lint disable*/
/* es-lint disable */

'use strict'

Expand Down
1 change: 0 additions & 1 deletion storage-node/packages/colossus/lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`)
Expand Down
3 changes: 1 addition & 2 deletions storage-node/packages/colossus/paths/asset/v0/{id}.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down Expand Up @@ -181,7 +181,6 @@ module.exports = function (storage, runtime) {
req.pipe(stream)
} catch (err) {
errorHandler(res, err)
return
}
},

Expand Down
2 changes: 1 addition & 1 deletion storage-node/packages/runtime-api/balances.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/*
Expand Down
2 changes: 1 addition & 1 deletion storage-node/packages/runtime-api/identities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
31 changes: 15 additions & 16 deletions storage-node/packages/runtime-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -357,28 +356,28 @@ 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) {
// Note: For root origin calls, the dispatch error is logged to the joystream-node
// 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 })
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions storage-node/packages/runtime-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 7 additions & 24 deletions storage-node/packages/runtime-api/workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion storage-node/packages/storage/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
31 changes: 15 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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/[email protected]":
version "2.1.3"
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz#3a582bdb53804c6ba6d146579c46e52130cf4a3b"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand Down