Add pubsub interface definition (#54)
* Add pubsub interface definition * Functional JsonRpcCoder * Functional HttpProvider * Functional WsProvider * Functional split completed * Split actual method subscription * Update flow * Flatten no user-specified array in sub call
This commit is contained in:
@@ -4,11 +4,10 @@
|
||||
// @flow
|
||||
|
||||
import type { InterfaceInputType } from '@polkadot/api-jsonrpc/types';
|
||||
import type { Hash } from '@polkadot/primitives/base';
|
||||
|
||||
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 echo = require('./echo');
|
||||
const util = require('./util');
|
||||
@@ -16,8 +15,8 @@ const util = require('./util');
|
||||
const formatters = {
|
||||
'Address': accountIdEncode,
|
||||
'CallData': hashEncode,
|
||||
'H256': h256Encode,
|
||||
'HeaderHash': headerHashEncode,
|
||||
'H256': (value: Hash) => hashEncode(value, 256),
|
||||
'HeaderHash': hashEncode,
|
||||
'String': echo
|
||||
};
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ describe('formatInputs', () => {
|
||||
{ name: 'foo', type: 'Address' },
|
||||
{ name: 'bar', type: 'H256' }
|
||||
],
|
||||
['0x1234', '0xabcd']
|
||||
[new Uint8Array([0x12, 0x34]), new Uint8Array([0xab, 0xcd])]
|
||||
)
|
||||
).toEqual([
|
||||
'0x1234',
|
||||
|
||||
@@ -16,24 +16,22 @@ describe('formatOutput', () => {
|
||||
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])
|
||||
new Uint8Array([0x56, 0x78]),
|
||||
new Uint8Array([0x78, 0x9a])
|
||||
]
|
||||
}
|
||||
},
|
||||
number: new BN(0x1234),
|
||||
parentHash: new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x12, 0x34]),
|
||||
stateRoot: new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x56, 0x78]),
|
||||
transactionRoot: new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xab, 0xcd])
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -12,6 +12,8 @@ type FormattersFunctionMap = {
|
||||
};
|
||||
|
||||
const isUndefined = require('@polkadot/util/is/undefined');
|
||||
const l = require('@polkadot/util/logger')('api-format');
|
||||
|
||||
const echo = require('./echo');
|
||||
|
||||
const arrayTypeRegex = /\[\]$/;
|
||||
@@ -20,7 +22,7 @@ function formatSingleType (formatters: FormattersFunctionMap, type: FormattersFu
|
||||
const formatter: FormatterFunction = formatters[type];
|
||||
|
||||
if (isUndefined(formatter)) {
|
||||
console.warn(`Unable to find default formatter for '${type}', falling back to echo`);
|
||||
l.warn(`Unable to find default formatter for '${type}', falling back to echo`);
|
||||
|
||||
return echo(value);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,9 @@ 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 echo");
|
||||
expect(warnSpy).toHaveBeenCalledWith(
|
||||
expect.anything(), expect.anything(), "Unable to find default formatter for 'Unknown', falling back to echo"
|
||||
);
|
||||
});
|
||||
|
||||
it('wraps exceptions with the type', () => {
|
||||
|
||||
Reference in New Issue
Block a user