Browse Source

cleanup api-examples workspace, rename to api-scripts

Mokhtar Naamani 4 years ago
parent
commit
3db6be3faa

+ 1 - 1
package.json

@@ -18,7 +18,7 @@
     "devops/prettier-config",
     "pioneer",
     "pioneer/packages/*",
-    "utils/api-examples",
+    "utils/api-scripts",
     "content-directory-schemas"
   ],
   "resolutions": {

+ 0 - 107
utils/api-examples/src/dev-set-runtime-code.ts

@@ -1,107 +0,0 @@
-import { ApiPromise, WsProvider } from '@polkadot/api'
-import { types } from '@joystream/types'
-import { Keyring } from '@polkadot/keyring'
-import { ISubmittableResult } from '@polkadot/types/types/'
-import { DispatchError, DispatchResult } from '@polkadot/types/interfaces/system'
-import { TypeRegistry, Bytes } from '@polkadot/types'
-import fs from 'fs'
-import Call from '@polkadot/types/generic/Call'
-import { compactAddLength } from '@polkadot/util'
-
-function onApiDisconnected() {
-  process.exit(2)
-}
-
-function onApiError() {
-  process.exit(3)
-}
-
-async function main() {
-  const file = process.argv[2]
-
-  if (!file) {
-    console.log('No wasm file argument provided.')
-    process.exit(1)
-  }
-
-  const wasm = Uint8Array.from(fs.readFileSync(file))
-  console.log('WASM bytes:', wasm.byteLength)
-
-  const provider = new WsProvider('ws://127.0.0.1:9944')
-
-  let api: ApiPromise
-  let retry = 3
-  while (true) {
-    try {
-      api = await ApiPromise.create({ provider, types })
-      await api.isReady
-      break
-    } catch (err) {
-      // failed to connect to node
-    }
-
-    if (retry-- === 0) {
-      process.exit(-1)
-    }
-
-    await new Promise((resolve) => {
-      setTimeout(resolve, 5000)
-    })
-  }
-
-  api.on('disconnected', onApiDisconnected)
-  api.on('error', onApiError)
-
-  const keyring = new Keyring()
-  const sudo = keyring.addFromUri('//Alice', undefined, 'sr25519')
-
-  const nonce = (await api.query.system.account(sudo.address)).nonce
-
-  // DO SET UNCHECKED!
-  // const tx = api.tx.system.setCodeWithoutChecks(wasm)
-
-  const setCodeTx = api.tx.system.setCode(compactAddLength(wasm))
-
-  const sudoTx = api.tx.sudo.sudoUncheckedWeight(setCodeTx, 1)
-  const signedTx = sudoTx.sign(sudo, { nonce })
-  console.log('Tx size:', signedTx.length)
-  const wasmCodeInTxArg = (signedTx.method.args[0] as Call).args[0]
-  console.log('WASM code arg byte length:', (wasmCodeInTxArg as Bytes).byteLength)
-
-  signedTx.send((result: ISubmittableResult) => {
-    if (result.status.isInBlock && result.events !== undefined) {
-      result.events.forEach((event) => {
-        if (event.event.method === 'ExtrinsicFailed') {
-          console.log('ExtrinsicFailed', (event.event.data[0] as DispatchError).toHuman())
-          process.exit(4)
-        }
-
-        if (event.event.method === 'Sudid') {
-          const result = event.event.data[0] as DispatchResult
-          if (result.isOk) {
-            process.exit(0)
-          } else if (result.isError) {
-            const err = result.asError
-            console.log('Error:', err.toHuman())
-            if (err.isModule) {
-              const { name, documentation } = (api.registry as TypeRegistry).findMetaError(err.asModule)
-              console.log(`${name}\n${documentation}`)
-            }
-            process.exit(5)
-          } else {
-            console.log('Sudid result:', result.toHuman())
-            process.exit(-1)
-          }
-        }
-      })
-
-      process.exit(0)
-    }
-  })
-
-  await new Promise(() => {
-    // wait until transaction finalizes
-  })
-}
-
-main()

+ 0 - 22
utils/api-examples/src/get-code.ts

@@ -1,22 +0,0 @@
-import { ApiPromise, WsProvider } from '@polkadot/api'
-import { types } from '@joystream/types'
-
-async function main() {
-  const provider = new WsProvider('ws://127.0.0.1:9944')
-
-  const api = await ApiPromise.create({ provider, types })
-
-  await api.isReady
-
-  const currentBlockHash = await api.rpc.chain.getBlockHash(1)
-
-  console.log('getting code as of block hash', currentBlockHash.toString())
-
-  const substrateWasm = await api.query.substrate.code.at(currentBlockHash)
-
-  console.log(substrateWasm.toHex())
-
-  api.disconnect()
-}
-
-main()

+ 0 - 30
utils/api-examples/src/tohex.ts

@@ -1,30 +0,0 @@
-import { CuratorApplicationId } from '@joystream/types/content-working-group'
-import { BTreeSet, createType, TypeRegistry } from '@polkadot/types'
-import { types } from '@joystream/types'
-
-async function main() {
-  const wgId = [1, 2]
-
-  const registry = new TypeRegistry()
-  registry.register(types)
-
-  const set = new BTreeSet<CuratorApplicationId>(registry, CuratorApplicationId, [])
-
-  wgId.forEach((id) => {
-    set.add(createType(registry, 'CuratorApplicationId', id))
-  })
-
-  /*
-    Replace the integers inside the bracket in:
-    let wgId:number[] = [1, 2];
-    With the "WG ID"s of the curators you wish to hire, in ascending order.
-
-    To hire "WG ID" 18 21 and 16:
-    let wgId:number[] = [16, 18, 21];
-    */
-
-  console.log('copy/paste the output below to hire curator applicant(s) with WG IDs:', wgId)
-  console.log(set.toHex())
-}
-
-main()

+ 0 - 0
utils/api-examples/README.md → utils/api-scripts/README.md


+ 1 - 1
utils/api-examples/package.json → utils/api-scripts/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "api-examples",
+  "name": "api-scripts",
   "private": true,
   "version": "0.1.0",
   "license": "GPL-3.0-only",

+ 0 - 0
utils/api-examples/scripts/example.js → utils/api-scripts/scripts/example.js


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


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


+ 0 - 0
utils/api-examples/scripts/inject-data-objects.js → utils/api-scripts/scripts/inject-data-objects.js


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


+ 0 - 0
utils/api-examples/scripts/transfer.js → utils/api-scripts/scripts/transfer.js


+ 0 - 0
utils/api-examples/src/script.ts → utils/api-scripts/src/script.ts


+ 0 - 0
utils/api-examples/src/status.ts → utils/api-scripts/src/status.ts


+ 1 - 1
utils/api-examples/tsconfig.json → utils/api-scripts/tsconfig.json

@@ -13,7 +13,7 @@
     "baseUrl": "./",
     "paths": {
       "@polkadot/types/augment": ["../../types/augment-codec/augment-types.ts"],
-      "@polkadot/api/augment": [ "../../types/augment-codec/augment-api.ts"]
+      "@polkadot/api/augment": ["../../types/augment-codec/augment-api.ts"]
     }
   },
   "include": ["src/**/*"]