@@ -23,14 +23,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) {
23
23
try {
24
24
boolean visible = Util .getVisible (request );
25
25
long getNum = Long .parseLong (request .getParameter ("num" ));
26
- if (getNum > 0 && getNum < BLOCK_LIMIT_NUM ) {
27
- BlockList reply = wallet .getBlockByLatestNum (getNum );
28
- if (reply != null ) {
29
- response .getWriter ().println (Util .printBlockList (reply , visible ));
30
- return ;
31
- }
32
- }
33
- response .getWriter ().println ("{}" );
26
+ outWrite (getNum , visible , response );
34
27
} catch (Exception e ) {
35
28
Util .processError (e , response );
36
29
}
@@ -45,16 +38,25 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
45
38
NumberMessage .Builder build = NumberMessage .newBuilder ();
46
39
JsonFormat .merge (input , build , visible );
47
40
long getNum = build .getNum ();
48
- if (getNum > 0 && getNum < BLOCK_LIMIT_NUM ) {
49
- BlockList reply = wallet .getBlockByLatestNum (getNum );
50
- if (reply != null ) {
51
- response .getWriter ().println (Util .printBlockList (reply , visible ));
52
- return ;
53
- }
54
- }
55
- response .getWriter ().println ("{}" );
41
+ outWrite (getNum , visible , response );
56
42
} catch (Exception e ) {
57
43
Util .processError (e , response );
58
44
}
59
45
}
46
+
47
+ private void outWrite (long getNum , boolean visible , HttpServletResponse response ) throws Exception {
48
+ if (getNum > 0 && getNum < BLOCK_LIMIT_NUM ) {
49
+ BlockList reply = wallet .getBlockByLatestNum (getNum );
50
+ if (reply != null ) {
51
+ response .getWriter ().println (Util .printBlockList (reply , visible ));
52
+ return ;
53
+ }
54
+ else {
55
+ response .getWriter ().println ("{}" );
56
+ }
57
+ }else {
58
+ response .getWriter ().println ("{}" );
59
+ }
60
+ }
61
+
60
62
}
0 commit comments