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
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-format",
"version": "0.12.15",
"version": "0.13.0",
"description": "Input/Output formatters for JsonRPC exchange",
"main": "index.js",
"keywords": [
@@ -31,8 +31,8 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.47",
"@polkadot/jsonrpc": "^0.16.15",
"@polkadot/primitives-json": "^0.16.15",
"@polkadot/jsonrpc": "^0.17.2",
"@polkadot/primitives-json": "^0.17.2",
"@polkadot/util": "^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.
// @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 bytesEncode = require('@polkadot/primitives-json/bytes/encode');
@@ -20,7 +20,7 @@ const formatters = {
// flowlint-next-line unclear-type:off
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);
};
+4 -4
View File
@@ -8,10 +8,10 @@ describe('formatInputs', () => {
it('formats each value in an array', () => {
expect(
formatInputs(
{
foo: { type: 'Bytes' },
bar: { type: 'Hash' }
},
[
{ name: 'foo', type: 'Bytes' },
{ name: 'bar', type: 'Hash' }
],
[
new Uint8Array([0x12, 0x34]),
new Uint8Array([0xab, 0xcd])
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-provider",
"version": "0.12.15",
"version": "0.13.0",
"description": "Transport providers for the API",
"main": "index.js",
"keywords": [
@@ -35,7 +35,7 @@
},
"dependencies": {
"@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-crypto": "^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 headerEncode = require('@polkadot/primitives-json/header/encode');
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 u8aToHex = require('@polkadot/util/u8a/toHex');
const randomAsU8a = require('@polkadot/util-crypto/random/asU8a');
@@ -76,11 +76,11 @@ module.exports = function mocks ({ emitter, storage, subscriptions }: MockState)
newHead = makeBlockHeader(newHead.number);
keyring.getPairs().forEach(({ publicKey }: KeyringPair, index: number) => {
setStorageBn(storage, state.staking.keys.freeBalanceOf, newHead.number.muln(3).iaddn(index), publicKey());
setStorageBn(storage, state.system.keys.accountIndexOf, newHead.number.addn(index), publicKey());
setStorageBn(storage, state.staking.public.freeBalanceOf, newHead.number.muln(3).iaddn(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));
}, 5000);
+6 -3
View File
@@ -13,8 +13,8 @@ const l = require('@polkadot/util/logger')('api-mock');
const SUBSCRIPTIONS = Array.prototype.concat.apply(
[], Object.keys(interfaces).map((section) => {
return Object
.keys(interfaces[section].methods)
.filter((method) => interfaces[section].methods[method].isSubscription)
.keys(interfaces[section].public)
.filter((method) => interfaces[section].public[method].isSubscription)
.map((method) => `subscribe_${method}`);
})
);
@@ -25,7 +25,10 @@ const REQUESTS = {
// flowlint-next-line unclear-type:off
storage[((params[0]: any): string)]
);
}
},
'system_chain': (): string => 'mockChain',
'system_name': (): string => 'mockClient',
'system_version': (): string => '9.8.7'
};
module.exports = function state (): MockState {
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-rx",
"version": "0.12.15",
"version": "0.13.0",
"description": "An RxJs wrapper around the Polkadot JS API",
"main": "index.js",
"keywords": [
@@ -31,8 +31,8 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.47",
"@polkadot/api": "^0.12.15",
"@polkadot/api-provider": "^0.12.15",
"@polkadot/api": "^0.13.0",
"@polkadot/api-provider": "^0.13.0",
"rxjs": "^5.5.10"
}
}
+5 -5
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api",
"version": "0.12.15",
"version": "0.13.0",
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
"main": "index.js",
"keywords": [
@@ -31,10 +31,10 @@
},
"dependencies": {
"@babel/runtime": "^7.0.0-beta.47",
"@polkadot/api-format": "^0.12.15",
"@polkadot/api-provider": "^0.12.15",
"@polkadot/jsonrpc": "^0.16.15",
"@polkadot/params": "^0.16.15",
"@polkadot/api-format": "^0.13.0",
"@polkadot/api-provider": "^0.13.0",
"@polkadot/jsonrpc": "^0.17.2",
"@polkadot/params": "^0.17.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 {
const exposed: $Shape<ApiInterface$Section> = {};
const { methods } = interfaces[section];
const methods = interfaces[section].public;
return Object
.keys(methods)
@@ -22,10 +22,9 @@ module.exports = function createInterface (provider: ProviderInterface, section:
const rpcName = `${section}_${name}`;
const def = methods[name];
// flowlint-next-line sketchy-null-bool:off
exposed[name] = def.isSubscription
? methodSubscribe(provider, rpcName, name, methods[name])
: methodSend(provider, rpcName, name, methods[name]);
? methodSubscribe(provider, rpcName, name, def)
: methodSend(provider, rpcName, name, def);
return exposed;
}, exposed);
+6 -6
View File
@@ -6,20 +6,20 @@ const isFunction = require('@polkadot/util/is/function');
jest.mock('@polkadot/jsonrpc', () => ({
test: {
methods: {
public: {
blah: {
params: {
foo: { type: 'Address' }
},
params: [
{ name: 'foo', type: 'Address' }
],
type: 'Address'
},
bleh: {
params: {},
params: [],
type: 'Address'
},
pubsub: {
isSubscription: true,
params: {},
params: [],
type: 'Address'
}
}
+4 -4
View File
@@ -12,14 +12,14 @@ describe('methodCall', () => {
methods = {
blah: {
name: 'blah',
params: {
foo: { type: 'Bytes' }
},
params: [
{ name: 'foo', type: 'Bytes' }
],
type: 'Bytes'
},
bleh: {
name: 'bleh',
params: {},
params: [],
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 assert = require('@polkadot/util/assert');
module.exports = function createParams (_params: Params, values: Array<mixed>): Array<mixed> {
const params = Object.keys(_params).map((key) => _params[key]);
module.exports = function createParams (params: Params, values: Array<mixed>): Array<mixed> {
const required = params.filter(({ isOptional }) => !isOptional);
const optionalText = params.length
? ` (${(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`);
return formatInputs(_params, values);
return formatInputs(params, values);
};
+6 -6
View File
@@ -10,15 +10,15 @@ describe('params', () => {
beforeEach(() => {
methods = {
blah: {
params: {
foo: { type: 'Bytes' }
},
params: [
{ name: 'foo', type: 'Bytes' }
],
type: 'Bytes'
},
bleh: {
params: {
foo: { type: 'Bytes', isOptional: true }
},
params: [
{ name: 'foo', type: 'Bytes', isOptional: true }
],
type: 'Bytes'
}
};