Add chain_getBlock & author_pendingExtrinsics (#132)

* Add chain_getBlock & author_pendingExtrinsics

* Remove sample

* TSLint
This commit is contained in:
Jaco Greeff
2018-08-15 15:34:16 +02:00
committed by GitHub
parent 5756a7a30d
commit a369c8804a
44 changed files with 306 additions and 132 deletions
+2 -2
View File
@@ -37,7 +37,7 @@
"@babel/runtime": "^7.0.0-beta.51", "@babel/runtime": "^7.0.0-beta.51",
"@polkadot/jsonrpc": "^0.28.11", "@polkadot/jsonrpc": "^0.28.11",
"@polkadot/primitives": "^0.28.11", "@polkadot/primitives": "^0.28.11",
"@polkadot/util": "^0.28.1", "@polkadot/util": "^0.28.2",
"@polkadot/util-keyring": "^0.28.1" "@polkadot/util-keyring": "^0.28.2"
} }
} }
+2
View File
@@ -10,6 +10,7 @@ import bnDecode from '@polkadot/primitives/json/bn/decode';
import bytesDecode from '@polkadot/primitives/json/bytes/decode'; import bytesDecode from '@polkadot/primitives/json/bytes/decode';
import hashDecode from '@polkadot/primitives/json/hash/decode'; import hashDecode from '@polkadot/primitives/json/hash/decode';
import headerDecode from '@polkadot/primitives/json/header/decode'; import headerDecode from '@polkadot/primitives/json/header/decode';
import blockDecode from '@polkadot/primitives/json/block/decode';
import isNull from '@polkadot/util/is/null'; import isNull from '@polkadot/util/is/null';
import isUndefined from '@polkadot/util/is/undefined'; import isUndefined from '@polkadot/util/is/undefined';
@@ -22,6 +23,7 @@ const formatters = new Map<Param$Types, FormatterFunction>([
['Bytes', bytesDecode], ['Bytes', bytesDecode],
['Hash', hashDecode], ['Hash', hashDecode],
['Header', headerDecode], ['Header', headerDecode],
['SignedBlock', blockDecode],
['u64', bnDecode] ['u64', bnDecode]
]); ]);
+3 -3
View File
@@ -40,9 +40,9 @@
"dependencies": { "dependencies": {
"@babel/runtime": "^7.0.0-beta.51", "@babel/runtime": "^7.0.0-beta.51",
"@polkadot/storage": "^0.28.11", "@polkadot/storage": "^0.28.11",
"@polkadot/util": "^0.28.1", "@polkadot/util": "^0.28.2",
"@polkadot/util-crypto": "^0.28.1", "@polkadot/util-crypto": "^0.28.2",
"@polkadot/util-keyring": "^0.28.1", "@polkadot/util-keyring": "^0.28.2",
"@types/nock": "^9.1.3", "@types/nock": "^9.1.3",
"eventemitter3": "^2.0.3", "eventemitter3": "^2.0.3",
"isomorphic-fetch": "^2.2.1", "isomorphic-fetch": "^2.2.1",
+42 -13
View File
@@ -38,22 +38,51 @@ describe.skip('e2e', () => {
it('subscribes to storage', (done) => { it('subscribes to storage', (done) => {
api.state api.state
.subscribeStorage([ .subscribeStorage(
[storage.staking.public.freeBalanceOf, '5Ejbye9R8ygByQPrDSasaUid1munedPZUmg4f118HGmtodGp'], [
[storage.staking.public.freeBalanceOf, '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFacT7'] [storage.system.public.accountIndexOf, '5Ejbye9R8ygByQPrDSasaUid1munedPZUmg4f118HGmtodGp'],
], (error, data) => { [storage.staking.public.freeBalanceOf, '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFacT7']
if (error) { ],
return done(error); (error, data) => {
if (error) {
return done(error);
}
expect(data).toHaveLength(2);
expect(data[0].toNumber()).toEqual(0);
expect(data[1].toNumber()).not.toEqual(0);
done();
} }
)
expect(data).toHaveLength(2);
expect(data[0].toNumber()).toEqual(0);
expect(data[1].toNumber()).not.toEqual(0);
done();
})
.then((subscriptionId) => { .then((subscriptionId) => {
console.log('newHead: subscriptionId =', subscriptionId); console.log('newHead: subscriptionId =', subscriptionId);
}); });
}); });
it('retrieves a block by hash', () => {
return api.chain
.getBlock('0x627847bffdf5f3e01ac440d057dec6a37a12a6f329db7ef8367665574b76b5df')
.then((block) => {
expect(block).toBeDefined();
})
.catch((error) => {
console.error(error);
throw error;
});
});
it.skip('retrieves the pending extrinsics', () => {
return api.author
.pendingExtrinsics()
.then((extrinsics) => {
console.error('extrinsics', extrinsics);
})
.catch((error) => {
console.error(error);
throw error;
});
});
}); });
+1 -1
View File
@@ -39,6 +39,6 @@
"@polkadot/api-provider": "^0.28.11", "@polkadot/api-provider": "^0.28.11",
"@polkadot/jsonrpc": "^0.28.11", "@polkadot/jsonrpc": "^0.28.11",
"@polkadot/params": "^0.28.11", "@polkadot/params": "^0.28.11",
"@polkadot/util": "^0.28.1" "@polkadot/util": "^0.28.2"
} }
} }
+1 -1
View File
@@ -18,6 +18,6 @@
"@babel/runtime": "^7.0.0-beta.51", "@babel/runtime": "^7.0.0-beta.51",
"@polkadot/params": "^0.28.11", "@polkadot/params": "^0.28.11",
"@polkadot/primitives": "^0.28.11", "@polkadot/primitives": "^0.28.11",
"@polkadot/util": "^0.28.1" "@polkadot/util": "^0.28.2"
} }
} }
+1 -1
View File
@@ -32,7 +32,7 @@ const setStorage: CreateItemOptions = {
type: [] type: []
}; };
export default (name: Extrinsic$Sections, index: number): Section<Extrinsics> => export default (name: Extrinsic$Sections, index: number): Section<Extrinsics, any, any> =>
createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({ createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({
description: 'Consensus', description: 'Consensus',
public: { public: {
+1 -1
View File
@@ -86,7 +86,7 @@ const setTermDuration: CreateItemOptions = {
type: [] type: []
}; };
export default (name: Extrinsic$Sections, index: number): Section<Extrinsics> => export default (name: Extrinsic$Sections, index: number): Section<Extrinsics, any, any> =>
createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({ createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({
description: 'Council', description: 'Council',
public: { public: {
@@ -49,7 +49,7 @@ const setVotingPeriod: CreateItemOptions = {
type: [] type: []
}; };
export default (name: Extrinsic$Sections, index: number): Section<Extrinsics> => export default (name: Extrinsic$Sections, index: number): Section<Extrinsics, any, any> =>
createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({ createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({
description: 'Council Voting', description: 'Council Voting',
public: { public: {
+1 -1
View File
@@ -51,7 +51,7 @@ const cancelReferendum: CreateItemOptions = {
type: [] type: []
}; };
export default (name: Extrinsic$Sections, index: number): Section<Extrinsics> => export default (name: Extrinsic$Sections, index: number): Section<Extrinsics, any, any> =>
createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({ createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({
description: 'Democracy', description: 'Democracy',
public: { public: {
+1 -1
View File
@@ -35,7 +35,7 @@ const setHeads: CreateItemOptions = {
type: [] type: []
}; };
export default (name: Extrinsic$Sections, index: number): Section<Extrinsics> => export default (name: Extrinsic$Sections, index: number): Section<Extrinsics, any, any> =>
createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({ createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({
description: 'Parchains', description: 'Parchains',
public: { public: {
+1 -1
View File
@@ -30,7 +30,7 @@ const forceNewSession: CreateItemOptions = {
type: [] type: []
}; };
export default (name: Extrinsic$Sections, index: number): Section<Extrinsics> => export default (name: Extrinsic$Sections, index: number): Section<Extrinsics, any, any> =>
createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({ createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({
description: 'Session', description: 'Session',
public: { public: {
+1 -1
View File
@@ -77,7 +77,7 @@ const forceNewEra: CreateItemOptions = {
type: [] type: []
}; };
export default (name: Extrinsic$Sections, index: number): Section<Extrinsics> => export default (name: Extrinsic$Sections, index: number): Section<Extrinsics, any, any> =>
createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({ createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({
description: 'Staking', description: 'Staking',
public: { public: {
+1 -1
View File
@@ -17,7 +17,7 @@ const set: CreateItemOptions = {
type: [] type: []
}; };
export default (name: Extrinsic$Sections, index: number): Section<Extrinsics> => export default (name: Extrinsic$Sections, index: number): Section<Extrinsics, any, any> =>
createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({ createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({
description: 'Timestamp', description: 'Timestamp',
public: { public: {
+1 -1
View File
@@ -7,7 +7,7 @@ import { Extrinsics, Extrinsic$Sections } from './types';
import createSection from '@polkadot/params/section'; import createSection from '@polkadot/params/section';
export default (name: Extrinsic$Sections, index: number): Section<Extrinsics> => export default (name: Extrinsic$Sections, index: number): Section<Extrinsics, any, any> =>
createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({ createSection(name, index)((createMethod: CreateItems<Extrinsics>) => ({
description: 'Timestamp' description: 'Timestamp'
})); }));
+9 -9
View File
@@ -6,16 +6,16 @@ import { Section } from '@polkadot/params/types';
export type Extrinsics = { export type Extrinsics = {
// substrate // substrate
consensus: Section<Extrinsics>, consensus: Section<Extrinsics, any, any>,
council: Section<Extrinsics>, council: Section<Extrinsics, any, any>,
councilVoting: Section<Extrinsics>, councilVoting: Section<Extrinsics, any, any>,
democracy: Section<Extrinsics>, democracy: Section<Extrinsics, any, any>,
session: Section<Extrinsics>, session: Section<Extrinsics, any, any>,
staking: Section<Extrinsics>, staking: Section<Extrinsics, any, any>,
timestamp: Section<Extrinsics>, timestamp: Section<Extrinsics, any, any>,
treasury: Section<Extrinsics>, treasury: Section<Extrinsics, any, any>,
// polkadot // polkadot
parachains: Section<Extrinsics> parachains: Section<Extrinsics, any, any>
}; };
export type Extrinsic$Sections = keyof Extrinsics; export type Extrinsic$Sections = keyof Extrinsics;
+22 -6
View File
@@ -2,12 +2,18 @@
// This software may be modified and distributed under the terms // This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details. // of the ISC license. See the LICENSE file for details.
import { CreateItems, CreateItemOptions, Section } from '@polkadot/params/types'; import { CreateItems, CreateItemOptions, CreateItemOptionsMap, Section, SectionItems } from '@polkadot/params/types';
import { Interfaces, Interface$Sections } from './types'; import { Interfaces, Interface$Sections } from './types';
import param from '@polkadot/params/param'; import param from '@polkadot/params/param';
import createSection from '@polkadot/params/section'; import createSection from '@polkadot/params/section';
const pendingExtrinsics: CreateItemOptions = {
description: 'Returns all pending extrinsics, potentially grouped by sender',
params: [],
type: 'PrendingExtrinsics'
};
const submitExtrinsic: CreateItemOptions = { const submitExtrinsic: CreateItemOptions = {
isSigned: true, isSigned: true,
description: 'Submit a fully formatted extrinsic for block inclusion', description: 'Submit a fully formatted extrinsic for block inclusion',
@@ -17,14 +23,24 @@ const submitExtrinsic: CreateItemOptions = {
type: 'Hash' type: 'Hash'
}; };
const privateMethods: CreateItemOptionsMap = {};
const publicMethods: CreateItemOptionsMap = {
pendingExtrinsics, submitExtrinsic
};
export type PrivateMethods = typeof privateMethods;
export type PublicMethods = typeof publicMethods;
/** /**
* @summary Methods to work with authors & contributors. * @summary Methods to work with authors & contributors.
*/ */
export default (name: Interface$Sections): Section<Interfaces> => export default (name: Interface$Sections): Section<Interfaces, PrivateMethods, PublicMethods> =>
createSection(name)((createMethod: CreateItems<Interfaces>) => ({ createSection(name)((createMethod: CreateItems<Interfaces>) => ({
description: 'Authoring of network items', description: 'Authoring of network items',
public: { public: Object.keys(publicMethods).reduce((result, key) => {
submitExtrinsic: result[key] = createMethod(key)(publicMethods[key]);
createMethod('submitExtrinsic')(submitExtrinsic)
} return result;
}, {} as SectionItems<Interfaces, PublicMethods>)
})); }));
+24 -10
View File
@@ -2,12 +2,20 @@
// This software may be modified and distributed under the terms // This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details. // of the ISC license. See the LICENSE file for details.
import { CreateItems, CreateItemOptions, Section } from '@polkadot/params/types'; import { CreateItems, CreateItemOptions, CreateItemOptionsMap, Section, SectionItems } from '@polkadot/params/types';
import { Interfaces, Interface$Sections } from './types'; import { Interfaces, Interface$Sections } from './types';
import param from '@polkadot/params/param'; import param from '@polkadot/params/param';
import createSection from '@polkadot/params/section'; import createSection from '@polkadot/params/section';
const getBlock: CreateItemOptions = {
description: 'Get header and body of a relay chain block',
params: [
param('hash', 'Hash')
],
type: 'SignedBlock'
};
const getHead: CreateItemOptions = { const getHead: CreateItemOptions = {
description: 'Retrieves the best headerHash', description: 'Retrieves the best headerHash',
params: [], params: [],
@@ -29,18 +37,24 @@ const subscribeNewHead: CreateItemOptions = {
type: 'Header' type: 'Header'
}; };
const privateMethods: CreateItemOptionsMap = {};
const publicMethods: CreateItemOptionsMap = {
getBlock, getHead, getHeader, subscribeNewHead
};
export type PublicMethods = typeof publicMethods;
export type PrivateMethods = typeof privateMethods;
/** /**
* @summary Methods to retrieve chain data. * @summary Methods to retrieve chain data.
*/ */
export default (name: Interface$Sections): Section<Interfaces> => export default (name: Interface$Sections): Section<Interfaces, PrivateMethods, PublicMethods> =>
createSection(name)((createMethod: CreateItems<Interfaces>) => ({ createSection(name)((createMethod: CreateItems<Interfaces>) => ({
description: 'Retrieval of chain data', description: 'Retrieval of chain data',
public: { public: Object.keys(publicMethods).reduce((result, key) => {
getHead: result[key] = createMethod(key)(publicMethods[key]);
createMethod('getHead')(getHead),
getHeader: return result;
createMethod('getHeader')(getHeader), }, {} as SectionItems<Interfaces, PublicMethods>)
subscribeNewHead:
createMethod('subscribeNewHead')(subscribeNewHead)
}
})); }));
+11 -2
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms // This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details. // of the ISC license. See the LICENSE file for details.
import { CreateItems, CreateItemOptions, Section } from '@polkadot/params/types'; import { CreateItems, CreateItemOptions, CreateItemOptionsMap, Section } from '@polkadot/params/types';
import { Interfaces, Interface$Sections } from './types'; import { Interfaces, Interface$Sections } from './types';
import param from '@polkadot/params/param'; import param from '@polkadot/params/param';
@@ -87,10 +87,19 @@ const subscribeStorage: CreateItemOptions = {
type: 'StorageResultSet' type: 'StorageResultSet'
}; };
const privateMethods: CreateItemOptionsMap = {};
const publicMethods: CreateItemOptionsMap = {
call, callAt, getStorage, getStorageAt, getStorageHash, getStorageHashAt, getStorageSize, getStorageSizeAt, subscribeStorage
};
export type PrivateMethods = typeof privateMethods;
export type PublicMethods = typeof publicMethods;
/** /**
* @summary Query the state and state storage. * @summary Query the state and state storage.
*/ */
export default (name: Interface$Sections): Section<Interfaces> => export default (name: Interface$Sections): Section<Interfaces, PrivateMethods, PublicMethods> =>
createSection(name)((createMethod: CreateItems<Interfaces>) => ({ createSection(name)((createMethod: CreateItems<Interfaces>) => ({
description: 'Query of state', description: 'Query of state',
public: { public: {
+11 -2
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms // This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details. // of the ISC license. See the LICENSE file for details.
import { CreateItems, CreateItemOptions, Section } from '@polkadot/params/types'; import { CreateItems, CreateItemOptions, CreateItemOptionsMap, Section } from '@polkadot/params/types';
import { Interfaces, Interface$Sections } from './types'; import { Interfaces, Interface$Sections } from './types';
import createSection from '@polkadot/params/section'; import createSection from '@polkadot/params/section';
@@ -25,10 +25,19 @@ const version: CreateItemOptions = {
type: 'String' type: 'String'
}; };
const privateMethods: CreateItemOptionsMap = {};
const publicMethods: CreateItemOptionsMap = {
chain, name, version
};
export type PrivateMethods = typeof privateMethods;
export type PublicMethods = typeof publicMethods;
/** /**
* @summary Methods to retrieve system info. * @summary Methods to retrieve system info.
*/ */
export default (sname: Interface$Sections): Section<Interfaces> => export default (sname: Interface$Sections): Section<Interfaces, PrivateMethods, PublicMethods> =>
createSection(sname)((createMethod: CreateItems<Interfaces>) => ({ createSection(sname)((createMethod: CreateItems<Interfaces>) => ({
description: 'Methods to retrieve system info', description: 'Methods to retrieve system info',
public: { public: {
+8 -4
View File
@@ -3,12 +3,16 @@
// of the ISC license. See the LICENSE file for details. // of the ISC license. See the LICENSE file for details.
import { Section } from '@polkadot/params/types'; import { Section } from '@polkadot/params/types';
import { PrivateMethods as AuthorPrivate, PublicMethods as AuthorPublic} from './author';
import { PrivateMethods as ChainPrivate, PublicMethods as ChainPublic} from './chain';
import { PrivateMethods as StatePrivate, PublicMethods as StatePublic} from './state';
import { PrivateMethods as SystemPrivate, PublicMethods as SystemPublic} from './system';
export type Interfaces = { export type Interfaces = {
author: Section<Interfaces>, author: Section<Interfaces, AuthorPrivate, AuthorPrivate>,
chain: Section<Interfaces>, chain: Section<Interfaces, ChainPrivate, ChainPublic>,
state: Section<Interfaces>, state: Section<Interfaces, StatePrivate, StatePublic>,
system:Section<Interfaces> system: Section<Interfaces, SystemPrivate, SystemPublic>
} }
export type Interface$Sections = keyof Interfaces; export type Interface$Sections = keyof Interfaces;
+2 -2
View File
@@ -37,7 +37,7 @@
"@polkadot/extrinsics": "^0.28.11", "@polkadot/extrinsics": "^0.28.11",
"@polkadot/params": "^0.28.11", "@polkadot/params": "^0.28.11",
"@polkadot/primitives": "^0.28.11", "@polkadot/primitives": "^0.28.11",
"@polkadot/util": "^0.28.1", "@polkadot/util": "^0.28.2",
"@polkadot/util-keyring": "^0.28.1" "@polkadot/util-keyring": "^0.28.2"
} }
} }
@@ -24,7 +24,7 @@ export default function call (decode: Decoder, input: Uint8Array | null | undefi
} as Param$Decoded; } as Param$Decoded;
} }
const section: Section<Extrinsics> | undefined = Object.values(extrinsics).find(({ index }) => const section: Section<Extrinsics, any, any> | undefined = Object.values(extrinsics).find(({ index }) =>
index[0] === input[0] index[0] === input[0]
); );
+2 -2
View File
@@ -8,9 +8,9 @@ import bnToU8a from '@polkadot/util/bn/toU8a';
import createMethod from './method'; import createMethod from './method';
export default function createSection <T> (name: keyof T, _index: number = 0): CreateSection<T> { export default function createSection <T> (name: keyof T, _index: number = 0): CreateSection<T, any, any> {
const index = bnToU8a(_index, 8, true); const index = bnToU8a(_index, 8, true);
const creator = (optOrFn: CreateSectionOptions<T>): Section<T> => { const creator = (optOrFn: CreateSectionOptions<T, any, any>): Section<T, any, any> => {
if (typeof optOrFn === 'function') { if (typeof optOrFn === 'function') {
return creator( return creator(
optOrFn( optOrFn(
+31 -13
View File
@@ -14,7 +14,7 @@ export type EncodingVersions = 'poc-1' | 'latest';
// - @polkadot/storage/key/params.ts // - @polkadot/storage/key/params.ts
// - decode/value/index.js // - decode/value/index.js
// - encode/type/index.js // - encode/type/index.js
export type Param$Type = 'AccountId' | 'AccountIndex' | 'Balance' | 'BlockNumber' | 'bool' | 'Bytes' | 'Call' | 'CandidateReceipt' | 'Code' | 'Digest' | 'Gas' | 'Hash' | 'Header' | 'KeyValue' | 'MisbehaviorReport' | 'ParachainId' | 'PropIndex' | 'Proposal' | 'ReferendumIndex' | 'SessionKey' | 'Signature' | 'StorageKey' | 'StorageKeyValue' | 'StorageResult' | 'StorageResultSet' | 'String' | 'Timestamp' | 'u32' | 'u64' | 'u128' | 'VoteIndex' | 'VoteThreshold'; export type Param$Type = 'AccountId' | 'AccountIndex' | 'Balance' | 'BlockNumber' | 'bool' | 'Bytes' | 'Call' | 'CandidateReceipt' | 'Code' | 'Digest' | 'Gas' | 'Hash' | 'Header' | 'KeyValue' | 'MisbehaviorReport' | 'ParachainId' | 'PrendingExtrinsics' | 'PropIndex' | 'Proposal' | 'ReferendumIndex' | 'SessionKey' | 'Signature' | 'SignedBlock' | 'StorageKey' | 'StorageKeyValue' | 'StorageResult' | 'StorageResultSet' | 'String' | 'Timestamp' | 'u32' | 'u64' | 'u128' | 'VoteIndex' | 'VoteThreshold';
export type Param$Type$Array = Array<Param$Type | Array<Param$Type | Array<Param$Type>>>; export type Param$Type$Array = Array<Param$Type | Array<Param$Type | Array<Param$Type>>>;
@@ -25,6 +25,20 @@ export type ExtrinsicDecoded = {
params: Array<any> params: Array<any>
} }
export type BlockExtrinsicDecoded = {
address: string,
nonce: BN,
extrinsic: SectionItem<Extrinsics>,
params: Array<any>,
signature: Uint8Array
}
export type BlockDecoded = {
header: Header,
extrinsics: Array<BlockExtrinsicDecoded>,
justification: any
};
export type KeyValue = { export type KeyValue = {
key: Uint8Array, key: Uint8Array,
value: Uint8Array value: Uint8Array
@@ -68,21 +82,21 @@ export type SectionItem<T> = {
type: Param$Types type: Param$Types
}; };
export type SectionItems<T> = { export type SectionItems<T, K> = {
[index: string]: SectionItem<T> [key in keyof K]: SectionItem<T>
}; };
export type Section<T> = { export type Section<T, Priv, Pub> = {
isDeprecated: boolean, isDeprecated: boolean,
isHidden: boolean, isHidden: boolean,
description: string, description: string,
index: Uint8Array, index: Uint8Array,
name: keyof T, name: keyof T,
private: SectionItems<T>, private: SectionItems<T, Priv>,
public: SectionItems<T> public: SectionItems<T, Pub>
}; };
export type Sections<T> = Map<T, Section<T>>; export type Sections<T, Priv, Pub> = Map<T, Section<T, Priv, Pub>>;
export type CreateItemOptions = { export type CreateItemOptions = {
description: string, description: string,
@@ -96,20 +110,24 @@ export type CreateItemOptions = {
type: Param$Types type: Param$Types
}; };
export type CreateItemOptionsMap = {
[index: string]: CreateItemOptions
};
export type CreateItem<T> = (options: CreateItemOptions) => SectionItem<T>; export type CreateItem<T> = (options: CreateItemOptions) => SectionItem<T>;
export type CreateItems<T> = (name: string, index?: number) => CreateItem<T>; export type CreateItems<T> = (name: string, index?: number) => CreateItem<T>;
export type CreateSectionOptions$Only<T> = { export type CreateSectionOptions$Only<T, Priv, Pub> = {
description: string, description: string,
isDeprecated?: boolean, isDeprecated?: boolean,
isHidden?: boolean, isHidden?: boolean,
'private'?: SectionItems<T>, 'private'?: SectionItems<T, Priv>,
'public'?: SectionItems<T> 'public'?: SectionItems<T, Pub>
}; };
export type CreateSectionOptions$Fn<T> = (method: CreateItems<T>) => CreateSectionOptions$Only<T>; export type CreateSectionOptions$Fn<T, Priv, Pub> = (method: CreateItems<T>) => CreateSectionOptions$Only<T, Priv, Pub>;
export type CreateSectionOptions<T> = CreateSectionOptions$Only<T> | CreateSectionOptions$Fn<T>; export type CreateSectionOptions<T, Priv, Pub> = CreateSectionOptions$Only<T, Priv, Pub> | CreateSectionOptions$Fn<T, Priv, Pub>;
export type CreateSection<T> = (options: CreateSectionOptions<T>) => Section<T>; export type CreateSection<T, Priv, Pub> = (options: CreateSectionOptions<T, Priv, Pub>) => Section<T, Priv, Pub>;
+2 -2
View File
@@ -34,8 +34,8 @@
}, },
"dependencies": { "dependencies": {
"@babel/runtime": "^7.0.0-beta.51", "@babel/runtime": "^7.0.0-beta.51",
"@polkadot/trie-hash": "^0.28.1", "@polkadot/trie-hash": "^0.28.2",
"@polkadot/util": "^0.28.1" "@polkadot/util": "^0.28.2"
}, },
"devDependencies": { "devDependencies": {
"bn.js": "^4.11.8" "bn.js": "^4.11.8"
@@ -0,0 +1,18 @@
// Copyright 2017-2018 @polkadot/primitives authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { Block } from '../../block';
import createBlock from '../../create/block';
import decodeHeader from '../header/decode';
import decodeRaw from './decodeRaw';
export default function decodeBlock (u8a: Uint8Array): Block {
const { header, extrinsics } = decodeRaw(u8a);
return createBlock({
header: decodeHeader(header),
extrinsics
});
}
@@ -0,0 +1,24 @@
// Copyright 2017-2018 @polkadot/primitives authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { BlockDecoded } from '@polkadot/params/types';
import { JsonBlock } from '../types';
import toU8a from '@polkadot/util/u8a/toU8a';
import decodeExtrinsic from '../extrinsic/decode';
import decodeHeader from '../header/decode';
export default function blockDecode ({ block: { extrinsics, header }, justification }: JsonBlock): BlockDecoded {
return {
// TODO We should decode the justifications (and change type from any)
justification,
header: decodeHeader(header),
extrinsics: extrinsics.map((extrinsic) =>
decodeExtrinsic(
toU8a(extrinsic as any)
)
)
};
}
@@ -0,0 +1,22 @@
// Copyright 2017-2018 @polkadot/primitives authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { BlockExtrinsicDecoded, ExtrinsicDecoded } from '@polkadot/params/types';
import BN from 'bn.js';
import decoder from '@polkadot/params/decode';
export default function extrinsicDecode (extrinsic: Uint8Array): BlockExtrinsicDecoded {
const addressDecoded = decoder('AccountId', extrinsic, 'latest');
const nonceDecoded = decoder('AccountIndex', extrinsic.subarray(addressDecoded.length), 'latest');
const extrinsicDecoded = decoder('Call', extrinsic.subarray(addressDecoded.length + nonceDecoded.length), 'latest');
const signature = extrinsic.subarray(addressDecoded.length + nonceDecoded.length + extrinsicDecoded.length);
return {
...(extrinsicDecoded.value as ExtrinsicDecoded),
address: addressDecoded.value as string,
nonce: nonceDecoded.value as BN,
signature
};
}
@@ -6,7 +6,10 @@ import { Hash } from '../../base';
import { JsonHash } from '../types'; import { JsonHash } from '../types';
import u8aToHex from '@polkadot/util/u8a/toHex'; import u8aToHex from '@polkadot/util/u8a/toHex';
import toU8a from '@polkadot/util/u8a/toU8a';
export default function hashEncode (value: Hash, bitLength: number = -1): JsonHash { export default function hashEncode (value: Hash | string, bitLength: number = -1): JsonHash {
return u8aToHex(value); return u8aToHex(
toU8a(value)
);
} }
+9 -3
View File
@@ -2,6 +2,8 @@
// This software may be modified and distributed under the terms // This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details. // of the ISC license. See the LICENSE file for details.
import { ExtrinsicDecoded } from '@polkadot/params/types';
export type JsonBnType = string; export type JsonBnType = string;
export type JsonHash = string; export type JsonHash = string;
@@ -44,8 +46,12 @@ export type JsonHeader = {
digest: JsonDigest digest: JsonDigest
}; };
export type JsonJustification = {};
export type JsonBlock = { export type JsonBlock = {
header: JsonHeader, block: {
timestamp: JsonU64, extrinsics: Array<Array<JsonBytes>>,
transactions: Array<JsonUnchecked> header: JsonHeader,
},
justification: JsonJustification
}; };
+3 -3
View File
@@ -37,8 +37,8 @@
"@babel/runtime": "^7.0.0-beta.51", "@babel/runtime": "^7.0.0-beta.51",
"@polkadot/params": "^0.28.11", "@polkadot/params": "^0.28.11",
"@polkadot/primitives": "^0.28.11", "@polkadot/primitives": "^0.28.11",
"@polkadot/util": "^0.28.1", "@polkadot/util": "^0.28.2",
"@polkadot/util-crypto": "^0.28.1", "@polkadot/util-crypto": "^0.28.2",
"@polkadot/util-keyring": "^0.28.1" "@polkadot/util-keyring": "^0.28.2"
} }
} }
+1 -1
View File
@@ -34,7 +34,7 @@ const code: CreateItemOptions = {
type: 'Code' type: 'Code'
}; };
export default (name: Storage$Sections): Section<Storages> => export default (name: Storage$Sections): Section<Storages, any, any> =>
createSection(name)((createMethod: CreateItems<Storages>) => ({ createSection(name)((createMethod: CreateItems<Storages>) => ({
description: 'Consensus', description: 'Consensus',
public: { public: {
+1 -1
View File
@@ -52,7 +52,7 @@ const codeOf: CreateItemOptions = {
type: 'Code' type: 'Code'
}; };
export default (name: Storage$Sections): Section<Storages> => export default (name: Storage$Sections): Section<Storages, any, any> =>
createSection(name)((createMethod: CreateItems<Storages>) => ({ createSection(name)((createMethod: CreateItems<Storages>) => ({
description: 'Contract', description: 'Contract',
public: { public: {
+1 -1
View File
@@ -154,7 +154,7 @@ const leaderboard: CreateItemOptions = {
type: [['Balance', 'AccountId']] type: [['Balance', 'AccountId']]
}; };
export default (name: keyof Storages): Section<Storages> => export default (name: keyof Storages): Section<Storages, any, any> =>
createSection(name)((createMethod: CreateItems<Storages>) => ({ createSection(name)((createMethod: CreateItems<Storages>) => ({
description: 'Council', description: 'Council',
public: { public: {
+1 -1
View File
@@ -66,7 +66,7 @@ const vetoedProposal: CreateItemOptions = {
type: ['BlockNumber', 'AccountId'] type: ['BlockNumber', 'AccountId']
}; };
export default (name: Storage$Sections): Section<Storages> => export default (name: Storage$Sections): Section<Storages, any, any> =>
createSection(name)((createMethod: CreateItems<Storages>) => ({ createSection(name)((createMethod: CreateItems<Storages>) => ({
description: 'Council voting', description: 'Council voting',
public: { public: {
+1 -1
View File
@@ -94,7 +94,7 @@ const voteOf: CreateItemOptions = {
type: 'bool' type: 'bool'
}; };
export default (name: Storage$Sections): Section<Storages> => export default (name: Storage$Sections): Section<Storages, any, any> =>
createSection(name)((createMethod: CreateItems<Storages>) => ({ createSection(name)((createMethod: CreateItems<Storages>) => ({
description: 'Democracy', description: 'Democracy',
public: { public: {
+1 -1
View File
@@ -40,7 +40,7 @@ const didUpdate: CreateItemOptions = {
type: 'bool' type: 'bool'
}; };
export default (name: Storage$Sections): Section<Storages> => export default (name: Storage$Sections): Section<Storages, any, any> =>
createSection(name)((createMethod: CreateItems<Storages>) => ({ createSection(name)((createMethod: CreateItems<Storages>) => ({
description: 'Parachain related entries', description: 'Parachain related entries',
public: { public: {
+1 -1
View File
@@ -73,7 +73,7 @@ const nextLength: CreateItemOptions = {
type: 'BlockNumber' type: 'BlockNumber'
}; };
export default (name: Storage$Sections): Section<Storages> => export default (name: Storage$Sections): Section<Storages, any, any> =>
createSection(name)((createMethod: CreateItems<Storages>) => ({ createSection(name)((createMethod: CreateItems<Storages>) => ({
description: 'Session management information', description: 'Session management information',
public: { public: {
+1 -1
View File
@@ -197,7 +197,7 @@ const bondageOf: CreateItemOptions = {
type: 'Balance' type: 'Balance'
}; };
export default (name: Storage$Sections): Section<Storages> => export default (name: Storage$Sections): Section<Storages, any, any> =>
createSection(name)((createMethod: CreateItems<Storages>) => ({ createSection(name)((createMethod: CreateItems<Storages>) => ({
description: 'Staking', description: 'Staking',
public: { public: {
+1 -1
View File
@@ -70,7 +70,7 @@ const digest: CreateItemOptions = {
type: 'Digest' type: 'Digest'
}; };
export default (name: Storage$Sections): Section<Storages> => export default (name: Storage$Sections): Section<Storages, any, any> =>
createSection(name)((createMethod: CreateItems<Storages>) => ({ createSection(name)((createMethod: CreateItems<Storages>) => ({
description: 'System', description: 'System',
public: { public: {
+1 -1
View File
@@ -28,7 +28,7 @@ const didUpdate: CreateItemOptions = {
type: 'bool' type: 'bool'
}; };
export default (name: Storage$Sections): Section<Storages> => export default (name: Storage$Sections): Section<Storages, any, any> =>
createSection(name)((createMethod: CreateItems<Storages>) => ({ createSection(name)((createMethod: CreateItems<Storages>) => ({
description: 'Timestamp related entries', description: 'Timestamp related entries',
public: { public: {
+10 -10
View File
@@ -8,16 +8,16 @@ import { Section } from '@polkadot/params/types';
export type Storage$Key$Value = number | BN | Uint8Array | string; export type Storage$Key$Value = number | BN | Uint8Array | string;
export type Storages = { export type Storages = {
consensus: Section<Storages>, consensus: Section<Storages, any, any>,
// contract: Section<Storages>, // contract: Section<Storages, any, any>,
council: Section<Storages>, council: Section<Storages, any, any>,
councilVoting: Section<Storages>, councilVoting: Section<Storages, any, any>,
democracy: Section<Storages>, democracy: Section<Storages, any, any>,
parachains: Section<Storages>, parachains: Section<Storages, any, any>,
session: Section<Storages>, session: Section<Storages, any, any>,
staking: Section<Storages>, staking: Section<Storages, any, any>,
system: Section<Storages>, system: Section<Storages, any, any>,
timestamp: Section<Storages> timestamp: Section<Storages, any, any>
}; };
export type Storage$Sections = keyof Storages; export type Storage$Sections = keyof Storages;
+22 -22
View File
@@ -734,50 +734,50 @@
typedoc "^0.11.1" typedoc "^0.11.1"
typescript "^2.9.2" typescript "^2.9.2"
"@polkadot/trie-hash@^0.28.1": "@polkadot/trie-hash@^0.28.2":
version "0.28.1" version "0.28.2"
resolved "https://registry.yarnpkg.com/@polkadot/trie-hash/-/trie-hash-0.28.1.tgz#8e220bd2280813818d6d90e4d7d826edfb0d407d" resolved "https://registry.yarnpkg.com/@polkadot/trie-hash/-/trie-hash-0.28.2.tgz#89eb0bca267a5a576bf1629a1d9b173f4ab02c50"
dependencies: dependencies:
"@babel/runtime" "^7.0.0-beta.51" "@babel/runtime" "^7.0.0-beta.51"
"@polkadot/util" "^0.28.1" "@polkadot/util" "^0.28.2"
"@polkadot/util-crypto" "^0.28.1" "@polkadot/util-crypto" "^0.28.2"
"@polkadot/util-rlp" "^0.28.1" "@polkadot/util-rlp" "^0.28.2"
"@polkadot/ts@^0.1.10": "@polkadot/ts@^0.1.10":
version "0.1.10" version "0.1.10"
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.10.tgz#784d460cf4b2e9b38bb1c77f9366dd01425f220d" resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.10.tgz#784d460cf4b2e9b38bb1c77f9366dd01425f220d"
"@polkadot/util-crypto@^0.28.1": "@polkadot/util-crypto@^0.28.2":
version "0.28.1" version "0.28.2"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.28.1.tgz#07bef16d5b68889f96ff9b9c034b92e22bd6f63d" resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.28.2.tgz#17bf06af6e3e57c9c6541ee4a166011dfda18434"
dependencies: dependencies:
"@babel/runtime" "^7.0.0-beta.51" "@babel/runtime" "^7.0.0-beta.51"
"@polkadot/util" "^0.28.1" "@polkadot/util" "^0.28.2"
blakejs "^1.1.0" blakejs "^1.1.0"
js-sha3 "^0.7.0" js-sha3 "^0.7.0"
tweetnacl "^1.0.0" tweetnacl "^1.0.0"
xxhashjs "^0.2.2" xxhashjs "^0.2.2"
"@polkadot/util-keyring@^0.28.1": "@polkadot/util-keyring@^0.28.2":
version "0.28.1" version "0.28.2"
resolved "https://registry.yarnpkg.com/@polkadot/util-keyring/-/util-keyring-0.28.1.tgz#68fac78bc7154226d7e6d06acfcfaebc6232814c" resolved "https://registry.yarnpkg.com/@polkadot/util-keyring/-/util-keyring-0.28.2.tgz#a391e785a0710518be349f0ca2d688c89879a69d"
dependencies: dependencies:
"@babel/runtime" "^7.0.0-beta.51" "@babel/runtime" "^7.0.0-beta.51"
"@polkadot/util" "^0.28.1" "@polkadot/util" "^0.28.2"
"@polkadot/util-crypto" "^0.28.1" "@polkadot/util-crypto" "^0.28.2"
"@types/bs58" "^3.0.30" "@types/bs58" "^3.0.30"
bs58 "^4.0.1" bs58 "^4.0.1"
"@polkadot/util-rlp@^0.28.1": "@polkadot/util-rlp@^0.28.2":
version "0.28.1" version "0.28.2"
resolved "https://registry.yarnpkg.com/@polkadot/util-rlp/-/util-rlp-0.28.1.tgz#101cecbb30223fc3b66bd3448371eb5404d46ac6" resolved "https://registry.yarnpkg.com/@polkadot/util-rlp/-/util-rlp-0.28.2.tgz#21c326cdca437b1b31a44bbbf26bf9adcac4fb7f"
dependencies: dependencies:
"@babel/runtime" "^7.0.0-beta.51" "@babel/runtime" "^7.0.0-beta.51"
"@polkadot/util" "^0.28.1" "@polkadot/util" "^0.28.2"
"@polkadot/util@^0.28.1": "@polkadot/util@^0.28.2":
version "0.28.1" version "0.28.2"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.28.1.tgz#7c566cc46741c422d93f535fbd27db4e6eff5f80" resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.28.2.tgz#59fb5a0f3f34d73520a5e0ac54f55ccfde94a8b5"
dependencies: dependencies:
"@babel/runtime" "^7.0.0-beta.51" "@babel/runtime" "^7.0.0-beta.51"
"@types/bn.js" "^4.11.1" "@types/bn.js" "^4.11.1"