Skip to content

Commit

Permalink
comments and nits
Browse files Browse the repository at this point in the history
  • Loading branch information
golangisfun123 committed Apr 30, 2024
1 parent 0b7b3e9 commit 8b8297a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 14 deletions.
6 changes: 3 additions & 3 deletions contrib/screener-api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c clientImpl) ScreenAddress(ctx context.Context, ruleset, address string)

type BlackListBody struct {

Check failure on line 68 in contrib/screener-api/client/client.go

View workflow job for this annotation

GitHub Actions / Lint (contrib/screener-api)

exported type `BlackListBody` should have comment or be unexported (golint)
TypeReq string `json:"typereq"`
Id string `json:"id"`
ID string `json:"id"`
Data string `json:"data"`
Address string `json:"address"`
Network string `json:"network"`
Expand All @@ -88,9 +88,9 @@ func (c clientImpl) BlacklistAddress(ctx context.Context, body BlackListBody) (s
appsecret := "appsecret"
appid := "appid"

nonce := strings.Replace(uuid.New().String(), "-", "", -1)[:32]
nonce := strings.ReplaceAll(uuid.New().String(), "-", "")[:32]
timestamp := fmt.Sprintf("%d", time.Now().Unix())
queryString := "" // there is no query string in this post request, ask about this
queryString := ""

signature := GenerateSignature(appsecret, appid, timestamp, nonce, queryString, body)

Expand Down
6 changes: 4 additions & 2 deletions contrib/screener-api/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import (
"github.com/synapsecns/sanguine/contrib/screener-api/trmlabs"
)

// TODO: make a general db interface.
// BlacklistedAddressWriterDB provides methods to write blacklisted addresses to the database.
type BlacklistedAddressWriterDB interface {
PutBlacklistedAddress(ctx context.Context, body BlacklistedAddress) error
DeleteBlacklistedAddress(ctx context.Context, id string) error
UpdateBlacklistedAddress(ctx context.Context, id string, body BlacklistedAddress) error
}

// BlacklistedAddressReaderDB provides methods to read blacklisted addresses from the database.
type BlacklistedAddressReaderDB interface {
GetBlacklistedAddress(ctx context.Context, address string) (*BlacklistedAddress, error)
}

// BlacklistedAddressDB is the interface for reading and writing blacklisted addresses to the database.
type BlacklistedAddressDB interface {
BlacklistedAddressWriterDB
BlacklistedAddressReaderDB
Expand All @@ -41,7 +43,7 @@ type RuleDB interface {
RuleReaderDB
}

// DB is the general database interface for the screener-api
// DB is the general database interface for the screener-api.
type DB interface {
BlacklistedAddressDB
RuleDB
Expand Down
6 changes: 3 additions & 3 deletions contrib/screener-api/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (d *DBSuite) TestBlacklist() {

blacklistBody := db.BlacklistedAddress{
TypeReq: "create",
Id: "testId",
ID: "testId",
Address: testAddress,
Network: "bitcoin",
Tag: "testTag",
Expand All @@ -91,7 +91,7 @@ func (d *DBSuite) TestBlacklist() {
// update the address
blacklistBody.TypeReq = "update"
blacklistBody.Remark = "testRemarkUpdated"
err = testDB.UpdateBlacklistedAddress(d.GetTestContext(), blacklistBody.Id, blacklistBody)
err = testDB.UpdateBlacklistedAddress(d.GetTestContext(), blacklistBody.ID, blacklistBody)
d.Require().NoError(err)

// check to make sure it updated
Expand All @@ -106,7 +106,7 @@ func (d *DBSuite) TestBlacklist() {
d.Require().Nil(res)

// delete it
err = testDB.DeleteBlacklistedAddress(d.GetTestContext(), blacklistBody.Id)
err = testDB.DeleteBlacklistedAddress(d.GetTestContext(), blacklistBody.ID)
d.Require().NoError(err)

// delete nonexistent
Expand Down
5 changes: 4 additions & 1 deletion contrib/screener-api/db/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,20 @@ type BlacklistedAddress struct {
UpdatedAt time.Time

TypeReq string `gorm:"column:typereq"`
Id string `gorm:"column:id;primary_key"`
ID string `gorm:"column:id;primary_key"`
Data string `gorm:"column:data"`
Address string `gorm:"column:address"`
Network string `gorm:"column:network"`
Tag string `gorm:"column:tag"`
Remark string `gorm:"column:remark"`
}

// GormDataType returns the data type for the column.
func (b BlacklistedAddress) GormDataType() string {
return "json"

Check warning on line 34 in contrib/screener-api/db/models.go

View check run for this annotation

Codecov / codecov/patch

contrib/screener-api/db/models.go#L33-L34

Added lines #L33 - L34 were not covered by tests
}

// Value prepares the struct for database storage.
func (b BlacklistedAddress) Value() (driver.Value, error) {
if b == (BlacklistedAddress{}) {
return nil, nil
Expand All @@ -41,6 +43,7 @@ func (b BlacklistedAddress) Value() (driver.Value, error) {
return string(ba), err

Check warning on line 43 in contrib/screener-api/db/models.go

View check run for this annotation

Codecov / codecov/patch

contrib/screener-api/db/models.go#L38-L43

Added lines #L38 - L43 were not covered by tests
}

// Scan scans the struct from the database.
func (b *BlacklistedAddress) Scan(val interface{}) error {
if val == nil {
*b = BlacklistedAddress{}
Expand Down
2 changes: 1 addition & 1 deletion contrib/screener-api/db/sql/base/namer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func init() {
indicatorName = namer.GetConsistentName("Indicators")

typeReqName = namer.GetConsistentName("TypeReq")
idName = namer.GetConsistentName("Id")
idName = namer.GetConsistentName("ID")
dataName = namer.GetConsistentName("Data")
networkName = namer.GetConsistentName("Network")
tagName = namer.GetConsistentName("Tag")
Expand Down
4 changes: 2 additions & 2 deletions contrib/screener-api/screener/screener.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (s *screenerImpl) blacklistAddress(c *gin.Context) {

blacklistedAddress := db.BlacklistedAddress{
TypeReq: blacklistBody.TypeReq,
Id: blacklistBody.Id,
ID: blacklistBody.ID,
Data: blacklistBody.Data,
Network: blacklistBody.Network,
Tag: blacklistBody.Tag,
Expand All @@ -153,7 +153,7 @@ func (s *screenerImpl) blacklistAddress(c *gin.Context) {
return

case "update":
if err := s.db.UpdateBlacklistedAddress(c, blacklistedAddress.Id, blacklistedAddress); err != nil {
if err := s.db.UpdateBlacklistedAddress(c, blacklistedAddress.ID, blacklistedAddress); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

Check warning on line 159 in contrib/screener-api/screener/screener.go

View check run for this annotation

Codecov / codecov/patch

contrib/screener-api/screener/screener.go#L157-L159

Added lines #L157 - L159 were not covered by tests
Expand Down
4 changes: 2 additions & 2 deletions contrib/screener-api/screener/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (s *ScreenerSuite) TestScreener() {
// now test crud screener
blacklistBody := client.BlackListBody{
TypeReq: "create",
Id: "1",
ID: "1",
Data: "{\"test\":\"data\"}",
Address: "0x123",
Network: "eth",
Expand All @@ -177,7 +177,7 @@ func (s *ScreenerSuite) TestScreener() {

// delete the address on the blacklist
blacklistBody.TypeReq = "delete"
blacklistBody.Id = "1"
blacklistBody.ID = "1"

status, err = apiClient.BlacklistAddress(s.GetTestContext(), blacklistBody)
Equal(s.T(), "success", status)
Expand Down

0 comments on commit 8b8297a

Please sign in to comment.