Update from new @polkadot/params (#95)

This commit is contained in:
Jaco Greeff
2018-05-29 12:26:19 +02:00
committed by GitHub
parent 7873a6dc0c
commit c68bf8a689
15 changed files with 94 additions and 109 deletions
+1 -1
View File
@@ -10,5 +10,5 @@
"packages": [ "packages": [
"packages/*" "packages/*"
], ],
"version": "0.12.15" "version": "0.13.0"
} }
+3 -3
View File
@@ -1,6 +1,6 @@
{ {
"name": "@polkadot/api-format", "name": "@polkadot/api-format",
"version": "0.12.15", "version": "0.13.0",
"description": "Input/Output formatters for JsonRPC exchange", "description": "Input/Output formatters for JsonRPC exchange",
"main": "index.js", "main": "index.js",
"keywords": [ "keywords": [
@@ -31,8 +31,8 @@
}, },
"dependencies": { "dependencies": {
"@babel/runtime": "^7.0.0-beta.47", "@babel/runtime": "^7.0.0-beta.47",
"@polkadot/jsonrpc": "^0.16.15", "@polkadot/jsonrpc": "^0.17.2",
"@polkadot/primitives-json": "^0.16.15", "@polkadot/primitives-json": "^0.17.2",
"@polkadot/util": "^0.22.2", "@polkadot/util": "^0.22.2",
"@polkadot/util-keyring": "^0.22.2" "@polkadot/util-keyring": "^0.22.2"
} }
+2 -2
View File
@@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details. // of the ISC license. See the LICENSE file for details.
// @flow // @flow
import type { Params, Param$Types } from '@polkadot/params/types'; import type { Params } from '@polkadot/params/types';
const addressDecode = require('@polkadot/util-keyring/address/decode'); const addressDecode = require('@polkadot/util-keyring/address/decode');
const bytesEncode = require('@polkadot/primitives-json/bytes/encode'); const bytesEncode = require('@polkadot/primitives-json/bytes/encode');
@@ -20,7 +20,7 @@ const formatters = {
// flowlint-next-line unclear-type:off // flowlint-next-line unclear-type:off
module.exports = function formatInputs (params: Params, values: Array<any>): Array<any> { module.exports = function formatInputs (params: Params, values: Array<any>): Array<any> {
const types: Array<Param$Types> = Object.keys(params).map((name) => params[name].type); const types = params.map(({ type }) => type);
return format(formatters, types, values); return format(formatters, types, values);
}; };
+4 -4
View File
@@ -8,10 +8,10 @@ describe('formatInputs', () => {
it('formats each value in an array', () => { it('formats each value in an array', () => {
expect( expect(
formatInputs( formatInputs(
{ [
foo: { type: 'Bytes' }, { name: 'foo', type: 'Bytes' },
bar: { type: 'Hash' } { name: 'bar', type: 'Hash' }
}, ],
[ [
new Uint8Array([0x12, 0x34]), new Uint8Array([0x12, 0x34]),
new Uint8Array([0xab, 0xcd]) new Uint8Array([0xab, 0xcd])
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "@polkadot/api-provider", "name": "@polkadot/api-provider",
"version": "0.12.15", "version": "0.13.0",
"description": "Transport providers for the API", "description": "Transport providers for the API",
"main": "index.js", "main": "index.js",
"keywords": [ "keywords": [
@@ -35,7 +35,7 @@
}, },
"dependencies": { "dependencies": {
"@babel/runtime": "^7.0.0-beta.47", "@babel/runtime": "^7.0.0-beta.47",
"@polkadot/storage-substrate": "^0.16.15", "@polkadot/storage": "^0.17.2",
"@polkadot/util": "^0.22.2", "@polkadot/util": "^0.22.2",
"@polkadot/util-crypto": "^0.22.2", "@polkadot/util-crypto": "^0.22.2",
"@polkadot/util-keyring": "^0.22.2", "@polkadot/util-keyring": "^0.22.2",
+4 -4
View File
@@ -13,7 +13,7 @@ import type { MockState, MockState$Subscription$Callback } from './types';
const BN = require('bn.js'); const BN = require('bn.js');
const headerEncode = require('@polkadot/primitives-json/header/encode'); const headerEncode = require('@polkadot/primitives-json/header/encode');
const createKey = require('@polkadot/storage/key'); const createKey = require('@polkadot/storage/key');
const state = require('@polkadot/storage-substrate/keys'); const state = require('@polkadot/storage');
const bnToU8a = require('@polkadot/util/bn/toU8a'); const bnToU8a = require('@polkadot/util/bn/toU8a');
const u8aToHex = require('@polkadot/util/u8a/toHex'); const u8aToHex = require('@polkadot/util/u8a/toHex');
const randomAsU8a = require('@polkadot/util-crypto/random/asU8a'); const randomAsU8a = require('@polkadot/util-crypto/random/asU8a');
@@ -76,11 +76,11 @@ module.exports = function mocks ({ emitter, storage, subscriptions }: MockState)
newHead = makeBlockHeader(newHead.number); newHead = makeBlockHeader(newHead.number);
keyring.getPairs().forEach(({ publicKey }: KeyringPair, index: number) => { keyring.getPairs().forEach(({ publicKey }: KeyringPair, index: number) => {
setStorageBn(storage, state.staking.keys.freeBalanceOf, newHead.number.muln(3).iaddn(index), publicKey()); setStorageBn(storage, state.staking.public.freeBalanceOf, newHead.number.muln(3).iaddn(index), publicKey());
setStorageBn(storage, state.system.keys.accountIndexOf, newHead.number.addn(index), publicKey()); setStorageBn(storage, state.system.public.accountIndexOf, newHead.number.addn(index), publicKey());
}); });
setStorageBn(storage, state.timestamp.keys.current, Math.floor(Date.now() / 1000)); setStorageBn(storage, state.timestamp.public.current, Math.floor(Date.now() / 1000));
updateSubs(subscriptions, 'subscribe_newHead', headerEncode(newHead)); updateSubs(subscriptions, 'subscribe_newHead', headerEncode(newHead));
}, 5000); }, 5000);
+6 -3
View File
@@ -13,8 +13,8 @@ const l = require('@polkadot/util/logger')('api-mock');
const SUBSCRIPTIONS = Array.prototype.concat.apply( const SUBSCRIPTIONS = Array.prototype.concat.apply(
[], Object.keys(interfaces).map((section) => { [], Object.keys(interfaces).map((section) => {
return Object return Object
.keys(interfaces[section].methods) .keys(interfaces[section].public)
.filter((method) => interfaces[section].methods[method].isSubscription) .filter((method) => interfaces[section].public[method].isSubscription)
.map((method) => `subscribe_${method}`); .map((method) => `subscribe_${method}`);
}) })
); );
@@ -25,7 +25,10 @@ const REQUESTS = {
// flowlint-next-line unclear-type:off // flowlint-next-line unclear-type:off
storage[((params[0]: any): string)] storage[((params[0]: any): string)]
); );
} },
'system_chain': (): string => 'mockChain',
'system_name': (): string => 'mockClient',
'system_version': (): string => '9.8.7'
}; };
module.exports = function state (): MockState { module.exports = function state (): MockState {
+3 -3
View File
@@ -1,6 +1,6 @@
{ {
"name": "@polkadot/api-rx", "name": "@polkadot/api-rx",
"version": "0.12.15", "version": "0.13.0",
"description": "An RxJs wrapper around the Polkadot JS API", "description": "An RxJs wrapper around the Polkadot JS API",
"main": "index.js", "main": "index.js",
"keywords": [ "keywords": [
@@ -31,8 +31,8 @@
}, },
"dependencies": { "dependencies": {
"@babel/runtime": "^7.0.0-beta.47", "@babel/runtime": "^7.0.0-beta.47",
"@polkadot/api": "^0.12.15", "@polkadot/api": "^0.13.0",
"@polkadot/api-provider": "^0.12.15", "@polkadot/api-provider": "^0.13.0",
"rxjs": "^5.5.10" "rxjs": "^5.5.10"
} }
} }
+5 -5
View File
@@ -1,6 +1,6 @@
{ {
"name": "@polkadot/api", "name": "@polkadot/api",
"version": "0.12.15", "version": "0.13.0",
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface", "description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
"main": "index.js", "main": "index.js",
"keywords": [ "keywords": [
@@ -31,10 +31,10 @@
}, },
"dependencies": { "dependencies": {
"@babel/runtime": "^7.0.0-beta.47", "@babel/runtime": "^7.0.0-beta.47",
"@polkadot/api-format": "^0.12.15", "@polkadot/api-format": "^0.13.0",
"@polkadot/api-provider": "^0.12.15", "@polkadot/api-provider": "^0.13.0",
"@polkadot/jsonrpc": "^0.16.15", "@polkadot/jsonrpc": "^0.17.2",
"@polkadot/params": "^0.16.15", "@polkadot/params": "^0.17.2",
"@polkadot/util": "^0.22.2" "@polkadot/util": "^0.22.2"
} }
} }
+3 -4
View File
@@ -14,7 +14,7 @@ const methodSubscribe = require('./methodSubscribe');
module.exports = function createInterface (provider: ProviderInterface, section: Interface$Sections): ApiInterface$Section { module.exports = function createInterface (provider: ProviderInterface, section: Interface$Sections): ApiInterface$Section {
const exposed: $Shape<ApiInterface$Section> = {}; const exposed: $Shape<ApiInterface$Section> = {};
const { methods } = interfaces[section]; const methods = interfaces[section].public;
return Object return Object
.keys(methods) .keys(methods)
@@ -22,10 +22,9 @@ module.exports = function createInterface (provider: ProviderInterface, section:
const rpcName = `${section}_${name}`; const rpcName = `${section}_${name}`;
const def = methods[name]; const def = methods[name];
// flowlint-next-line sketchy-null-bool:off
exposed[name] = def.isSubscription exposed[name] = def.isSubscription
? methodSubscribe(provider, rpcName, name, methods[name]) ? methodSubscribe(provider, rpcName, name, def)
: methodSend(provider, rpcName, name, methods[name]); : methodSend(provider, rpcName, name, def);
return exposed; return exposed;
}, exposed); }, exposed);
+6 -6
View File
@@ -6,20 +6,20 @@ const isFunction = require('@polkadot/util/is/function');
jest.mock('@polkadot/jsonrpc', () => ({ jest.mock('@polkadot/jsonrpc', () => ({
test: { test: {
methods: { public: {
blah: { blah: {
params: { params: [
foo: { type: 'Address' } { name: 'foo', type: 'Address' }
}, ],
type: 'Address' type: 'Address'
}, },
bleh: { bleh: {
params: {}, params: [],
type: 'Address' type: 'Address'
}, },
pubsub: { pubsub: {
isSubscription: true, isSubscription: true,
params: {}, params: [],
type: 'Address' type: 'Address'
} }
} }
+4 -4
View File
@@ -12,14 +12,14 @@ describe('methodCall', () => {
methods = { methods = {
blah: { blah: {
name: 'blah', name: 'blah',
params: { params: [
foo: { type: 'Bytes' } { name: 'foo', type: 'Bytes' }
}, ],
type: 'Bytes' type: 'Bytes'
}, },
bleh: { bleh: {
name: 'bleh', name: 'bleh',
params: {}, params: [],
type: 'Bytes' type: 'Bytes'
} }
}; };
+2 -3
View File
@@ -8,8 +8,7 @@ import type { Params } from '@polkadot/params/types';
const formatInputs = require('@polkadot/api-format/input'); const formatInputs = require('@polkadot/api-format/input');
const assert = require('@polkadot/util/assert'); const assert = require('@polkadot/util/assert');
module.exports = function createParams (_params: Params, values: Array<mixed>): Array<mixed> { module.exports = function createParams (params: Params, values: Array<mixed>): Array<mixed> {
const params = Object.keys(_params).map((key) => _params[key]);
const required = params.filter(({ isOptional }) => !isOptional); const required = params.filter(({ isOptional }) => !isOptional);
const optionalText = params.length const optionalText = params.length
? ` (${(params.length - required.length) || 'none'} optional)` ? ` (${(params.length - required.length) || 'none'} optional)`
@@ -17,5 +16,5 @@ module.exports = function createParams (_params: Params, values: Array<mixed>):
assert(values.length >= required.length && values.length <= params.length, `${params.length || 'no'} params expected${optionalText}, found ${values.length} instead`); assert(values.length >= required.length && values.length <= params.length, `${params.length || 'no'} params expected${optionalText}, found ${values.length} instead`);
return formatInputs(_params, values); return formatInputs(params, values);
}; };
+6 -6
View File
@@ -10,15 +10,15 @@ describe('params', () => {
beforeEach(() => { beforeEach(() => {
methods = { methods = {
blah: { blah: {
params: { params: [
foo: { type: 'Bytes' } { name: 'foo', type: 'Bytes' }
}, ],
type: 'Bytes' type: 'Bytes'
}, },
bleh: { bleh: {
params: { params: [
foo: { type: 'Bytes', isOptional: true } { name: 'foo', type: 'Bytes', isOptional: true }
}, ],
type: 'Bytes' type: 'Bytes'
} }
}; };
+43 -59
View File
@@ -700,102 +700,86 @@
mkdirp "^0.5.1" mkdirp "^0.5.1"
rimraf "^2.6.2" rimraf "^2.6.2"
"@polkadot/extrinsics-substrate@^0.16.15": "@polkadot/extrinsics@^0.17.2":
version "0.16.15" version "0.17.2"
resolved "https://registry.yarnpkg.com/@polkadot/extrinsics-substrate/-/extrinsics-substrate-0.16.15.tgz#c8ad42f38b568629a3de9089413a8275ef06dc8d" resolved "https://registry.yarnpkg.com/@polkadot/extrinsics/-/extrinsics-0.17.2.tgz#74c09019268ff81ebc5023a5c6d3bd2fd08385ee"
dependencies: dependencies:
"@babel/runtime" "^7.0.0-beta.47" "@babel/runtime" "^7.0.0-beta.47"
"@polkadot/extrinsics" "^0.16.15" "@polkadot/params" "^0.17.2"
"@polkadot/primitives" "^0.17.2"
"@polkadot/extrinsics@^0.16.15":
version "0.16.15"
resolved "https://registry.yarnpkg.com/@polkadot/extrinsics/-/extrinsics-0.16.15.tgz#103cd7beb4049fee07d86ac34f02e14360dc9b32"
dependencies:
"@babel/runtime" "^7.0.0-beta.47"
"@polkadot/params" "^0.16.15"
"@polkadot/primitives" "^0.16.15"
"@polkadot/util" "^0.22.2" "@polkadot/util" "^0.22.2"
"@polkadot/jsonrpc@^0.16.15": "@polkadot/jsonrpc@^0.17.2":
version "0.16.15" version "0.17.2"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.16.15.tgz#aaa9bdff6af8fb32b49740843e203490a5285f15" resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.17.2.tgz#8056b2fddb41d1f15c2f428fb3622aeffa6d4d42"
dependencies: dependencies:
"@polkadot/params" "^0.16.15" "@polkadot/params" "^0.17.2"
babel-runtime "^6.26.0" babel-runtime "^6.26.0"
"@polkadot/params@^0.16.15": "@polkadot/params@^0.17.2":
version "0.16.15" version "0.17.2"
resolved "https://registry.yarnpkg.com/@polkadot/params/-/params-0.16.15.tgz#31d419b6bdb815cdb87cd1a3bd251a670a5e02c7" resolved "https://registry.yarnpkg.com/@polkadot/params/-/params-0.17.2.tgz#eeb7d1427c375398f110e34b1fcf7d649af6ab40"
dependencies: dependencies:
"@babel/runtime" "^7.0.0-beta.47" "@babel/runtime" "^7.0.0-beta.47"
"@polkadot/extrinsics" "^0.16.15" "@polkadot/extrinsics" "^0.17.2"
"@polkadot/extrinsics-substrate" "^0.16.15" "@polkadot/primitives" "^0.17.2"
"@polkadot/primitives" "^0.16.15"
"@polkadot/util" "^0.22.2" "@polkadot/util" "^0.22.2"
"@polkadot/primitives-builder@^0.16.15": "@polkadot/primitives-builder@^0.17.2":
version "0.16.15" version "0.17.2"
resolved "https://registry.yarnpkg.com/@polkadot/primitives-builder/-/primitives-builder-0.16.15.tgz#89e986a6e7167247beea8dc2dcc8278b7cfd4404" resolved "https://registry.yarnpkg.com/@polkadot/primitives-builder/-/primitives-builder-0.17.2.tgz#a470e9dc2665a7177318517884afb396f718825b"
dependencies: dependencies:
"@babel/runtime" "^7.0.0-beta.47" "@babel/runtime" "^7.0.0-beta.47"
"@polkadot/primitives" "^0.16.15" "@polkadot/primitives" "^0.17.2"
"@polkadot/primitives-codec" "^0.16.15" "@polkadot/primitives-codec" "^0.17.2"
"@polkadot/util" "^0.22.2" "@polkadot/util" "^0.22.2"
"@polkadot/util-crypto" "^0.22.2" "@polkadot/util-crypto" "^0.22.2"
"@polkadot/util-triehash" "^0.22.2" "@polkadot/util-triehash" "^0.22.2"
"@polkadot/primitives-codec@^0.16.15": "@polkadot/primitives-codec@^0.17.2":
version "0.16.15" version "0.17.2"
resolved "https://registry.yarnpkg.com/@polkadot/primitives-codec/-/primitives-codec-0.16.15.tgz#ecbe4c9cfc77da49361920ded193c5c2ff2c7aa0" resolved "https://registry.yarnpkg.com/@polkadot/primitives-codec/-/primitives-codec-0.17.2.tgz#310d113b75191787b8b7fa45fdc1fd5858e5e00a"
dependencies: dependencies:
"@babel/runtime" "^7.0.0-beta.47" "@babel/runtime" "^7.0.0-beta.47"
"@polkadot/primitives" "^0.16.15" "@polkadot/primitives" "^0.17.2"
"@polkadot/primitives-builder" "^0.16.15" "@polkadot/primitives-builder" "^0.17.2"
"@polkadot/primitives-rlp" "^0.16.15" "@polkadot/primitives-rlp" "^0.17.2"
"@polkadot/util" "^0.22.2" "@polkadot/util" "^0.22.2"
"@polkadot/util-keyring" "^0.22.2" "@polkadot/util-keyring" "^0.22.2"
"@polkadot/primitives-json@^0.16.15": "@polkadot/primitives-json@^0.17.2":
version "0.16.15" version "0.17.2"
resolved "https://registry.yarnpkg.com/@polkadot/primitives-json/-/primitives-json-0.16.15.tgz#decb1fa9a134dd92a792d16a970bc9c1e783b81b" resolved "https://registry.yarnpkg.com/@polkadot/primitives-json/-/primitives-json-0.17.2.tgz#4db3603bb668f4bfae59fdddc72780860c83cd86"
dependencies: dependencies:
"@babel/runtime" "^7.0.0-beta.47" "@babel/runtime" "^7.0.0-beta.47"
"@polkadot/primitives" "^0.16.15" "@polkadot/primitives" "^0.17.2"
"@polkadot/primitives-builder" "^0.16.15" "@polkadot/primitives-builder" "^0.17.2"
"@polkadot/util" "^0.22.2" "@polkadot/util" "^0.22.2"
"@polkadot/primitives-rlp@^0.16.15": "@polkadot/primitives-rlp@^0.17.2":
version "0.16.15" version "0.17.2"
resolved "https://registry.yarnpkg.com/@polkadot/primitives-rlp/-/primitives-rlp-0.16.15.tgz#863b78da6273887631193730fab96e5d81c11b33" resolved "https://registry.yarnpkg.com/@polkadot/primitives-rlp/-/primitives-rlp-0.17.2.tgz#a142e55a5cb42277ba5f2d6bd7ee34ffd31ff55e"
dependencies: dependencies:
"@babel/runtime" "^7.0.0-beta.47" "@babel/runtime" "^7.0.0-beta.47"
"@polkadot/primitives" "^0.16.15" "@polkadot/primitives" "^0.17.2"
"@polkadot/primitives-builder" "^0.16.15" "@polkadot/primitives-builder" "^0.17.2"
"@polkadot/util" "^0.22.2" "@polkadot/util" "^0.22.2"
"@polkadot/util-crypto" "^0.22.2" "@polkadot/util-crypto" "^0.22.2"
"@polkadot/primitives@^0.16.15": "@polkadot/primitives@^0.17.2":
version "0.16.15" version "0.17.2"
resolved "https://registry.yarnpkg.com/@polkadot/primitives/-/primitives-0.16.15.tgz#b7f63adc89eb744d956ec93344dd74886cf9139e" resolved "https://registry.yarnpkg.com/@polkadot/primitives/-/primitives-0.17.2.tgz#44bd4a56708550054ad41d6fda46d66c0e1f6bcb"
dependencies: dependencies:
"@babel/runtime" "^7.0.0-beta.47" "@babel/runtime" "^7.0.0-beta.47"
"@polkadot/util" "^0.22.2" "@polkadot/util" "^0.22.2"
"@polkadot/storage-substrate@^0.16.15": "@polkadot/storage@^0.17.2":
version "0.16.15" version "0.17.2"
resolved "https://registry.yarnpkg.com/@polkadot/storage-substrate/-/storage-substrate-0.16.15.tgz#f0ab2dc9c85ebe9f72e223d15bb84ef3f42dc5ad" resolved "https://registry.yarnpkg.com/@polkadot/storage/-/storage-0.17.2.tgz#bbb779879faec6c3b6691aedd4af898bf54c3e55"
dependencies: dependencies:
"@babel/runtime" "^7.0.0-beta.47" "@babel/runtime" "^7.0.0-beta.47"
"@polkadot/storage" "^0.16.15" "@polkadot/params" "^0.17.2"
"@polkadot/util" "^0.22.2" "@polkadot/primitives" "^0.17.2"
"@polkadot/storage@^0.16.15":
version "0.16.15"
resolved "https://registry.yarnpkg.com/@polkadot/storage/-/storage-0.16.15.tgz#e1cb8cf618ab75eb6483a236a52da14a46e15781"
dependencies:
"@babel/runtime" "^7.0.0-beta.47"
"@polkadot/params" "^0.16.15"
"@polkadot/primitives" "^0.16.15"
"@polkadot/util" "^0.22.2" "@polkadot/util" "^0.22.2"
"@polkadot/util-keyring" "^0.22.2" "@polkadot/util-keyring" "^0.22.2"