Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/api-format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@polkadot/api-jsonrpc": "^0.6.4"
},
"dependencies": {
"@polkadot/primitives-json": "^0.1.5",
"@polkadot/util": "^0.6.7",
"babel-runtime": "^6.26.0"
}
Expand Down
26 changes: 26 additions & 0 deletions packages/api-format/src/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// ISC, Copyright 2017 Jaco Greeff
// @flow

import type { FormatInputType, InterfaceInputType } from '@polkadot/api-jsonrpc/types';
import type { FormatterFunction } from './types';

const accountIdToJson = require('@polkadot/primitives-json/accountId/toJson');
const h256ToJson = require('@polkadot/primitives-json/h256/toJson');
const hashToJson = require('@polkadot/primitives-json/hash/toJson');

const formatNoop = require('./noop');
const util = require('./util');

const formatters: { [FormatInputType]: FormatterFunction } = {
'Address': accountIdToJson,
'CallData': hashToJson,
'H256': h256ToJson,
'HeaderHash': h256ToJson,
'String': formatNoop
};

module.exports = function formatInputs (inputs: Array<InterfaceInputType>, values: Array<any>): Array<any> {
const types = inputs.map(({ type }) => type);

return util.formatArray(formatters, types, values);
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// ISC, Copyright 2017 Jaco Greeff

const format = require('./index');
const { formatInputs } = require('./index');

describe('input', () => {
describe('formatInputs', () => {
describe('format', () => {
it('formats each value in an array', () => {
expect(
format(
formatInputs(
[
{ name: 'foo', type: 'Address' },
{ name: 'bar', type: 'H256' }
Expand Down
10 changes: 0 additions & 10 deletions packages/api-format/src/input/address.js

This file was deleted.

13 changes: 0 additions & 13 deletions packages/api-format/src/input/address.spec.js

This file was deleted.

33 changes: 0 additions & 33 deletions packages/api-format/src/input/hex.js

This file was deleted.

53 changes: 0 additions & 53 deletions packages/api-format/src/input/hex.spec.js

This file was deleted.

24 changes: 0 additions & 24 deletions packages/api-format/src/input/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
// @flow

import type { FormatOutputType, InterfaceOutputType } from '@polkadot/api-jsonrpc/types';
import type { FormatterFunction } from '../types';
import type { FormatterFunction } from './types';

const formatNoop = require('../noop');
const util = require('../util');
const headerFromJson = require('@polkadot/primitives-json/header/fromJson');

const formatNoop = require('./noop');
const util = require('./util');

const formatters: { [FormatOutputType]: FormatterFunction } = {
'Header': formatNoop,
'Header': headerFromJson,
'OutData': formatNoop,
'StorageData': formatNoop
};

module.exports = function format (output: InterfaceOutputType, value: any): any {
module.exports = function formatOutput (output: InterfaceOutputType, value: any): any {
return util.format(formatters, output.type, value);
};
40 changes: 40 additions & 0 deletions packages/api-format/src/output.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// ISC, Copyright 2017 Jaco Greeff

const BN = require('bn.js');

const { formatOutput } = require('./index');

describe('formatOutput', () => {
describe('format', () => {
it('formats the value', () => {
expect(
JSON.stringify(
formatOutput({ type: 'Header' }, {
parentHash: '0x1234',
number: '0x1234',
stateRoot: '0x5678',
transactionRoot: '0xabcd',
digest: {
parachainActivityBitfield: '0x1234',
logs: ['0x5678', '0x789a']
}
})
)
).toEqual(
JSON.stringify({
parentHash: '0x1234',
number: new BN(0x1234),
stateRoot: '0x5678',
transactionRoot: '0xabcd',
digest: {
parachainActivityBitfield: Buffer.from([0x12, 0x34]),
logs: [
Buffer.from([0x56, 0x78]),
Buffer.from([0x78, 0x9a])
]
}
})
);
});
});
});
13 changes: 0 additions & 13 deletions packages/api-format/src/output/index.spec.js

This file was deleted.

4 changes: 1 addition & 3 deletions packages/api-format/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ function format (formatters: { [any]: FormatterFunction }, type: string, value:

function formatArray (formatters: { [any]: FormatterFunction }, types: Array<string>, values: Array<any>): Array<any> {
return types.map((type, index) => {
const value = values[index];

return format(formatters, type, value);
return format(formatters, type, values[index]);
});
}

Expand Down
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@
stylelint "^8.2.0"
stylelint-config-standard "^18.0.0"

"@polkadot/primitives-json@^0.1.5":
version "0.1.5"
resolved "https://registry.yarnpkg.com/@polkadot/primitives-json/-/primitives-json-0.1.5.tgz#bd3f1dc2532190ebf78ba9d89f64b518d105eae8"
dependencies:
"@polkadot/primitives" "^0.1.5"
"@polkadot/util" "^0.6.8"

"@polkadot/primitives@^0.1.5":
version "0.1.5"
resolved "https://registry.yarnpkg.com/@polkadot/primitives/-/primitives-0.1.5.tgz#6eb2fbccb06bda8bd774d205528d9b3a1d3e0b21"

"@polkadot/util@^0.6.7":
version "0.6.7"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.6.7.tgz#eb9a6bd3717b69c962f6fb70830ebc60380c333f"
Expand All @@ -99,6 +110,14 @@
bn.js "^4.11.8"
keccak "^1.3.0"

"@polkadot/util@^0.6.8":
version "0.6.10"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.6.10.tgz#09417e607ec64a404ae63fa64f8f008d91c79856"
dependencies:
babel-runtime "^6.26.0"
bn.js "^4.11.8"
keccak "^1.3.0"

JSONStream@^1.0.4:
version "1.3.1"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.1.tgz#707f761e01dae9e16f1bcf93703b78c70966579a"
Expand Down