feat: add opensea api key (#2528)
This commit is contained in:
parent
6cfe0f1369
commit
66d511e33f
|
@ -110,7 +110,7 @@ func (b *StatusNode) initServices(config *params.NodeConfig) error {
|
|||
}
|
||||
|
||||
if config.WalletConfig.Enabled {
|
||||
walletService := b.walletService(accountsFeed)
|
||||
walletService := b.walletService(accountsFeed, config.WalletConfig.OpenseaAPIKey)
|
||||
services = append(services, walletService)
|
||||
}
|
||||
|
||||
|
@ -406,9 +406,9 @@ func (b *StatusNode) appmetricsService() common.StatusService {
|
|||
return b.appMetricsSrvc
|
||||
}
|
||||
|
||||
func (b *StatusNode) walletService(accountsFeed *event.Feed) common.StatusService {
|
||||
func (b *StatusNode) walletService(accountsFeed *event.Feed, openseaAPIKey string) common.StatusService {
|
||||
if b.walletSrvc == nil {
|
||||
b.walletSrvc = wallet.NewService(b.appDB, b.rpcClient, accountsFeed)
|
||||
b.walletSrvc = wallet.NewService(b.appDB, b.rpcClient, accountsFeed, openseaAPIKey)
|
||||
}
|
||||
return b.walletSrvc
|
||||
}
|
||||
|
|
|
@ -504,6 +504,7 @@ type Network struct {
|
|||
// WalletConfig extra configuration for wallet.Service.
|
||||
type WalletConfig struct {
|
||||
Enabled bool
|
||||
OpenseaAPIKey string `json:"OpenseaAPIKey"`
|
||||
}
|
||||
|
||||
// LocalNotificationsConfig extra configuration for localnotifications.Service.
|
||||
|
|
|
@ -229,7 +229,7 @@ func (api *API) GetCryptoOnRamps(ctx context.Context) ([]CryptoOnRamp, error) {
|
|||
|
||||
func (api *API) GetOpenseaCollectionsByOwner(ctx context.Context, chainID uint64, owner common.Address) ([]OpenseaCollection, error) {
|
||||
log.Debug("call to get opensea collections")
|
||||
client, err := newOpenseaClient(chainID)
|
||||
client, err := newOpenseaClient(chainID, api.s.openseaAPIKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ func (api *API) GetOpenseaCollectionsByOwner(ctx context.Context, chainID uint64
|
|||
|
||||
func (api *API) GetOpenseaAssetsByOwnerAndCollection(ctx context.Context, chainID uint64, owner common.Address, collectionSlug string, limit int) ([]OpenseaAsset, error) {
|
||||
log.Debug("call to get opensea assets")
|
||||
client, err := newOpenseaClient(chainID)
|
||||
client, err := newOpenseaClient(chainID, api.s.openseaAPIKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -109,15 +109,16 @@ type OpenseaCollection struct {
|
|||
type OpenseaClient struct {
|
||||
client *http.Client
|
||||
url string
|
||||
apiKey string
|
||||
}
|
||||
|
||||
// new opensea client.
|
||||
func newOpenseaClient(chainID uint64) (*OpenseaClient, error) {
|
||||
func newOpenseaClient(chainID uint64, apiKey string) (*OpenseaClient, error) {
|
||||
client := &http.Client{
|
||||
Timeout: time.Second * 5,
|
||||
}
|
||||
if url, ok := BaseURLs[chainID]; ok {
|
||||
return &OpenseaClient{client: client, url: url}, nil
|
||||
return &OpenseaClient{client: client, url: url, apiKey: apiKey}, nil
|
||||
}
|
||||
|
||||
return nil, errors.New("ChainID not supported")
|
||||
|
@ -184,6 +185,7 @@ func (o *OpenseaClient) doOpenseaRequest(url string) ([]byte, error) {
|
|||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:96.0) Gecko/20100101 Firefox/96.0")
|
||||
req.Header.Set("X-API-KEY", o.apiKey)
|
||||
|
||||
resp, err := o.client.Do(req)
|
||||
if err != nil {
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
// NewService initializes service instance.
|
||||
func NewService(db *sql.DB, rpcClient *rpc.Client, accountFeed *event.Feed) *Service {
|
||||
func NewService(db *sql.DB, rpcClient *rpc.Client, accountFeed *event.Feed, openseaAPIKey string) *Service {
|
||||
cryptoOnRampManager := NewCryptoOnRampManager(&CryptoOnRampOptions{
|
||||
dataSourceType: DataSourceStatic,
|
||||
})
|
||||
|
@ -31,6 +31,7 @@ func NewService(db *sql.DB, rpcClient *rpc.Client, accountFeed *event.Feed) *Ser
|
|||
transactionManager: transactionManager,
|
||||
transferController: transferController,
|
||||
cryptoOnRampManager: cryptoOnRampManager,
|
||||
openseaAPIKey: openseaAPIKey,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +45,7 @@ type Service struct {
|
|||
cryptoOnRampManager *CryptoOnRampManager
|
||||
transferController *transfer.Controller
|
||||
started bool
|
||||
openseaAPIKey string
|
||||
}
|
||||
|
||||
// Start signals transmitter.
|
||||
|
|
Loading…
Reference in New Issue