@@ -38,73 +38,65 @@ export default class Bp implements BpInterface {
38
38
this . debug = debugFactory ( 'cql:bp' )
39
39
}
40
40
41
- public getProtocolVersion ( ) : Promise < string > {
41
+ public async getProtocolVersion ( ) : Promise < string > {
42
42
let req : RPCObject = constructRPCObj ( BpMethodType . GET_PROTOCOL_VERSION )
43
43
this . debug ( 'Send getProtocolVersion request' , req )
44
- return new Promise ( resolve => {
45
- this . client . send ( req , res => {
46
- this . debug ( 'Got getProtocolVersion response' , res )
47
- resolve ( res . result )
48
- } )
49
- } )
44
+
45
+ let result = await this . client . sendRpc ( req )
46
+ this . debug ( 'Got getProtocolVersion response' , result )
47
+
48
+ return result
50
49
}
51
50
52
- public getRunningStatus ( ) : Promise < object > {
51
+ public async getRunningStatus ( ) : Promise < object > {
53
52
let req : RPCObject = constructRPCObj ( BpMethodType . GET_RUNNING_STATUS )
54
53
this . debug ( 'Send getRunningStatus request' , req )
55
- return new Promise ( resolve => {
56
- this . client . send ( req , res => {
57
- this . debug ( 'Got getRunningStatus response' , res )
58
- resolve ( res . result )
59
- } )
60
- } )
54
+
55
+ let result = await this . client . sendRpc ( req )
56
+ this . debug ( 'Got getRunningStatus response' , result )
57
+
58
+ return result
61
59
}
62
60
63
- public getBlockList (
61
+ public async getBlockList (
64
62
page : number ,
65
63
size : number ,
66
64
since : number = 0
67
65
) : Promise < object > {
68
66
let params = [ since , page , size ]
69
67
let req : RPCObject = constructRPCObj ( BpMethodType . GET_BLOCK_LIST , params )
70
-
71
68
this . debug ( 'Send getBlockList request' , req )
72
- return new Promise ( ( resolve ) => {
73
- this . client . send ( req , ( res ) => {
74
- this . debug ( 'Got getBlockList response' , res )
75
- resolve ( res . result )
76
- } )
77
- } )
69
+
70
+ let result = await this . client . sendRpc ( req )
71
+ this . debug ( 'Got getBlockList response' , result )
72
+
73
+ return result
78
74
}
79
75
80
- public getBlockByHeight (
76
+ public async getBlockByHeight (
81
77
height : number
82
78
) : Promise < object > {
83
79
let params = [ height ]
84
80
let req : RPCObject = constructRPCObj ( BpMethodType . GET_BLOCK_BY_HEIGHT , params )
85
-
86
81
this . debug ( 'Send getBlockByHeight request' , req )
87
- return new Promise ( ( resolve ) => {
88
- this . client . send ( req , ( res ) => {
89
- this . debug ( 'Got getBlockByHeight response' , res )
90
- resolve ( res . result )
91
- } )
92
- } )
82
+
83
+ let result = await this . client . sendRpc ( req )
84
+ this . debug ( 'Got getBlockByHeight response' , result )
85
+
86
+ return result
93
87
}
94
88
95
- public getBlockByHash (
89
+ public async getBlockByHash (
96
90
hash : string
97
91
) : Promise < object > {
98
92
let params = [ hash ]
99
93
let req : RPCObject = constructRPCObj ( BpMethodType . GET_BLOCK_BY_HASH , params )
100
-
101
94
this . debug ( 'Send getBlockByHash request' , req )
102
- return new Promise ( ( resolve ) => {
103
- this . client . send ( req , ( res ) => {
104
- this . debug ( 'Got getBlockByHash response' , res )
105
- resolve ( res . result )
106
- } )
107
- } )
95
+
96
+ let result = await this . client . sendRpc ( req )
97
+ this . debug ( 'Got getBlockByHash response' , result )
98
+
99
+ return result
108
100
}
109
101
110
102
public async getTransactionList (
@@ -114,43 +106,39 @@ export default class Bp implements BpInterface {
114
106
) : Promise < object > {
115
107
let params = [ since , page , size ]
116
108
let req : RPCObject = constructRPCObj ( BpMethodType . GET_TRANSACTION_LIST , params )
117
-
118
109
this . debug ( 'Send getTransactionList request' , req )
110
+
119
111
let result = await this . client . sendRpc ( req )
120
112
this . debug ( 'Got getTransactionList response' , result )
121
113
122
114
return result
123
115
}
124
116
125
- public getTransactionListOfBlock (
117
+ public async getTransactionListOfBlock (
126
118
height : number ,
127
119
from : number ,
128
120
to : number
129
121
) : Promise < Array < object > > {
130
122
let params = [ height , from , to ]
131
123
let req : RPCObject = constructRPCObj ( BpMethodType . GET_TRANSACTION_LIST_OF_BLOCK , params )
132
-
133
124
this . debug ( 'Send getTransactionListOfBlock request' , req )
134
- return new Promise ( ( resolve ) => {
135
- this . client . send ( req , ( res ) => {
136
- this . debug ( 'Got getTransactionListOfBlock response' , res )
137
- resolve ( res . result )
138
- } )
139
- } )
125
+
126
+ let result = await this . client . sendRpc ( req )
127
+ this . debug ( 'Got getTransactionListOfBlock response' , result )
128
+
129
+ return result
140
130
}
141
131
142
- public getTransactionByHash (
132
+ public async getTransactionByHash (
143
133
hash : string
144
134
) : Promise < object > {
145
135
let params = [ hash ]
146
136
let req : RPCObject = constructRPCObj ( BpMethodType . GET_TRANSACTION_BY_HASH , params )
147
-
148
137
this . debug ( 'Send getTransactionByHash request' , req )
149
- return new Promise ( ( resolve ) => {
150
- this . client . send ( req , ( res ) => {
151
- this . debug ( 'Got getTransactionByHash response' , res )
152
- resolve ( res . result )
153
- } )
154
- } )
138
+
139
+ let result = await this . client . sendRpc ( req )
140
+ this . debug ( 'Got getTransactionByHash response' , result )
141
+
142
+ return result
155
143
}
156
144
}
0 commit comments