Skip to content

Commit

Permalink
add env vars to opensea scraper.
Browse files Browse the repository at this point in the history
  • Loading branch information
jppade committed May 10, 2022
1 parent 7344164 commit 384e479
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/nftTradescrapers/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/diadata-org/diadata/cmd/nftTradescrapers
go 1.17

require (
github.com/diadata-org/diadata v1.4.1-rc-159
github.com/diadata-org/diadata v1.4.1-rc-160
github.com/jackc/pgconn v1.10.0
github.com/sirupsen/logrus v1.8.1
)
4 changes: 2 additions & 2 deletions cmd/nftTradescrapers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func handleData(tradeChannel chan dia.NFTTrade, wg *sync.WaitGroup, rdb *models.
log.Info("got trade: %s -> (%s) -> %s for %s (%.4f USD) \n", trade.FromAddress, trade.NFT.NFTClass.Name, trade.ToAddress, trade.CurrencySymbol, trade.PriceUSD)
}

// err := rdb.SetNFTTradeToTable(trade, models.NfttradeCurrTable)
err := rdb.SetNFTTradeToTable(trade, models.NfttradeSumeriaTable)
err := rdb.SetNFTTradeToTable(trade, models.NfttradeCurrTable)
// err := rdb.SetNFTTradeToTable(trade, models.NfttradeSumeriaTable)
if err != nil {
var pgErr *pgconn.PgError
if errors.As(err, &pgErr) {
Expand Down
32 changes: 26 additions & 6 deletions pkg/dia/nft/nftTrade-scrapers/opensea.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"math/big"
"net/http"
"strconv"
"strings"
"sync"
"time"
Expand All @@ -32,8 +33,6 @@ import (
const (
// we assume all of the NFTs traded on OpenSea are ERC721(1155 is an extension of it)
openSeaNFTContractType = "ERC721"

OpenSea = "OpenSeacurr"
)

type OpenSeaScraperConfig struct {
Expand Down Expand Up @@ -118,7 +117,8 @@ var (
// default values are valid for the first run which is it saves
// these configs to the DB
defOpenSeaConf = &OpenSeaScraperConfig{
ContractAddr: "0x7be8076f4ea4a4ad08075c2508e481d6c946d12b",
// ContractAddr: "0x7be8076f4ea4a4ad08075c2508e481d6c946d12b", // Wyvern V1
ContractAddr: "0x7f268357A8c2552623316e2562D90e642bB538E5", // Wyvern V2
BatchSize: 5000,
WaitPeriod: 5 * time.Second,
FollowDist: 2,
Expand All @@ -129,9 +129,16 @@ var (
MetadataTimeout: 30 * time.Second,
}

// OpenSea market contract has been deployed on the mainnet at
// block num 5774644, so scraper starts from this block
defOpenSeaState = &OpenSeaScraperState{LastBlockNum: 5774644}
// // OpenSea V1 market contract has been deployed on the mainnet at
// // block num 5774644, so scraper starts from this block
// defOpenSeaState = &OpenSeaScraperState{LastBlockNum: 5774644}

// OpenSea market V2 contract has been deployed on the mainnet at
// block num 14120913, so scraper starts from this block.
defOpenSeaState = &OpenSeaScraperState{LastBlockNum: 14120913}

// This string is the identifier of the scraper in conf and state fields in postgres.
OpenSea = ""

openSeaABI abi.ABI
erc20ABI abi.ABI
Expand All @@ -155,6 +162,17 @@ func init() {
if err != nil {
panic(err)
}

OpenSea = utils.Getenv("SCRAPER_NAME_STATE", "")

// If scraper state is not set yet, start from this block
initBlockNumString := utils.Getenv("LAST_BLOCK_NUM", "14120913")
initBlockNum, err := strconv.ParseInt(initBlockNumString, 10, 64)
if err != nil {
log.Error("parse timeFinal: ", err)
}
defOpenSeaState.LastBlockNum = uint64(initBlockNum)

}

func NewOpenSeaScraper(rdb *models.RelDB) *OpenSeaScraper {
Expand Down Expand Up @@ -183,6 +201,8 @@ func NewOpenSeaScraper(rdb *models.RelDB) *OpenSeaScraper {
return nil
}

log.Info("scraper %s starts at block: %s", OpenSea, s.state.LastBlockNum)
time.Sleep(2 * time.Minute)
go s.mainLoop()

return s
Expand Down

0 comments on commit 384e479

Please sign in to comment.