Skip to content

Commit

Permalink
add type to origin table (#116)
Browse files Browse the repository at this point in the history
* add type to origin table

* add operation vt

* fix index timestamp
  • Loading branch information
iostream1308 authored Jan 2, 2025
1 parent abfaf92 commit 8e66fce
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
49 changes: 49 additions & 0 deletions v2/cmd/migrations/00016_add_column_txorigin.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
ALTER TABLE txorigin ADD COLUMN type TEXT;
UPDATE txorigin SET type = 'cow';

INSERT INTO txorigin (address, name, type) VALUES
('0x421925abb2e3311571f18e545e37fb983318f274', 'ktt-operator-00', 'vt'),
('0xd2e018c16dc6a4ce18e7880bed5b1b3b64fc35c7', 'ktt-operator-01', 'vt'),
('0x86ee24a1effa6bdf75a311c9a3b73ca0b0ec3207', 'ktt-operator-10', 'vt'),
('0x866bdd48566d984f94c55f5ff8988208b3aa0008', 'ktt-operator-11', 'vt'),
('0x869f1a409aa364ed2d7f1a0327fe8844d547f909', 'ktt-operator-12', 'vt'),
('0x8686ca74753f976ff7ead5a692096f2cd1388c00', 'ktt-operator-02', 'vt'),
('0x8686301a430112d76fef8331821aef42c8c48686', 'ktt-operator-03', 'vt,uniswapx,pcsx'),
('0x8686e88c147fadc829bfef8e2d853e3d91ff8101', 'ktt-operator-04', 'uniswapx,pcsx'),
('0x868601d3693003cfd2f6b8ddd6945569ce5d7602', 'ktt-operator-05', '1inch-resolver'),
('0x8686b3d43415e3d4bfbf686450a2799b9249fd03', 'ktt-operator-06', '1inch-resolver'),
('0x86b1980c889ad981837a5e8b587ae82100fe8e04', 'ktt-operator-07', 'vt'),
('0x860d6604b813376645b996278464e9953f884705', 'ktt-operator-08', 'vt'),
('0x86e81996242d1dce7fc5f9b9d060bbd3410fc206', 'ktt-operator-09', 'vt');

DROP INDEX zerox_timestamp_idx;
DROP INDEX kyberswap_timestamp_idx;
DROP INDEX kyberswap_rfq_timestamp_idx;
DROP INDEX paraswap_timestamp_idx;
DROP INDEX hashflow_v3_timestamp_idx;
DROP INDEX oneinch_v6_timestamp_idx;
DROP INDEX uniswapx_timestamp_idx;
DROP INDEX bebop_timestamp_idx;
DROP INDEX zerox_v3_timestamp_idx;
DROP INDEX pancakeswap_timestamp_idx;

create index zerox_timestamp_idx
on tradelogs_zerox (timestamp DESC);
create index kyberswap_timestamp_idx
on tradelogs_kyberswap (timestamp DESC);
create index kyberswap_rfq_timestamp_idx
on tradelogs_kyberswap_rfq (timestamp DESC);
create index paraswap_timestamp_idx
on tradelogs_paraswap (timestamp DESC);
create index hashflow_v3_timestamp_idx
on tradelogs_hashflow_v3 (timestamp DESC);
create index oneinch_v6_timestamp_idx
on tradelogs_oneinch_v6 (timestamp DESC);
create index uniswapx_timestamp_idx
on tradelogs_uniswapx (timestamp DESC);
create index bebop_timestamp_idx
on tradelogs_bebop (timestamp DESC);
create index zerox_v3_timestamp_idx
on tradelogs_zerox_v3 (timestamp DESC);
create index pancakeswap_timestamp_idx
on tradelogs_pancakeswap (timestamp DESC);
7 changes: 6 additions & 1 deletion v2/internal/server/tradelogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ func (s *TradeLogs) addMakerName(c *gin.Context) {
}

func (s *TradeLogs) getTxOrigin(c *gin.Context) {
data, err := s.dashStorage.GetTxOrigin()
var queries dashboardTypes.TxOriginQuery
if err := c.ShouldBind(&queries); err != nil {
responseErr(c, http.StatusBadRequest, err)
return
}
data, err := s.dashStorage.GetTxOrigin(queries)
if err != nil {
responseErr(c, http.StatusInternalServerError, err)
return
Expand Down
18 changes: 16 additions & 2 deletions v2/pkg/storage/dashboard/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func (s *Storage) InsertTxOrigin(txOrigins []types.TxOrigin) error {
}
q, p, err := b.Suffix(`ON CONFLICT (address) DO UPDATE
SET
name=excluded.name
name=excluded.name,
type=excluded.type
`).ToSql()
if err != nil {
s.l.Errorw("Error build insert", "error", err)
Expand Down Expand Up @@ -165,10 +166,23 @@ func (s *Storage) GetMakerName() ([]types.MakerName, error) {
return makerName, nil
}

func (s *Storage) GetTxOrigin() ([]types.TxOrigin, error) {
func (s *Storage) GetTxOrigin(query types.TxOriginQuery) ([]types.TxOrigin, error) {
builder := squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar).
Select(types.TxOriginColumns()...).
From(txOriginTable)
v := reflect.ValueOf(query)
fields := v.Type()
for i := 0; i < v.NumField(); i++ {
tag := string(fields.Field(i).Tag.Get("form"))
if v.Field(i).IsZero() {
continue
}
if tag == "type" {
builder = builder.Where(squirrel.Like{tag: "%" + strings.ToLower(v.Field(i).String()) + "%"})
continue
}
builder = builder.Where(squirrel.Eq{tag: strings.ToLower(v.Field(i).String())})
}

q, p, err := builder.ToSql()
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions v2/pkg/storage/dashboard/types/tx_origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@ import "strings"
type TxOrigin struct {
Address string `db:"address" json:"address"`
Name string `db:"name" json:"name"`
Type string `db:"type" json:"type"`
}

type TxOriginQuery struct {
Type string `form:"type" json:"type,omitempty"`
Address string `form:"address" json:"address,omitempty"`
}

func (o *TxOrigin) SerializeTxOrigin() []interface{} {
return []interface{}{
strings.ToLower(o.Address),
o.Name,
o.Type,
}
}

func TxOriginColumns() []string {
return []string{
"address",
"name",
"type",
}
}

0 comments on commit 8e66fce

Please sign in to comment.