Round out available extrinsic methods (#8)
* Expand methods * Remove extra params label * Move shared extrinsic definitions * Split extrinsics into own packages * Update entry location * Include all method calls * Expand to include all extrinsics * Cleanup extrinsic definitions * Build folder change
This commit is contained in:
parent
81a5411dcb
commit
b71e029cc8
@ -12,5 +12,7 @@ all=warn
|
||||
|
||||
[options]
|
||||
include_warnings=true
|
||||
module.name_mapper='^@polkadot/app-\(accounts\|explorer\|extrinsics\|home\|settings\)\(.*\)$' -> '<PROJECT_ROOT>/packages/app-\1/src\2'
|
||||
module.name_mapper='^@polkadot/portal\(.*\)$' -> '<PROJECT_ROOT>/packages/portal/src\1'
|
||||
module.name_mapper='^@polkadot/app-\(accounts\|explorer\|extrinsics\|home\|rpc\|settings\|storage\)\(.*\)$' -> '<PROJECT_ROOT>/packages/app-\1/src\2'
|
||||
module.name_mapper='^@polkadot/apps\(.*\)$' -> '<PROJECT_ROOT>/packages/apps/src\1'
|
||||
module.name_mapper='^@polkadot/extrinsics-\(codec\|polkadot\|substrate\)\(.*\)$' -> '<PROJECT_ROOT>/packages/extrinsics-\1/src\2'
|
||||
module.name_mapper='^@polkadot/extrinsics\(.*\)$' -> '<PROJECT_ROOT>/packages/extrinsics/src\1'
|
||||
|
||||
6
flow-typed/semantic-ui-react.js
vendored
6
flow-typed/semantic-ui-react.js
vendored
@ -23,7 +23,11 @@ declare module 'semantic-ui-react/dist/es/elements/Label' {
|
||||
}
|
||||
|
||||
declare module 'semantic-ui-react/dist/es/modules/Dropdown' {
|
||||
declare module.exports: React$StatelessFunctionalComponent<*>
|
||||
declare module.exports: React$StatelessFunctionalComponent<*> & {
|
||||
Divider: React$StatelessFunctionalComponent<*>,
|
||||
Header: React$StatelessFunctionalComponent<*>,
|
||||
Item: React$StatelessFunctionalComponent<*>
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'semantic-ui-react/dist/es/modules/Modal' {
|
||||
|
||||
13
package.json
13
package.json
@ -6,15 +6,12 @@
|
||||
"packages/*"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "polkadot-dev-build-babel && yarn run build:portal",
|
||||
"build:portal": "cd packages/portal && react-scripts build",
|
||||
"build": "polkadot-dev-build-babel && yarn run build:apps",
|
||||
"build:apps": "cd packages/apps && react-scripts build",
|
||||
"check": "eslint packages && flow check",
|
||||
"deploy:ghpages": "gh-pages -d packages/portal/build",
|
||||
"start": "cd packages/portal && react-scripts start",
|
||||
"test": "echo 'to tests executed'"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/portal": "^0.1.1"
|
||||
"deploy:ghpages": "gh-pages -d packages/apps/build",
|
||||
"start": "cd packages/apps && react-scripts start",
|
||||
"test": "echo 'no tests executed'"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/dev": "^0.17.12",
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@polkadot/app-explorer",
|
||||
"version": "0.1.3",
|
||||
"main": "src/index.js",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/polkadot-js/portal.git",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"license": "ISC",
|
||||
@ -11,12 +11,12 @@
|
||||
"test": "jest --coverage"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/primitives": "^0.10.3",
|
||||
"@polkadot/primitives-codec": "^0.10.3",
|
||||
"@polkadot/primitives-json": "^0.10.3",
|
||||
"@polkadot/rx-react": "^0.4.6",
|
||||
"@polkadot/util": "^0.19.2",
|
||||
"@polkadot/util-crypto": "^0.19.2",
|
||||
"@polkadot/primitives": "^0.10.4",
|
||||
"@polkadot/primitives-codec": "^0.10.4",
|
||||
"@polkadot/primitives-json": "^0.10.4",
|
||||
"@polkadot/rx-react": "^0.4.7",
|
||||
"@polkadot/util": "^0.19.4",
|
||||
"@polkadot/util-crypto": "^0.19.4",
|
||||
"react": "^16.3.1",
|
||||
"react-dom": "^16.3.1",
|
||||
"react-i18next": "^7.5.1",
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { BaseProps } from '@polkadot/portal/types';
|
||||
import type { BaseProps } from '../types';
|
||||
|
||||
import './App.css';
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@polkadot/app-extrinsics",
|
||||
"version": "0.1.3",
|
||||
"main": "src/index.js",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/polkadot-js/portal.git",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"license": "ISC",
|
||||
@ -11,10 +11,13 @@
|
||||
"test": "jest --coverage"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/rx-react": "^0.4.6",
|
||||
"@polkadot/ui-react": "^0.9.11",
|
||||
"@polkadot/util": "^0.19.2",
|
||||
"@polkadot/util-keyring": "^0.19.2",
|
||||
"@polkadot/extrinsics": "^0.1.3",
|
||||
"@polkadot/extrinsics-codec": "^0.1.3",
|
||||
"@polkadot/extrinsics-polkadot": "^0.1.3",
|
||||
"@polkadot/rx-react": "^0.4.7",
|
||||
"@polkadot/ui-react": "^0.9.12",
|
||||
"@polkadot/util": "^0.19.4",
|
||||
"@polkadot/util-keyring": "^0.19.4",
|
||||
"react": "^16.3.1",
|
||||
"react-dom": "^16.3.1",
|
||||
"react-i18next": "^7.5.1",
|
||||
|
||||
@ -14,11 +14,12 @@ import translate from './translate';
|
||||
import InputAddress from './InputAddress';
|
||||
|
||||
type Props = BaseProps & {
|
||||
isError?: boolean,
|
||||
label: string,
|
||||
subject: rxjs$BehaviorSubject<Uint8Array>
|
||||
};
|
||||
|
||||
function Account ({ className, label, subject, style, t }: Props): React$Node {
|
||||
function Account ({ className, isError, label, subject, style, t }: Props): React$Node {
|
||||
const AccountBalance = withObservableParams(subject)(Balance);
|
||||
|
||||
return (
|
||||
|
||||
@ -14,12 +14,13 @@ import Params from '../Params';
|
||||
import createSubjects from './subjects';
|
||||
|
||||
type Props = BareProps & {
|
||||
isError?: boolean,
|
||||
isPrivate?: boolean,
|
||||
label: string,
|
||||
subject: rxjs$BehaviorSubject<EncodedParams>
|
||||
};
|
||||
|
||||
export default function ExtrinsicMethod ({ className, isPrivate, label, style, subject }: Props): React$Node {
|
||||
export default function Extrinsic ({ className, isError, isPrivate, label, style, subject }: Props): React$Node {
|
||||
const subjects = createSubjects(subject);
|
||||
const MethodParams = withObservable(subjects.method)(Params);
|
||||
|
||||
@ -31,6 +32,7 @@ export default function ExtrinsicMethod ({ className, isPrivate, label, style, s
|
||||
<div className='full'>
|
||||
<Label>{label}</Label>
|
||||
<InputExtrinsic
|
||||
isError={isError}
|
||||
isPrivate={isPrivate}
|
||||
subject={subjects.method}
|
||||
/>
|
||||
|
||||
@ -3,14 +3,13 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Extrinsic } from '../extrinsics/types';
|
||||
import type { Extrinsic } from '@polkadot/extrinsics/types';
|
||||
import type { EncodedParams, RawParam } from '../types';
|
||||
|
||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||
import encodeExtrinsic from '@polkadot/extrinsics-codec/src/encode/extrinsic';
|
||||
import isUndefined from '@polkadot/util/is/undefined';
|
||||
|
||||
import encodeExtrinsic from '../encode/extrinsic';
|
||||
|
||||
type Subjects = {
|
||||
method: rxjs$BehaviorSubject<Extrinsic>,
|
||||
params: rxjs$BehaviorSubject<Array<RawParam>>
|
||||
@ -38,7 +37,6 @@ export default function subjects (subject: rxjs$BehaviorSubject<EncodedParams>):
|
||||
});
|
||||
};
|
||||
|
||||
subjects.method.subscribe(onChange);
|
||||
subjects.params.subscribe(onChange);
|
||||
|
||||
return subjects;
|
||||
|
||||
@ -17,6 +17,7 @@ import keyring from '../keyring';
|
||||
|
||||
type Props = {
|
||||
className?: string,
|
||||
isError?: boolean,
|
||||
onChange?: (event: SyntheticEvent<*>, value: Uint8Array) => void,
|
||||
style?: {
|
||||
[string]: string
|
||||
@ -44,11 +45,16 @@ export default function InputAddress (props: Props): React$Node {
|
||||
}
|
||||
};
|
||||
|
||||
const _props = {...props};
|
||||
|
||||
delete _props.isError;
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
selection
|
||||
{...props}
|
||||
{..._props}
|
||||
className={['ui--InputAddress', props.className].join(' ')}
|
||||
error={props.isError}
|
||||
options={options}
|
||||
onChange={onChange}
|
||||
/>
|
||||
|
||||
@ -4,8 +4,6 @@
|
||||
|
||||
.ui--InputExtrinsic {}
|
||||
|
||||
.ui--InputExtrinsic-Header {}
|
||||
|
||||
.ui--InputExtrinsic .text {
|
||||
box-sizing: border-box;
|
||||
display: flex !important;
|
||||
|
||||
@ -5,18 +5,19 @@
|
||||
|
||||
// TODO: This is a useful, shared component, move out
|
||||
|
||||
import type { Extrinsic } from '../extrinsics/types';
|
||||
import type { Extrinsic } from '@polkadot/extrinsics/types';
|
||||
|
||||
import './InputExtrinsic.css';
|
||||
|
||||
import React from 'react';
|
||||
import Dropdown from 'semantic-ui-react/dist/es/modules/Dropdown';
|
||||
import extrinsics from '@polkadot/extrinsics-polkadot/src';
|
||||
|
||||
import extrinsics from '../extrinsics';
|
||||
import options from './options';
|
||||
|
||||
type Props = {
|
||||
className?: string,
|
||||
isError?: boolean,
|
||||
isPrivate?: boolean,
|
||||
onChange?: (event: SyntheticEvent<*>, value: Extrinsic) => void,
|
||||
style?: {
|
||||
@ -41,6 +42,7 @@ export default function InputExtrinsic (props: Props): React$Node {
|
||||
|
||||
const _props = Object.assign({}, props);
|
||||
|
||||
delete _props.isError;
|
||||
delete _props.isPrivate;
|
||||
|
||||
return (
|
||||
@ -48,6 +50,7 @@ export default function InputExtrinsic (props: Props): React$Node {
|
||||
selection
|
||||
{..._props}
|
||||
className={['ui--InputExtrinsic', props.className].join(' ')}
|
||||
error={props.isError}
|
||||
onChange={onChange}
|
||||
options={
|
||||
// flowlint-next-line sketchy-null-bool:off
|
||||
|
||||
@ -4,33 +4,40 @@
|
||||
// @flow
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import extrinsics from '../extrinsics';
|
||||
import Dropdown from 'semantic-ui-react/dist/es/modules/Dropdown';
|
||||
import extrinsics from '@polkadot/extrinsics-polkadot/src';
|
||||
|
||||
const options = {
|
||||
private: [],
|
||||
public: []
|
||||
};
|
||||
|
||||
extrinsics.sections.forEach(({ description, hasPrivate, hasPublic, methods, name }) => {
|
||||
const header = {
|
||||
className: 'ui--InputExtrinsic-Header',
|
||||
disabled: true,
|
||||
text: description,
|
||||
value: name
|
||||
};
|
||||
const sortByName = (a, b) =>
|
||||
a.name.localeCompare(b.name);
|
||||
|
||||
hasPublic && options.public.push(header);
|
||||
hasPrivate && options.private.push(header);
|
||||
const addHeader = (shouldAdd, to, description) => {
|
||||
if (shouldAdd) {
|
||||
to.push(<Dropdown.Divider />);
|
||||
to.push(
|
||||
<Dropdown.Header>
|
||||
{description}
|
||||
</Dropdown.Header>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
methods.forEach(({ description, name, params, isPrivate }) => {
|
||||
extrinsics.sections.sort(sortByName).forEach(({ description, hasPrivate, hasPublic, methods, name }) => {
|
||||
addHeader(hasPublic, options.public, description);
|
||||
addHeader(hasPrivate, options.private, description);
|
||||
|
||||
methods.sort(sortByName).forEach(({ description, name, params, isPrivate }) => {
|
||||
const inputs = params.map(({ name }) => name).join(', ');
|
||||
|
||||
options[isPrivate ? 'private' : 'public'].push({
|
||||
className: 'ui--InputExtrinsic-Item',
|
||||
text: [
|
||||
<div className='ui--InputExtrinsic-Item-text' key='name'>
|
||||
{description}
|
||||
{description || name}
|
||||
</div>,
|
||||
<div className='ui--InputExtrinsic-Item-call' key='call'>
|
||||
{name}({inputs})
|
||||
|
||||
@ -10,18 +10,19 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||
|
||||
import BaseAccount from '../Account';
|
||||
|
||||
export default function Account ({ label, subject }: Props): React$Node {
|
||||
export default function Account ({ isError, label, subject }: Props): React$Node {
|
||||
const account: rxjs$BehaviorSubject<Uint8Array> = new BehaviorSubject(new Uint8Array([]));
|
||||
|
||||
account.subscribe((value: Uint8Array) => {
|
||||
account.subscribe((value: Uint8Array) =>
|
||||
subject.next({
|
||||
isValid: !!(value && value.length),
|
||||
value
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
return (
|
||||
<BaseAccount
|
||||
isError={isError}
|
||||
label={label}
|
||||
subject={account}
|
||||
/>
|
||||
|
||||
@ -11,17 +11,16 @@ import Input from 'semantic-ui-react/dist/es/elements/Input';
|
||||
|
||||
import Base from './Base';
|
||||
|
||||
export default function Amount ({ label, subject, t, value: { options: { initValue = 0, maxValue, minValue = 0 } = {} }, type }: Props): React$Node {
|
||||
export default function Amount ({ isError, label, subject, t, value: { options: { initValue = 0, maxValue, minValue = 0 } = {} } }: Props): React$Node {
|
||||
// flowlint-next-line sketchy-null-mixed:off, sketchy-null-number:off
|
||||
const defaultValue = initValue || minValue;
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const onChange = (event: SyntheticEvent<*>, { value }): void => {
|
||||
const onChange = (event: SyntheticEvent<*>, { value }) =>
|
||||
subject.next({
|
||||
isValid: true,
|
||||
// flowlint-next-line sketchy-null-mixed:off, sketchy-null-number:off
|
||||
value: new BN(value || minValue || 0)
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Base
|
||||
@ -30,6 +29,7 @@ export default function Amount ({ label, subject, t, value: { options: { initVal
|
||||
>
|
||||
<Input
|
||||
defaultValue={defaultValue}
|
||||
error={isError}
|
||||
max={maxValue}
|
||||
min={minValue}
|
||||
onChange={onChange}
|
||||
|
||||
39
packages/app-extrinsics/src/Params/Bool.js
Normal file
39
packages/app-extrinsics/src/Params/Bool.js
Normal file
@ -0,0 +1,39 @@
|
||||
// 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 { Props } from './types';
|
||||
|
||||
import React from 'react';
|
||||
import Dropdown from 'semantic-ui-react/dist/es/modules/Dropdown';
|
||||
|
||||
import Base from './Base';
|
||||
|
||||
const options = [
|
||||
{ text: 'No', value: false },
|
||||
{ text: 'Yes', value: true }
|
||||
];
|
||||
|
||||
export default function Bool ({ isError, label, subject, t, value: { options: { initValue = false } = {} } }: Props): React$Node {
|
||||
const onChange = (event: SyntheticEvent<*>, { value }) =>
|
||||
subject.next({
|
||||
isValid: true,
|
||||
value
|
||||
});
|
||||
|
||||
return (
|
||||
<Base
|
||||
label={label}
|
||||
size='small'
|
||||
>
|
||||
<Dropdown
|
||||
error={isError}
|
||||
selection
|
||||
defaultValue={initValue}
|
||||
options={options}
|
||||
onChange={onChange}
|
||||
/>
|
||||
</Base>
|
||||
);
|
||||
}
|
||||
37
packages/app-extrinsics/src/Params/Hash.js
Normal file
37
packages/app-extrinsics/src/Params/Hash.js
Normal file
@ -0,0 +1,37 @@
|
||||
// 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 { Props } from './types';
|
||||
|
||||
import React from 'react';
|
||||
import Input from 'semantic-ui-react/dist/es/elements/Input';
|
||||
import hexToU8a from '@polkadot/util/hex/toU8a';
|
||||
|
||||
import Base from './Base';
|
||||
|
||||
export default function Hash ({ isError, label, subject, t }: Props): React$Node {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const onChange = (event: SyntheticEvent<*>, { value }) => {
|
||||
const u8a = hexToU8a(value);
|
||||
|
||||
subject.next({
|
||||
isValid: u8a.length === 32,
|
||||
value: u8a
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Base
|
||||
label={label}
|
||||
size='small'
|
||||
>
|
||||
<Input
|
||||
error={isError}
|
||||
onChange={onChange}
|
||||
type='text'
|
||||
/>
|
||||
</Base>
|
||||
);
|
||||
}
|
||||
@ -3,33 +3,24 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { BaseProps } from './types';
|
||||
import type { Extrinsic$Param } from '@polkadot/extrinsics/types';
|
||||
import type { BareProps, RawParam } from '../types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import Account from './Account';
|
||||
import Amount from './Amount';
|
||||
import Proposal from './Proposal';
|
||||
import Unknown from './Unknown';
|
||||
import findComponent from './findComponent';
|
||||
import typeToText from './typeToText';
|
||||
|
||||
type Props = BaseProps & {
|
||||
label?: string;
|
||||
type Props = BareProps & {
|
||||
label?: string,
|
||||
subject: rxjs$BehaviorSubject<RawParam>,
|
||||
value: Extrinsic$Param
|
||||
}
|
||||
|
||||
const Components = {
|
||||
'AccountId': Account,
|
||||
'Balance': Amount,
|
||||
'BlockNumber': Amount,
|
||||
'Bytes': Unknown,
|
||||
'Proposal': Proposal,
|
||||
'u32': Amount,
|
||||
'u64': Amount
|
||||
};
|
||||
|
||||
export default function Param ({ className, label, style, subject, value }: Props): React$Node {
|
||||
// flowlint-next-line sketchy-null-string:off
|
||||
const defaultLabel = label || `${value.name}: ${value.type}`;
|
||||
const Component = Components[value.type];
|
||||
const defaultLabel = label || `${value.name}: ${typeToText(value.type)}`;
|
||||
const Component = findComponent(value.type);
|
||||
|
||||
return (
|
||||
<Component
|
||||
|
||||
@ -11,18 +11,19 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||
|
||||
import Extrinsic from '../Extrinsic';
|
||||
|
||||
export default function Proposal ({ label, subject }: Props): React$Node {
|
||||
export default function Proposal ({ isError, label, subject }: Props): React$Node {
|
||||
const extrinsic: rxjs$BehaviorSubject<EncodedParams> = new BehaviorSubject(({ isValid: false }: $Shape<EncodedParams>));
|
||||
|
||||
extrinsic.subscribe(({ data, isValid }: EncodedParams) => {
|
||||
extrinsic.subscribe(({ data, isValid }: EncodedParams) =>
|
||||
subject.next({
|
||||
isValid,
|
||||
value: data
|
||||
});
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
return (
|
||||
<Extrinsic
|
||||
isError={isError}
|
||||
isPrivate
|
||||
label={label}
|
||||
subject={extrinsic}
|
||||
|
||||
@ -9,22 +9,28 @@ import React from 'react';
|
||||
|
||||
import translate from '../translate';
|
||||
import Base from './Base';
|
||||
import typeToText from './typeToText';
|
||||
|
||||
type Props = BaseProps & {
|
||||
t: I18Next$Translate
|
||||
};
|
||||
|
||||
function Unknown ({ label, t, value: { type } }: Props): React$Node {
|
||||
function Unknown ({ label, subject, t, value: { type } }: Props): React$Node {
|
||||
subject.next({
|
||||
isValid: false,
|
||||
value: new Uint8Array([])
|
||||
});
|
||||
|
||||
return (
|
||||
<Base
|
||||
size='full'
|
||||
label={label}
|
||||
>
|
||||
<div className='extrinsics--Param-Unknown ui disabled dropdown selection'>
|
||||
<div className='extrinsics--Param-Unknown ui dropdown error selection'>
|
||||
{t('param.unknown', {
|
||||
defaultValue: `ERROR: Unknown input of type '{{type}}' found. No renderer exists`,
|
||||
defaultValue: `ERROR: Unimplemented type '{{type}}' requested. No renderer exists`,
|
||||
replace: {
|
||||
type
|
||||
type: typeToText(type)
|
||||
}
|
||||
})}
|
||||
</div>
|
||||
|
||||
39
packages/app-extrinsics/src/Params/VoteThreshold.js
Normal file
39
packages/app-extrinsics/src/Params/VoteThreshold.js
Normal file
@ -0,0 +1,39 @@
|
||||
// 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 { Props } from './types';
|
||||
|
||||
import React from 'react';
|
||||
import Dropdown from 'semantic-ui-react/dist/es/modules/Dropdown';
|
||||
|
||||
import Base from './Base';
|
||||
|
||||
const options = [
|
||||
{ text: 'Super majority approval', value: 0 },
|
||||
{ text: 'Super majority rejection', value: 1 },
|
||||
{ text: 'Simple majority', value: 2 }
|
||||
];
|
||||
|
||||
export default function VoteThreshold ({ label, subject, t, value: { options: { initValue = 0 } = {} } }: Props): React$Node {
|
||||
const onChange = (event: SyntheticEvent<*>, { value }) =>
|
||||
subject.next({
|
||||
isValid: true,
|
||||
value
|
||||
});
|
||||
|
||||
return (
|
||||
<Base
|
||||
label={label}
|
||||
size='small'
|
||||
>
|
||||
<Dropdown
|
||||
selection
|
||||
defaultValue={initValue}
|
||||
options={options}
|
||||
onChange={onChange}
|
||||
/>
|
||||
</Base>
|
||||
);
|
||||
}
|
||||
40
packages/app-extrinsics/src/Params/findComponent.js
Normal file
40
packages/app-extrinsics/src/Params/findComponent.js
Normal file
@ -0,0 +1,40 @@
|
||||
// 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 { Extrinsic$Type } from '@polkadot/extrinsics/types';
|
||||
|
||||
import Account from './Account';
|
||||
import Amount from './Amount';
|
||||
import Bool from './Bool';
|
||||
import Hash from './Hash';
|
||||
import Proposal from './Proposal';
|
||||
import Unknown from './Unknown';
|
||||
import VoteThreshold from './VoteThreshold';
|
||||
|
||||
const Components = {
|
||||
'AccountId': Account,
|
||||
'Balance': Amount,
|
||||
'BlockNumber': Amount,
|
||||
'bool': Bool,
|
||||
'Bytes': Unknown,
|
||||
'Hash': Hash,
|
||||
'MisbehaviorReport': Unknown,
|
||||
'Proposal': Proposal,
|
||||
'SessionKey': Unknown,
|
||||
'u32': Amount,
|
||||
'u64': Amount,
|
||||
'VoteThreshold': VoteThreshold
|
||||
};
|
||||
|
||||
export default function findComponent (type: Extrinsic$Type): React$ComponentType<*> {
|
||||
if (Array.isArray(type)) {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const [outer, inner] = type;
|
||||
|
||||
return findComponent(inner);
|
||||
}
|
||||
|
||||
return Components[type];
|
||||
}
|
||||
@ -3,24 +3,30 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Extrinsic } from '../extrinsics/types';
|
||||
import type { Extrinsic } from '@polkadot/extrinsics/types';
|
||||
import type { BaseProps, RawParam } from '../types';
|
||||
|
||||
import './Params.css';
|
||||
|
||||
import React from 'react';
|
||||
import Label from 'semantic-ui-react/dist/es/elements/Label';
|
||||
// import Label from 'semantic-ui-react/dist/es/elements/Label';
|
||||
// <Label>
|
||||
// {t('params.intro', {
|
||||
// defaultValue: 'with the supplied parameters'
|
||||
// })}
|
||||
// </Label>
|
||||
|
||||
import translate from '../translate';
|
||||
import Param from './Param';
|
||||
import createSubscriber from './subscriber';
|
||||
import typeToText from './typeToText';
|
||||
|
||||
type Props = BaseProps & {
|
||||
subject: rxjs$BehaviorSubject<Array<RawParam>>,
|
||||
value: Extrinsic;
|
||||
};
|
||||
|
||||
function Params ({ className, style, subject, t, value: { name, params } }: Props): React$Node {
|
||||
function Params ({ className, style, subject, value: { name, params } }: Props): React$Node {
|
||||
if (!params || !params.length) {
|
||||
return null;
|
||||
}
|
||||
@ -33,18 +39,13 @@ function Params ({ className, style, subject, t, value: { name, params } }: Prop
|
||||
style={style}
|
||||
>
|
||||
<div className='full'>
|
||||
<Label>
|
||||
{t('params.intro', {
|
||||
defaultValue: 'with the supplied parameters'
|
||||
})}
|
||||
</Label>
|
||||
<div className='extrinsics--Params-Content'>
|
||||
{params.map((param, index) => (
|
||||
{params.map((value, index) => (
|
||||
<Param
|
||||
className='extrinsics--Params-Param'
|
||||
key={`${name}:${param.name}:${param.type}`}
|
||||
key={`${name}:${value.name}:${typeToText(value.type)}`}
|
||||
value={value}
|
||||
subject={subjects[index]}
|
||||
value={param}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@ -2,24 +2,27 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
// flowlint sketchy-null-mixed:off
|
||||
|
||||
import type { Extrinsic$Param } from '../extrinsics/types';
|
||||
import type { Extrinsic$Param } from '@polkadot/extrinsics/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
export default function getInitValue ({ options: { initValue, minValue } = {}, type }: Extrinsic$Param): mixed {
|
||||
// flowlint-next-line sketchy-null-mixed:off
|
||||
const defaultValue = initValue || minValue;
|
||||
|
||||
switch (type) {
|
||||
case 'Balance':
|
||||
case 'BlockNumber':
|
||||
case 'u32':
|
||||
case 'u64':
|
||||
// flowlint-next-line sketchy-null-mixed:off
|
||||
return new BN(defaultValue || 0);
|
||||
return new BN(initValue || minValue || 0);
|
||||
|
||||
case 'bool':
|
||||
return initValue || false;
|
||||
|
||||
case 'VoteThreshold':
|
||||
return initValue || 0;
|
||||
|
||||
default:
|
||||
return defaultValue;
|
||||
return initValue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Extrinsic$Params } from '../extrinsics/types';
|
||||
import type { Extrinsic$Params } from '@polkadot/extrinsics/types';
|
||||
import type { RawParam } from '../types';
|
||||
|
||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Extrinsic$Params } from '../extrinsics/types';
|
||||
import type { Extrinsic$Params } from '@polkadot/extrinsics/types';
|
||||
import type { RawParam } from '../types';
|
||||
|
||||
import createSubjects from './subjects';
|
||||
|
||||
16
packages/app-extrinsics/src/Params/typeToText.js
Normal file
16
packages/app-extrinsics/src/Params/typeToText.js
Normal file
@ -0,0 +1,16 @@
|
||||
// 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 { Extrinsic$Type } from '@polkadot/extrinsics/types';
|
||||
|
||||
export default function typeToText (type: Extrinsic$Type): string {
|
||||
if (Array.isArray(type)) {
|
||||
const [outer, inner] = type;
|
||||
|
||||
return `${outer}<${inner}>`;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Extrinsic$Param } from '../extrinsics/types';
|
||||
import type { Extrinsic$Param } from '@polkadot/extrinsics/types';
|
||||
import type { BareProps, RawParam } from '../types';
|
||||
|
||||
export type BaseProps = BareProps & {
|
||||
@ -12,5 +12,6 @@ export type BaseProps = BareProps & {
|
||||
};
|
||||
|
||||
export type Props = BaseProps & {
|
||||
isError?: boolean,
|
||||
label: string
|
||||
};
|
||||
|
||||
@ -1,21 +0,0 @@
|
||||
// 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
|
||||
|
||||
// TODO: Move to portal
|
||||
|
||||
import type { KeyringPair } from '@polkadot/util-keyring/types';
|
||||
|
||||
const assert = require('@polkadot/util/assert');
|
||||
const u8aConcat = require('@polkadot/util/u8a/concat');
|
||||
|
||||
module.exports = function sign (sender?: ?KeyringPair, message: Uint8Array): Uint8Array {
|
||||
assert(sender, 'Expected a valid sender to sign');
|
||||
|
||||
return u8aConcat(
|
||||
message,
|
||||
// $FlowFixMe sender has an actual value
|
||||
sender.sign(message)
|
||||
);
|
||||
};
|
||||
@ -6,19 +6,21 @@
|
||||
import type { RxApiInterface } from '@polkadot/rx-api/types';
|
||||
import type { QueueTx } from '../types';
|
||||
|
||||
import encodeCall from '../encode/call';
|
||||
import encodeCall from '@polkadot/extrinsics-codec/src/encode/call';
|
||||
import u8aConcat from '@polkadot/util/u8a/concat';
|
||||
import u8aToHex from '@polkadot/util/u8a/toHex';
|
||||
|
||||
import keyring from '../keyring';
|
||||
|
||||
import sign from './sign';
|
||||
|
||||
export default function submit (api: RxApiInterface, tx: QueueTx, subject: rxjs$BehaviorSubject<QueueTx>): Promise<void> {
|
||||
const message = encodeCall(tx.publicKey, tx.index, tx.data);
|
||||
const signature = keyring.getPair(tx.publicKey).sign(message);
|
||||
|
||||
console.log('submitExtrinsic: message =', u8aToHex(message));
|
||||
console.log('submitExtrinsic: signature =', u8aToHex(signature));
|
||||
|
||||
return api.author
|
||||
.submitExtrinsic(
|
||||
sign(
|
||||
keyring.getPair(tx.publicKey),
|
||||
encodeCall(tx.publicKey, tx.index, tx.data)
|
||||
)
|
||||
)
|
||||
.submitExtrinsic(u8aConcat(message, signature))
|
||||
.toPromise()
|
||||
.then((result) => {
|
||||
console.log('submitExtrinsic: result=', result);
|
||||
|
||||
@ -36,6 +36,12 @@ function Submission ({ className, subject, style, t }: Props): React$Node {
|
||||
})}
|
||||
subject={subjects.sender}
|
||||
/>
|
||||
<Extrinsic
|
||||
label={t('display.method', {
|
||||
defaultValue: 'submit the following extrinsic'
|
||||
})}
|
||||
subject={subjects.method}
|
||||
/>
|
||||
<Nonce
|
||||
label={t('display.nonce', {
|
||||
defaultValue: 'with an index'
|
||||
@ -43,12 +49,6 @@ function Submission ({ className, subject, style, t }: Props): React$Node {
|
||||
subject={subjects.index}
|
||||
value={subjects.sender}
|
||||
/>
|
||||
<Extrinsic
|
||||
label={t('display.method', {
|
||||
defaultValue: 'submit the following extrinsic'
|
||||
})}
|
||||
subject={subjects.method}
|
||||
/>
|
||||
<div className='extrinsics--Submission-ButtonRow'>
|
||||
<Button subject={subject} />
|
||||
</div>
|
||||
|
||||
@ -18,8 +18,12 @@ type Subjects = {
|
||||
export default function createSubjects (): Subjects {
|
||||
const subjects = {
|
||||
index: new BehaviorSubject(new BN(0)),
|
||||
call: new BehaviorSubject(({ isValid: false }: $Shape<QueueTx>)),
|
||||
method: new BehaviorSubject(({ isValid: false }: $Shape<EncodedParams>)),
|
||||
call: new BehaviorSubject(({
|
||||
isValid: false
|
||||
}: $Shape<QueueTx>)),
|
||||
method: new BehaviorSubject(({
|
||||
isValid: false
|
||||
}: $Shape<EncodedParams>)),
|
||||
sender: new BehaviorSubject(new Uint8Array([]))
|
||||
};
|
||||
|
||||
|
||||
@ -1,34 +0,0 @@
|
||||
// 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 { Extrinsic$Param } from '../extrinsics/types';
|
||||
|
||||
const bnToU8a = require('@polkadot/util/bn/toU8a');
|
||||
const u8aToU8a = require('@polkadot/util/u8a/toU8a');
|
||||
|
||||
// flowlint-next-line unclear-type:off
|
||||
module.exports = function encodeValue ({ type }: Extrinsic$Param, value: any): Uint8Array {
|
||||
switch (type) {
|
||||
case 'AccountId':
|
||||
return value;
|
||||
|
||||
case 'Balance':
|
||||
case 'BlockNumber':
|
||||
case 'u64':
|
||||
return bnToU8a(value, 64, true);
|
||||
|
||||
case 'Bytes':
|
||||
return u8aToU8a(value);
|
||||
|
||||
case 'Proposal':
|
||||
return u8aToU8a(value);
|
||||
|
||||
case 'u32':
|
||||
return bnToU8a(value, 32, true);
|
||||
|
||||
default:
|
||||
throw new Error(`Unable to encode value with type '${type}'`);
|
||||
}
|
||||
};
|
||||
@ -1,14 +0,0 @@
|
||||
// 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 { ExtrinsicsBasic } from './types';
|
||||
|
||||
module.exports = ({
|
||||
description: 'Consensus',
|
||||
methods: {
|
||||
public: [],
|
||||
private: []
|
||||
}
|
||||
}: ExtrinsicsBasic);
|
||||
@ -1,14 +0,0 @@
|
||||
// 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 { ExtrinsicsBasic } from './types';
|
||||
|
||||
module.exports = ({
|
||||
description: 'Council',
|
||||
methods: {
|
||||
public: [],
|
||||
private: []
|
||||
}
|
||||
}: ExtrinsicsBasic);
|
||||
@ -1,14 +0,0 @@
|
||||
// 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 { ExtrinsicsBasic } from './types';
|
||||
|
||||
module.exports = ({
|
||||
description: 'Council Voting',
|
||||
methods: {
|
||||
public: [],
|
||||
private: []
|
||||
}
|
||||
}: ExtrinsicsBasic);
|
||||
@ -1,24 +0,0 @@
|
||||
// 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 { ExtrinsicsBasic } from './types';
|
||||
|
||||
module.exports = ({
|
||||
description: 'Democracy',
|
||||
methods: {
|
||||
public: [
|
||||
{
|
||||
description: 'Propose',
|
||||
index: 0,
|
||||
name: 'propose',
|
||||
params: [
|
||||
{ name: 'proposal', type: 'Proposal' },
|
||||
{ name: 'value', type: 'Balance' }
|
||||
]
|
||||
}
|
||||
],
|
||||
private: []
|
||||
}
|
||||
}: ExtrinsicsBasic);
|
||||
@ -1,82 +0,0 @@
|
||||
// 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
|
||||
|
||||
// TODO: Move to API
|
||||
|
||||
import type { Extrinsic, Extrinsics, ExtrinsicBasic, ExtrinsicsBasic, ExtrinsicsMap, ExtrinsicSection } from './types';
|
||||
|
||||
const assert = require('@polkadot/util/assert');
|
||||
const bnToU8a = require('@polkadot/util/bn/toU8a');
|
||||
const u8aConcat = require('@polkadot/util/u8a/concat');
|
||||
|
||||
const consensus = require('./consensus');
|
||||
const council = require('./council');
|
||||
const councilVoting = require('./councilVoting');
|
||||
const democracy = require('./democracy');
|
||||
const session = require('./session');
|
||||
const staking = require('./staking');
|
||||
|
||||
const map: { [string]: ExtrinsicsBasic } = {
|
||||
consensus, // 0
|
||||
session, // 1
|
||||
staking, // 2
|
||||
democracy, // 3
|
||||
council, // 4
|
||||
councilVoting // 5
|
||||
};
|
||||
const extrinsicsMap: ExtrinsicsMap = {};
|
||||
const extrinsics: Extrinsics = {
|
||||
sections: [],
|
||||
get: (method: string): Extrinsic => {
|
||||
const extrinsic = extrinsicsMap[method];
|
||||
|
||||
assert(extrinsic, `Unable to retrieve extrinsic with name '${method}'`);
|
||||
|
||||
return extrinsic;
|
||||
}
|
||||
};
|
||||
|
||||
const sectionNames = Object.keys(map);
|
||||
|
||||
function mapMethods (sectionSource: ExtrinsicsBasic, section: ExtrinsicSection, isPrivate: boolean): void {
|
||||
const methods = sectionSource.methods[isPrivate ? 'private' : 'public'];
|
||||
|
||||
methods.forEach(({ description, index, name, params }: ExtrinsicBasic) => {
|
||||
const method: Extrinsic = {
|
||||
description,
|
||||
index: u8aConcat(section.index, bnToU8a(index, 8)),
|
||||
isPrivate,
|
||||
name: `${section.name}_${name}`,
|
||||
params
|
||||
};
|
||||
|
||||
extrinsicsMap[method.name] = method;
|
||||
section[isPrivate ? 'hasPrivate' : 'hasPublic'] = true;
|
||||
|
||||
section.methods.push(method);
|
||||
});
|
||||
}
|
||||
|
||||
sectionNames.reduce((sections: Array<ExtrinsicSection>, sectionName: string, index: number) => {
|
||||
const sectionSource = map[sectionName];
|
||||
|
||||
const section: ExtrinsicSection = {
|
||||
description: sectionSource.description,
|
||||
hasPrivate: false,
|
||||
hasPublic: false,
|
||||
index: bnToU8a(index, 8),
|
||||
methods: [],
|
||||
name: sectionName
|
||||
};
|
||||
|
||||
mapMethods(sectionSource, section, true);
|
||||
mapMethods(sectionSource, section, false);
|
||||
|
||||
sections.push(section);
|
||||
|
||||
return sections;
|
||||
}, extrinsics.sections);
|
||||
|
||||
module.exports = extrinsics;
|
||||
@ -1,67 +0,0 @@
|
||||
// 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 { ExtrinsicsBasic } from './types';
|
||||
|
||||
module.exports = ({
|
||||
description: 'Staking',
|
||||
methods: {
|
||||
public: [
|
||||
{
|
||||
description: 'Transfer',
|
||||
index: 0,
|
||||
name: 'transfer',
|
||||
params: [
|
||||
{ name: 'recipient', type: 'AccountId' },
|
||||
{ name: 'value', type: 'Balance', options: { minValue: 1 } }
|
||||
]
|
||||
},
|
||||
{
|
||||
description: 'Stake',
|
||||
index: 1,
|
||||
name: 'stake',
|
||||
params: []
|
||||
},
|
||||
{
|
||||
description: 'Unstake',
|
||||
index: 2,
|
||||
name: 'unstake',
|
||||
params: []
|
||||
}
|
||||
],
|
||||
private: [
|
||||
{
|
||||
description: 'Set sessions per era',
|
||||
index: 0,
|
||||
name: 'setSessionsPerEra',
|
||||
params: [
|
||||
{ name: 'sessions', type: 'u64' }
|
||||
]
|
||||
},
|
||||
{
|
||||
description: 'Set bonding duration',
|
||||
index: 1,
|
||||
name: 'setBondingDuration',
|
||||
params: [
|
||||
{ name: 'duration', type: 'u64' }
|
||||
]
|
||||
},
|
||||
{
|
||||
description: 'Set validator count',
|
||||
index: 2,
|
||||
name: 'setValidatorCount',
|
||||
params: [
|
||||
{ name: 'count', type: 'u32' }
|
||||
]
|
||||
},
|
||||
{
|
||||
description: 'Force new era',
|
||||
index: 3,
|
||||
name: 'forceNewEra',
|
||||
params: []
|
||||
}
|
||||
]
|
||||
}
|
||||
}: ExtrinsicsBasic);
|
||||
@ -4,7 +4,7 @@
|
||||
// @flow
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { Extrinsic } from './extrinsics/types';
|
||||
import type { Extrinsic } from '@polkadot/extrinsics/types';
|
||||
|
||||
export type BareProps = {
|
||||
className?: string,
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "@polkadot/portal",
|
||||
"name": "@polkadot/apps",
|
||||
"version": "0.1.3",
|
||||
"description": "A Portal into the Polkadot network",
|
||||
"main": "src/index.js",
|
||||
"description": "An Apps portal into the Polkadot network",
|
||||
"main": "index.js",
|
||||
"homepage": ".",
|
||||
"repository": "https://github.com/polkadot-js/portal.git",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
@ -16,8 +16,8 @@
|
||||
"devDependencies": {
|
||||
"@polkadot/app-explorer": "^0.1.3",
|
||||
"@polkadot/app-extrinsics": "^0.1.3",
|
||||
"@polkadot/rx-react": "^0.4.6",
|
||||
"@polkadot/ui-react": "^0.9.11",
|
||||
"@polkadot/rx-react": "^0.4.7",
|
||||
"@polkadot/ui-react": "^0.9.12",
|
||||
"i18next": "^11.1.1",
|
||||
"i18next-browser-languagedetector": "^2.2.0",
|
||||
"i18next-xhr-backend": "^1.5.1",
|
||||
BIN
packages/apps/public/favicon.ico
Normal file
BIN
packages/apps/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
@ -6,7 +6,7 @@
|
||||
<meta name="theme-color" content="#000000">
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
|
||||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||
<title>Polkadot Portal</title>
|
||||
<title>Polkadot Apps Portal</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { Routes } from '../types';
|
||||
|
||||
import Explorer from '@polkadot/app-explorer';
|
||||
import Explorer from '@polkadot/app-explorer/src';
|
||||
|
||||
export default ([
|
||||
{
|
||||
@ -5,7 +5,7 @@
|
||||
|
||||
import type { Routes } from '../types';
|
||||
|
||||
import Extrinsics from '@polkadot/app-extrinsics';
|
||||
import Extrinsics from '@polkadot/app-extrinsics/src';
|
||||
|
||||
export default ([
|
||||
{
|
||||
15
packages/extrinsics-codec/LICENSE
Normal file
15
packages/extrinsics-codec/LICENSE
Normal file
@ -0,0 +1,15 @@
|
||||
ISC License (ISC)
|
||||
|
||||
Copyright 2017-2018 Jaco Greeff <jacogr@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
1
packages/extrinsics-codec/README.md
Normal file
1
packages/extrinsics-codec/README.md
Normal file
@ -0,0 +1 @@
|
||||
# @polkadot/extrinsics-codec
|
||||
21
packages/extrinsics-codec/package.json
Normal file
21
packages/extrinsics-codec/package.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@polkadot/extrinsics-codec",
|
||||
"version": "0.1.3",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/polkadot-js/portal.git",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"license": "ISC",
|
||||
"scripts": {
|
||||
"build": "polkadot-dev-build-babel",
|
||||
"check": "stylelint 'src/**/*.css' && eslint src && flow check",
|
||||
"test": "jest --coverage"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/extrinsics": "^0.1.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/util": "^0.19.4",
|
||||
"babel-runtime": "^6.26.0",
|
||||
"bn.js": "^4.11.8"
|
||||
}
|
||||
}
|
||||
@ -3,8 +3,6 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
// TODO: Move to API
|
||||
|
||||
import type BN from 'bn.js';
|
||||
|
||||
const bnToU8a = require('@polkadot/util/bn/toU8a');
|
||||
@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Extrinsic } from '../extrinsics/types';
|
||||
import type { Extrinsic } from '@polkadot/extrinsics/types';
|
||||
|
||||
const u8aConcat = require('@polkadot/util/u8a/concat');
|
||||
|
||||
@ -3,10 +3,8 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
// TODO: Move to API
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { Extrinsic } from '../extrinsics/types';
|
||||
import type { Extrinsic } from '@polkadot/extrinsics/types';
|
||||
|
||||
const encodeCall = require('./call');
|
||||
const encodeExtrinsic = require('./extrinsic');
|
||||
32
packages/extrinsics-codec/src/encode/param.js
Normal file
32
packages/extrinsics-codec/src/encode/param.js
Normal file
@ -0,0 +1,32 @@
|
||||
// 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 { Extrinsic$Param } from '@polkadot/extrinsics/types';
|
||||
|
||||
const u8aConcat = require('@polkadot/util/u8a/concat');
|
||||
const bnToU8a = require('@polkadot/util/bn/toU8a');
|
||||
|
||||
const encodeType = require('./type');
|
||||
|
||||
// flowlint-next-line unclear-type:off
|
||||
module.exports = function encodeParam (param: Extrinsic$Param, value: any): Uint8Array {
|
||||
if (Array.isArray(param.type)) {
|
||||
const [outer, inner] = param.type;
|
||||
|
||||
switch (outer) {
|
||||
case 'Array':
|
||||
return u8aConcat(
|
||||
bnToU8a((value: Array<*>).length, 32, true),
|
||||
u8aConcat.apply(null, (value: Array<*>).map((v) =>
|
||||
encodeType(inner, v)
|
||||
))
|
||||
);
|
||||
|
||||
default:
|
||||
return encodeType(inner, value);
|
||||
}
|
||||
}
|
||||
return encodeType(param.type, value);
|
||||
};
|
||||
@ -3,7 +3,7 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { Extrinsic$Params } from '../extrinsics/types';
|
||||
import type { Extrinsic$Params } from '@polkadot/extrinsics/types';
|
||||
|
||||
const u8aConcat = require('@polkadot/util/u8a/concat');
|
||||
|
||||
47
packages/extrinsics-codec/src/encode/type.js
Normal file
47
packages/extrinsics-codec/src/encode/type.js
Normal file
@ -0,0 +1,47 @@
|
||||
// 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 { Extrinsic$TypeName } from '@polkadot/extrinsics/types';
|
||||
|
||||
const bnToU8a = require('@polkadot/util/bn/toU8a');
|
||||
const u8aToU8a = require('@polkadot/util/u8a/toU8a');
|
||||
|
||||
// flowlint-next-line unclear-type:off
|
||||
module.exports = function encodeType (type: Extrinsic$TypeName, value: any): Uint8Array {
|
||||
try {
|
||||
switch (type) {
|
||||
case 'AccountId':
|
||||
return value;
|
||||
|
||||
case 'Balance':
|
||||
case 'BlockNumber':
|
||||
case 'u64':
|
||||
return bnToU8a(value, 64, true);
|
||||
|
||||
case 'Bytes':
|
||||
case 'Hash':
|
||||
return u8aToU8a(value);
|
||||
|
||||
case 'bool':
|
||||
return bnToU8a(value ? 1 : 0, 8, true);
|
||||
|
||||
case 'Proposal':
|
||||
return u8aToU8a(value);
|
||||
|
||||
case 'u32':
|
||||
return bnToU8a(value, 32, true);
|
||||
|
||||
case 'VoteThreshold':
|
||||
return bnToU8a(value || 0, 8, true);
|
||||
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error, 'with', value, 'encoded with', type);
|
||||
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
15
packages/extrinsics-polkadot/LICENSE
Normal file
15
packages/extrinsics-polkadot/LICENSE
Normal file
@ -0,0 +1,15 @@
|
||||
ISC License (ISC)
|
||||
|
||||
Copyright 2017-2018 Jaco Greeff <jacogr@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
1
packages/extrinsics-polkadot/README.md
Normal file
1
packages/extrinsics-polkadot/README.md
Normal file
@ -0,0 +1 @@
|
||||
# @polkadot/extrinsics
|
||||
17
packages/extrinsics-polkadot/package.json
Normal file
17
packages/extrinsics-polkadot/package.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@polkadot/extrinsics-polkadot",
|
||||
"version": "0.1.3",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/polkadot-js/portal.git",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"license": "ISC",
|
||||
"scripts": {
|
||||
"build": "polkadot-dev-build-babel",
|
||||
"check": "stylelint 'src/**/*.css' && eslint src && flow check",
|
||||
"test": "jest --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/extrinsics": "^0.1.3",
|
||||
"babel-runtime": "^6.26.0"
|
||||
}
|
||||
}
|
||||
30
packages/extrinsics-polkadot/src/consensus.js
Normal file
30
packages/extrinsics-polkadot/src/consensus.js
Normal file
@ -0,0 +1,30 @@
|
||||
// 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 { ExtrinsicsBaseSection } from '@polkadot/extrinsics/types';
|
||||
|
||||
module.exports = ({
|
||||
description: 'Consensus',
|
||||
methods: {
|
||||
public: {
|
||||
reportMisbehavior: {
|
||||
description: 'Report misbehavior',
|
||||
index: 0,
|
||||
params: {
|
||||
report: { type: 'MisbehaviorReport' }
|
||||
}
|
||||
}
|
||||
},
|
||||
private: {
|
||||
setCode: {
|
||||
description: 'Set new code',
|
||||
index: 0,
|
||||
params: {
|
||||
code: { type: 'Bytes' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}: ExtrinsicsBaseSection);
|
||||
85
packages/extrinsics-polkadot/src/council.js
Normal file
85
packages/extrinsics-polkadot/src/council.js
Normal file
@ -0,0 +1,85 @@
|
||||
// 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 { ExtrinsicsBaseSection } from '@polkadot/extrinsics/types';
|
||||
|
||||
module.exports = ({
|
||||
description: 'Council',
|
||||
methods: {
|
||||
public: {
|
||||
setApprovals: {
|
||||
description: 'Set approvals',
|
||||
index: 0,
|
||||
params: {
|
||||
votes: { type: ['Array', 'bool'] },
|
||||
index: { type: 'u32' }
|
||||
}
|
||||
},
|
||||
reapInactiveVoter: {
|
||||
description: 'Remove insactive voter',
|
||||
index: 1,
|
||||
params: {
|
||||
signedIndex: { type: 'u32' },
|
||||
who: { type: 'AccountId' },
|
||||
whoIndex: { type: 'u32' },
|
||||
assumedVoteIndex: { type: 'u32' }
|
||||
}
|
||||
},
|
||||
retractVoter: {
|
||||
description: 'Retract voter',
|
||||
index: 2,
|
||||
params: {
|
||||
index: { type: 'u32' }
|
||||
}
|
||||
},
|
||||
submitCandidacy: {
|
||||
description: 'Submit candidacy',
|
||||
index: 3,
|
||||
params: {
|
||||
slot: { type: 'u32' }
|
||||
}
|
||||
},
|
||||
presentWinner: {
|
||||
description: 'Present winner',
|
||||
index: 4,
|
||||
params: {
|
||||
candidate: { type: 'AccountId' },
|
||||
total: { type: 'Balance' },
|
||||
index: { type: 'u32' }
|
||||
}
|
||||
}
|
||||
},
|
||||
private: {
|
||||
setDesiredSeats: {
|
||||
description: 'Set desired seats',
|
||||
index: 0,
|
||||
params: {
|
||||
count: { type: 'u32' }
|
||||
}
|
||||
},
|
||||
removeMember: {
|
||||
description: 'Remove member',
|
||||
index: 1,
|
||||
params: {
|
||||
member: { type: 'AccountId' }
|
||||
}
|
||||
},
|
||||
setPresentationDuration: {
|
||||
description: 'Set presentation duration',
|
||||
index: 2,
|
||||
params: {
|
||||
duration: { type: 'u64' }
|
||||
}
|
||||
},
|
||||
setTermDuration: {
|
||||
description: 'Set term duration',
|
||||
index: 3,
|
||||
params: {
|
||||
duration: { type: 'u64' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}: ExtrinsicsBaseSection);
|
||||
52
packages/extrinsics-polkadot/src/councilVoting.js
Normal file
52
packages/extrinsics-polkadot/src/councilVoting.js
Normal file
@ -0,0 +1,52 @@
|
||||
// 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 { ExtrinsicsBaseSection } from '@polkadot/extrinsics/types';
|
||||
|
||||
module.exports = ({
|
||||
description: 'Council Voting',
|
||||
methods: {
|
||||
public: {
|
||||
propose: {
|
||||
description: 'Propose',
|
||||
index: 0,
|
||||
params: {
|
||||
proposal: { type: 'Proposal' }
|
||||
}
|
||||
},
|
||||
vote: {
|
||||
description: 'Vote',
|
||||
index: 1,
|
||||
params: {
|
||||
proposal: { type: 'Hash' },
|
||||
approve: { type: 'bool' }
|
||||
}
|
||||
},
|
||||
veto: {
|
||||
description: 'Veto',
|
||||
index: 2,
|
||||
params: {
|
||||
proposal: { type: 'Hash' }
|
||||
}
|
||||
}
|
||||
},
|
||||
private: {
|
||||
setCooloffPeriod: {
|
||||
description: 'Set cooloff period',
|
||||
index: 0,
|
||||
params: {
|
||||
blocks: { type: 'BlockNumber' }
|
||||
}
|
||||
},
|
||||
setVotingPeriod: {
|
||||
description: 'Set voting period',
|
||||
index: 1,
|
||||
params: {
|
||||
blocks: { type: 'BlockNumber' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}: ExtrinsicsBaseSection);
|
||||
54
packages/extrinsics-polkadot/src/democracy.js
Normal file
54
packages/extrinsics-polkadot/src/democracy.js
Normal file
@ -0,0 +1,54 @@
|
||||
// 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 { ExtrinsicsBaseSection } from '@polkadot/extrinsics/types';
|
||||
|
||||
module.exports = ({
|
||||
description: 'Democracy',
|
||||
methods: {
|
||||
public: {
|
||||
propose: {
|
||||
description: 'Propose',
|
||||
index: 0,
|
||||
params: {
|
||||
proposal: { type: 'Proposal' },
|
||||
value: { type: 'Balance' }
|
||||
}
|
||||
},
|
||||
second: {
|
||||
description: 'Second',
|
||||
index: 1,
|
||||
params: {
|
||||
proposal: { type: 'u32' }
|
||||
}
|
||||
},
|
||||
vote: {
|
||||
description: 'Vote',
|
||||
index: 2,
|
||||
params: {
|
||||
referendumIndex: { type: 'u32' },
|
||||
vote: { type: 'bool' }
|
||||
}
|
||||
}
|
||||
},
|
||||
private: {
|
||||
startReferendum: {
|
||||
description: 'Start referendum',
|
||||
index: 0,
|
||||
params: {
|
||||
proposal: { type: 'Proposal' },
|
||||
voteThreshold: { type: 'VoteThreshold' }
|
||||
}
|
||||
},
|
||||
cancelReferendum: {
|
||||
description: 'Cancel referendum',
|
||||
index: 1,
|
||||
params: {
|
||||
referendumIndex: { type: 'u32' }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}: ExtrinsicsBaseSection);
|
||||
26
packages/extrinsics-polkadot/src/index.js
Normal file
26
packages/extrinsics-polkadot/src/index.js
Normal file
@ -0,0 +1,26 @@
|
||||
// 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 { ExtrinsicsBaseMap } from '@polkadot/extrinsics/types';
|
||||
|
||||
const init = require('@polkadot/extrinsics');
|
||||
|
||||
const consensus = require('./consensus');
|
||||
const council = require('./council');
|
||||
const councilVoting = require('./councilVoting');
|
||||
const democracy = require('./democracy');
|
||||
const session = require('./session');
|
||||
const staking = require('./staking');
|
||||
|
||||
const map: ExtrinsicsBaseMap = {
|
||||
consensus,
|
||||
council,
|
||||
councilVoting,
|
||||
democracy,
|
||||
session,
|
||||
staking
|
||||
};
|
||||
|
||||
module.exports = init(map);
|
||||
35
packages/extrinsics-polkadot/src/session.js
Normal file
35
packages/extrinsics-polkadot/src/session.js
Normal file
@ -0,0 +1,35 @@
|
||||
// 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 { ExtrinsicsBaseSection } from '@polkadot/extrinsics/types';
|
||||
|
||||
module.exports = ({
|
||||
description: 'Session',
|
||||
methods: {
|
||||
public: {
|
||||
setKey: {
|
||||
description: 'Set session key',
|
||||
index: 0,
|
||||
params: {
|
||||
key: { type: 'SessionKey' }
|
||||
}
|
||||
}
|
||||
},
|
||||
private: {
|
||||
setLength: {
|
||||
description: 'Set session length',
|
||||
index: 0,
|
||||
params: {
|
||||
length: { type: 'u64' }
|
||||
}
|
||||
},
|
||||
forceNewSession: {
|
||||
description: 'Force new session',
|
||||
index: 1,
|
||||
params: {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}: ExtrinsicsBaseSection);
|
||||
60
packages/extrinsics-polkadot/src/staking.js
Normal file
60
packages/extrinsics-polkadot/src/staking.js
Normal file
@ -0,0 +1,60 @@
|
||||
// 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 { ExtrinsicsBaseSection } from '@polkadot/extrinsics/types';
|
||||
|
||||
module.exports = ({
|
||||
description: 'Staking',
|
||||
methods: {
|
||||
public: {
|
||||
transfer: {
|
||||
description: 'Transfer',
|
||||
index: 0,
|
||||
params: {
|
||||
recipient: { type: 'AccountId' },
|
||||
value: { type: 'Balance', options: { minValue: 1 } }
|
||||
}
|
||||
},
|
||||
stake: {
|
||||
description: 'Stake',
|
||||
index: 1,
|
||||
params: {}
|
||||
},
|
||||
unstake: {
|
||||
description: 'Unstake',
|
||||
index: 2,
|
||||
params: {}
|
||||
}
|
||||
},
|
||||
private: {
|
||||
setSessionsPerEra: {
|
||||
description: 'Set sessions per era',
|
||||
index: 0,
|
||||
params: {
|
||||
sessions: { type: 'u64' }
|
||||
}
|
||||
},
|
||||
setBondingDuration: {
|
||||
description: 'Set bonding duration',
|
||||
index: 1,
|
||||
params: {
|
||||
duration: { type: 'u64' }
|
||||
}
|
||||
},
|
||||
setValidatorCount: {
|
||||
description: 'Set validator count',
|
||||
index: 2,
|
||||
params: {
|
||||
count: { type: 'u32' }
|
||||
}
|
||||
},
|
||||
forceNewEra: {
|
||||
description: 'Force new era',
|
||||
index: 3,
|
||||
params: {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}: ExtrinsicsBaseSection);
|
||||
15
packages/extrinsics/LICENSE
Normal file
15
packages/extrinsics/LICENSE
Normal file
@ -0,0 +1,15 @@
|
||||
ISC License (ISC)
|
||||
|
||||
Copyright 2017-2018 Jaco Greeff <jacogr@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
1
packages/extrinsics/README.md
Normal file
1
packages/extrinsics/README.md
Normal file
@ -0,0 +1 @@
|
||||
# @polkadot/extrinsics
|
||||
@ -3,12 +3,6 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
import type { ExtrinsicsBasic } from './types';
|
||||
// HACK: Only here because of CRA's lack of proper workspace + src/* support
|
||||
|
||||
module.exports = ({
|
||||
description: 'Session',
|
||||
methods: {
|
||||
public: [],
|
||||
private: []
|
||||
}
|
||||
}: ExtrinsicsBasic);
|
||||
module.exports = require('./src');
|
||||
17
packages/extrinsics/package.json
Normal file
17
packages/extrinsics/package.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "@polkadot/extrinsics",
|
||||
"version": "0.1.3",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/polkadot-js/portal.git",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"license": "ISC",
|
||||
"scripts": {
|
||||
"build": "polkadot-dev-build-babel",
|
||||
"check": "stylelint 'src/**/*.css' && eslint src && flow check",
|
||||
"test": "jest --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/util": "^0.19.4",
|
||||
"babel-runtime": "^6.26.0"
|
||||
}
|
||||
}
|
||||
46
packages/extrinsics/src/index.js
Normal file
46
packages/extrinsics/src/index.js
Normal file
@ -0,0 +1,46 @@
|
||||
// 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 { Extrinsic, Extrinsics, ExtrinsicsBaseMap, ExtrinsicSectionName, ExtrinsicsMap, ExtrinsicSection } from './types';
|
||||
|
||||
const assert = require('@polkadot/util/assert');
|
||||
|
||||
const expandSection = require('./section');
|
||||
|
||||
// NOTE: Order here is important, counts as an index
|
||||
const BASIC_KEYS: Array<ExtrinsicSectionName> = ['consensus', 'session', 'staking', 'democracy', 'council', 'councilVoting'];
|
||||
|
||||
module.exports = function init (baseMap: ExtrinsicsBaseMap): Extrinsics {
|
||||
const map: ExtrinsicsMap = {};
|
||||
|
||||
const get = (method: string): Extrinsic => {
|
||||
const extrinsic = map[method];
|
||||
|
||||
assert(extrinsic, `Unable to retrieve extrinsic with name '${method}'`);
|
||||
|
||||
return extrinsic;
|
||||
};
|
||||
|
||||
const sections: Array<ExtrinsicSection> = BASIC_KEYS.reduce((sections: Array<ExtrinsicSection>, sectionName: ExtrinsicSectionName, sectionIndex: number) => {
|
||||
const sectionSource = baseMap[sectionName];
|
||||
|
||||
if (sectionSource) {
|
||||
const section = expandSection(sectionSource, sectionName, sectionIndex);
|
||||
|
||||
section.methods.forEach((method) => {
|
||||
map[method.name] = method;
|
||||
});
|
||||
|
||||
sections.push(section);
|
||||
}
|
||||
|
||||
return sections;
|
||||
}, []);
|
||||
|
||||
return {
|
||||
get,
|
||||
sections
|
||||
};
|
||||
};
|
||||
35
packages/extrinsics/src/methods.js
Normal file
35
packages/extrinsics/src/methods.js
Normal file
@ -0,0 +1,35 @@
|
||||
// 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 { Extrinsic, ExtrinsicsBaseSection, ExtrinsicSectionName } from './types';
|
||||
|
||||
const bnToU8a = require('@polkadot/util/bn/toU8a');
|
||||
const u8aConcat = require('@polkadot/util/u8a/concat');
|
||||
|
||||
const expandParams = require('./params');
|
||||
|
||||
const TYPES = ['private', 'public'];
|
||||
|
||||
module.exports = function expandMethods (sectionSource: ExtrinsicsBaseSection, sectionName: ExtrinsicSectionName, sectionIndex: Uint8Array): Array<Extrinsic> {
|
||||
const [priMethods, pubMethods] = TYPES.map((type) => {
|
||||
const isPrivate = type === 'private';
|
||||
const methods = sectionSource.methods[type];
|
||||
const methodNames = Object.keys(methods);
|
||||
|
||||
return methodNames.map((name: string): Extrinsic => {
|
||||
const { description, index, params } = methods[name];
|
||||
|
||||
return {
|
||||
description,
|
||||
index: u8aConcat(sectionIndex, bnToU8a(index, 8)),
|
||||
isPrivate,
|
||||
name: `${sectionName}_${name}`,
|
||||
params: expandParams(params)
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
return [].concat(priMethods, pubMethods);
|
||||
};
|
||||
19
packages/extrinsics/src/params.js
Normal file
19
packages/extrinsics/src/params.js
Normal file
@ -0,0 +1,19 @@
|
||||
// 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 { ExtrinsicBase$Params, Extrinsic$Param, Extrinsic$Params } from './types';
|
||||
|
||||
module.exports = function expandParams (base: ExtrinsicBase$Params): Extrinsic$Params {
|
||||
const paramNames = Object.keys(base);
|
||||
|
||||
return paramNames.map((name: string): Extrinsic$Param => {
|
||||
const source = base[name];
|
||||
|
||||
return {
|
||||
...source,
|
||||
name
|
||||
};
|
||||
});
|
||||
};
|
||||
23
packages/extrinsics/src/section.js
Normal file
23
packages/extrinsics/src/section.js
Normal file
@ -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 { ExtrinsicSectionName, ExtrinsicsBaseSection, ExtrinsicSection } from './types';
|
||||
|
||||
const bnToU8a = require('@polkadot/util/bn/toU8a');
|
||||
|
||||
const expandMethods = require('./methods');
|
||||
|
||||
module.exports = function expandSection (sectionSource: ExtrinsicsBaseSection, name: ExtrinsicSectionName, sectionIndex: number): ExtrinsicSection {
|
||||
const index = bnToU8a(sectionIndex, 8);
|
||||
|
||||
return {
|
||||
description: sectionSource.description || name,
|
||||
hasPrivate: !!Object.keys(sectionSource.methods.private).length,
|
||||
hasPublic: !!Object.keys(sectionSource.methods.public).length,
|
||||
index,
|
||||
methods: expandMethods(sectionSource, name, index),
|
||||
name
|
||||
};
|
||||
};
|
||||
@ -3,7 +3,47 @@
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
// @flow
|
||||
|
||||
export type Extrinsic$Type = 'AccountId' | 'Balance' | 'BlockNumber' | 'Bytes' | 'Proposal' | 'u32' | 'u64';
|
||||
export type Extrinsic$TypeName = 'AccountId' | 'Balance' | 'BlockNumber' | 'bool' | 'Bytes' | 'Hash' | 'MisbehaviorReport' | 'Proposal' | 'SessionKey' | 'u32' | 'u64' | 'VoteThreshold';
|
||||
|
||||
export type Extrinsic$Type =
|
||||
Extrinsic$TypeName |
|
||||
['Array', Extrinsic$TypeName];
|
||||
|
||||
export type ExtrinsicBase$Param = {
|
||||
options?: {
|
||||
initValue?: mixed,
|
||||
minValue?: mixed,
|
||||
maxValue?: mixed
|
||||
},
|
||||
type: Extrinsic$Type
|
||||
};
|
||||
|
||||
export type ExtrinsicBase$Params = {
|
||||
[string]: ExtrinsicBase$Param
|
||||
};
|
||||
|
||||
export type ExtrinsicBase = {
|
||||
description: string,
|
||||
index: number,
|
||||
params: ExtrinsicBase$Params
|
||||
}
|
||||
|
||||
export type ExtrinsicSectionName = 'consensus' | 'council' | 'councilVoting' | 'democracy' | 'session' | 'staking';
|
||||
|
||||
export type ExtrinsicsBaseSection = {
|
||||
description: string,
|
||||
methods: {
|
||||
private: {
|
||||
[string]: ExtrinsicBase
|
||||
},
|
||||
public: {
|
||||
[string]: ExtrinsicBase
|
||||
}
|
||||
}
|
||||
}
|
||||
export type ExtrinsicsBaseMap = {
|
||||
[ExtrinsicSectionName]: ExtrinsicsBaseSection
|
||||
};
|
||||
|
||||
export type Extrinsic$Param = {
|
||||
name: string,
|
||||
@ -17,22 +57,6 @@ export type Extrinsic$Param = {
|
||||
|
||||
export type Extrinsic$Params = Array<Extrinsic$Param>;
|
||||
|
||||
export type ExtrinsicBasic = {
|
||||
description: string,
|
||||
index: number,
|
||||
isPrivate?: boolean,
|
||||
name: string,
|
||||
params: Extrinsic$Params
|
||||
}
|
||||
|
||||
export type ExtrinsicsBasic = {
|
||||
description: string,
|
||||
methods: {
|
||||
private: Array<ExtrinsicBasic>,
|
||||
public: Array<ExtrinsicBasic>
|
||||
}
|
||||
}
|
||||
|
||||
export type Extrinsic = {
|
||||
description: string,
|
||||
index: Uint8Array,
|
||||
@ -47,7 +71,7 @@ export type ExtrinsicSection = {
|
||||
hasPublic: boolean,
|
||||
index: Uint8Array,
|
||||
methods: Array<Extrinsic>,
|
||||
name: string
|
||||
name: ExtrinsicSectionName
|
||||
};
|
||||
|
||||
export type Extrinsics = {
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.8 KiB |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user