diff --git a/contrib/screener-api/client/client.go b/contrib/screener-api/client/client.go index 47fba106bd..95f3608e9e 100644 --- a/contrib/screener-api/client/client.go +++ b/contrib/screener-api/client/client.go @@ -67,7 +67,7 @@ func (c clientImpl) ScreenAddress(ctx context.Context, ruleset, address string) type BlackListBody struct { TypeReq string `json:"typereq"` - Id string `json:"id"` + ID string `json:"id"` Data string `json:"data"` Address string `json:"address"` Network string `json:"network"` @@ -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) diff --git a/contrib/screener-api/db/db.go b/contrib/screener-api/db/db.go index 1b03f965ac..f7bc78d33a 100644 --- a/contrib/screener-api/db/db.go +++ b/contrib/screener-api/db/db.go @@ -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 @@ -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 diff --git a/contrib/screener-api/db/db_test.go b/contrib/screener-api/db/db_test.go index df2909aedd..68aa96b660 100644 --- a/contrib/screener-api/db/db_test.go +++ b/contrib/screener-api/db/db_test.go @@ -74,7 +74,7 @@ func (d *DBSuite) TestBlacklist() { blacklistBody := db.BlacklistedAddress{ TypeReq: "create", - Id: "testId", + ID: "testId", Address: testAddress, Network: "bitcoin", Tag: "testTag", @@ -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 @@ -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 diff --git a/contrib/screener-api/db/models.go b/contrib/screener-api/db/models.go index f91a8aee71..7458f47cea 100644 --- a/contrib/screener-api/db/models.go +++ b/contrib/screener-api/db/models.go @@ -21,7 +21,7 @@ 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"` @@ -29,10 +29,12 @@ type BlacklistedAddress struct { Remark string `gorm:"column:remark"` } +// GormDataType returns the data type for the column. func (b BlacklistedAddress) GormDataType() string { return "json" } +// Value prepares the struct for database storage. func (b BlacklistedAddress) Value() (driver.Value, error) { if b == (BlacklistedAddress{}) { return nil, nil @@ -41,6 +43,7 @@ func (b BlacklistedAddress) Value() (driver.Value, error) { return string(ba), err } +// Scan scans the struct from the database. func (b *BlacklistedAddress) Scan(val interface{}) error { if val == nil { *b = BlacklistedAddress{} diff --git a/contrib/screener-api/db/sql/base/namer.go b/contrib/screener-api/db/sql/base/namer.go index a8a4366c44..c69ba15a00 100644 --- a/contrib/screener-api/db/sql/base/namer.go +++ b/contrib/screener-api/db/sql/base/namer.go @@ -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") diff --git a/contrib/screener-api/screener/screener.go b/contrib/screener-api/screener/screener.go index 1391abf631..cac32e551c 100644 --- a/contrib/screener-api/screener/screener.go +++ b/contrib/screener-api/screener/screener.go @@ -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, @@ -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 } diff --git a/contrib/screener-api/screener/suite_test.go b/contrib/screener-api/screener/suite_test.go index 717724c1e1..376572d96c 100644 --- a/contrib/screener-api/screener/suite_test.go +++ b/contrib/screener-api/screener/suite_test.go @@ -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", @@ -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)