API Subscriptions (#62)

* Upgrades

* Add getHead & newHead

* Handle pubsub interfaces

* Flow fixes
This commit is contained in:
Jaco Greeff
2018-04-16 09:03:06 +02:00
committed by GitHub
parent 409db09ec1
commit 68edc80e82
16 changed files with 101 additions and 137 deletions
+20
View File
@@ -0,0 +1,20 @@
// 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 getHead
@signature chain_getHead (): HeaderHash
@summary Retrieves the best headerHash.
@description
Return the block hash for the lastest/best.
*/
module.exports = ({
inputs: [],
output: {
type: 'HeaderHash'
}
}: InterfaceMethodDefinition);
+5 -1
View File
@@ -5,13 +5,17 @@
import type { InterfaceDefinition } from '../types';
const getHead = require('./getHead');
const getHeader = require('./getHeader');
const newHead = require('./newHead');
/**
@summary Methods to retrieve chain data.
*/
module.exports = ({
methods: {
getHeader
getHead,
getHeader,
newHead
}
}: InterfaceDefinition);
+21
View File
@@ -0,0 +1,21 @@
// 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 getHead
@signature chain_newHead (): HeaderHash
@summary Retrieves the best headerHash via subscription.
@description
Return the block hash for the lastest/best.
*/
module.exports = ({
isSubscription: true,
inputs: [],
output: {
type: 'HeaderHash'
}
}: InterfaceMethodDefinition);
+8 -2
View File
@@ -7,7 +7,7 @@ export type InterfaceTypes = 'author' | 'chain' | 'extra' | 'state';
export type FormatInputType = 'Bytes' | 'H256' | 'HeaderHash' | 'String';
export type FormatOutputType = 'BlockNumber' | 'Bytes' | 'Header' | 'U64';
export type FormatOutputType = 'BlockNumber' | 'Bytes' | 'Header' | 'HeaderHash' | 'U64';
export type InterfaceInputType = {
name: string,
@@ -18,8 +18,14 @@ export type InterfaceOutputType = {
type: FormatOutputType
};
export type InterfaceMethodDefinition$Subscribe = {
subscribe: string,
unsubscribe: string
}
export type InterfaceMethodDefinition = {
deprecated?: boolean,
isDeprecated?: boolean,
isSubscription?: boolean,
inputs: Array<InterfaceInputType>,
output: InterfaceOutputType
};