From 1c5cd826b03148c28129d72eef93dceb18c4fd1d Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 11 Apr 2018 11:27:46 +0200 Subject: [PATCH 1/3] Package updates --- package.json | 2 +- packages/api-format/package.json | 2 +- packages/api-provider/package.json | 2 +- packages/api/package.json | 2 +- yarn.lock | 23 ++++++++++++++++------- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 0be44507bcab..92d0402657cc 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "test": "jest --coverage" }, "devDependencies": { - "@polkadot/dev": "^0.17.1", + "@polkadot/dev": "^0.17.4", "lerna": "^2.5.1" } } diff --git a/packages/api-format/package.json b/packages/api-format/package.json index e36550d4a4c7..32cffdb40c78 100644 --- a/packages/api-format/package.json +++ b/packages/api-format/package.json @@ -34,7 +34,7 @@ }, "dependencies": { "@polkadot/primitives-json": "^0.9.5", - "@polkadot/util": "^0.17.3", + "@polkadot/util": "^0.18.2", "babel-runtime": "^6.26.0" } } diff --git a/packages/api-provider/package.json b/packages/api-provider/package.json index e0a6facd2569..ae0e47a22a32 100644 --- a/packages/api-provider/package.json +++ b/packages/api-provider/package.json @@ -34,7 +34,7 @@ "nock": "^9.1.0" }, "dependencies": { - "@polkadot/util": "^0.17.3", + "@polkadot/util": "^0.18.2", "babel-runtime": "^6.26.0", "isomorphic-fetch": "^2.2.1", "websocket": "^1.0.25" diff --git a/packages/api/package.json b/packages/api/package.json index b8d0d045bbff..2eb15bddb487 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -33,7 +33,7 @@ "@polkadot/api-format": "^0.8.5", "@polkadot/api-jsonrpc": "^0.8.5", "@polkadot/api-provider": "^0.8.5", - "@polkadot/util": "^0.17.3", + "@polkadot/util": "^0.18.2", "babel-runtime": "^6.26.0" } } diff --git a/yarn.lock b/yarn.lock index 450b6b91054d..a4e65bf8a069 100644 --- a/yarn.lock +++ b/yarn.lock @@ -79,9 +79,9 @@ lodash "^4.2.0" to-fast-properties "^2.0.0" -"@polkadot/dev@^0.17.1": - version "0.17.1" - resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.17.1.tgz#f3b2273b61e37bc0a5b01b3999f2c5ba8f63fdc5" +"@polkadot/dev@^0.17.4": + version "0.17.4" + resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.17.4.tgz#d5bcbbb0a6531ebbce222d946be9ae4a52eea1e4" dependencies: babel-cli "^6.26.0" babel-core "^6.26.0" @@ -106,7 +106,7 @@ eslint-plugin-promise "^3.6.0" eslint-plugin-react "^7.7.0" eslint-plugin-standard "^3.0.1" - flow-bin "^0.68.0" + flow-bin "^0.69.0" flow-copy-source "^1.3.0" jest "^22.4.2" makeshift "^1.1.0" @@ -209,6 +209,15 @@ deasync "^0.1.12" ip-regex "^2.1.0" +"@polkadot/util@^0.18.2": + version "0.18.2" + resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.18.2.tgz#a00fc2c27e63f9ed1b297eb9109db97234677194" + dependencies: + babel-runtime "^6.26.0" + bn.js "^4.11.8" + deasync "^0.1.12" + ip-regex "^2.1.0" + "@types/node@*": version "8.5.2" resolved "https://registry.yarnpkg.com/@types/node/-/node-8.5.2.tgz#83b8103fa9a2c2e83d78f701a9aa7c9539739aa5" @@ -2462,9 +2471,9 @@ flat-cache@^1.2.1: graceful-fs "^4.1.2" write "^0.2.1" -flow-bin@^0.68.0: - version "0.68.0" - resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.68.0.tgz#86c2d14857d306eb2e85e274f2eebf543564f623" +flow-bin@^0.69.0: + version "0.69.0" + resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.69.0.tgz#053159a684a6051fcbf0b71a2eb19a9679082da6" flow-copy-source@^1.3.0: version "1.3.0" From fa1680ae6c75d941028184a81276690087a0aad7 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 11 Apr 2018 14:12:45 +0200 Subject: [PATCH 2/3] Add author_submitExtrinsic --- packages/api-format/src/input.js | 11 ++++----- packages/api-format/src/input.spec.js | 2 +- packages/api-format/src/output.js | 5 ++-- packages/api-jsonrpc/src/author/index.js | 17 ++++++++++++++ .../api-jsonrpc/src/author/submitExtrinsic.js | 23 +++++++++++++++++++ packages/api-jsonrpc/src/chain/getHeader.js | 4 +++- packages/api-jsonrpc/src/index.js | 2 ++ packages/api-jsonrpc/src/state/call.js | 4 ++-- packages/api-jsonrpc/src/state/getStorage.js | 14 ++++------- packages/api-jsonrpc/src/types.js | 8 +++---- packages/api/src/create/method.spec.js | 8 +++---- packages/api/src/index.js | 13 ++++++----- 12 files changed, 74 insertions(+), 37 deletions(-) create mode 100644 packages/api-jsonrpc/src/author/index.js create mode 100644 packages/api-jsonrpc/src/author/submitExtrinsic.js diff --git a/packages/api-format/src/input.js b/packages/api-format/src/input.js index 3c431263ae63..06ebeab4b609 100644 --- a/packages/api-format/src/input.js +++ b/packages/api-format/src/input.js @@ -4,20 +4,17 @@ // @flow import type { InterfaceInputType } from '@polkadot/api-jsonrpc/types'; -import type { Hash } from '@polkadot/primitives/base'; -const accountIdEncode = require('@polkadot/primitives-json/accountId/encode'); +const bytesEncode = require('@polkadot/primitives-json/bytes/encode'); const hashEncode = require('@polkadot/primitives-json/hash/encode'); -const echo = require('./echo'); const util = require('./util'); const formatters = { - 'Address': accountIdEncode, + 'Bytes': bytesEncode, 'CallData': hashEncode, - 'H256': (value: Hash) => hashEncode(value, 256), - 'HeaderHash': hashEncode, - 'String': echo + 'H256': hashEncode, + 'HeaderHash': hashEncode }; module.exports = function formatInputs (inputs: Array, values: Array): Array { diff --git a/packages/api-format/src/input.spec.js b/packages/api-format/src/input.spec.js index 1c4155eb8e90..fc011149fc8d 100644 --- a/packages/api-format/src/input.spec.js +++ b/packages/api-format/src/input.spec.js @@ -9,7 +9,7 @@ describe('formatInputs', () => { expect( formatInputs( [ - { name: 'foo', type: 'Address' }, + { name: 'foo', type: 'Bytes' }, { name: 'bar', type: 'H256' } ], [new Uint8Array([0x12, 0x34]), new Uint8Array([0xab, 0xcd])] diff --git a/packages/api-format/src/output.js b/packages/api-format/src/output.js index 64c8bac5e738..e99997438b3c 100644 --- a/packages/api-format/src/output.js +++ b/packages/api-format/src/output.js @@ -6,16 +6,15 @@ import type { InterfaceOutputType } from '@polkadot/api-jsonrpc/types'; const bnDecode = require('@polkadot/primitives-json/bn/decode'); +const bytesDecode = require('@polkadot/primitives-json/bytes/decode'); const headerDecode = require('@polkadot/primitives-json/header/decode'); -const echo = require('./echo'); const util = require('./util'); const formatters = { 'BlockNumber': bnDecode, + 'Bytes': bytesDecode, 'Header': headerDecode, - 'OutData': echo, - 'StorageData': echo, 'U64': bnDecode }; diff --git a/packages/api-jsonrpc/src/author/index.js b/packages/api-jsonrpc/src/author/index.js new file mode 100644 index 000000000000..d6a08a968a15 --- /dev/null +++ b/packages/api-jsonrpc/src/author/index.js @@ -0,0 +1,17 @@ +// Copyright 2017-2018 Jaco Greeff +// This software may be modified and distributed under the terms +// of the ISC license. See the LICENSE file for details. +// @flow + +import type { InterfaceDefinition } from '../types'; + +const submitExtrinsic = require('./submitExtrinsic'); + +/** + @summary Methods to work with authors. +*/ +module.exports = ({ + methods: { + submitExtrinsic + } +}: InterfaceDefinition); diff --git a/packages/api-jsonrpc/src/author/submitExtrinsic.js b/packages/api-jsonrpc/src/author/submitExtrinsic.js new file mode 100644 index 000000000000..53fcfd7a1a9b --- /dev/null +++ b/packages/api-jsonrpc/src/author/submitExtrinsic.js @@ -0,0 +1,23 @@ +// Copyright 2017-2018 Jaco Greeff +// This software may be modified and distributed under the terms +// of the ISC license. See the LICENSE file for details. +// @flow + +import type { InterfaceMethodDefinition } from '../types'; + +/** + @name submitExtrinsic + @signature author_submitExtrinsic (extrinsic: Bytes): Header + @summary Submit a fully formatted extrinsic for block inclusion. + @description + Given a block header specified by `hash`, return the full block `Header` information. +*/ +module.exports = ({ + inputs: [ + { + name: 'extrinsic', + type: 'Bytes' + } + ], + output: { type: 'Header' } +}: InterfaceMethodDefinition); diff --git a/packages/api-jsonrpc/src/chain/getHeader.js b/packages/api-jsonrpc/src/chain/getHeader.js index 8959eac71538..55546894b8c0 100644 --- a/packages/api-jsonrpc/src/chain/getHeader.js +++ b/packages/api-jsonrpc/src/chain/getHeader.js @@ -19,5 +19,7 @@ module.exports = ({ type: 'HeaderHash' } ], - output: { type: 'Header' } + output: { + type: 'Header' + } }: InterfaceMethodDefinition); diff --git a/packages/api-jsonrpc/src/index.js b/packages/api-jsonrpc/src/index.js index 6d845b04ef5e..ab2b2722d0e3 100644 --- a/packages/api-jsonrpc/src/index.js +++ b/packages/api-jsonrpc/src/index.js @@ -5,6 +5,7 @@ import type { InterfaceDefinitions } from './types'; +const author = require('./author'); const chain = require('./chain'); const extra = require('./extra'); const state = require('./state'); @@ -13,6 +14,7 @@ const state = require('./state'); @summary Exposes the definition for the RPC endpoints for a Polkadot client node */ module.exports = ({ + author, chain, extra, state diff --git a/packages/api-jsonrpc/src/state/call.js b/packages/api-jsonrpc/src/state/call.js index d001033a7539..cc9cdf43a744 100644 --- a/packages/api-jsonrpc/src/state/call.js +++ b/packages/api-jsonrpc/src/state/call.js @@ -7,7 +7,7 @@ import type { InterfaceMethodDefinition } from '../types'; /** @name call - @signature chain_call (address: Address, method: String, data: CallData, block: HeaderHash): OutData + @signature chain_call (address: Address, method: String, data: Bytes, block: HeaderHash): OutData @summary Perform a call to a builtin on the chain. @description Calls a `method` at a specific `address`, passing the encoded `data`. The query is executed at the block specified by `block`. @@ -24,7 +24,7 @@ module.exports = ({ }, { name: 'data', - type: 'CallData' + type: 'Bytes' }, { name: 'block', diff --git a/packages/api-jsonrpc/src/state/getStorage.js b/packages/api-jsonrpc/src/state/getStorage.js index cf1d51a7e7ce..3fcebe81ab9e 100644 --- a/packages/api-jsonrpc/src/state/getStorage.js +++ b/packages/api-jsonrpc/src/state/getStorage.js @@ -7,27 +7,23 @@ import type { InterfaceMethodDefinition } from '../types'; /** @name getStorage - @signature chain_getStorage (address: Address, key: H256, block: HeaderHash): StorageData - @summary Retrieves the storage for an address. + @signature chain_getStorage (key: H256, blockHash: HeaderHash): StorageData + @summary Retrieves the storage for a key at a specific block. @description - Retrieves the storage `key` at a specific `address`, executing the query at a specific `block`. + Retrieves the storage `key` at a specific `blockHash`. */ module.exports = ({ inputs: [ - { - name: 'address', - type: 'Address' - }, { name: 'key', type: 'H256' }, { - name: 'block', + name: 'blockHash', type: 'HeaderHash' } ], output: { - type: 'StorageData' + type: 'Bytes' } }: InterfaceMethodDefinition); diff --git a/packages/api-jsonrpc/src/types.js b/packages/api-jsonrpc/src/types.js index 3a3f2235481b..465d33365952 100644 --- a/packages/api-jsonrpc/src/types.js +++ b/packages/api-jsonrpc/src/types.js @@ -3,9 +3,11 @@ // of the ISC license. See the LICENSE file for details. // @flow -export type FormatInputType = 'Address' | 'CallData' | 'H256' | 'HeaderHash' | 'String'; +export type InterfaceTypes = 'author' | 'chain' | 'extra' | 'state'; -export type FormatOutputType = 'BlockNumber' | 'Header' | 'OutData' | 'StorageData' | 'U64'; +export type FormatInputType = 'Bytes' | 'H256' | 'HeaderHash' | 'String'; + +export type FormatOutputType = 'BlockNumber' | 'Bytes' | 'Header' | 'U64'; export type InterfaceInputType = { name: string, @@ -22,8 +24,6 @@ export type InterfaceMethodDefinition = { output: InterfaceOutputType }; -export type InterfaceTypes = 'chain' | 'extra' | 'state'; - export type InterfaceDefinition$Methods = { [string]: InterfaceMethodDefinition }; diff --git a/packages/api/src/create/method.spec.js b/packages/api/src/create/method.spec.js index f207726085ab..616432695556 100644 --- a/packages/api/src/create/method.spec.js +++ b/packages/api/src/create/method.spec.js @@ -12,13 +12,13 @@ describe('createMethod', () => { methods = { blah: { inputs: [ - { name: 'foo', type: 'Address' } + { name: 'foo', type: 'Bytes' } ], - output: { type: 'Address' } + output: { type: 'Bytes' } }, bleh: { inputs: [], - output: { type: 'Address' } + output: { type: 'Bytes' } } }; @@ -33,7 +33,7 @@ describe('createMethod', () => { const method = createMethod(provider, 'test_blah', methods.blah); return method().catch((error) => { - expect(error.message).toMatch(/test_blah \(foo: Address\): Address/); + expect(error.message).toMatch(/test_blah \(foo: Bytes\): Bytes/); }); }); diff --git a/packages/api/src/index.js b/packages/api/src/index.js index ca25c7b65017..ff5a77a56bd9 100644 --- a/packages/api/src/index.js +++ b/packages/api/src/index.js @@ -7,19 +7,20 @@ import type { InterfaceTypes } from '@polkadot/api-jsonrpc/types'; import type { ProviderInterface } from '@polkadot/api-provider/types'; import type { ApiInterface } from './types'; +const interfaces = require('@polkadot/api-jsonrpc'); const assert = require('@polkadot/util/assert'); const isFunction = require('@polkadot/util/is/function'); const createInterface = require('./create/interface'); -const ALL_INTERFACES: Array = ['chain', 'extra', 'state']; - module.exports = function api (provider: ProviderInterface): ApiInterface { assert(provider && isFunction(provider.send), 'Expected Provider to API create'); - return ALL_INTERFACES.reduce((result, type: InterfaceTypes) => { - result[type] = createInterface(provider, type); + return Object + .keys(interfaces) + .reduce((result, type: InterfaceTypes) => { + result[type] = createInterface(provider, type); - return result; - }, ({}: $Shape)); + return result; + }, ({}: $Shape)); }; From 3fad508171b4de1786267353e1639fe537f3533e Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 11 Apr 2018 14:15:03 +0200 Subject: [PATCH 3/3] Fix types --- packages/api-format/src/input.js | 1 - packages/api-jsonrpc/src/state/call.js | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/api-format/src/input.js b/packages/api-format/src/input.js index 06ebeab4b609..2b1561dee092 100644 --- a/packages/api-format/src/input.js +++ b/packages/api-format/src/input.js @@ -12,7 +12,6 @@ const util = require('./util'); const formatters = { 'Bytes': bytesEncode, - 'CallData': hashEncode, 'H256': hashEncode, 'HeaderHash': hashEncode }; diff --git a/packages/api-jsonrpc/src/state/call.js b/packages/api-jsonrpc/src/state/call.js index cc9cdf43a744..c868d9406a15 100644 --- a/packages/api-jsonrpc/src/state/call.js +++ b/packages/api-jsonrpc/src/state/call.js @@ -14,10 +14,6 @@ import type { InterfaceMethodDefinition } from '../types'; */ module.exports = ({ inputs: [ - { - name: 'address', - type: 'Address' - }, { name: 'method', type: 'String' @@ -32,6 +28,6 @@ module.exports = ({ } ], output: { - type: 'OutData' + type: 'Bytes' } }: InterfaceMethodDefinition);