author_submitExtrinsic (#61)

* Package updates

* Add author_submitExtrinsic

* Fix types
This commit is contained in:
Jaco Greeff
2018-04-11 14:23:16 +02:00
committed by GitHub
parent 6bcffb1232
commit 17cbec7d81
17 changed files with 95 additions and 54 deletions
+1 -1
View File
@@ -10,7 +10,7 @@
"test": "jest --coverage"
},
"devDependencies": {
"@polkadot/dev": "^0.17.1",
"@polkadot/dev": "^0.17.4",
"lerna": "^2.5.1"
}
}
+1 -1
View File
@@ -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"
}
}
+4 -8
View File
@@ -4,20 +4,16 @@
// @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,
'CallData': hashEncode,
'H256': (value: Hash) => hashEncode(value, 256),
'HeaderHash': hashEncode,
'String': echo
'Bytes': bytesEncode,
'H256': hashEncode,
'HeaderHash': hashEncode
};
module.exports = function formatInputs (inputs: Array<InterfaceInputType>, values: Array<mixed>): Array<mixed> {
+1 -1
View File
@@ -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])]
+2 -3
View File
@@ -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
};
+17
View File
@@ -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);
@@ -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);
+3 -1
View File
@@ -19,5 +19,7 @@ module.exports = ({
type: 'HeaderHash'
}
],
output: { type: 'Header' }
output: {
type: 'Header'
}
}: InterfaceMethodDefinition);
+2
View File
@@ -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
+3 -7
View File
@@ -7,24 +7,20 @@ 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`.
*/
module.exports = ({
inputs: [
{
name: 'address',
type: 'Address'
},
{
name: 'method',
type: 'String'
},
{
name: 'data',
type: 'CallData'
type: 'Bytes'
},
{
name: 'block',
@@ -32,6 +28,6 @@ module.exports = ({
}
],
output: {
type: 'OutData'
type: 'Bytes'
}
}: InterfaceMethodDefinition);
+5 -9
View File
@@ -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);
+4 -4
View File
@@ -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
};
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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"
}
}
+4 -4
View File
@@ -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/);
});
});
+7 -6
View File
@@ -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<InterfaceTypes> = ['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<ApiInterface>));
return result;
}, ({}: $Shape<ApiInterface>));
};
+16 -7
View File
@@ -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"