UNPKG

904 BPlain TextView Raw
1// Copyright 2017-2018 @polkadot/api-provider authors & contributors
2// This software may be modified and distributed under the terms
3// of the ISC license. See the LICENSE file for details.
4
5import { JsonRpcRequest, JsonRpcResponse } from '../../types';
6import { RpcCoder, RpcCoderState } from './types';
7
8import decodeResponse from './decodeResponse';
9import encodeJson from './encodeJson';
10import encodeObject from './encodeObject';
11
12export default function rpcCoder (): RpcCoder {
13 const self: RpcCoderState = {
14 id: 0
15 };
16
17 return {
18 decodeResponse: (response: JsonRpcResponse): any =>
19 decodeResponse(self, response),
20 encodeJson: (method: string, params: Array<any>): string =>
21 encodeJson(self, method, params),
22 encodeObject: (method: string, params: Array<any>): JsonRpcRequest =>
23 encodeObject(self, method, params),
24 getId: (): number =>
25 self.id
26 };
27}