Add chain_getBlock & author_pendingExtrinsics (#132)
* Add chain_getBlock & author_pendingExtrinsics * Remove sample * TSLint
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
"@babel/runtime": "^7.0.0-beta.51",
|
||||
"@polkadot/jsonrpc": "^0.28.11",
|
||||
"@polkadot/primitives": "^0.28.11",
|
||||
"@polkadot/util": "^0.28.1",
|
||||
"@polkadot/util-keyring": "^0.28.1"
|
||||
"@polkadot/util": "^0.28.2",
|
||||
"@polkadot/util-keyring": "^0.28.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import bnDecode from '@polkadot/primitives/json/bn/decode';
|
||||
import bytesDecode from '@polkadot/primitives/json/bytes/decode';
|
||||
import hashDecode from '@polkadot/primitives/json/hash/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 isUndefined from '@polkadot/util/is/undefined';
|
||||
|
||||
@@ -22,6 +23,7 @@ const formatters = new Map<Param$Types, FormatterFunction>([
|
||||
['Bytes', bytesDecode],
|
||||
['Hash', hashDecode],
|
||||
['Header', headerDecode],
|
||||
['SignedBlock', blockDecode],
|
||||
['u64', bnDecode]
|
||||
]);
|
||||
|
||||
|
||||
@@ -40,9 +40,9 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.0.0-beta.51",
|
||||
"@polkadot/storage": "^0.28.11",
|
||||
"@polkadot/util": "^0.28.1",
|
||||
"@polkadot/util-crypto": "^0.28.1",
|
||||
"@polkadot/util-keyring": "^0.28.1",
|
||||
"@polkadot/util": "^0.28.2",
|
||||
"@polkadot/util-crypto": "^0.28.2",
|
||||
"@polkadot/util-keyring": "^0.28.2",
|
||||
"@types/nock": "^9.1.3",
|
||||
"eventemitter3": "^2.0.3",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
|
||||
@@ -38,22 +38,51 @@ describe.skip('e2e', () => {
|
||||
|
||||
it('subscribes to storage', (done) => {
|
||||
api.state
|
||||
.subscribeStorage([
|
||||
[storage.staking.public.freeBalanceOf, '5Ejbye9R8ygByQPrDSasaUid1munedPZUmg4f118HGmtodGp'],
|
||||
[storage.staking.public.freeBalanceOf, '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFacT7']
|
||||
], (error, data) => {
|
||||
if (error) {
|
||||
return done(error);
|
||||
.subscribeStorage(
|
||||
[
|
||||
[storage.system.public.accountIndexOf, '5Ejbye9R8ygByQPrDSasaUid1munedPZUmg4f118HGmtodGp'],
|
||||
[storage.staking.public.freeBalanceOf, '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFacT7']
|
||||
],
|
||||
(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) => {
|
||||
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;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -39,6 +39,6 @@
|
||||
"@polkadot/api-provider": "^0.28.11",
|
||||
"@polkadot/jsonrpc": "^0.28.11",
|
||||
"@polkadot/params": "^0.28.11",
|
||||
"@polkadot/util": "^0.28.1"
|
||||
"@polkadot/util": "^0.28.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,6 @@
|
||||
"@babel/runtime": "^7.0.0-beta.51",
|
||||
"@polkadot/params": "^0.28.11",
|
||||
"@polkadot/primitives": "^0.28.11",
|
||||
"@polkadot/util": "^0.28.1"
|
||||
"@polkadot/util": "^0.28.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ const setStorage: CreateItemOptions = {
|
||||
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>) => ({
|
||||
description: 'Consensus',
|
||||
public: {
|
||||
|
||||
@@ -86,7 +86,7 @@ const setTermDuration: CreateItemOptions = {
|
||||
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>) => ({
|
||||
description: 'Council',
|
||||
public: {
|
||||
|
||||
@@ -49,7 +49,7 @@ const setVotingPeriod: CreateItemOptions = {
|
||||
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>) => ({
|
||||
description: 'Council Voting',
|
||||
public: {
|
||||
|
||||
@@ -51,7 +51,7 @@ const cancelReferendum: CreateItemOptions = {
|
||||
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>) => ({
|
||||
description: 'Democracy',
|
||||
public: {
|
||||
|
||||
@@ -35,7 +35,7 @@ const setHeads: CreateItemOptions = {
|
||||
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>) => ({
|
||||
description: 'Parchains',
|
||||
public: {
|
||||
|
||||
@@ -30,7 +30,7 @@ const forceNewSession: CreateItemOptions = {
|
||||
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>) => ({
|
||||
description: 'Session',
|
||||
public: {
|
||||
|
||||
@@ -77,7 +77,7 @@ const forceNewEra: CreateItemOptions = {
|
||||
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>) => ({
|
||||
description: 'Staking',
|
||||
public: {
|
||||
|
||||
@@ -17,7 +17,7 @@ const set: CreateItemOptions = {
|
||||
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>) => ({
|
||||
description: 'Timestamp',
|
||||
public: {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Extrinsics, Extrinsic$Sections } from './types';
|
||||
|
||||
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>) => ({
|
||||
description: 'Timestamp'
|
||||
}));
|
||||
|
||||
+9
-9
@@ -6,16 +6,16 @@ import { Section } from '@polkadot/params/types';
|
||||
|
||||
export type Extrinsics = {
|
||||
// substrate
|
||||
consensus: Section<Extrinsics>,
|
||||
council: Section<Extrinsics>,
|
||||
councilVoting: Section<Extrinsics>,
|
||||
democracy: Section<Extrinsics>,
|
||||
session: Section<Extrinsics>,
|
||||
staking: Section<Extrinsics>,
|
||||
timestamp: Section<Extrinsics>,
|
||||
treasury: Section<Extrinsics>,
|
||||
consensus: Section<Extrinsics, any, any>,
|
||||
council: Section<Extrinsics, any, any>,
|
||||
councilVoting: Section<Extrinsics, any, any>,
|
||||
democracy: Section<Extrinsics, any, any>,
|
||||
session: Section<Extrinsics, any, any>,
|
||||
staking: Section<Extrinsics, any, any>,
|
||||
timestamp: Section<Extrinsics, any, any>,
|
||||
treasury: Section<Extrinsics, any, any>,
|
||||
// polkadot
|
||||
parachains: Section<Extrinsics>
|
||||
parachains: Section<Extrinsics, any, any>
|
||||
};
|
||||
|
||||
export type Extrinsic$Sections = keyof Extrinsics;
|
||||
|
||||
@@ -2,12 +2,18 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// 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 param from '@polkadot/params/param';
|
||||
import createSection from '@polkadot/params/section';
|
||||
|
||||
const pendingExtrinsics: CreateItemOptions = {
|
||||
description: 'Returns all pending extrinsics, potentially grouped by sender',
|
||||
params: [],
|
||||
type: 'PrendingExtrinsics'
|
||||
};
|
||||
|
||||
const submitExtrinsic: CreateItemOptions = {
|
||||
isSigned: true,
|
||||
description: 'Submit a fully formatted extrinsic for block inclusion',
|
||||
@@ -17,14 +23,24 @@ const submitExtrinsic: CreateItemOptions = {
|
||||
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.
|
||||
*/
|
||||
export default (name: Interface$Sections): Section<Interfaces> =>
|
||||
export default (name: Interface$Sections): Section<Interfaces, PrivateMethods, PublicMethods> =>
|
||||
createSection(name)((createMethod: CreateItems<Interfaces>) => ({
|
||||
description: 'Authoring of network items',
|
||||
public: {
|
||||
submitExtrinsic:
|
||||
createMethod('submitExtrinsic')(submitExtrinsic)
|
||||
}
|
||||
public: Object.keys(publicMethods).reduce((result, key) => {
|
||||
result[key] = createMethod(key)(publicMethods[key]);
|
||||
|
||||
return result;
|
||||
}, {} as SectionItems<Interfaces, PublicMethods>)
|
||||
}));
|
||||
|
||||
@@ -2,12 +2,20 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// 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 param from '@polkadot/params/param';
|
||||
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 = {
|
||||
description: 'Retrieves the best headerHash',
|
||||
params: [],
|
||||
@@ -29,18 +37,24 @@ const subscribeNewHead: CreateItemOptions = {
|
||||
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.
|
||||
*/
|
||||
export default (name: Interface$Sections): Section<Interfaces> =>
|
||||
export default (name: Interface$Sections): Section<Interfaces, PrivateMethods, PublicMethods> =>
|
||||
createSection(name)((createMethod: CreateItems<Interfaces>) => ({
|
||||
description: 'Retrieval of chain data',
|
||||
public: {
|
||||
getHead:
|
||||
createMethod('getHead')(getHead),
|
||||
getHeader:
|
||||
createMethod('getHeader')(getHeader),
|
||||
subscribeNewHead:
|
||||
createMethod('subscribeNewHead')(subscribeNewHead)
|
||||
}
|
||||
public: Object.keys(publicMethods).reduce((result, key) => {
|
||||
result[key] = createMethod(key)(publicMethods[key]);
|
||||
|
||||
return result;
|
||||
}, {} as SectionItems<Interfaces, PublicMethods>)
|
||||
}));
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// 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 param from '@polkadot/params/param';
|
||||
@@ -87,10 +87,19 @@ const subscribeStorage: CreateItemOptions = {
|
||||
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.
|
||||
*/
|
||||
export default (name: Interface$Sections): Section<Interfaces> =>
|
||||
export default (name: Interface$Sections): Section<Interfaces, PrivateMethods, PublicMethods> =>
|
||||
createSection(name)((createMethod: CreateItems<Interfaces>) => ({
|
||||
description: 'Query of state',
|
||||
public: {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// 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 createSection from '@polkadot/params/section';
|
||||
@@ -25,10 +25,19 @@ const version: CreateItemOptions = {
|
||||
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.
|
||||
*/
|
||||
export default (sname: Interface$Sections): Section<Interfaces> =>
|
||||
export default (sname: Interface$Sections): Section<Interfaces, PrivateMethods, PublicMethods> =>
|
||||
createSection(sname)((createMethod: CreateItems<Interfaces>) => ({
|
||||
description: 'Methods to retrieve system info',
|
||||
public: {
|
||||
|
||||
Vendored
+8
-4
@@ -3,12 +3,16 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
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 = {
|
||||
author: Section<Interfaces>,
|
||||
chain: Section<Interfaces>,
|
||||
state: Section<Interfaces>,
|
||||
system:Section<Interfaces>
|
||||
author: Section<Interfaces, AuthorPrivate, AuthorPrivate>,
|
||||
chain: Section<Interfaces, ChainPrivate, ChainPublic>,
|
||||
state: Section<Interfaces, StatePrivate, StatePublic>,
|
||||
system: Section<Interfaces, SystemPrivate, SystemPublic>
|
||||
}
|
||||
|
||||
export type Interface$Sections = keyof Interfaces;
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
"@polkadot/extrinsics": "^0.28.11",
|
||||
"@polkadot/params": "^0.28.11",
|
||||
"@polkadot/primitives": "^0.28.11",
|
||||
"@polkadot/util": "^0.28.1",
|
||||
"@polkadot/util-keyring": "^0.28.1"
|
||||
"@polkadot/util": "^0.28.2",
|
||||
"@polkadot/util-keyring": "^0.28.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export default function call (decode: Decoder, input: Uint8Array | null | undefi
|
||||
} 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]
|
||||
);
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ import bnToU8a from '@polkadot/util/bn/toU8a';
|
||||
|
||||
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 creator = (optOrFn: CreateSectionOptions<T>): Section<T> => {
|
||||
const creator = (optOrFn: CreateSectionOptions<T, any, any>): Section<T, any, any> => {
|
||||
if (typeof optOrFn === 'function') {
|
||||
return creator(
|
||||
optOrFn(
|
||||
|
||||
Vendored
+31
-13
@@ -14,7 +14,7 @@ export type EncodingVersions = 'poc-1' | 'latest';
|
||||
// - @polkadot/storage/key/params.ts
|
||||
// - decode/value/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>>>;
|
||||
|
||||
@@ -25,6 +25,20 @@ export type ExtrinsicDecoded = {
|
||||
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 = {
|
||||
key: Uint8Array,
|
||||
value: Uint8Array
|
||||
@@ -68,21 +82,21 @@ export type SectionItem<T> = {
|
||||
type: Param$Types
|
||||
};
|
||||
|
||||
export type SectionItems<T> = {
|
||||
[index: string]: SectionItem<T>
|
||||
export type SectionItems<T, K> = {
|
||||
[key in keyof K]: SectionItem<T>
|
||||
};
|
||||
|
||||
export type Section<T> = {
|
||||
export type Section<T, Priv, Pub> = {
|
||||
isDeprecated: boolean,
|
||||
isHidden: boolean,
|
||||
description: string,
|
||||
index: Uint8Array,
|
||||
name: keyof T,
|
||||
private: SectionItems<T>,
|
||||
public: SectionItems<T>
|
||||
private: SectionItems<T, Priv>,
|
||||
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 = {
|
||||
description: string,
|
||||
@@ -96,20 +110,24 @@ export type CreateItemOptions = {
|
||||
type: Param$Types
|
||||
};
|
||||
|
||||
export type CreateItemOptionsMap = {
|
||||
[index: string]: CreateItemOptions
|
||||
};
|
||||
|
||||
export type CreateItem<T> = (options: CreateItemOptions) => SectionItem<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,
|
||||
isDeprecated?: boolean,
|
||||
isHidden?: boolean,
|
||||
'private'?: SectionItems<T>,
|
||||
'public'?: SectionItems<T>
|
||||
'private'?: SectionItems<T, Priv>,
|
||||
'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>;
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.0.0-beta.51",
|
||||
"@polkadot/trie-hash": "^0.28.1",
|
||||
"@polkadot/util": "^0.28.1"
|
||||
"@polkadot/trie-hash": "^0.28.2",
|
||||
"@polkadot/util": "^0.28.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"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 u8aToHex from '@polkadot/util/u8a/toHex';
|
||||
import toU8a from '@polkadot/util/u8a/toU8a';
|
||||
|
||||
export default function hashEncode (value: Hash, bitLength: number = -1): JsonHash {
|
||||
return u8aToHex(value);
|
||||
export default function hashEncode (value: Hash | string, bitLength: number = -1): JsonHash {
|
||||
return u8aToHex(
|
||||
toU8a(value)
|
||||
);
|
||||
}
|
||||
|
||||
+9
-3
@@ -2,6 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { ExtrinsicDecoded } from '@polkadot/params/types';
|
||||
|
||||
export type JsonBnType = string;
|
||||
export type JsonHash = string;
|
||||
|
||||
@@ -44,8 +46,12 @@ export type JsonHeader = {
|
||||
digest: JsonDigest
|
||||
};
|
||||
|
||||
export type JsonJustification = {};
|
||||
|
||||
export type JsonBlock = {
|
||||
header: JsonHeader,
|
||||
timestamp: JsonU64,
|
||||
transactions: Array<JsonUnchecked>
|
||||
block: {
|
||||
extrinsics: Array<Array<JsonBytes>>,
|
||||
header: JsonHeader,
|
||||
},
|
||||
justification: JsonJustification
|
||||
};
|
||||
|
||||
@@ -37,8 +37,8 @@
|
||||
"@babel/runtime": "^7.0.0-beta.51",
|
||||
"@polkadot/params": "^0.28.11",
|
||||
"@polkadot/primitives": "^0.28.11",
|
||||
"@polkadot/util": "^0.28.1",
|
||||
"@polkadot/util-crypto": "^0.28.1",
|
||||
"@polkadot/util-keyring": "^0.28.1"
|
||||
"@polkadot/util": "^0.28.2",
|
||||
"@polkadot/util-crypto": "^0.28.2",
|
||||
"@polkadot/util-keyring": "^0.28.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ const code: CreateItemOptions = {
|
||||
type: 'Code'
|
||||
};
|
||||
|
||||
export default (name: Storage$Sections): Section<Storages> =>
|
||||
export default (name: Storage$Sections): Section<Storages, any, any> =>
|
||||
createSection(name)((createMethod: CreateItems<Storages>) => ({
|
||||
description: 'Consensus',
|
||||
public: {
|
||||
|
||||
@@ -52,7 +52,7 @@ const codeOf: CreateItemOptions = {
|
||||
type: 'Code'
|
||||
};
|
||||
|
||||
export default (name: Storage$Sections): Section<Storages> =>
|
||||
export default (name: Storage$Sections): Section<Storages, any, any> =>
|
||||
createSection(name)((createMethod: CreateItems<Storages>) => ({
|
||||
description: 'Contract',
|
||||
public: {
|
||||
|
||||
@@ -154,7 +154,7 @@ const leaderboard: CreateItemOptions = {
|
||||
type: [['Balance', 'AccountId']]
|
||||
};
|
||||
|
||||
export default (name: keyof Storages): Section<Storages> =>
|
||||
export default (name: keyof Storages): Section<Storages, any, any> =>
|
||||
createSection(name)((createMethod: CreateItems<Storages>) => ({
|
||||
description: 'Council',
|
||||
public: {
|
||||
|
||||
@@ -66,7 +66,7 @@ const vetoedProposal: CreateItemOptions = {
|
||||
type: ['BlockNumber', 'AccountId']
|
||||
};
|
||||
|
||||
export default (name: Storage$Sections): Section<Storages> =>
|
||||
export default (name: Storage$Sections): Section<Storages, any, any> =>
|
||||
createSection(name)((createMethod: CreateItems<Storages>) => ({
|
||||
description: 'Council voting',
|
||||
public: {
|
||||
|
||||
@@ -94,7 +94,7 @@ const voteOf: CreateItemOptions = {
|
||||
type: 'bool'
|
||||
};
|
||||
|
||||
export default (name: Storage$Sections): Section<Storages> =>
|
||||
export default (name: Storage$Sections): Section<Storages, any, any> =>
|
||||
createSection(name)((createMethod: CreateItems<Storages>) => ({
|
||||
description: 'Democracy',
|
||||
public: {
|
||||
|
||||
@@ -40,7 +40,7 @@ const didUpdate: CreateItemOptions = {
|
||||
type: 'bool'
|
||||
};
|
||||
|
||||
export default (name: Storage$Sections): Section<Storages> =>
|
||||
export default (name: Storage$Sections): Section<Storages, any, any> =>
|
||||
createSection(name)((createMethod: CreateItems<Storages>) => ({
|
||||
description: 'Parachain related entries',
|
||||
public: {
|
||||
|
||||
@@ -73,7 +73,7 @@ const nextLength: CreateItemOptions = {
|
||||
type: 'BlockNumber'
|
||||
};
|
||||
|
||||
export default (name: Storage$Sections): Section<Storages> =>
|
||||
export default (name: Storage$Sections): Section<Storages, any, any> =>
|
||||
createSection(name)((createMethod: CreateItems<Storages>) => ({
|
||||
description: 'Session management information',
|
||||
public: {
|
||||
|
||||
@@ -197,7 +197,7 @@ const bondageOf: CreateItemOptions = {
|
||||
type: 'Balance'
|
||||
};
|
||||
|
||||
export default (name: Storage$Sections): Section<Storages> =>
|
||||
export default (name: Storage$Sections): Section<Storages, any, any> =>
|
||||
createSection(name)((createMethod: CreateItems<Storages>) => ({
|
||||
description: 'Staking',
|
||||
public: {
|
||||
|
||||
@@ -70,7 +70,7 @@ const digest: CreateItemOptions = {
|
||||
type: 'Digest'
|
||||
};
|
||||
|
||||
export default (name: Storage$Sections): Section<Storages> =>
|
||||
export default (name: Storage$Sections): Section<Storages, any, any> =>
|
||||
createSection(name)((createMethod: CreateItems<Storages>) => ({
|
||||
description: 'System',
|
||||
public: {
|
||||
|
||||
@@ -28,7 +28,7 @@ const didUpdate: CreateItemOptions = {
|
||||
type: 'bool'
|
||||
};
|
||||
|
||||
export default (name: Storage$Sections): Section<Storages> =>
|
||||
export default (name: Storage$Sections): Section<Storages, any, any> =>
|
||||
createSection(name)((createMethod: CreateItems<Storages>) => ({
|
||||
description: 'Timestamp related entries',
|
||||
public: {
|
||||
|
||||
Vendored
+10
-10
@@ -8,16 +8,16 @@ import { Section } from '@polkadot/params/types';
|
||||
export type Storage$Key$Value = number | BN | Uint8Array | string;
|
||||
|
||||
export type Storages = {
|
||||
consensus: Section<Storages>,
|
||||
// contract: Section<Storages>,
|
||||
council: Section<Storages>,
|
||||
councilVoting: Section<Storages>,
|
||||
democracy: Section<Storages>,
|
||||
parachains: Section<Storages>,
|
||||
session: Section<Storages>,
|
||||
staking: Section<Storages>,
|
||||
system: Section<Storages>,
|
||||
timestamp: Section<Storages>
|
||||
consensus: Section<Storages, any, any>,
|
||||
// contract: Section<Storages, any, any>,
|
||||
council: Section<Storages, any, any>,
|
||||
councilVoting: Section<Storages, any, any>,
|
||||
democracy: Section<Storages, any, any>,
|
||||
parachains: Section<Storages, any, any>,
|
||||
session: Section<Storages, any, any>,
|
||||
staking: Section<Storages, any, any>,
|
||||
system: Section<Storages, any, any>,
|
||||
timestamp: Section<Storages, any, any>
|
||||
};
|
||||
|
||||
export type Storage$Sections = keyof Storages;
|
||||
|
||||
Reference in New Issue
Block a user