📒 Allow to store arbitrary data to the blockchain with sub buckets

This commit is contained in:
Ettore Di Giacinto
2021-10-30 23:16:26 +02:00
parent 61b69df5b5
commit dadccf07cb
8 changed files with 210 additions and 142 deletions

View File

@@ -7,6 +7,8 @@ import (
"github.com/labstack/echo/v4"
"github.com/mudler/edgevpn/pkg/blockchain"
"github.com/mudler/edgevpn/pkg/edgevpn"
"github.com/mudler/edgevpn/pkg/edgevpn/types"
)
//go:embed public
@@ -25,10 +27,22 @@ func API(l string, ledger *blockchain.Ledger) error {
ec := echo.New()
assetHandler := http.FileServer(getFileSystem())
ec.GET("/api/data", func(c echo.Context) error {
list := []blockchain.Data{}
for _, v := range ledger.CurrentData() {
list = append(list, v)
ec.GET("/api/machines", func(c echo.Context) error {
list := []*types.Machine{}
for _, v := range ledger.CurrentData()[edgevpn.MachinesLedgerKey] {
machine := &types.Machine{}
v.Unmarshal(machine)
list = append(list, machine)
}
return c.JSON(http.StatusOK, list)
})
ec.GET("/api/services", func(c echo.Context) error {
list := []*types.Service{}
for _, v := range ledger.CurrentData()[edgevpn.ServicesLedgerKey] {
srvc := &types.Service{}
v.Unmarshal(srvc)
list = append(list, srvc)
}
return c.JSON(http.StatusOK, list)
})