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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test": "jest --coverage"
},
"devDependencies": {
"@polkadot/dev": "^0.13.3",
"@polkadot/dev": "^0.13.4",
"lerna": "^2.5.1"
}
}
4 changes: 2 additions & 2 deletions packages/api-format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"@polkadot/api-jsonrpc": "^0.6.5"
},
"dependencies": {
"@polkadot/primitives-json": "^0.1.5",
"@polkadot/util": "^0.6.7",
"@polkadot/primitives-json": "^0.3.1",
"@polkadot/util": "^0.9.1",
"babel-runtime": "^6.26.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ISC, Copyright 2017 Jaco Greeff
// @flow

module.exports = function format (value: any): any {
module.exports = function echo (value: any): any {
return value;
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// ISC, Copyright 2017 Jaco Greeff

const format = require('./noop');
const echo = require('./echo');

describe('noop', () => {
describe('echo', () => {
it('returns input value as output value', () => {
const input = { 'some': 'object' };

expect(
format(input)
echo(input)
).toEqual(input);
});
});
19 changes: 10 additions & 9 deletions packages/api-format/src/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
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 accountIdEncode = require('@polkadot/primitives-json/accountId/encode');
const h256Encode = require('@polkadot/primitives-json/h256/encode');
const hashEncode = require('@polkadot/primitives-json/hash/encode');
const headerHashEncode = require('@polkadot/primitives-json/headerHash/encode');

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

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

module.exports = function formatInputs (inputs: Array<InterfaceInputType>, values: Array<any>): Array<any> {
Expand Down
28 changes: 13 additions & 15 deletions packages/api-format/src/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@
const { formatInputs } = require('./index');

describe('formatInputs', () => {
describe('format', () => {
it('formats each value in an array', () => {
expect(
formatInputs(
[
{ name: 'foo', type: 'Address' },
{ name: 'bar', type: 'H256' }
],
['0x1234', '0xabcd']
)
).toEqual([
'0x0000000000000000000000000000000000001234',
'0x000000000000000000000000000000000000000000000000000000000000abcd'
]);
});
it('formats each value in an array', () => {
expect(
formatInputs(
[
{ name: 'foo', type: 'Address' },
{ name: 'bar', type: 'H256' }
],
['0x1234', '0xabcd']
)
).toEqual([
'0x0000000000000000000000000000000000001234',
'0x000000000000000000000000000000000000000000000000000000000000abcd'
]);
});
});
10 changes: 5 additions & 5 deletions packages/api-format/src/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import type { FormatOutputType, InterfaceOutputType } from '@polkadot/api-jsonrpc/types';
import type { FormatterFunction } from './types';

const headerFromJson = require('@polkadot/primitives-json/header/fromJson');
const headerDecode = require('@polkadot/primitives-json/header/decode');

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

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

module.exports = function formatOutput (output: InterfaceOutputType, value: any): any {
Expand Down
48 changes: 23 additions & 25 deletions packages/api-format/src/output.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,34 @@ 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({
it('formats the value', () => {
expect(
JSON.stringify(
formatOutput({ type: 'Header' }, {
parentHash: '0x1234',
number: new BN(0x1234),
number: '0x1234',
stateRoot: '0x5678',
transactionRoot: '0xabcd',
digest: {
parachainActivityBitfield: Buffer.from([0x12, 0x34]),
logs: [
Buffer.from([0x56, 0x78]),
Buffer.from([0x78, 0x9a])
]
parachainActivityBitfield: '0x1234',
logs: ['0x5678', '0x789a']
}
})
);
});
)
).toEqual(
JSON.stringify({
parentHash: '0x0000000000000000000000000000000000000000000000000000000000001234',
number: new BN(0x1234),
stateRoot: '0x0000000000000000000000000000000000000000000000000000000000005678',
transactionRoot: '0x000000000000000000000000000000000000000000000000000000000000abcd',
digest: {
parachainActivityBitfield: Buffer.from([0x12, 0x34]),
logs: [
Buffer.from([0x56, 0x78]),
Buffer.from([0x78, 0x9a])
]
}
})
);
});
});
6 changes: 3 additions & 3 deletions packages/api-format/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import type { FormatterFunction } from './types';

const assert = require('@polkadot/util/assert');
const isUndefined = require('@polkadot/util/is/undefined');
const formatNoop = require('./noop');
const echo = require('./echo');

const arrayTypeRegex = /\[\]$/;

function formatSingleType (formatters: { [any]: FormatterFunction }, type: string, value: any): any {
const formatter: FormatterFunction = formatters[type];

if (isUndefined(formatter)) {
console.warn(`Unable to find default formatter for '${type}', falling back to noop`);
console.warn(`Unable to find default formatter for '${type}', falling back to echo`);

return formatNoop(value);
return echo(value);
}

try {
Expand Down
20 changes: 10 additions & 10 deletions packages/api-format/src/util.spec.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
// ISC, Copyright 2017 Jaco Greeff

const { format, formatArray } = require('./util');
const formatNoop = require('./noop');
const echo = require('./echo');

describe('util', () => {
let formatters;
let noopSpy;
let echoSpy;
let warnSpy;

beforeEach(() => {
noopSpy = jest.fn(formatNoop);
echoSpy = jest.fn(echo);
warnSpy = jest.spyOn(console, 'warn');

formatters = {
'Address': noopSpy,
'Address[]': noopSpy,
'Address': echoSpy,
'Address[]': echoSpy,
'Exception': () => {
throw new Error('something went wrong');
}
};
});

afterEach(() => {
noopSpy.mockRestore();
echoSpy.mockRestore();
warnSpy.mockRestore();
});

Expand All @@ -35,7 +35,7 @@ describe('util', () => {

it('logs a warning with unknown types', () => {
format(formatters, 'Unknown', 'test');
expect(warnSpy).toHaveBeenCalledWith("Unable to find default formatter for 'Unknown', falling back to noop");
expect(warnSpy).toHaveBeenCalledWith("Unable to find default formatter for 'Unknown', falling back to echo");
});

it('wraps exceptions with the type', () => {
Expand All @@ -48,7 +48,7 @@ describe('util', () => {
it('formats known types using the supplied formatter', () => {
format(formatters, 'Address', '0xaddress');

expect(noopSpy).toHaveBeenCalledWith('0xaddress');
expect(echoSpy).toHaveBeenCalledWith('0xaddress');
});
});

Expand All @@ -62,8 +62,8 @@ describe('util', () => {
it('formats using the primitive type', () => {
format(formatters, 'Address[]', ['0x123', '0x234']);

expect(noopSpy).toHaveBeenCalledWith('0x123');
expect(noopSpy).toHaveBeenCalledWith('0x234');
expect(echoSpy).toHaveBeenCalledWith('0x123');
expect(echoSpy).toHaveBeenCalledWith('0x234');
});

it('returns formatted values as arrays', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"nock": "^9.1.0"
},
"dependencies": {
"@polkadot/util": "^0.6.7",
"@polkadot/util": "^0.9.1",
"babel-runtime": "^6.26.0",
"isomorphic-fetch": "^2.2.1",
"websocket": "^1.0.25"
Expand Down
4 changes: 3 additions & 1 deletion packages/api-provider/src/ws/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ module.exports = class WsProvider extends JsonRpcCoder implements ProviderInterf

Object.keys(this._queued).forEach((id: string) => {
try {
this._websocket.send(this._queued[((id: any): number)]);
this._websocket.send(
this._queued[((id: any): number)]
);
delete this._queued[((id: any): number)];
} catch (error) {
console.error(error);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@polkadot/api-format": "^0.6.5",
"@polkadot/api-jsonrpc": "^0.6.5",
"@polkadot/api-provider": "^0.6.5",
"@polkadot/util": "^0.6.7",
"@polkadot/util": "^0.9.1",
"babel-runtime": "^6.26.0"
}
}
49 changes: 25 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"

"@polkadot/dev@^0.13.3":
version "0.13.3"
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.13.3.tgz#e90caf191134d233fb6321012914f951b8a3ec17"
"@polkadot/dev@^0.13.4":
version "0.13.4"
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.13.4.tgz#beaa45da1655f8335b4a8294db3803f95cd3cc4e"
dependencies:
babel-cli "^6.26.0"
babel-core "^6.26.0"
Expand All @@ -80,7 +80,7 @@
eslint-plugin-promise "^3.6.0"
eslint-plugin-react "^7.4.0"
eslint-plugin-standard "^3.0.1"
flow-bin "^0.60.0"
flow-bin "^0.61.0"
flow-copy-source "^1.2.1"
jest "^21.2.1"
makeshift "^1.1.0"
Expand All @@ -91,31 +91,28 @@
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"
"@polkadot/primitives-json@^0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@polkadot/primitives-json/-/primitives-json-0.3.1.tgz#7c18589b944d792019ed08155363a29504604d23"
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/primitives" "^0.3.1"
"@polkadot/util" "^0.9.1"
babel-runtime "^6.26.0"

"@polkadot/util@^0.6.7":
version "0.6.7"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.6.7.tgz#eb9a6bd3717b69c962f6fb70830ebc60380c333f"
"@polkadot/primitives@^0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@polkadot/primitives/-/primitives-0.3.1.tgz#420220a8e9c3118f613e47218b038ca7c3724922"
dependencies:
"@polkadot/util" "^0.9.1"
babel-runtime "^6.26.0"
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"
"@polkadot/util@^0.9.1":
version "0.9.1"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.9.1.tgz#222a31f0325468044736792bd5652e483b8336db"
dependencies:
babel-runtime "^6.26.0"
bn.js "^4.11.8"
ip-regex "^2.1.0"
keccak "^1.3.0"

JSONStream@^1.0.4:
Expand Down Expand Up @@ -2105,9 +2102,9 @@ flat-cache@^1.2.1:
graceful-fs "^4.1.2"
write "^0.2.1"

flow-bin@^0.60.0:
version "0.60.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.60.0.tgz#885d0d92a90f94c29445e0f9a0382f5b5debaaed"
flow-bin@^0.61.0:
version "0.61.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.61.0.tgz#d0473a8c35dbbf4de573823f4932124397d32d35"

flow-copy-source@^1.2.1:
version "1.2.1"
Expand Down Expand Up @@ -2601,6 +2598,10 @@ invert-kv@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6"

ip-regex@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-2.1.0.tgz#fa78bf5d2e6913c911ce9f819ee5146bb6d844e9"

is-alphabetical@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-alphabetical/-/is-alphabetical-1.0.1.tgz#c77079cc91d4efac775be1034bf2d243f95e6f08"
Expand Down