Przeglądaj źródła

storage-node: Fix dev-check command.

Shamil Gadelshin 4 lat temu
rodzic
commit
d31a385606

+ 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)).freeBalance
   }
 
   /*

+ 9 - 9
storage-node/packages/runtime-api/index.js

@@ -208,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
@@ -232,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)
@@ -250,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

+ 6 - 23
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 }
   }