Don't export constants as ConstantCodec (TS casting) (#1140)
* Don't export constants as ConstantCodec (TS casting) * Import ConstantCodec from types
This commit is contained in:
@@ -34,6 +34,6 @@
|
||||
"memoizee": "^0.4.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^0.94.0-beta.11"
|
||||
"@polkadot/keyring": "^0.94.0-beta.12"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.5.4",
|
||||
"@polkadot/types": "^0.82.0-beta.66",
|
||||
"@polkadot/util": "^0.94.0-beta.11",
|
||||
"@polkadot/util-crypto": "^0.94.0-beta.11"
|
||||
"@polkadot/util": "^0.94.0-beta.12",
|
||||
"@polkadot/util-crypto": "^0.94.0-beta.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^0.94.0-beta.11"
|
||||
"@polkadot/keyring": "^0.94.0-beta.12"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 { Constants, ConstantCodec, ModuleConstants } from './types';
|
||||
import { Constants, ConstantCodec, ModuleConstants } from '../types';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
import Metadata from '@polkadot/types/Metadata';
|
||||
@@ -24,14 +24,13 @@ export default function fromMetadata (metadata: Metadata): Constants {
|
||||
// For access, we change the index names, i.e. Democracy.EnactmentPeriod -> democracy.enactmentPeriod
|
||||
result[stringCamelCase(name.toString())] = moduleMetadata.constants.reduce((newModule, meta): ModuleConstants => {
|
||||
const codec = createType(meta.type, meta.value);
|
||||
const ccodec = codec as ConstantCodec;
|
||||
|
||||
// This is not a perfect idea, however as it stands with number-only constants on the metadata
|
||||
// does not have any effect. However, this could become problematic in cases where items are
|
||||
// exposed that contain their own metadata. As of now, the compatibility with current, e.g.
|
||||
// storage is the driving factor, one consistent way of handling interfaces
|
||||
ccodec.meta = meta;
|
||||
newModule[stringCamelCase(meta.name.toString())] = ccodec;
|
||||
(codec as ConstantCodec).meta = meta;
|
||||
newModule[stringCamelCase(meta.name.toString())] = codec;
|
||||
|
||||
return newModule;
|
||||
}, {} as unknown as ModuleConstants);
|
||||
|
||||
+1
-1
@@ -9,6 +9,6 @@ export interface ConstantCodec extends Codec {
|
||||
meta: MetaV6;
|
||||
}
|
||||
|
||||
export type ModuleConstants = Record<string, ConstantCodec>;
|
||||
export type ModuleConstants = Record<string, Codec>;
|
||||
|
||||
export type Constants = Record<string, ModuleConstants>;
|
||||
@@ -32,9 +32,9 @@
|
||||
"@polkadot/rpc-core": "^0.82.0-beta.66",
|
||||
"@polkadot/rpc-provider": "^0.82.0-beta.66",
|
||||
"@polkadot/types": "^0.82.0-beta.66",
|
||||
"@polkadot/util-crypto": "^0.94.0-beta.11"
|
||||
"@polkadot/util-crypto": "^0.94.0-beta.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^0.94.0-beta.11"
|
||||
"@polkadot/keyring": "^0.94.0-beta.12"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import decorateDerive from '@polkadot/api-derive';
|
||||
import constantsFromMeta from '@polkadot/api-metadata/consts/fromMetadata';
|
||||
import { Constants } from '@polkadot/api-metadata/consts/fromMetadata/types';
|
||||
import { Constants } from '@polkadot/api-metadata/consts/types';
|
||||
import extrinsicsFromMeta from '@polkadot/api-metadata/extrinsics/fromMetadata';
|
||||
import { Storage } from '@polkadot/api-metadata/storage/types';
|
||||
import storageFromMeta from '@polkadot/api-metadata/storage/fromMetadata';
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
import { HeaderExtended } from '@polkadot/api-derive';
|
||||
import { ConstantCodec } from '@polkadot/api-metadata/consts/types';
|
||||
import testKeyring from '@polkadot/keyring/testingPairs';
|
||||
import { IExtrinsic, IMethod } from '@polkadot/types/types';
|
||||
import { Header, Nonce } from '@polkadot/types';
|
||||
@@ -52,7 +53,7 @@ export default async function test (): Promise<void> {
|
||||
// constants has actual value & metadata
|
||||
console.log(
|
||||
api.consts.balances.creationFee.toHex(),
|
||||
api.consts.balances.creationFee.meta.documentation.map((s): string => s.toString()).join('')
|
||||
(api.consts.balances.creationFee as ConstantCodec).meta.documentation.map((s): string => s.toString()).join('')
|
||||
);
|
||||
|
||||
const transfer = api.tx.balances.transfer(keyring.bob.address, 12345);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { DeriveCustom } from '@polkadot/api-derive';
|
||||
import { Constants } from '@polkadot/api-metadata/consts/fromMetadata/types';
|
||||
import { Constants } from '@polkadot/api-metadata/consts/types';
|
||||
import { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
|
||||
import { Hash, RuntimeVersion, u64 as U64 } from '@polkadot/types';
|
||||
import { AnyFunction, Callback, Codec, CodecArg, IExtrinsic, RegistryTypes, SignatureOptions } from '@polkadot/types/types';
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
"@polkadot/jsonrpc": "^0.82.0-beta.66",
|
||||
"@polkadot/rpc-provider": "^0.82.0-beta.66",
|
||||
"@polkadot/types": "^0.82.0-beta.66",
|
||||
"@polkadot/util": "^0.94.0-beta.11",
|
||||
"@polkadot/util": "^0.94.0-beta.12",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.5.2"
|
||||
}
|
||||
|
||||
@@ -28,15 +28,15 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.5.4",
|
||||
"@polkadot/api-metadata": "^0.82.0-beta.66",
|
||||
"@polkadot/util": "^0.94.0-beta.11",
|
||||
"@polkadot/util-crypto": "^0.94.0-beta.11",
|
||||
"@polkadot/util": "^0.94.0-beta.12",
|
||||
"@polkadot/util-crypto": "^0.94.0-beta.12",
|
||||
"@types/nock": "^10.0.3",
|
||||
"eventemitter3": "^4.0.0",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"websocket": "^1.0.29"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^0.94.0-beta.11",
|
||||
"@polkadot/keyring": "^0.94.0-beta.12",
|
||||
"mock-socket": "^8.0.5",
|
||||
"nock": "^10.0.4"
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.5.4",
|
||||
"@polkadot/util": "^0.94.0-beta.11",
|
||||
"@polkadot/util-crypto": "^0.94.0-beta.11"
|
||||
"@polkadot/util": "^0.94.0-beta.12",
|
||||
"@polkadot/util-crypto": "^0.94.0-beta.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^0.94.0-beta.11"
|
||||
"@polkadot/keyring": "^0.94.0-beta.12"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1840,14 +1840,14 @@
|
||||
typescript "^3.5.3"
|
||||
vuepress "^1.0.2"
|
||||
|
||||
"@polkadot/keyring@^0.94.0-beta.11":
|
||||
version "0.94.0-beta.11"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.94.0-beta.11.tgz#80352e9679e2f857a9b2d295a87a13ab4244103f"
|
||||
integrity sha512-2lxZOIOajliBhcAfX8tWcW3fMpkqRVHtYmuOTIGSS2ZyKS5DYPIJHzyBixHzHjyZZBJcKvIbG8UEvAPfYnXeZA==
|
||||
"@polkadot/keyring@^0.94.0-beta.12":
|
||||
version "0.94.0-beta.12"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.94.0-beta.12.tgz#0dd51c41d9452ae0eb08f2e015807384fe4ab223"
|
||||
integrity sha512-T1rYl0DboMLCsFku/p09DY7SlzS23DSsaHQdcb4qwUfLaggACA6sQ4oxq3dRrXTWIJhYSMopcBEq60BVnXXpuw==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.5.4"
|
||||
"@polkadot/util" "^0.94.0-beta.11"
|
||||
"@polkadot/util-crypto" "^0.94.0-beta.11"
|
||||
"@polkadot/util" "^0.94.0-beta.12"
|
||||
"@polkadot/util-crypto" "^0.94.0-beta.12"
|
||||
|
||||
"@polkadot/ts@^0.1.62":
|
||||
version "0.1.62"
|
||||
@@ -1856,13 +1856,13 @@
|
||||
dependencies:
|
||||
"@types/chrome" "^0.0.86"
|
||||
|
||||
"@polkadot/util-crypto@^0.94.0-beta.11":
|
||||
version "0.94.0-beta.11"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.94.0-beta.11.tgz#ad10bb25605f7194754724a55d56cbcae75c2f87"
|
||||
integrity sha512-KAs1be9b3KJo0he4lm4wNzKfu6MI57JGALBiGcQdY2xLuSCBLUhahsjlwvpS9oIuymsz/jmQHPk1AkzM//d91Q==
|
||||
"@polkadot/util-crypto@^0.94.0-beta.12":
|
||||
version "0.94.0-beta.12"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.94.0-beta.12.tgz#b5f42023b3b18e9e6b8601004cd426390b90adbf"
|
||||
integrity sha512-H+rUBvYIwyxEZj4PNdQOKug4CjA1o1FxtmKqcZCp6ttLdbUVZRBWRtCHE5kjPBtVD5GDQHns9NDme0zbP1F1FA==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.5.4"
|
||||
"@polkadot/util" "^0.94.0-beta.11"
|
||||
"@polkadot/util" "^0.94.0-beta.12"
|
||||
"@polkadot/wasm-crypto" "^0.11.1"
|
||||
"@types/bip39" "^2.4.2"
|
||||
"@types/bs58" "^4.0.0"
|
||||
@@ -1878,10 +1878,10 @@
|
||||
tweetnacl "^1.0.1"
|
||||
xxhashjs "^0.2.2"
|
||||
|
||||
"@polkadot/util@^0.94.0-beta.11":
|
||||
version "0.94.0-beta.11"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.94.0-beta.11.tgz#0ecac8b025e922e392ec9f9c9572995676c00384"
|
||||
integrity sha512-0gNbooJLo5VlSq0gKPC7gdp7ULHuyaLiQOBprjtHwJvkThGkDBe+h9VkmGVJsiIsZUt7tFZHP6o9BbCr2Z1+VA==
|
||||
"@polkadot/util@^0.94.0-beta.12":
|
||||
version "0.94.0-beta.12"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.94.0-beta.12.tgz#c05fd3ccad761e691ef195fee508dc12cd97e8b6"
|
||||
integrity sha512-5/xjHAZ5Eo4nhNC9f+vpTczL1QuFVdKrN2xhjJutAx/lpM+3X9qlp6AAKwiR8IVqcKwPZ1tPAr3do6Ku1Z7dkQ==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.5.4"
|
||||
"@types/bn.js" "^4.11.5"
|
||||
|
||||
Reference in New Issue
Block a user