1 |
|
2 |
|
3 |
|
4 |
|
5 | import { JsonRpcRequest, JsonRpcResponse } from '../../types';
|
6 | import { RpcCoder, RpcCoderState } from './types';
|
7 |
|
8 | import decodeResponse from './decodeResponse';
|
9 | import encodeJson from './encodeJson';
|
10 | import encodeObject from './encodeObject';
|
11 |
|
12 | export 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 | }
|