Skip to content

Commit 5336f8f

Browse files
authored
feat: add block info service (#42)
* feat: add block info api spec * feat: add block info server implementation
1 parent c414fd1 commit 5336f8f

29 files changed

+1574
-30
lines changed

.github/workflows/release.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
app: ["transaction_service", "analytics_service"]
14+
app: ["transaction_service", "analytics_service", "block_info_service"]
1515
steps:
1616
- uses: actions/checkout@v2
1717
- name: Set up Docker Buildx

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
runs-on: ubuntu-latest
4646
strategy:
4747
matrix:
48-
app: ["transaction_service", "analytics_service"]
48+
app: ["transaction_service", "analytics_service", "block_info_service"]
4949
services:
5050
redis:
5151
image: redis:alpine

node_packages/openapi_specs/specs/analytics_service.yaml

+22-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ tags:
1313
description: "Get server's health info"
1414

1515
servers:
16-
- url: https://api.etdchain.net/stats/analytics
16+
- url: https://api.etdchain.net/stats/transaction
1717
description: Production server
18-
- url: https://api.debugchain.net/stats/analytics
18+
- url: https://api.debugchain.net/stats/transaction
1919
description: Testing server
2020

2121
paths:
22-
/:
22+
/analytics:
2323
post:
2424
tags:
2525
- "analytics"
@@ -32,7 +32,25 @@ paths:
3232
application/json:
3333
schema:
3434
$ref: "#/components/schemas/analytics"
35-
35+
/health:
36+
get:
37+
tags:
38+
- "health"
39+
summary: "Get server's health info"
40+
description: "Will return a error reason if not healthy"
41+
responses:
42+
"200":
43+
description: "Server is up"
44+
content:
45+
application/json:
46+
schema:
47+
$ref: "health_service.spec.yaml#/components/schemas/error"
48+
"500":
49+
description: "Server is down"
50+
content:
51+
application/json:
52+
schema:
53+
$ref: "health_service.spec.yaml#/components/schemas/error"
3654
components:
3755
schemas:
3856
analytics:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
openapi: "3.0.0"
2+
info:
3+
description: "This belongs part of ETDStats microservices which will provide a analytics service"
4+
version: "1.0.0"
5+
title: "Block Info service"
6+
termsOfService: "https://github.com/etherdata-blockchain"
7+
8+
9+
tags:
10+
- name: "block-info"
11+
description: "Get blocks and transactions details"
12+
- name: "node"
13+
description: "Get nodes info"
14+
- name: "health"
15+
description: "Get server's health info"
16+
17+
servers:
18+
- url: https://api.etdchain.net/stats/block_info
19+
description: Production server
20+
- url: https://api.debugchain.net/stats/block_info
21+
description: Testing server
22+
23+
paths:
24+
/:
25+
get:
26+
tags:
27+
- "block-info"
28+
summary: "Get latest block info"
29+
description: "Will returns the latest block info from server"
30+
responses:
31+
"200":
32+
description: "OK"
33+
content:
34+
application/json:
35+
schema:
36+
$ref: "#/components/schemas/block-info"
37+
/nodes:
38+
get:
39+
tags:
40+
- "node"
41+
summary: Get list of nodes (Pending)
42+
responses:
43+
200:
44+
description: "OK"
45+
/health:
46+
get:
47+
tags:
48+
- "health"
49+
summary: "Get server's health info"
50+
description: "Will return a error reason if not healthy"
51+
responses:
52+
"200":
53+
description: "Server is up"
54+
content:
55+
application/json:
56+
schema:
57+
$ref: "health_service.spec.yaml#/components/schemas/error"
58+
"500":
59+
description: "Server is down"
60+
content:
61+
application/json:
62+
schema:
63+
$ref: "health_service.spec.yaml#/components/schemas/error"
64+
components:
65+
schemas:
66+
block-info:
67+
type: object
68+
required: [ "numBlocks", "numTransactions", "blockTime", "blockTimeHistory", "difficultyHistory" ]
69+
properties:
70+
numBlocks:
71+
type: number
72+
description: Current block number
73+
numTransactions:
74+
type: number
75+
description: Total number of transactions
76+
blockTime:
77+
type: number
78+
description: Average time for each block in seconds
79+
block:
80+
$ref: "transaction_service.spec.yaml#/components/schemas/block"
81+
description: Latest block
82+
blockTimeChangePercentage:
83+
type: string
84+
description: Difference between latest block time and previous block time
85+
example: "10.02%"
86+
difficultyChangePercentage:
87+
type: string
88+
description: Difference between latest block difficulty and previous block difficulty
89+
example: "-10.02%"
90+
blockTimeHistory:
91+
type: array
92+
description: List of blocks' time
93+
items:
94+
type: number
95+
difficultyHistory:
96+
type: array
97+
description: List of blocks' difficulty
98+
items:
99+
type: number
100+
101+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
openapi: "3.0.0"
2+
info:
3+
description: "This belongs part of ETDStats microservices which will provide a node service. Pending!"
4+
version: "1.0.0"
5+
title: "Node service"
6+
termsOfService: "https://github.com/etherdata-blockchain"
7+
8+
9+
tags:
10+
- name: "node"
11+
description: "Get blocks and transactions details"
12+
- name: "health"
13+
description: "Get server's health info"
14+
15+
servers:
16+
- url: https://api.etdchain.net/stats/node
17+
description: Production server
18+
- url: https://api.debugchain.net/stats/node
19+
description: Testing server
20+
21+
paths:
22+
/info:
23+
post:
24+
tags:
25+
- "node"
26+
summary: "Submit latest block info"
27+
responses:
28+
"200":
29+
description: "OK"
30+
/login:
31+
post:
32+
tags:
33+
- node
34+
summary: Log in
35+
responses:
36+
201:
37+
description: "OK"
38+
39+
/health:
40+
get:
41+
tags:
42+
- "health"
43+
summary: "Get server's health info"
44+
description: "Will return a error reason if not healthy"
45+
responses:
46+
"200":
47+
description: "Server is up"
48+
content:
49+
application/json:
50+
schema:
51+
$ref: "health_service.spec.yaml#/components/schemas/error"
52+
"500":
53+
description: "Server is down"
54+
content:
55+
application/json:
56+
schema:
57+
$ref: "health_service.spec.yaml#/components/schemas/error"
58+
components:
59+
schemas:
60+
node-info:
61+
type: object

node_packages/openapi_specs/specs/transaction_service.spec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ paths:
3131
content:
3232
application/json:
3333
schema:
34-
$ref: "#/components/schemas/reason"
34+
$ref: "health_service.spec.yaml#/components/schemas/error"
3535
"500":
3636
description: "Server is down"
3737
content:
3838
application/json:
3939
schema:
40-
$ref: "#/components/schemas/reason"
40+
$ref: "health_service.spec.yaml#/components/schemas/error"
4141

4242
/{id}:
4343
get:

node_packages/openapi_specs/src/analytics_service.json

+90-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"openapi": "3.0.0",
33
"info": {
44
"description": "This belongs part of ETDStats microservices which will provide a analytics service",
5-
"version": "0.19.0",
5+
"version": "0.21.0",
66
"title": "Analytics service",
77
"termsOfService": "https://github.com/etherdata-blockchain"
88
},
@@ -18,16 +18,16 @@
1818
],
1919
"servers": [
2020
{
21-
"url": "https://api.etdchain.net/stats/analytics",
21+
"url": "https://api.etdchain.net/stats/transaction",
2222
"description": "Production server"
2323
},
2424
{
25-
"url": "https://api.debugchain.net/stats/analytics",
25+
"url": "https://api.debugchain.net/stats/transaction",
2626
"description": "Testing server"
2727
}
2828
],
2929
"paths": {
30-
"/": {
30+
"/analytics": {
3131
"post": {
3232
"tags": [
3333
"analytics"
@@ -47,10 +47,96 @@
4747
}
4848
}
4949
}
50+
},
51+
"/health": {
52+
"get": {
53+
"tags": [
54+
"health"
55+
],
56+
"summary": "Get server's health info",
57+
"description": "Will return a error reason if not healthy",
58+
"responses": {
59+
"200": {
60+
"description": "Server is up",
61+
"content": {
62+
"application/json": {
63+
"schema": {
64+
"$ref": "#/components/schemas/error"
65+
}
66+
}
67+
}
68+
},
69+
"500": {
70+
"description": "Server is down",
71+
"content": {
72+
"application/json": {
73+
"schema": {
74+
"$ref": "#/components/schemas/error"
75+
}
76+
}
77+
}
78+
}
79+
}
80+
}
5081
}
5182
},
5283
"components": {
5384
"schemas": {
85+
"error": {
86+
"type": "object",
87+
"required": [
88+
"reason"
89+
],
90+
"properties": {
91+
"services": {
92+
"type": "array",
93+
"title": "Services",
94+
"items": {
95+
"type": "object",
96+
"properties": {
97+
"status": {
98+
"type": "string",
99+
"enum": [
100+
"ok",
101+
"warning",
102+
"error"
103+
]
104+
},
105+
"total": {
106+
"type": "number",
107+
"example": 11,
108+
"description": "Total number of child services"
109+
},
110+
"numHealthyServices": {
111+
"type": "number",
112+
"example": 10,
113+
"description": "Number of services in healthy condition"
114+
},
115+
"isLeaf": {
116+
"type": "boolean",
117+
"example": true,
118+
"description": "If this is the leaf node (no children)"
119+
},
120+
"services": {
121+
"type": "array",
122+
"minItems": 0,
123+
"items": {
124+
"type": "object",
125+
"$ref": "#/components/schemas/error"
126+
}
127+
}
128+
},
129+
"required": [
130+
"status",
131+
"total",
132+
"numHealthyServices",
133+
"isLeaf",
134+
"services"
135+
]
136+
}
137+
}
138+
}
139+
},
54140
"analytics": {
55141
"type": "object",
56142
"required": [

0 commit comments

Comments
 (0)