Browse Source

storage-node: fix workers api

Mokhtar Naamani 4 years ago
parent
commit
2b2855713d

+ 0 - 1
storage-node/packages/runtime-api/assets.js

@@ -76,7 +76,6 @@ class AssetsApi
       throw new Error(`No DataObject created for content ID: ${contentId}`);
     }
 
-    const encoded = encodeAddress(obj.raw.liaison);
     if (obj.raw.liaison.neq(storageProviderId)) {
       throw new Error(`This storage node is not liaison for the content ID: ${contentId}`);
     }

+ 17 - 9
storage-node/packages/runtime-api/workers.js

@@ -19,9 +19,7 @@
 'use strict'
 
 const debug = require('debug')('joystream:runtime:roles')
-const { Null } = require('@polkadot/types')
-const { _ } = require('lodash')
-const { Worker } = require('@joystream/types/lib/working-group')
+const BN = require('bn.js')
 /*
  * Add worker related functionality to the substrate API.
  */
@@ -41,6 +39,8 @@ class WorkersApi {
    * Check whether the given account and id represent an active storage provider
    */
   async isRoleAccountOfStorageProvider (storageProviderId, roleAccountId) {
+    storageProviderId = new BN(storageProviderId)
+    roleAccountId = this.base.identities.keyring.decodeAddress(roleAccountId)
     const worker = await this.storageWorkerByProviderId(storageProviderId)
     return worker && worker.role_account.eq(roleAccountId)
   }
@@ -51,16 +51,24 @@ class WorkersApi {
   }
 
   async storageWorkerByProviderId (storageProviderId) {
-    // FIXME: single linked entry
-    const workerEntry = await this.base.api.query.storageWorkingGroup.workerById(storageProviderId)
+    storageProviderId = new BN(storageProviderId)
+    const nextWorkerId = await this.base.api.query.storageWorkingGroup.nextWorkerId()
 
-    // use .isEmpty instead ?
-    if (_.isEqual(workerEntry.raw, new Null())) {
+    if (storageProviderId.gte(nextWorkerId)) {
       return null
     }
 
-    // return value
-    return new Worker(workerEntry[0])
+    const workerEntry = await this.base.api.query.storageWorkingGroup.workerById(storageProviderId)
+    return workerEntry[0]
+  }
+
+  async storageProviderRoleAccount (storageProviderId) {
+    const worker = await this.storageWorkerByProviderId(storageProviderId)
+    if (worker == null) {
+      throw new Error('Storage Provider Does Not Exist')
+    } else {
+      return worker.role_account
+    }
   }
 }