-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnftdetector.go
More file actions
46 lines (35 loc) · 966 Bytes
/
nftdetector.go
File metadata and controls
46 lines (35 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package nfts
import (
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
// INFTDetector defines the interface for NFT detection
type INFTDetector interface {
IsNFTTransaction(tx *types.Transaction) bool
}
// NFTDetector implements the INFTDetector interface
type NFTDetector struct {
nftContracts sync.Map
}
func NewNFTDetector() INFTDetector {
detector := &NFTDetector{}
// Initialize known contracts
knownContracts := map[string]bool{
"0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D": true, // BAYC
"0x23581767a106ae21c074b2276D25e5C3e136a68b": true, // Moonbirds
}
for addr := range knownContracts {
detector.nftContracts.Store(common.HexToAddress(addr), true)
}
return detector
}
func (d *NFTDetector) IsNFTTransaction(tx *types.Transaction) bool {
if tx.To() == nil {
return false
}
if isContract, ok := d.nftContracts.Load(*tx.To()); ok {
return isContract.(bool)
}
return false
}