-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: test feat: cronjob sync icy tx fix: cmt fix: cmt fix: cmt
- Loading branch information
Showing
18 changed files
with
413 additions
and
0 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
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
15 changes: 15 additions & 0 deletions
15
migrations/schemas/20230513041758-create_icy_transactions_table.sql
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,15 @@ | ||
-- +migrate Up | ||
CREATE TABLE IF NOT EXISTS icy_transactions ( | ||
id uuid PRIMARY KEY DEFAULT (uuid()), | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), | ||
deleted_at TIMESTAMPTZ, | ||
vault TEXT NOT NULL, | ||
amount TEXT NOT NULL, | ||
token TEXT NOT NULL, | ||
sender_discord_id TEXT NOT NULL, | ||
recipient_address TEXT NOT NULL, | ||
recipient_discord_id TEXT NOT NULL | ||
); | ||
-- +migrate Down | ||
DROP TABLE IF EXISTS icy_transactions; |
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,7 @@ | ||
package vault | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
type IHandler interface { | ||
StoreVaultTransaction(c *gin.Context) | ||
} |
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,91 @@ | ||
package vault | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"github.com/gin-gonic/gin" | ||
|
||
"github.com/dwarvesf/fortress-api/pkg/config" | ||
"github.com/dwarvesf/fortress-api/pkg/logger" | ||
"github.com/dwarvesf/fortress-api/pkg/model" | ||
"github.com/dwarvesf/fortress-api/pkg/service" | ||
"github.com/dwarvesf/fortress-api/pkg/store" | ||
"github.com/dwarvesf/fortress-api/pkg/utils/timeutil" | ||
"github.com/dwarvesf/fortress-api/pkg/view" | ||
) | ||
|
||
type handler struct { | ||
store *store.Store | ||
service *service.Service | ||
logger logger.Logger | ||
repo store.DBRepo | ||
config *config.Config | ||
} | ||
|
||
// New returns a handler | ||
func New(store *store.Store, repo store.DBRepo, service *service.Service, logger logger.Logger, cfg *config.Config) IHandler { | ||
return &handler{ | ||
store: store, | ||
repo: repo, | ||
service: service, | ||
logger: logger, | ||
config: cfg, | ||
} | ||
} | ||
|
||
// StoreVaultTransaction godoc | ||
// @Summary Store vault tx as icy tx from Mochi service | ||
// @Description Store vault tx as icy tx from Mochi service | ||
// @Tags Vault | ||
// @Accept json | ||
// @Produce json | ||
// @Success 200 {object} view.MessageResponse | ||
// @Failure 400 {object} view.ErrorResponse | ||
// @Failure 404 {object} view.ErrorResponse | ||
// @Failure 500 {object} view.ErrorResponse | ||
// @Router /cron-jobs/store-vault-transaction [post] | ||
func (h *handler) StoreVaultTransaction(c *gin.Context) { | ||
l := h.logger.Fields(logger.Fields{ | ||
"handler": "vault", | ||
"method": "StoreVaultTransaction", | ||
}) | ||
|
||
// currently support | ||
supportedVaults := []string{"18", "19", "20"} | ||
|
||
startOfTheWeek := timeutil.FormatDateForCurl(timeutil.GetStartDayOfWeek(time.Now().Local()).Format(time.RFC3339)) | ||
endOfTheWeek := timeutil.FormatDateForCurl(timeutil.GetEndDayOfWeek(time.Now().Local()).Format(time.RFC3339)) | ||
|
||
for _, vaultId := range supportedVaults { | ||
req := &model.VaultTransactionRequest{ | ||
VaultId: vaultId, | ||
StartTime: startOfTheWeek, | ||
EndTime: endOfTheWeek, | ||
} | ||
res, err := h.service.Mochi.GetVaultTransaction(req) | ||
if err != nil { | ||
l.Error(err, "GetVaultTransaction failed") | ||
c.JSON(http.StatusInternalServerError, view.CreateResponse[any](nil, nil, err, nil, "")) | ||
return | ||
} | ||
|
||
for _, transaction := range res.Data { | ||
err := h.store.IcyTransaction.Create(h.repo.DB(), &model.IcyTransaction{ | ||
Vault: transaction.VaultName, | ||
Amount: transaction.Amount, | ||
Token: transaction.Token, | ||
SenderDiscordId: transaction.Sender, | ||
RecipientAddress: transaction.ToAddress, | ||
RecipientDiscordId: transaction.Target, | ||
}) | ||
if err != nil { | ||
l.Error(err, "Create IcyTransaction failed") | ||
c.JSON(http.StatusInternalServerError, view.CreateResponse[any](nil, nil, err, nil, "")) | ||
return | ||
} | ||
} | ||
} | ||
|
||
c.JSON(http.StatusOK, view.CreateResponse[any](nil, nil, nil, nil, "ok")) | ||
} |
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,11 @@ | ||
package model | ||
|
||
type IcyTransaction struct { | ||
BaseModel | ||
Vault string `json:"vault"` | ||
Amount string `json:"amount"` | ||
Token string `json:"token"` | ||
SenderDiscordId string `json:"sender_discord_id"` | ||
RecipientAddress string `json:"recipient_address"` | ||
RecipientDiscordId string `json:"recipient_discord_id"` | ||
} |
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,28 @@ | ||
package model | ||
|
||
type VaultTransactionRequest struct { | ||
VaultId string `json:"vault_id"` | ||
StartTime string `json:"start_time"` | ||
EndTime string `json:"end_time"` | ||
} | ||
|
||
type VaultTransactionResponse struct { | ||
Data []VaultTransaction `json:"data"` | ||
} | ||
|
||
type VaultTransaction struct { | ||
Id int64 `json:"id"` | ||
GuildId string `json:"guild_id"` | ||
VaultId int64 `json:"vault_id"` | ||
VaultName string `json:"vault_name"` | ||
Action string `json:"action"` | ||
FromAddress string `json:"from_address"` | ||
ToAddress string `json:"to_address"` | ||
Target string `json:"target"` | ||
Sender string `json:"sender"` | ||
Amount string `json:"amount"` | ||
Token string `json:"token"` | ||
Threshold string `json:"threshold"` | ||
CreatedAt string `json:"created_at"` | ||
UpdatedAt string `json:"updated_at"` | ||
} |
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.