-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add circulation and decentral endpoints
- Loading branch information
Showing
14 changed files
with
291 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package handler | ||
|
||
import ( | ||
"context" | ||
"github.com/labstack/echo/v4" | ||
"github.com/spacemeshos/explorer-backend/api/storage" | ||
"github.com/spacemeshos/go-spacemesh/log" | ||
"net/http" | ||
) | ||
|
||
func Circulation(c echo.Context) error { | ||
cc := c.(*ApiContext) | ||
|
||
if cached, err := cc.Cache.Get(context.Background(), "circulation", new(*storage.Circulation)); err == nil { | ||
return c.JSON(http.StatusOK, cached) | ||
} | ||
|
||
circulation, err := cc.StorageClient.GetCirculation(cc.Storage) | ||
if err != nil { | ||
log.Warning("failed to get circulation: %v", err) | ||
return c.NoContent(http.StatusInternalServerError) | ||
} | ||
|
||
if err = cc.Cache.Set(context.Background(), "circulation", circulation); err != nil { | ||
log.Warning("failed to cache circulation: %v", err) | ||
return c.NoContent(http.StatusInternalServerError) | ||
} | ||
|
||
return c.JSON(http.StatusOK, circulation) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package storage | ||
|
||
import ( | ||
"github.com/spacemeshos/economics/vesting" | ||
"github.com/spacemeshos/go-spacemesh/log" | ||
"github.com/spacemeshos/go-spacemesh/sql" | ||
) | ||
|
||
type Circulation struct { | ||
Circulation uint64 `json:"circulation"` | ||
} | ||
|
||
func (c *Client) GetCirculation(db *sql.Database) (*Circulation, error) { | ||
circulation := &Circulation{ | ||
Circulation: 0, | ||
} | ||
if !c.Testnet { | ||
accumulatedVest := vesting.AccumulatedVestAtLayer(c.NodeClock.CurrentLayer().Uint32()) | ||
circulation.Circulation = accumulatedVest | ||
} | ||
|
||
rewardsSum, _, err := c.GetRewardsSum(db) | ||
if err != nil { | ||
log.Warning("failed to get rewards count: %v", err) | ||
return nil, err | ||
} | ||
circulation.Circulation += rewardsSum | ||
|
||
return circulation, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.