Skip to content

Commit

Permalink
add nsfw check to cft20 metaprotocol
Browse files Browse the repository at this point in the history
  • Loading branch information
tomashanacek committed Jan 31, 2024
1 parent 35d2a74 commit 6e49bf1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion indexer/src/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func New(

metaprotocols := make(map[string]metaprotocol.Processor)
metaprotocols["inscription"] = metaprotocol.NewInscriptionProcessor(config.ChainID, db, nsfwWorker)
metaprotocols["cft20"] = metaprotocol.NewCFT20Processor(config.ChainID, db)
metaprotocols["cft20"] = metaprotocol.NewCFT20Processor(config.ChainID, db, nsfwWorker)
metaprotocols["marketplace"] = metaprotocol.NewMarketplaceProcessor(config.ChainID, db)

return &Indexer{
Expand Down
11 changes: 10 additions & 1 deletion indexer/src/indexer/metaprotocol/cft20.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/donovansolms/cosmos-inscriptions/indexer/src/indexer/models"
"github.com/donovansolms/cosmos-inscriptions/indexer/src/indexer/types"
"github.com/donovansolms/cosmos-inscriptions/indexer/src/nsfw"
"github.com/kelseyhightower/envconfig"
"github.com/leodido/go-urn"
"gorm.io/gorm"
Expand All @@ -36,6 +37,7 @@ type CFT20Config struct {
type CFT20 struct {
chainID string
db *gorm.DB
nsfwWorker *nsfw.Worker
s3Endpoint string
s3Region string
s3Bucket string
Expand All @@ -55,7 +57,7 @@ type CFT20 struct {
perWalletLimitMaxValue uint64
}

func NewCFT20Processor(chainID string, db *gorm.DB) *CFT20 {
func NewCFT20Processor(chainID string, db *gorm.DB, nsfwWorker *nsfw.Worker) *CFT20 {
// Parse config environment variables for self
var config InscriptionConfig
err := envconfig.Process("", &config)
Expand All @@ -66,6 +68,7 @@ func NewCFT20Processor(chainID string, db *gorm.DB) *CFT20 {
return &CFT20{
chainID: chainID,
db: db,
nsfwWorker: nsfwWorker,
s3Endpoint: config.S3Endpoint,
s3Region: config.S3Region,
s3Bucket: config.S3Bucket,
Expand Down Expand Up @@ -182,6 +185,8 @@ func (protocol *CFT20) Process(transactionModel models.Transaction, protocolURN
// TODO: Rework the content extraction
contentPath := ""
contentLength := 0
isExplicit := false

// If this token includes content, we need to store it and add to the record
if len(rawTransaction.Body.NonCriticalExtensionOptions) == 1 {
// Logo is stored in the non_critical_extension_options
Expand Down Expand Up @@ -219,6 +224,9 @@ func (protocol *CFT20) Process(transactionModel models.Transaction, protocolURN
return fmt.Errorf("unable to store content '%s'", err)
}

// check if content is explicit
isExplicit = <-protocol.nsfwWorker.CheckImage(logoContent)

contentLength = len(logoContent)
}

Expand All @@ -239,6 +247,7 @@ func (protocol *CFT20) Process(transactionModel models.Transaction, protocolURN
ContentPath: contentPath,
ContentSizeBytes: uint64(contentLength),
DateCreated: transactionModel.DateCreated,
IsExplicit: isExplicit,
CirculatingSupply: 0,
}

Expand Down
2 changes: 1 addition & 1 deletion indexer/src/indexer/metaprotocol/inscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (protocol *Inscription) Process(transactionModel models.Transaction, protoc
}

// check if content is explicit
isExplicit := <-protocol.nsfwWorker.Add(content)
isExplicit := <-protocol.nsfwWorker.CheckImage(content)

inscriptionModel := models.Inscription{
ChainID: parsedURN.ChainID,
Expand Down
1 change: 1 addition & 0 deletions indexer/src/indexer/models/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Token struct {
Metadata datatypes.JSON `gorm:"column:metadata"`
ContentPath string `gorm:"column:content_path"`
ContentSizeBytes uint64 `gorm:"column:content_size_bytes"`
IsExplicit bool `gorm:"column:is_explicit"`
CirculatingSupply uint64 `gorm:"column:circulating_supply"`
LastPriceBase uint64 `gorm:"column:last_price_base"`
Volume24Base uint64 `gorm:"column:volume_24_base"`
Expand Down
2 changes: 1 addition & 1 deletion indexer/src/nsfw/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (w Worker) Stop() {
}()
}

func (w Worker) Add(image []byte) <-chan bool {
func (w Worker) CheckImage(image []byte) <-chan bool {
w.work <- image
return w.result
}

0 comments on commit 6e49bf1

Please sign in to comment.