Skip to content

Commit

Permalink
sanitize influx queries
Browse files Browse the repository at this point in the history
  • Loading branch information
nnn-gif committed Aug 2, 2023
1 parent d0bbba3 commit 758fb03
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/services/filtersBlockService/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/diadata-org/diadata/services/filtersBlockService
go 1.17

require (
github.com/diadata-org/diadata v1.4.297
github.com/diadata-org/diadata v1.4.317-rc-1
github.com/segmentio/kafka-go v0.4.35
github.com/sirupsen/logrus v1.8.1
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/model/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/diadata-org/diadata/pkg/dia"
"github.com/go-redis/redis"
clientInfluxdb "github.com/influxdata/influxdb1-client/v2"
"github.com/influxdata/influxql"
)

type Datastore interface {
Expand Down Expand Up @@ -312,7 +313,7 @@ func (datastore *DB) CopyInfluxMeasurements(dbOrigin string, dbDestination strin

func (datastore *DB) SetVWAPFirefly(foreignName string, value float64, timestamp time.Time) error {
tags := map[string]string{
"foreignName": foreignName,
"foreignName": influxql.QuoteString(foreignName),
}
fields := map[string]interface{}{
"value": value,
Expand Down
5 changes: 3 additions & 2 deletions pkg/model/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/diadata-org/diadata/pkg/dia"
"github.com/go-redis/redis"
clientInfluxdb "github.com/influxdata/influxdb1-client/v2"
"github.com/influxdata/influxql"
)

// SetFilter stores a filter point
Expand Down Expand Up @@ -230,8 +231,8 @@ func (datastore *DB) SaveFilterInflux(filter string, asset dia.Asset, exchange s
// Create a point and add to batch
tags := map[string]string{
"filter": filter,
"symbol": asset.Symbol,
"address": asset.Address,
"symbol": influxql.QuoteString(asset.Symbol),
"address": influxql.QuoteString(asset.Address),
"blockchain": asset.Blockchain,
"exchange": exchange,
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/model/quotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/diadata-org/diadata/pkg/utils"
"github.com/go-redis/redis"
clientInfluxdb "github.com/influxdata/influxdb1-client/v2"
"github.com/influxdata/influxql"
"github.com/jackc/pgx/v4"
)

Expand Down Expand Up @@ -77,8 +78,8 @@ func (datastore *DB) GetAssetPriceUSD(asset dia.Asset, timestamp time.Time) (pri
func (datastore *DB) AddAssetQuotationsToBatch(quotations []*AssetQuotation) error {
for _, quotation := range quotations {
tags := map[string]string{
"symbol": quotation.Asset.Symbol,
"name": quotation.Asset.Name,
"symbol": influxql.QuoteString(quotation.Asset.Symbol),
"name": influxql.QuoteString(quotation.Asset.Name),
"address": quotation.Asset.Address,
"blockchain": quotation.Asset.Blockchain,
}
Expand All @@ -99,8 +100,8 @@ func (datastore *DB) AddAssetQuotationsToBatch(quotations []*AssetQuotation) err
func (datastore *DB) SetAssetQuotation(quotation *AssetQuotation) error {
// Write to influx
tags := map[string]string{
"symbol": quotation.Asset.Symbol,
"name": quotation.Asset.Name,
"symbol": influxql.QuoteString(quotation.Asset.Symbol),
"name": influxql.QuoteString(quotation.Asset.Name),
"address": quotation.Asset.Address,
"blockchain": quotation.Asset.Blockchain,
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/model/supplies.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/diadata-org/diadata/pkg/dia/helpers"
"github.com/go-redis/redis"
clientInfluxdb "github.com/influxdata/influxdb1-client/v2"
"github.com/influxdata/influxql"
)

func getKeySupply(asset dia.Asset) string {
Expand All @@ -32,8 +33,8 @@ func (datastore *DB) SaveSupplyInflux(supply *dia.Supply) error {
"source": supply.Source,
}
tags := map[string]string{
"symbol": supply.Asset.Symbol,
"name": supply.Asset.Name,
"symbol": influxql.QuoteString(supply.Asset.Symbol),
"name": influxql.QuoteString(supply.Asset.Name),
"address": supply.Asset.Address,
"blockchain": supply.Asset.Blockchain,
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/model/synthAssets.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/diadata-org/diadata/pkg/dia"
clientInfluxdb "github.com/influxdata/influxdb1-client/v2"
"github.com/influxdata/influxql"
)

// SaveSynthSupplyInflux stores a synth supply in influx. Flushed when more than maxPoints in batch.
Expand All @@ -21,8 +22,8 @@ func (datastore *DB) SaveSynthSupplyInfluxToTable(t *dia.SynthAssetSupply, table

// Create a point and add to batch
tags := map[string]string{
"synthassetsymbol": t.Asset.Symbol,
"underlyingassetsymbol": t.AssetUnderlying.Symbol,
"synthassetsymbol": influxql.QuoteString(t.Asset.Symbol),
"underlyingassetsymbol": influxql.QuoteString(t.AssetUnderlying.Symbol),
"synthtokenaddress": t.Asset.Address,
"underlyingtokenaddress": t.AssetUnderlying.Address,
"blockchain": t.Asset.Blockchain,
Expand Down
3 changes: 2 additions & 1 deletion pkg/model/trades.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/diadata-org/diadata/pkg/dia"
clientInfluxdb "github.com/influxdata/influxdb1-client/v2"
"github.com/influxdata/influxql"
)

// SaveTradeInflux stores a trade in influx. Flushed when more than maxPoints in batch.
Expand All @@ -24,7 +25,7 @@ func (datastore *DB) SaveTradeInfluxToTable(t *dia.Trade, table string) error {

// Create a point and add to batch
tags := map[string]string{
"symbol": t.Symbol,
"symbol": influxql.QuoteString(t.Symbol),
"pair": t.Pair,
"exchange": t.Source,
"verified": strconv.FormatBool(t.VerifiedPair),
Expand Down

0 comments on commit 758fb03

Please sign in to comment.