Skip to content

Commit

Permalink
feat: build a custom route for Rotki
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Oct 25, 2024
1 parent 05ec6ce commit 9e59d1f
Show file tree
Hide file tree
Showing 6 changed files with 423 additions and 229 deletions.
13 changes: 13 additions & 0 deletions cmd/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

type GetSimplifiedVaults func(c *gin.Context) []vaults.TSimplifiedExternalVault
type GetLegacyExternalVaults func(c *gin.Context) []vaults.TExternalVault
type GetCustomVaults func(c *gin.Context) []vaults.TRotkiVaults

func CacheSimplifiedVaults(cachingStore *cache.Cache, expire time.Duration, handle GetSimplifiedVaults) gin.HandlerFunc {
return func(c *gin.Context) {
Expand All @@ -35,3 +36,15 @@ func CacheLegacyVaults(cachingStore *cache.Cache, expire time.Duration, handle G
}
}
}

func CacheCustomVaults(cachingStore *cache.Cache, expire time.Duration, handle GetCustomVaults) gin.HandlerFunc {
return func(c *gin.Context) {
if result, found := cachingStore.Get(c.Request.URL.String()); found {
c.JSON(http.StatusOK, result)
} else {
result := handle(c)
cachingStore.Set(c.Request.URL.String(), result, expire)
c.JSON(http.StatusOK, result)
}
}
}
5 changes: 5 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func NewRouter() *gin.Engine {
router.GET(`:chainID/vaults/retired`, CacheLegacyVaults(cachingStore, 10*time.Minute, c.GetLegacyRetired))
router.GET(`:chainID/vaults/some/:addresses`, c.GetLegacySomeVaults)

/******************************************************************************************
** Vaults for a custom integration
******************************************************************************************/
router.GET(`rotki/vaults`, CacheCustomVaults(cachingStore, 10*time.Minute, c.GetVaultsForRotki))

/******************************************************************************************
** Retrieve a specific vault based on the address. This is chain specific and will return
** the vault for a specific chain.
Expand Down
Loading

0 comments on commit 9e59d1f

Please sign in to comment.