Skip to content

Commit aa76639

Browse files
committed
Add getProtocolVersion
1 parent 5403fd5 commit aa76639

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

src/__tests__/integrate.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import CQL from '../index'
88
console.log(cql.client.isConnected)
99

1010
// bp
11-
let list = await cql.bp.getBlockList(52170, 52175)
12-
console.log(list)
11+
let version = await cql.bp.getProtocolVersion()
12+
console.log(version)
13+
// let list = await cql.bp.getBlockList(52170, 52175)
14+
// console.log(list)
1315
})()

src/client/rpc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface RPCObject {
77

88
export const constructRPCObj = (
99
method: string,
10-
params: Array<any>
10+
params: Array<any> = []
1111
): RPCObject => {
1212
return {
1313
jsonrpc: '2.0',

src/libs/bp.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { CqlWebSocket } from '../client/socket'
33
import { RPCObject, constructRPCObj } from '../client/rpc'
44

55
export interface BpInterface {
6-
// getProtocolVersion(): Promise<any>
6+
getProtocolVersion(): Promise<string>
77
// getRunningStatus(): Promise<any>
88
getBlockList(from: number, to: number): Promise<Array<object>>
99
// getBlockListByTimeRange(): Promise<any>
@@ -14,6 +14,7 @@ export interface BpInterface {
1414
}
1515

1616
export enum BpMethodType {
17+
GET_PROTOCOL_VERSION = 'bp_getProtocolVersion',
1718
GET_BLOCK_LIST = 'bp_getBlockList'
1819
}
1920

@@ -29,14 +30,28 @@ export default class Bp implements BpInterface {
2930
this.debug = debugFactory('cql:bp')
3031
}
3132

32-
public getBlockList(from: number, to: number): Promise<Array<object>> {
33+
public getProtocolVersion(): Promise<string> {
34+
let req: RPCObject = constructRPCObj(BpMethodType.GET_PROTOCOL_VERSION)
35+
this.debug('Send getProtocolVersion')
36+
return new Promise(resolve => {
37+
this.client.send(req, res => {
38+
this.debug('Got getProtocolVersion response', res)
39+
resolve(res.result)
40+
})
41+
})
42+
}
43+
44+
public getBlockList(
45+
from: number,
46+
to: number
47+
): Promise<Array<object>> {
3348
let params = [from, to]
3449
let req: RPCObject = constructRPCObj(BpMethodType.GET_BLOCK_LIST, params)
3550

36-
this.debug('getBlockList of ', req)
51+
this.debug('Send getBlockList of ', req)
3752
return new Promise((resolve) => {
3853
this.client.send(req, (res) => {
39-
this.debug('get response', res)
54+
this.debug('Got getBlockList response', res)
4055
if (res.id === req.id) {
4156
resolve(res.result)
4257
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy