Misc small cleanups (#625)

* Misc small cleanups

* Bump deps
This commit is contained in:
Jaco Greeff
2019-01-23 22:10:38 +01:00
committed by GitHub
parent 64670bfc9c
commit 843f374ca7
15 changed files with 65 additions and 66 deletions
+1 -1
View File
@@ -25,6 +25,6 @@
"devDependencies": {
"@babel/core": "^7.2.2",
"@polkadot/dev": "^0.23.14",
"@polkadot/ts": "^0.1.51"
"@polkadot/ts": "^0.1.52"
}
}
+1 -1
View File
@@ -33,6 +33,6 @@
"@polkadot/jsonrpc": "^0.40.21",
"@polkadot/rpc-provider": "^0.40.21",
"@polkadot/types": "^0.40.21",
"@polkadot/util": "^0.33.35"
"@polkadot/util": "^0.33.36"
}
}
+3 -3
View File
@@ -30,10 +30,10 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
"dependencies": {
"@babel/runtime": "^7.2.0",
"@polkadot/keyring": "^0.33.35",
"@polkadot/keyring": "^0.33.36",
"@polkadot/storage": "^0.40.21",
"@polkadot/util": "^0.33.35",
"@polkadot/util-crypto": "^0.33.35",
"@polkadot/util": "^0.33.36",
"@polkadot/util-crypto": "^0.33.36",
"@types/nock": "^9.3.0",
"eventemitter3": "^3.1.0",
"isomorphic-fetch": "^2.2.1",
+1 -1
View File
@@ -12,6 +12,6 @@
"dependencies": {
"@babel/runtime": "^7.2.0",
"@polkadot/types": "^0.40.21",
"@polkadot/util": "^0.33.35"
"@polkadot/util": "^0.33.36"
}
}
+3 -3
View File
@@ -30,9 +30,9 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-storage#readme",
"dependencies": {
"@babel/runtime": "^7.2.0",
"@polkadot/keyring": "^0.33.35",
"@polkadot/keyring": "^0.33.36",
"@polkadot/types": "^0.40.21",
"@polkadot/util": "^0.33.35",
"@polkadot/util-crypto": "^0.33.35"
"@polkadot/util": "^0.33.36",
"@polkadot/util-crypto": "^0.33.36"
}
}
+2 -2
View File
@@ -30,8 +30,8 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
"dependencies": {
"@babel/runtime": "^7.2.0",
"@polkadot/keyring": "^0.33.35",
"@polkadot/util": "^0.33.35",
"@polkadot/keyring": "^0.33.36",
"@polkadot/util": "^0.33.36",
"core-js": "^2.6.2"
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ export default class AccountId extends U8aFixed {
} else if (isHex(value)) {
return hexToU8a(value.toString());
} else if (isString(value)) {
return decodeAddress((value as AnyString).toString());
return decodeAddress((value as String).toString());
}
return value;
+2 -16
View File
@@ -4,10 +4,9 @@
import BN from 'bn.js';
import { decodeAddress, encodeAddress } from '@polkadot/keyring';
import { bnToBn, isBn, isNumber, isU8a, isHex, hexToU8a, u8aToHex } from '@polkadot/util';
import { bnToBn, isBn, isNumber, isU8a, isHex } from '@polkadot/util';
import { AnyNumber } from './types';
import UInt from './codec/UInt';
import U32 from './U32';
export const ENUMSET_SIZE = new BN(64);
@@ -38,12 +37,8 @@ export default class AccountIndex extends U32 {
// `value.toBn()` on AccountIndex returns a pure BN (i.e. not an
// AccountIndex), which has the initial `toString()` implementation.
return value.toBn();
} else if (value instanceof UInt || isBn(value) || isNumber(value) || isU8a(value)) {
} else if (isBn(value) || isNumber(value) || isHex(value) || isU8a(value)) {
return value;
} else if (isHex(value)) {
// Here we convert via hexToU8a since we expect the LE encoded value representation. This
// is different than UInt where we expect a BE (human-readable representation)
return hexToU8a(value);
}
return AccountIndex.decodeAccountIndex(decodeAddress(value));
@@ -99,15 +94,6 @@ export default class AccountIndex extends U32 {
return super.eq(new AccountIndex(other));
}
/**
* @description Returns a hex string representation of the value
*/
toHex (): string {
// Like in our decoding function, we explicitly override this to allow us to output
// LE-hex encoded numbers (generally UInt in JSON are expected as BE, these LE)
return u8aToHex(this.toU8a());
}
/**
* @description Converts the Object to JSON, typically used for RPC transfers
*/
+3 -3
View File
@@ -38,14 +38,14 @@ describe('Address', () => {
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s'
);
testDecode(
'AccountIndex',
'AccountIndex (mixed prefixes)',
new Address('PrF3'),
// NOTE Expected adress here is encoded with prefix 42, input above with 68
'F7ih'
);
testDecode(
'AccountIndex',
new AccountIndex('0x0001'),
'AccountIndex (hex)',
new AccountIndex('0x0100'),
'25GUyk'
);
testDecode(
+1 -1
View File
@@ -20,7 +20,7 @@ export default class Bool extends Boolean implements Codec {
}
private static decodeBool (value: any): boolean {
if (value instanceof Bool || value instanceof Boolean) {
if (value instanceof Boolean) {
return value.valueOf();
} else if (isU8a(value)) {
return value[0] === 1;
+1
View File
@@ -46,6 +46,7 @@ export default class Bytes extends U8a {
// i.e. new Bytes(new Bytes(...)) will work as expected
return value;
} else if (isU8a(value)) {
// handle all other Uint8Array inputs, these do have a length prefix
const [offset, length] = Compact.decodeU8a(value);
return value.subarray(offset, offset + length.toNumber());
+15 -10
View File
@@ -5,14 +5,13 @@
import { Codec } from './types';
import { compareMap } from './codec/utils';
// TODO Expose known properties as they become known, currently we have `tokenSymbol` (e.g. BBQ)
/**
* @name ChainProperties
* @description
* Wraps the properties retrieved from the chain via the `system.properties` RPC call. It extends
* the standard JS Map with known values exposed as a getter. While it implements a Codec, it is
* limited ain that it can only be used with input objects, i.e. no hex decoding.
* the standard JS Map with de-facto values exposed as getters. While it implements a Codec, it is
* limited in that it can only be used with input objects via RPC, i.e. no hex decoding. Unlike a
* struct, this wrasp a JSON object with unknown keys and any values for those
* @noInheritDoc
*/
export default class ChainProperties extends Map<string, any> implements Codec {
@@ -32,11 +31,17 @@ export default class ChainProperties extends Map<string, any> implements Codec {
}
/**
* @description Returns a specific names entry in the structure
* @param name The name of the entry to retrieve
* @description The token decimals, if defined (de-facto standard only)
*/
get (name: string): any | undefined {
return super.get(name);
get tokenDecimals (): number | undefined {
return this.get('tokenDecimals');
}
/**
* @description The token system, if defined (de-facto standard only)
*/
get tokenSymbol (): number | undefined {
return this.get('tokenSymbol');
}
/**
@@ -57,8 +62,8 @@ export default class ChainProperties extends Map<string, any> implements Codec {
* @description Converts the Object to JSON, typically used for RPC transfers
*/
toJSON (): any {
return [...this.keys()].reduce((json, key) => {
json[key] = this.get(key);
return [...this.entries()].reduce((json, [key, value]) => {
json[key] = value;
return json;
}, {} as any);
+11 -2
View File
@@ -7,7 +7,8 @@ import Bool from './Bool';
import USize from './USize';
const JSON_MAP = new Map([
['isSyncing', 'is_syncing']
['isSyncing', 'is_syncing'],
['shouldHavePeers', 'should_have_peers']
]);
/**
@@ -19,7 +20,8 @@ export default class Health extends Struct {
constructor (value?: any) {
super({
peers: USize,
isSyncing: Bool
isSyncing: Bool,
shouldHavePeers: Bool
}, value, JSON_MAP);
}
@@ -36,4 +38,11 @@ export default class Health extends Struct {
get peers (): USize {
return this.get('peers') as USize;
}
/**
* @description Should this node have peers (not active on --dev)
*/
get shouldHavePeers (): Bool {
return this.get('shouldHavePeers') as Bool;
}
}
+1 -3
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { isFunction, isString, stringToU8a, u8aToString, u8aToHex } from '@polkadot/util';
import { isString, stringToU8a, u8aToString, u8aToHex } from '@polkadot/util';
import { AnyU8a, Codec } from './types';
import Compact from './codec/Compact';
@@ -34,8 +34,6 @@ export default class Text extends String implements Codec {
const [offset, length] = Compact.decodeU8a(value);
return u8aToString(value.subarray(offset, offset + length.toNumber()));
} else if (isFunction(value.toString)) {
return value.toString();
}
return `${value}`;
+19 -19
View File
@@ -1333,29 +1333,29 @@
typedoc-plugin-no-inherit "^1.1.2"
typescript "^3.2.2"
"@polkadot/keyring@^0.33.35":
version "0.33.35"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.33.35.tgz#c576321831bb9f50746678477a2304dab7914c6f"
integrity sha512-7obcqaFMxbUqxN9D4LtsJYcPSX+Ku/CKOsSrccLMUAY0hUTrK41UWMzyH3+B491gtdZpAaogjd7e5+6rEpD3nQ==
"@polkadot/keyring@^0.33.36":
version "0.33.36"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.33.36.tgz#def02631369b1a2288ae95d32cadd63299f877f7"
integrity sha512-UUyb0ua+b10FAt+dH5Vuua0mu+FH9WY+as+IoVNXyDY8PpHY+kg8MDXXrCGBueCF5CaiiAJP7gD5vp7U10nrEg==
dependencies:
"@babel/runtime" "^7.2.0"
"@polkadot/util" "^0.33.35"
"@polkadot/util-crypto" "^0.33.35"
"@polkadot/util" "^0.33.36"
"@polkadot/util-crypto" "^0.33.36"
"@types/bs58" "^4.0.0"
bs58 "^4.0.1"
"@polkadot/ts@^0.1.51":
version "0.1.51"
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.51.tgz#4ce26923b3d34c026e14081975718b716c988483"
integrity sha512-p+uQIZqxtlQGTQoNcd8mED66qfyPA4qy8HmCMpUYDaFHKNpZ7qun0dqSoT0NvUB32KTSQitKhf/N0att8sEdow==
"@polkadot/ts@^0.1.52":
version "0.1.52"
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.52.tgz#6fb09e494d244dad4b3a9ca581bfe13beec66565"
integrity sha512-sij1O0x4CY51A394RYD4/aQwDPwIxIeTOpYI4AZgdF/vq5nvF14b4XFq9vAcSnblaIosf0sYKoz1f3dkN3QqLw==
"@polkadot/util-crypto@^0.33.35":
version "0.33.35"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.33.35.tgz#d8e550330ca6dcdffae6ae23d3fcc4fb90f5614f"
integrity sha512-HRCyPXq/awSgIJVZRNKzhAOUbZpte6eZn5XdDmi5DnTea5QCfQLoSHEoU1oyQK8xhPa+xNE/IJjuN2YNl+pLHw==
"@polkadot/util-crypto@^0.33.36":
version "0.33.36"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.33.36.tgz#3b1fc84be7126fd92ee4de960baafb901e50b1a4"
integrity sha512-kjzdOrBL8NKfZZdWIhQFim3yDWo6sHjWOuxJQt8k22pHa/ATF8zVZ6Xqi4r+wsfBa9S+G6AE5yyVOirVPQYeCQ==
dependencies:
"@babel/runtime" "^7.2.0"
"@polkadot/util" "^0.33.35"
"@polkadot/util" "^0.33.36"
"@types/bip39" "^2.4.1"
bip39 "^2.5.0"
blakejs "^1.1.0"
@@ -1363,10 +1363,10 @@
tweetnacl "^1.0.0"
xxhashjs "^0.2.2"
"@polkadot/util@^0.33.35":
version "0.33.35"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.33.35.tgz#b6a544135ca71e125fb21b88277b96f2dfff7f36"
integrity sha512-dO40ypUhwzLHuch/W1/wzYcGdvak0B616+q0A6HUeYfdD/k7mva7fKlQR8jOeBM6jFiNLTENTlyvew7P59rotg==
"@polkadot/util@^0.33.36":
version "0.33.36"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.33.36.tgz#975590dd059f78209c9d398f72651ac393dd8245"
integrity sha512-N5b46NYTNJODILXNGRxvW/8yeKiHjQv4k3YmJhYnslMsEbaXPvkePFUA2N8Ji1LQrAD8sQbaoG8aYoNaqHSJMA==
dependencies:
"@babel/runtime" "^7.2.0"
"@types/bn.js" "^4.11.3"