Skip to content

Commit 231e39d

Browse files
committed
Enhance API documentation and implement genesis block update functionality
- Added a new PUT endpoint `/networks/{id}/genesis` to update the genesis block for a network with change tracking, improving network management capabilities. - Introduced `UpdateGenesisBlockRequest` and `UpdateGenesisBlockResponse` models to handle request and response structures for the genesis block update operation, ensuring clear data representation. - Updated Swagger documentation (`swagger.json`, `swagger.yaml`, and `docs.go`) to include details for the new endpoint and its parameters, enhancing API clarity and usability. - Implemented service-level logic to handle genesis block updates with tracking, including validation and error handling, ensuring robust operation. These changes significantly improve the functionality and maintainability of the network management API, providing better tools for managing genesis block updates effectively. Signed-off-by: David VIEJO <dviejo@kungfusoftware.es>
1 parent 0508cbf commit 231e39d

File tree

26 files changed

+1598
-244
lines changed

26 files changed

+1598
-244
lines changed

docs/docs.go

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package docs Code generated by swaggo/swag at 2025-07-28 14:54:38.035644 +0200 CEST m=+6.723588334. DO NOT EDIT
1+
// Package docs Code generated by swaggo/swag at 2025-07-29 22:14:11.67409 +0200 CEST m=+3.957196876. DO NOT EDIT
22
package docs
33

44
import "github.com/swaggo/swag"
@@ -5498,6 +5498,66 @@ const docTemplate = `{
54985498
}
54995499
}
55005500
},
5501+
"/networks/{id}/genesis": {
5502+
"put": {
5503+
"description": "Update the genesis block for a network with change tracking",
5504+
"consumes": [
5505+
"application/json"
5506+
],
5507+
"produces": [
5508+
"application/json"
5509+
],
5510+
"tags": [
5511+
"Fabric Networks",
5512+
"Besu Networks"
5513+
],
5514+
"summary": "Update genesis block for a network",
5515+
"parameters": [
5516+
{
5517+
"type": "integer",
5518+
"description": "Network ID",
5519+
"name": "id",
5520+
"in": "path",
5521+
"required": true
5522+
},
5523+
{
5524+
"description": "Genesis block update request",
5525+
"name": "request",
5526+
"in": "body",
5527+
"required": true,
5528+
"schema": {
5529+
"$ref": "#/definitions/http.UpdateGenesisBlockRequest"
5530+
}
5531+
}
5532+
],
5533+
"responses": {
5534+
"200": {
5535+
"description": "OK",
5536+
"schema": {
5537+
"$ref": "#/definitions/http.UpdateGenesisBlockResponse"
5538+
}
5539+
},
5540+
"400": {
5541+
"description": "Bad Request",
5542+
"schema": {
5543+
"$ref": "#/definitions/github_com_chainlaunch_chainlaunch_pkg_networks_http.ErrorResponse"
5544+
}
5545+
},
5546+
"404": {
5547+
"description": "Not Found",
5548+
"schema": {
5549+
"$ref": "#/definitions/github_com_chainlaunch_chainlaunch_pkg_networks_http.ErrorResponse"
5550+
}
5551+
},
5552+
"500": {
5553+
"description": "Internal Server Error",
5554+
"schema": {
5555+
"$ref": "#/definitions/github_com_chainlaunch_chainlaunch_pkg_networks_http.ErrorResponse"
5556+
}
5557+
}
5558+
}
5559+
}
5560+
},
55015561
"/nodes": {
55025562
"get": {
55035563
"description": "Get a paginated list of nodes with optional platform filter",
@@ -13507,6 +13567,15 @@ const docTemplate = `{
1350713567
"genesisBlock": {
1350813568
"type": "string"
1350913569
},
13570+
"genesisChangeReason": {
13571+
"type": "string"
13572+
},
13573+
"genesisChangedAt": {
13574+
"type": "string"
13575+
},
13576+
"genesisChangedBy": {
13577+
"type": "integer"
13578+
},
1351013579
"id": {
1351113580
"type": "integer"
1351213581
},
@@ -14302,6 +14371,32 @@ const docTemplate = `{
1430214371
}
1430314372
}
1430414373
},
14374+
"http.UpdateGenesisBlockRequest": {
14375+
"type": "object",
14376+
"required": [
14377+
"genesisBlock",
14378+
"reason"
14379+
],
14380+
"properties": {
14381+
"genesisBlock": {
14382+
"type": "string"
14383+
},
14384+
"reason": {
14385+
"type": "string"
14386+
}
14387+
}
14388+
},
14389+
"http.UpdateGenesisBlockResponse": {
14390+
"type": "object",
14391+
"properties": {
14392+
"message": {
14393+
"type": "string"
14394+
},
14395+
"networkId": {
14396+
"type": "integer"
14397+
}
14398+
}
14399+
},
1430514400
"http.UpdateNodeRequest": {
1430614401
"type": "object",
1430714402
"properties": {

docs/swagger.json

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5487,6 +5487,66 @@
54875487
}
54885488
}
54895489
},
5490+
"/networks/{id}/genesis": {
5491+
"put": {
5492+
"description": "Update the genesis block for a network with change tracking",
5493+
"consumes": [
5494+
"application/json"
5495+
],
5496+
"produces": [
5497+
"application/json"
5498+
],
5499+
"tags": [
5500+
"Fabric Networks",
5501+
"Besu Networks"
5502+
],
5503+
"summary": "Update genesis block for a network",
5504+
"parameters": [
5505+
{
5506+
"type": "integer",
5507+
"description": "Network ID",
5508+
"name": "id",
5509+
"in": "path",
5510+
"required": true
5511+
},
5512+
{
5513+
"description": "Genesis block update request",
5514+
"name": "request",
5515+
"in": "body",
5516+
"required": true,
5517+
"schema": {
5518+
"$ref": "#/definitions/http.UpdateGenesisBlockRequest"
5519+
}
5520+
}
5521+
],
5522+
"responses": {
5523+
"200": {
5524+
"description": "OK",
5525+
"schema": {
5526+
"$ref": "#/definitions/http.UpdateGenesisBlockResponse"
5527+
}
5528+
},
5529+
"400": {
5530+
"description": "Bad Request",
5531+
"schema": {
5532+
"$ref": "#/definitions/github_com_chainlaunch_chainlaunch_pkg_networks_http.ErrorResponse"
5533+
}
5534+
},
5535+
"404": {
5536+
"description": "Not Found",
5537+
"schema": {
5538+
"$ref": "#/definitions/github_com_chainlaunch_chainlaunch_pkg_networks_http.ErrorResponse"
5539+
}
5540+
},
5541+
"500": {
5542+
"description": "Internal Server Error",
5543+
"schema": {
5544+
"$ref": "#/definitions/github_com_chainlaunch_chainlaunch_pkg_networks_http.ErrorResponse"
5545+
}
5546+
}
5547+
}
5548+
}
5549+
},
54905550
"/nodes": {
54915551
"get": {
54925552
"description": "Get a paginated list of nodes with optional platform filter",
@@ -13496,6 +13556,15 @@
1349613556
"genesisBlock": {
1349713557
"type": "string"
1349813558
},
13559+
"genesisChangeReason": {
13560+
"type": "string"
13561+
},
13562+
"genesisChangedAt": {
13563+
"type": "string"
13564+
},
13565+
"genesisChangedBy": {
13566+
"type": "integer"
13567+
},
1349913568
"id": {
1350013569
"type": "integer"
1350113570
},
@@ -14291,6 +14360,32 @@
1429114360
}
1429214361
}
1429314362
},
14363+
"http.UpdateGenesisBlockRequest": {
14364+
"type": "object",
14365+
"required": [
14366+
"genesisBlock",
14367+
"reason"
14368+
],
14369+
"properties": {
14370+
"genesisBlock": {
14371+
"type": "string"
14372+
},
14373+
"reason": {
14374+
"type": "string"
14375+
}
14376+
}
14377+
},
14378+
"http.UpdateGenesisBlockResponse": {
14379+
"type": "object",
14380+
"properties": {
14381+
"message": {
14382+
"type": "string"
14383+
},
14384+
"networkId": {
14385+
"type": "integer"
14386+
}
14387+
}
14388+
},
1429414389
"http.UpdateNodeRequest": {
1429514390
"type": "object",
1429614391
"properties": {

docs/swagger.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,6 +2150,12 @@ definitions:
21502150
type: array
21512151
genesisBlock:
21522152
type: string
2153+
genesisChangeReason:
2154+
type: string
2155+
genesisChangedAt:
2156+
type: string
2157+
genesisChangedBy:
2158+
type: integer
21532159
id:
21542160
type: integer
21552161
name:
@@ -2686,6 +2692,23 @@ definitions:
26862692
version:
26872693
type: string
26882694
type: object
2695+
http.UpdateGenesisBlockRequest:
2696+
properties:
2697+
genesisBlock:
2698+
type: string
2699+
reason:
2700+
type: string
2701+
required:
2702+
- genesisBlock
2703+
- reason
2704+
type: object
2705+
http.UpdateGenesisBlockResponse:
2706+
properties:
2707+
message:
2708+
type: string
2709+
networkId:
2710+
type: integer
2711+
type: object
26892712
http.UpdateNodeRequest:
26902713
properties:
26912714
besuNode:
@@ -6854,6 +6877,46 @@ paths:
68546877
summary: Undeploy Prometheus instance
68556878
tags:
68566879
- Metrics
6880+
/networks/{id}/genesis:
6881+
put:
6882+
consumes:
6883+
- application/json
6884+
description: Update the genesis block for a network with change tracking
6885+
parameters:
6886+
- description: Network ID
6887+
in: path
6888+
name: id
6889+
required: true
6890+
type: integer
6891+
- description: Genesis block update request
6892+
in: body
6893+
name: request
6894+
required: true
6895+
schema:
6896+
$ref: '#/definitions/http.UpdateGenesisBlockRequest'
6897+
produces:
6898+
- application/json
6899+
responses:
6900+
"200":
6901+
description: OK
6902+
schema:
6903+
$ref: '#/definitions/http.UpdateGenesisBlockResponse'
6904+
"400":
6905+
description: Bad Request
6906+
schema:
6907+
$ref: '#/definitions/github_com_chainlaunch_chainlaunch_pkg_networks_http.ErrorResponse'
6908+
"404":
6909+
description: Not Found
6910+
schema:
6911+
$ref: '#/definitions/github_com_chainlaunch_chainlaunch_pkg_networks_http.ErrorResponse'
6912+
"500":
6913+
description: Internal Server Error
6914+
schema:
6915+
$ref: '#/definitions/github_com_chainlaunch_chainlaunch_pkg_networks_http.ErrorResponse'
6916+
summary: Update genesis block for a network
6917+
tags:
6918+
- Fabric Networks
6919+
- Besu Networks
68576920
/networks/besu:
68586921
get:
68596922
description: Get a paginated list of Besu networks

pkg/db/db.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/dev-queries.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Remove genesis change tracking fields
2+
-- Note: SQLite doesn't support DROP COLUMN, so we need to recreate the table
3+
-- This is a simplified down migration - in practice, you'd need to recreate the table
4+
5+
-- For now, we'll just document what needs to be done
6+
-- In a real implementation, you would:
7+
-- 1. Create a new table with the old schema
8+
-- 2. Copy data from the current table to the new table
9+
-- 3. Drop the current table
10+
-- 4. Rename the new table to the original name
11+
12+
-- This is left as a placeholder since SQLite doesn't support DROP COLUMN
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Add fields to track genesis block changes
2+
ALTER TABLE networks ADD COLUMN genesis_changed_at TIMESTAMP;
3+
ALTER TABLE networks ADD COLUMN genesis_changed_by INTEGER REFERENCES users(id);
4+
ALTER TABLE networks ADD COLUMN genesis_change_reason TEXT;

pkg/db/models.go

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/querier.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)