diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d9d35659b..bdf4f8efea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - The `@polkadot/types/codec/create` has been moved to `@polkadot/types/create`, imports from `@polkadot/types` are unaffected - Expose chain properies on registry (and use for API type formatting) +- Add `toHuman(isExtended?: boolean)` to all codec types, formatting into a human-readable structure # 1.2.1 Feb 16, 2020 diff --git a/packages/api-contract/package.json b/packages/api-contract/package.json index 194dc43628..894c2757fe 100644 --- a/packages/api-contract/package.json +++ b/packages/api-contract/package.json @@ -30,7 +30,7 @@ "@polkadot/api": "^1.3.0-beta.8", "@polkadot/rpc-core": "^1.3.0-beta.8", "@polkadot/types": "^1.3.0-beta.8", - "@polkadot/util": "^2.3.1", + "@polkadot/util": "^2.4.0-beta.0", "bn.js": "^5.1.1", "rxjs": "^6.5.4" } diff --git a/packages/api-derive/package.json b/packages/api-derive/package.json index 067e7b7be9..2db45b372a 100644 --- a/packages/api-derive/package.json +++ b/packages/api-derive/package.json @@ -32,13 +32,13 @@ "@polkadot/rpc-core": "^1.3.0-beta.8", "@polkadot/rpc-provider": "^1.3.0-beta.8", "@polkadot/types": "^1.3.0-beta.8", - "@polkadot/util": "^2.3.1", - "@polkadot/util-crypto": "^2.3.1", + "@polkadot/util": "^2.4.0-beta.0", + "@polkadot/util-crypto": "^2.4.0-beta.0", "bn.js": "^5.1.1", "memoizee": "^0.4.14", "rxjs": "^6.5.4" }, "devDependencies": { - "@polkadot/keyring": "^2.3.1" + "@polkadot/keyring": "^2.4.0-beta.0" } } diff --git a/packages/api/package.json b/packages/api/package.json index d22078e642..1deade2833 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -28,18 +28,18 @@ "dependencies": { "@babel/runtime": "^7.8.4", "@polkadot/api-derive": "^1.3.0-beta.8", - "@polkadot/keyring": "^2.3.1", + "@polkadot/keyring": "^2.4.0-beta.0", "@polkadot/metadata": "^1.3.0-beta.8", "@polkadot/rpc-core": "^1.3.0-beta.8", "@polkadot/rpc-provider": "^1.3.0-beta.8", "@polkadot/types": "^1.3.0-beta.8", - "@polkadot/util": "^2.3.1", - "@polkadot/util-crypto": "^2.3.1", + "@polkadot/util": "^2.4.0-beta.0", + "@polkadot/util-crypto": "^2.4.0-beta.0", "bn.js": "^5.1.1", "eventemitter3": "^4.0.0", "rxjs": "^6.5.4" }, "devDependencies": { - "@polkadot/keyring": "^2.3.1" + "@polkadot/keyring": "^2.4.0-beta.0" } } diff --git a/packages/jsonrpc/package.json b/packages/jsonrpc/package.json index dde863a71e..d3f137da0f 100644 --- a/packages/jsonrpc/package.json +++ b/packages/jsonrpc/package.json @@ -28,6 +28,6 @@ "dependencies": { "@babel/runtime": "^7.8.4", "@polkadot/types": "^1.3.0-beta.8", - "@polkadot/util": "^2.3.1" + "@polkadot/util": "^2.4.0-beta.0" } } diff --git a/packages/metadata/package.json b/packages/metadata/package.json index 1de229f94e..fd5dfa94e3 100644 --- a/packages/metadata/package.json +++ b/packages/metadata/package.json @@ -28,11 +28,11 @@ "dependencies": { "@babel/runtime": "^7.8.4", "@polkadot/types": "^1.3.0-beta.8", - "@polkadot/util": "^2.3.1", - "@polkadot/util-crypto": "^2.3.1", + "@polkadot/util": "^2.4.0-beta.0", + "@polkadot/util-crypto": "^2.4.0-beta.0", "bn.js": "^5.1.1" }, "devDependencies": { - "@polkadot/keyring": "^2.3.1" + "@polkadot/keyring": "^2.4.0-beta.0" } } diff --git a/packages/rpc-core/package.json b/packages/rpc-core/package.json index 14a2712f1f..23019e1b94 100644 --- a/packages/rpc-core/package.json +++ b/packages/rpc-core/package.json @@ -31,11 +31,11 @@ "@polkadot/metadata": "^1.3.0-beta.8", "@polkadot/rpc-provider": "^1.3.0-beta.8", "@polkadot/types": "^1.3.0-beta.8", - "@polkadot/util": "^2.3.1", + "@polkadot/util": "^2.4.0-beta.0", "memoizee": "^0.4.14", "rxjs": "^6.5.4" }, "devDependencies": { - "@polkadot/keyring": "^2.3.1" + "@polkadot/keyring": "^2.4.0-beta.0" } } diff --git a/packages/rpc-provider/package.json b/packages/rpc-provider/package.json index 50ee9f4084..ec0df9b0af 100644 --- a/packages/rpc-provider/package.json +++ b/packages/rpc-provider/package.json @@ -30,15 +30,15 @@ "@polkadot/jsonrpc": "^1.3.0-beta.8", "@polkadot/metadata": "^1.3.0-beta.8", "@polkadot/types": "^1.3.0-beta.8", - "@polkadot/util": "^2.3.1", - "@polkadot/util-crypto": "^2.3.1", + "@polkadot/util": "^2.4.0-beta.0", + "@polkadot/util-crypto": "^2.4.0-beta.0", "bn.js": "^5.1.1", "eventemitter3": "^4.0.0", "isomorphic-fetch": "^2.2.1", "websocket": "^1.0.31" }, "devDependencies": { - "@polkadot/keyring": "^2.3.1", + "@polkadot/keyring": "^2.4.0-beta.0", "mock-socket": "^9.0.3", "nock": "^11.8.2" } diff --git a/packages/typegen/package.json b/packages/typegen/package.json index b607a288a0..1de56602b2 100644 --- a/packages/typegen/package.json +++ b/packages/typegen/package.json @@ -40,7 +40,7 @@ "@polkadot/jsonrpc": "^1.3.0-beta.8", "@polkadot/metadata": "^1.3.0-beta.8", "@polkadot/types": "^1.3.0-beta.8", - "@polkadot/util": "^2.3.1", + "@polkadot/util": "^2.4.0-beta.0", "websocket": "^1.0.31", "yargs": "^15.1.0" }, diff --git a/packages/types/package.json b/packages/types/package.json index 573afe6dde..6128172053 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -28,15 +28,15 @@ "dependencies": { "@babel/runtime": "^7.8.4", "@polkadot/metadata": "^1.3.0-beta.8", - "@polkadot/util": "^2.3.1", - "@polkadot/util-crypto": "^2.3.1", + "@polkadot/util": "^2.4.0-beta.0", + "@polkadot/util-crypto": "^2.4.0-beta.0", "@types/bn.js": "^4.11.6", "bn.js": "^5.1.1", "memoizee": "^0.4.14", "rxjs": "^6.5.4" }, "devDependencies": { - "@polkadot/keyring": "^2.3.1", + "@polkadot/keyring": "^2.4.0-beta.0", "@types/memoizee": "^0.4.3" } } diff --git a/packages/types/src/codec/UInt.ts b/packages/types/src/codec/UInt.ts index c2c301e262..2bf6359f73 100644 --- a/packages/types/src/codec/UInt.ts +++ b/packages/types/src/codec/UInt.ts @@ -50,7 +50,7 @@ export default class UInt extends AbstractInt { public toHuman (isExpanded?: boolean): any { // FIXME we need proper expansion here return this instanceof ClassOf(this.registry, 'Balance') - ? formatBalance(this, { withSi: true, withUnit: true }) + ? formatBalance(this, { withSi: true, withUnit: this.registry.chainToken }, this.registry.chainDecimals) : super.toHuman(isExpanded); } diff --git a/packages/types/src/create/registry.ts b/packages/types/src/create/registry.ts index 1765ae0ac2..e1ddf4dc58 100644 --- a/packages/types/src/create/registry.ts +++ b/packages/types/src/create/registry.ts @@ -7,7 +7,7 @@ import { ChainProperties, DispatchErrorModule } from '../interfaces/types'; import { CallFunction, Codec, Constructor, InterfaceTypes, RegistryError, RegistryTypes, Registry, RegistryMetadata, TypeDef } from '../types'; import extrinsicsFromMeta from '@polkadot/metadata/Decorated/extrinsics/fromMetadata'; -import { assert, isFunction, isString, isU8a, isUndefined, stringCamelCase, u8aToHex } from '@polkadot/util'; +import { assert, formatBalance, isFunction, isString, isU8a, isUndefined, stringCamelCase, u8aToHex } from '@polkadot/util'; import Raw from '../codec/Raw'; import { EventData } from '../primitive/Generic/Event'; @@ -121,7 +121,7 @@ export class TypeRegistry implements Registry { public get chainToken (): string { return this._chainProperties?.tokenSymbol.isSome ? this._chainProperties.tokenSymbol.unwrap().toString() - : 'DEV'; + : formatBalance.getDefaults().unit; } // find a specific call diff --git a/packages/types/src/primitive/Generic/Call.ts b/packages/types/src/primitive/Generic/Call.ts index 7ee51c333c..f51b085d3a 100644 --- a/packages/types/src/primitive/Generic/Call.ts +++ b/packages/types/src/primitive/Generic/Call.ts @@ -215,7 +215,11 @@ export default class Call extends Struct implements IMethod { callIndex: u8aToHex(this.callIndex), section: call?.section, method: call?.method, - args: this.args.map((arg) => arg.toHuman(isExpanded)) + args: this.args.map((arg) => arg.toHuman(isExpanded)), + ...(isExpanded && call + ? { documentation: call.meta.documentation.map((d) => d.toString()) } + : {} + ) }; } diff --git a/packages/types/src/primitive/Generic/Event.ts b/packages/types/src/primitive/Generic/Event.ts index 9177cf9190..05a72579d5 100644 --- a/packages/types/src/primitive/Generic/Event.ts +++ b/packages/types/src/primitive/Generic/Event.ts @@ -5,7 +5,7 @@ import { TypeDef } from '../../create/types'; import { EventMetadataLatest } from '../../interfaces/metadata'; import { EventId } from '../../interfaces/system'; -import { Constructor, Registry, RegistryMetadataEvent } from '../../types'; +import { AnyJsonObject, Constructor, Registry, RegistryMetadataEvent } from '../../types'; import Struct from '../../codec/Struct'; import Tuple from '../../codec/Tuple'; @@ -141,4 +141,13 @@ export default class Event extends Struct { public get typeDef (): TypeDef[] { return this.data.typeDef; } + + /** + * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information + */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public toHuman (isExpanded?: boolean): AnyJsonObject { + // FIXME May this human-friendly + return this.toJSON(); + } } diff --git a/yarn.lock b/yarn.lock index 478b4cd514..32147c3963 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2077,14 +2077,14 @@ webpack-cli "^3.3.11" yargs "^15.1.0" -"@polkadot/keyring@^2.3.1": - version "2.3.1" - resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-2.3.1.tgz#64ed052760c6ebf3e71a2413a0f362d8522d0060" - integrity sha512-MvkyR/ohYAsSQrSEVBo6w/S5S9i4AEPYGNqPOyR7erEJD3YQjZhJJkJx23w6XsbWr0XDfzJG9SQ5uq585DIi4g== +"@polkadot/keyring@^2.4.0-beta.0": + version "2.4.0-beta.0" + resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-2.4.0-beta.0.tgz#d43996daf38c53b35eccd3016246726a26c7b483" + integrity sha512-dv4wonHpWnXDNHyidWdKzXZQnDesxQWWbATbDeZUv4P1Hwbn4zpa8+nQoRuKi7v5OmFJvm0Ailb84/sWQweoYA== dependencies: "@babel/runtime" "^7.8.4" - "@polkadot/util" "^2.3.1" - "@polkadot/util-crypto" "^2.3.1" + "@polkadot/util" "^2.4.0-beta.0" + "@polkadot/util-crypto" "^2.4.0-beta.0" "@polkadot/ts@^0.2.3": version "0.2.3" @@ -2093,13 +2093,13 @@ dependencies: "@types/chrome" "^0.0.95" -"@polkadot/util-crypto@^2.3.1": - version "2.3.1" - resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-2.3.1.tgz#e95bace6ef59408657df1068f8044766744f453c" - integrity sha512-I9lKhheW/cWeFSs5NBgiw5WkkfAsceEzW4/eWf/s39TLVueUnOiXG/+fcaRHBZmBDMhK9Mc2FxvLn2Df6YQGUg== +"@polkadot/util-crypto@^2.4.0-beta.0": + version "2.4.0-beta.0" + resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-2.4.0-beta.0.tgz#a821c29835ca6e23b0db6faecf3edc263fac75fb" + integrity sha512-fc6g5GNGDv1QbIeaa5BaBvdXQHmkBmsydVoZEzE49YLPHA142WzM1dof0SuP5/C/K6O11oq3yP9Ns7H+lWJf2g== dependencies: "@babel/runtime" "^7.8.4" - "@polkadot/util" "^2.3.1" + "@polkadot/util" "^2.4.0-beta.0" "@polkadot/wasm-crypto" "^1.0.1" base-x "^3.0.7" bip39 "^3.0.2" @@ -2112,10 +2112,10 @@ tweetnacl "^1.0.3" xxhashjs "^0.2.2" -"@polkadot/util@^2.3.1": - version "2.3.1" - resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-2.3.1.tgz#ea4142386e66db14eae78c8fda4fb62693cf072a" - integrity sha512-g00HThGm0t1sciOxDKuqnSsh6fyGUKtazVac0v58fMOtbX0geTu0TpddRdFav/L5KO6lkq8DBFUQW95x9Cf4gw== +"@polkadot/util@^2.4.0-beta.0": + version "2.4.0-beta.0" + resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-2.4.0-beta.0.tgz#2a289a1a9da1f59b1e07399252fdf8fbe2bf5d76" + integrity sha512-mSC/NSpqImx45f9FWf6qjzjqDpRnF1v7dfeRfRxkPGX94zrRRS/jTjPbPmOhnbfA3+vokShq3/t3DvESwYH9ZQ== dependencies: "@babel/runtime" "^7.8.4" bn.js "^5.1.1"