Cleanup imports from @polkadot/util (#315)

* Cleanup imports from @polkadot/util

* Example imports

* Alphabetic imports
This commit is contained in:
Jaco Greeff
2018-10-18 13:30:04 +02:00
committed by GitHub
parent 8b7b76ead8
commit 55ac4626d5
22 changed files with 29 additions and 46 deletions
@@ -1,7 +1,7 @@
// Import the API, Keyring and some utility functions
const { ApiPromise } = require('@polkadot/api');
const { Keyring } = require('@polkadot/keyring');
const u8aFromUtf8 = require('@polkadot/util/u8a/fromUtf8').default;
const { stringToU8a } = require('@polkadot/util');
const ALICE_SEED = 'Alice'.padEnd(32, ' ');
const BOB_ADDR = '5Gw3s7q4QLkSWwknsiPtjujPv3XM4Trxi5d4PgKMMk3gfGTE';
@@ -11,7 +11,7 @@ async function main () {
const keyring = new Keyring();
// Add Alice to our keyring (with the known seed for the account)
const alice = keyring.addFromSeed(u8aFromUtf8(ALICE_SEED));
const alice = keyring.addFromSeed(stringToU8a(ALICE_SEED));
// Instantiate the API
const api = await ApiPromise.create();
+1 -2
View File
@@ -14,8 +14,7 @@ import storageStatic from '@polkadot/storage/static';
import { Vector } from '@polkadot/types/codec';
import { Hash, Method } from '@polkadot/types/index';
import { StorageFunction } from '@polkadot/types/StorageKey';
import assert from '@polkadot/util/assert';
import isUndefined from '@polkadot/util/is/undefined';
import { assert, isUndefined } from '@polkadot/util';
type MapFn<R, T> = (combined: R) => T;
+1 -2
View File
@@ -10,8 +10,7 @@ import { switchMap, defaultIfEmpty, map } from 'rxjs/operators';
import { decodeAddress } from '@polkadot/keyring';
import { AccountId, AccountIndex, Balance, bool as Bool, BlockNumber, Moment, ReferendumIndex } from '@polkadot/types/index';
import { ENUMSET_SIZE } from '@polkadot/types/AccountIndex';
import assert from '@polkadot/util/assert';
import isString from '@polkadot/util/is/string';
import { assert, isString } from '@polkadot/util';
import ApiCalls from './Calls';
import { RxProposal, RxReferendum } from './classes';
+1 -3
View File
@@ -13,9 +13,7 @@ import { Storage } from '@polkadot/storage/types';
import storageFromMeta from '@polkadot/storage/fromMetadata';
import { Hash, Method, RuntimeVersion } from '@polkadot/types/index';
import RuntimeMetadata from '@polkadot/types/Metadata';
import assert from '@polkadot/util/assert';
import isUndefined from '@polkadot/util/is/undefined';
import logger from '@polkadot/util/logger';
import { assert, isUndefined, logger } from '@polkadot/util';
type MetaDecoration = {
callIndex?: Uint8Array,
+2 -2
View File
@@ -9,11 +9,11 @@ import Rpc from '@polkadot/rpc-core/index';
import { Extrinsics, ExtrinsicFunction } from '@polkadot/extrinsics/types';
import { Storage } from '@polkadot/storage/types';
import { Base } from '@polkadot/types/codec';
import isFunction from '@polkadot/util/is/function';
import { StorageFunction } from '@polkadot/types/StorageKey';
import { isFunction } from '@polkadot/util';
import ApiBase from '../Base';
import SubmittableExtrinsic from './SubmittableExtrinsic';
import { StorageFunction } from '@polkadot/types/StorageKey';
/**
* # @polkadot/api/promise
+1 -1
View File
@@ -12,7 +12,7 @@ import RpcRx from '@polkadot/rpc-rx/index';
import { Extrinsics, ExtrinsicFunction } from '@polkadot/extrinsics/types';
import { Storage } from '@polkadot/storage/types';
import { Base } from '@polkadot/types/codec';
import logger from '@polkadot/util/logger';
import { logger } from '@polkadot/util';
import ApiBase from '../Base';
import SubmittableExtrinsic from './SubmittableExtrinsic';
+1 -3
View File
@@ -10,9 +10,7 @@ import interfaces from '@polkadot/jsonrpc/index';
import WsProvider from '@polkadot/rpc-provider/ws';
import { Base, Vector, createType } from '@polkadot/types/codec';
import { StorageChangeSet, StorageKey } from '@polkadot/types/index';
import assert from '@polkadot/util/assert';
import ExtError from '@polkadot/util/ext/error';
import isFunction from '@polkadot/util/is/function';
import { ExtError, assert, isFunction } from '@polkadot/util';
/**
* @name Rpc
@@ -5,9 +5,7 @@
import { JsonRpcResponse, JsonRpcResponseBase$Error } from '../../types';
import { RpcCoderState } from './types';
import assert from '@polkadot/util/assert';
import isNumber from '@polkadot/util/is/number';
import isUndefined from '@polkadot/util/is/undefined';
import { assert, isNumber, isUndefined } from '@polkadot/util';
function checkError (error?: JsonRpcResponseBase$Error) {
if (!error) {
+1 -2
View File
@@ -8,8 +8,7 @@ import { ProviderInterface, ProviderInterface$Callback, ProviderInterface$Emitte
import './polyfill';
import assert from '@polkadot/util/assert';
import logger from '@polkadot/util/logger';
import { assert, logger } from '@polkadot/util';
import coder from '../coder/json';
import defaults from '../defaults';
+1 -2
View File
@@ -12,8 +12,7 @@ import { MockState, MockState$Db, MockState$Subscriptions } from './types';
import BN from 'bn.js';
import storage from '@polkadot/storage/static';
import Header from '@polkadot/types/Header';
import bnToU8a from '@polkadot/util/bn/toU8a';
import u8aToHex from '@polkadot/util/u8a/toHex';
import { bnToU8a, u8aToHex } from '@polkadot/util';
import { randomAsU8a } from '@polkadot/util-crypto';
import testKeyring from '@polkadot/keyring/testing';
+1 -2
View File
@@ -6,8 +6,7 @@ import { MockState, MockState$Db, MockState$Subscriptions } from './types';
import E3 from 'eventemitter3';
import interfaces from '@polkadot/jsonrpc/index';
import u8aToHex from '@polkadot/util/u8a/toHex';
import logger from '@polkadot/util/logger';
import { logger, u8aToHex } from '@polkadot/util';
const l = logger('api-mock');
+1 -4
View File
@@ -9,10 +9,7 @@ import { JsonRpcResponse, ProviderInterface, ProviderInterface$Callback, Provide
import './polyfill';
import EventEmitter from 'eventemitter3';
import assert from '@polkadot/util/assert';
import isNull from '@polkadot/util/is/null';
import isUndefined from '@polkadot/util/is/undefined';
import logger from '@polkadot/util/logger';
import { assert, isNull, isUndefined, logger } from '@polkadot/util';
import coder from '../coder/json';
import defaults from '../defaults';
+1 -1
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import isFunction from '@polkadot/util/is/function';
import { isFunction } from '@polkadot/util';
jest.mock('@polkadot/rpc-provider/ws', () => class {
isConnected = () => true;
+1 -2
View File
@@ -9,8 +9,7 @@ import { RpcRxInterface, RpcRxInterface$Events, RpcRxInterface$Section } from '.
import EventEmitter from 'eventemitter3';
import { BehaviorSubject, ReplaySubject, Observable, Subscriber, from } from 'rxjs';
import Rpc from '@polkadot/rpc-core/index';
import isFunction from '@polkadot/util/is/function';
import isUndefined from '@polkadot/util/is/undefined';
import { isFunction, isUndefined } from '@polkadot/util';
type CachedMap = {
[index: string]: {
+5 -4
View File
@@ -2,10 +2,11 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import camelCase from '@polkadot/util/string/camelCase';
import Metadata, { RuntimeModuleMetadata } from '@polkadot/types/Metadata';
import { Extrinsics, ModuleExtrinsics } from './types';
import Metadata, { RuntimeModuleMetadata } from '@polkadot/types/Metadata';
import { stringCamelCase } from '@polkadot/util';
import createUnchecked from './utils/createUnchecked';
import extrinsics from './index';
@@ -41,12 +42,12 @@ export default function fromMetadata (metadata: Metadata): Extrinsics {
return result;
}
const prefix = camelCase(meta.prefix.toString());
const prefix = stringCamelCase(meta.prefix.toString());
const index = findIndex(meta.prefix.toString());
result[prefix] = meta.module.call.functions.reduce((newModule, funcMeta) => {
// extrinsics.balances.set_balance -> extrinsics.balances.setBalance
const funcName = camelCase(funcMeta.name.toString());
const funcName = stringCamelCase(funcMeta.name.toString());
newModule[funcName] = createUnchecked(prefix, funcName, index, funcMeta);
+1 -1
View File
@@ -2,8 +2,8 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import hexToU8a from '@polkadot/util/hex/toU8a';
import testingPairs from '@polkadot/keyring/testingPairs';
import { hexToU8a } from '@polkadot/util';
import extrinsics from './static';
+1 -1
View File
@@ -4,7 +4,7 @@
import { RpcMethodOpt, RpcMethod } from '../types';
import isUndefined from '@polkadot/util/is/undefined';
import { isUndefined } from '@polkadot/util';
export default function createMethod (section: string, method: string, { description, isDeprecated = false, isHidden = false, isSigned = false, params, pubsub, type }: RpcMethodOpt): RpcMethod {
return {
+1 -1
View File
@@ -5,7 +5,7 @@
import { ModuleStorage, Storage } from './types';
import Metadata from '@polkadot/types/Metadata';
import { stringLowerFirst } from '@polkadot/util/string';
import { stringLowerFirst } from '@polkadot/util';
import createFunction from './utils/createFunction';
import storage from './index';
@@ -7,9 +7,7 @@ import { createType } from '@polkadot/types/codec';
import { StorageFunctionMetadata } from '@polkadot/types/Metadata';
import { StorageFunction } from '@polkadot/types/StorageKey';
import { Text } from '@polkadot/types/index';
import { stringLowerFirst } from '@polkadot/util/string';
import u8aConcat from '@polkadot/util/u8a/concat';
import stringToU8a from '@polkadot/util/string/toU8a';
import { stringLowerFirst, stringToU8a, u8aConcat } from '@polkadot/util';
import { xxhashAsU8a } from '@polkadot/util-crypto';
export interface CreateItemOptions {
+1 -1
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import hexToU8a from '@polkadot/util/hex/toU8a';
import { hexToU8a } from '@polkadot/util';
import Metadata from './Metadata';
import rpcdata from './Metadata.rpc';
+1 -2
View File
@@ -2,9 +2,8 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import assert from '@polkadot/util/assert';
import { ExtrinsicFunction, Extrinsics } from '@polkadot/extrinsics/types';
import { isHex, isObject, isU8a } from '@polkadot/util';
import { assert, isHex, isObject, isU8a } from '@polkadot/util';
import Base from './codec/Base';
import { Constructor } from './types';
+2 -2
View File
@@ -2,8 +2,8 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
const fs = require('fs');
import { stringCamelCase, stringLowerFirst } from '@polkadot/util/string';
import fs from 'fs';
import { stringCamelCase, stringLowerFirst } from '@polkadot/util';
import interfaces from '../../../type-jsonrpc/src';
import Metadata from '../Metadata';