Ver código fonte

api-examples: linter fixes

Mokhtar Naamani 4 anos atrás
pai
commit
9e28c05cf2

+ 5 - 6
utils/api-examples/README.md

@@ -5,25 +5,24 @@ Repo with examples on how to use the @joystream/types package along with @polkad
 ## Examples
 
 ```
-yarn && yarn build
+yarn
 yarn run status
 ```
 
 ## Example code
 
 ```javascript
-import { registerJoystreamTypes } from '@joystream/types'
+import { types } from '@joystream/types'
 import { ApiPromise, WsProvider } from '@polkadot/api'
 
 async function main() {
   // Initialise the provider to connect to the local node
   const provider = new WsProvider('ws://127.0.0.1:9944')
 
-  // Register types before creating the API
-  registerJoystreamTypes()
-
   // Create the API and wait until ready
-  const api = await ApiPromise.create({ provider })
+  const api = await ApiPromise.create({ provider, types })
+
+  await api.isReady
 
   // Retrieve the chain & node information information via rpc calls
   const [chain, nodeName, nodeVersion] = await Promise.all([

+ 1 - 1
utils/api-examples/scripts/example.js

@@ -1,4 +1,4 @@
-/* global api, hashing, keyring, types, util, window, joy */
+/* global api, hashing, keyring, types, util, joy */
 
 // run this script with:
 // yarn script example

+ 2 - 2
utils/api-examples/scripts/export-data-directory.js

@@ -20,7 +20,7 @@ const script = async ({ api, hashing, keyring, types, util }) => {
   // it if its not sorted.
   ids.sort()
 
-  let transformed = await Promise.all(
+  const transformed = await Promise.all(
     ids.map(async (id) => {
       let obj = await api.query.dataDirectory.dataObjectByContentId(id)
       if (obj.isNone) {
@@ -35,7 +35,7 @@ const script = async ({ api, hashing, keyring, types, util }) => {
           added_at: obj.added_at,
           type_id: obj.type_id,
           size: obj.size_in_bytes,
-          liaison: runtimeSpecVersion <= 15 ? new types.u64(0) : obj.liaison,
+          liaison: runtimeSpecVersion <= 15 ? api.createType('u64', 0) : obj.liaison,
           liaison_judgement: obj.liaison_judgement,
           ipfs_content_id: obj.ipfs_content_id,
         },

+ 0 - 2
utils/api-examples/scripts/index.js

@@ -1,5 +1,3 @@
-const typesVersion = require('@joystream/types/package.json')
-
 const exportedScripts = {}
 
 exportedScripts.example = require('./example.js')

Diferenças do arquivo suprimidas por serem muito extensas
+ 2 - 4
utils/api-examples/scripts/inject-data-objects.js


+ 1 - 1
utils/api-examples/scripts/list-data-directory.js

@@ -1,4 +1,4 @@
-/* global api, hashing, keyring, types, util */
+/* global api, hashing, keyring, types, util, joy */
 
 // run this script with:
 // yarn script listDataDirectory

+ 1 - 2
utils/api-examples/scripts/transfer.js

@@ -1,12 +1,11 @@
 /* global api, hashing, keyring, types, util, window */
 
 // run this script with:
-// yarn script injectDataObjects
+// yarn script testTransfer
 //
 // or copy and paste the code into the pioneer javascript toolbox at:
 // https://testnet.joystream.org/#/js
 //
-// requires nicaea release+
 
 const script = async ({ api, keyring }) => {
   const sudoAddress = (await api.query.sudo.key()).toString()

+ 3 - 4
utils/api-examples/src/get-code.ts

@@ -6,12 +6,11 @@ async function main() {
 
   const api = await ApiPromise.create({ provider, types })
 
-  let current_block_hash = await api.rpc.chain.getBlockHash()
+  const currentBlockHash = await api.rpc.chain.getBlockHash(1)
 
-  console.log('getting code as of block hash', current_block_hash.toString())
+  console.log('getting code as of block hash', currentBlockHash.toString())
 
-  const substrateWasm = await api.query.substrate.code.at(current_block_hash.toString())
-  // const substrateWasm = await api.rpc.state.getStorage('0x'+Buffer.from(':code').toString('hex'), current_block_hash);
+  const substrateWasm = await api.query.substrate.code.at(currentBlockHash)
 
   console.log(substrateWasm.toHex())
 

+ 1 - 0
utils/api-examples/src/script.ts

@@ -7,6 +7,7 @@ import joy, { types as joyTypes } from '@joystream/types'
 import * as hashing from '@polkadot/util-crypto'
 import { Keyring } from '@polkadot/keyring'
 
+// eslint-disable-next-line @typescript-eslint/no-var-requires
 const scripts = require('../scripts')
 
 async function main() {

+ 5 - 8
utils/api-examples/src/status.ts

@@ -3,12 +3,9 @@
 import { ApiPromise, WsProvider } from '@polkadot/api'
 import { types } from '@joystream/types'
 import { Seat } from '@joystream/types/council'
-// import { SubscriptionResult, QueryableStorageFunction } from '@polkadot/api/promise/types';
-// import { GenericAccountId } from '@polkadot/types';
 import { ValidatorId } from '@polkadot/types/interfaces'
 
-// import BN from 'bn.js';
-const BN = require('bn.js')
+import BN from 'bn.js'
 
 async function main() {
   // Initialise the provider to connect to the local node
@@ -26,9 +23,9 @@ async function main() {
 
   console.log(`Chain ${chain} using ${nodeName} v${nodeVersion}`)
 
-  let council = ((await api.query.council.activeCouncil()) as unknown) as Seat[]
-  let validators = ((await api.query.session.validators()) as unknown) as ValidatorId[]
-  let version = (await api.rpc.state.getRuntimeVersion()) as any
+  const council = ((await api.query.council.activeCouncil()) as unknown) as Seat[]
+  const validators = ((await api.query.session.validators()) as unknown) as ValidatorId[]
+  const version = (await api.rpc.state.getRuntimeVersion()) as any
 
   console.log(`Runtime Version: ${version.authoringVersion}.${version.specVersion}.${version.implVersion}`)
 
@@ -46,7 +43,7 @@ async function main() {
       validators.map((authorityId) => api.query.balances.account(authorityId))
     )
 
-    let totalValidatorBalances = validatorBalances.reduce((total, value) => total.add(value.free), new BN(0))
+    const totalValidatorBalances = validatorBalances.reduce((total, value) => total.add(value.free), new BN(0))
 
     // TODO: to get the staked amounts we need to read the account lock information.
 

+ 3 - 2
utils/api-examples/src/tohex.ts

@@ -7,9 +7,10 @@ async function main() {
   const provider = new WsProvider('ws://127.0.0.1:9944')
   const api = await ApiPromise.create({ provider, types })
 
-  let wgId = [1, 2]
+  const wgId = [1, 2]
 
-  let set = new BTreeSet<CuratorApplicationId>(api.registry, CuratorApplicationId, [])
+  // Is it not possible to create the registry without actually connecting to a node?
+  const set = new BTreeSet<CuratorApplicationId>(api.registry, CuratorApplicationId, [])
 
   wgId.forEach((id) => {
     set.add(new CuratorApplicationId(api.registry, id))

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff