Skip to content

Commit 08d90d6

Browse files
committed
add nsfw check to cft20 metaprotocol
1 parent fbc52e7 commit 08d90d6

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

indexer/src/indexer/indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func New(
7878

7979
metaprotocols := make(map[string]metaprotocol.Processor)
8080
metaprotocols["inscription"] = metaprotocol.NewInscriptionProcessor(config.ChainID, db, nsfwWorker)
81-
metaprotocols["cft20"] = metaprotocol.NewCFT20Processor(config.ChainID, db)
81+
metaprotocols["cft20"] = metaprotocol.NewCFT20Processor(config.ChainID, db, nsfwWorker)
8282
metaprotocols["marketplace"] = metaprotocol.NewMarketplaceProcessor(config.ChainID, db)
8383

8484
return &Indexer{

indexer/src/indexer/metaprotocol/cft20.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/aws/aws-sdk-go/service/s3/s3manager"
2020
"github.com/donovansolms/cosmos-inscriptions/indexer/src/indexer/models"
2121
"github.com/donovansolms/cosmos-inscriptions/indexer/src/indexer/types"
22+
"github.com/donovansolms/cosmos-inscriptions/indexer/src/nsfw"
2223
"github.com/kelseyhightower/envconfig"
2324
"github.com/leodido/go-urn"
2425
"gorm.io/gorm"
@@ -36,6 +37,7 @@ type CFT20Config struct {
3637
type CFT20 struct {
3738
chainID string
3839
db *gorm.DB
40+
nsfwWorker *nsfw.Worker
3941
s3Endpoint string
4042
s3Region string
4143
s3Bucket string
@@ -55,7 +57,7 @@ type CFT20 struct {
5557
perWalletLimitMaxValue uint64
5658
}
5759

58-
func NewCFT20Processor(chainID string, db *gorm.DB) *CFT20 {
60+
func NewCFT20Processor(chainID string, db *gorm.DB, nsfwWorker *nsfw.Worker) *CFT20 {
5961
// Parse config environment variables for self
6062
var config InscriptionConfig
6163
err := envconfig.Process("", &config)
@@ -66,6 +68,7 @@ func NewCFT20Processor(chainID string, db *gorm.DB) *CFT20 {
6668
return &CFT20{
6769
chainID: chainID,
6870
db: db,
71+
nsfwWorker: nsfwWorker,
6972
s3Endpoint: config.S3Endpoint,
7073
s3Region: config.S3Region,
7174
s3Bucket: config.S3Bucket,
@@ -182,6 +185,8 @@ func (protocol *CFT20) Process(transactionModel models.Transaction, protocolURN
182185
// TODO: Rework the content extraction
183186
contentPath := ""
184187
contentLength := 0
188+
isExplicit := false
189+
185190
// If this token includes content, we need to store it and add to the record
186191
if len(rawTransaction.Body.NonCriticalExtensionOptions) == 1 {
187192
// Logo is stored in the non_critical_extension_options
@@ -219,6 +224,9 @@ func (protocol *CFT20) Process(transactionModel models.Transaction, protocolURN
219224
return fmt.Errorf("unable to store content '%s'", err)
220225
}
221226

227+
// check if content is explicit
228+
isExplicit = <-protocol.nsfwWorker.CheckImage(logoContent)
229+
222230
contentLength = len(logoContent)
223231
}
224232

@@ -239,6 +247,7 @@ func (protocol *CFT20) Process(transactionModel models.Transaction, protocolURN
239247
ContentPath: contentPath,
240248
ContentSizeBytes: uint64(contentLength),
241249
DateCreated: transactionModel.DateCreated,
250+
IsExplicit: isExplicit,
242251
CirculatingSupply: 0,
243252
}
244253

indexer/src/indexer/metaprotocol/inscription.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (protocol *Inscription) Process(transactionModel models.Transaction, protoc
147147
}
148148

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

152152
inscriptionModel := models.Inscription{
153153
ChainID: parsedURN.ChainID,

indexer/src/indexer/models/token.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Token struct {
2424
Metadata datatypes.JSON `gorm:"column:metadata"`
2525
ContentPath string `gorm:"column:content_path"`
2626
ContentSizeBytes uint64 `gorm:"column:content_size_bytes"`
27+
IsExplicit bool `gorm:"column:is_explicit"`
2728
CirculatingSupply uint64 `gorm:"column:circulating_supply"`
2829
LastPriceBase uint64 `gorm:"column:last_price_base"`
2930
Volume24Base uint64 `gorm:"column:volume_24_base"`

indexer/src/nsfw/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (w Worker) Stop() {
6969
}()
7070
}
7171

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

0 commit comments

Comments
 (0)